Nouveau systeme de configuration des bornes
Les "anciennes" ne seront donc plus mises a jour... darcs-hash:20041231152041-d1718-d44fa18330d720707a108a78c60b8fffc0644b9c.gz
This commit is contained in:
parent
c2c1757288
commit
607b1c44d9
2 changed files with 33 additions and 326 deletions
|
@ -4,7 +4,7 @@
|
|||
import time, commands
|
||||
from gen_confs import gen_config, ERREUR, OK, anim
|
||||
|
||||
import sys
|
||||
import sys, os
|
||||
sys.path.append('/usr/scripts/gestion')
|
||||
from ldap_crans import crans_ldap
|
||||
|
||||
|
@ -142,7 +142,8 @@ Netmask= 0.0.0.0
|
|||
clients += "echo %(HOST)s %(IP)s %(MAC)s\n" % data
|
||||
|
||||
# Dans les clients, on rajoute les bornes
|
||||
for machine in self.db.search('host=*.wifi.crans.org&ipsec!=*')['machine'] :
|
||||
bornes = self.db.search('host=*.wifi.crans.org&ipsec!=*')['machine']
|
||||
for machine in bornes:
|
||||
self.anim.cycle()
|
||||
data = { 'HOST' : machine.nom().split('.')[0] ,
|
||||
'IP' : machine.ip() ,
|
||||
|
@ -167,318 +168,15 @@ Netmask= 0.0.0.0
|
|||
fd.write("\n}\n")
|
||||
fd.close()
|
||||
|
||||
|
||||
class bornes_wifi(gen_config) :
|
||||
""" Reconfiguration bornes wifi
|
||||
Si noms de borne fourni à l'initialisation restart uniquement celle-ci
|
||||
"""
|
||||
|
||||
clef = '/usr/scripts/gestion/clef-wifi' # Fichier clef ssh
|
||||
|
||||
# Fichier
|
||||
AUTOEXEC = '/etc/wifi/ftp/autoexec.sh'
|
||||
GET_CONFIG='/etc/wifi/wifi-update/shared/config/get_config'
|
||||
WIFI_UPDATE='/etc/wifi/wifi-update'
|
||||
GET_CONFIG='%s/shared/config/get_config' % WIFI_UPDATE
|
||||
|
||||
autoexec = u"""#! /bin/sh
|
||||
#***********************************************************
|
||||
# Ce fichier est généré dans wifi.py
|
||||
# Les données proviennent de la base LDAP et de la conf
|
||||
# présente au début du script.
|
||||
#
|
||||
# Génération : %(date)s
|
||||
# Fichier : %(AUTOEXEC)s
|
||||
#
|
||||
# NE PAS EDITER
|
||||
#
|
||||
#***********************************************************
|
||||
|
||||
## On configure la nvram de la borne selon son adresse MAC (celle inscrite sur la borne)
|
||||
cat <<EOF | grep -i $(nvram get et0macaddr) > /tmp/params
|
||||
%(BORNES)s
|
||||
EOF
|
||||
(
|
||||
|
||||
NECTARIS=138.231.148.1
|
||||
|
||||
echo -n "Mise en place de syslog..."
|
||||
|
||||
killall syslogd 2> /dev/null
|
||||
killall klogd 2> /dev/null
|
||||
/sbin/syslogd -R $NECTARIS
|
||||
/sbin/klogd
|
||||
|
||||
echo " ok"
|
||||
|
||||
read mac ip canal puissance nom < /tmp/params
|
||||
echo "Mac : $mac"
|
||||
echo "IP : $ip"
|
||||
echo "Canal : $canal"
|
||||
echo "Puiss : $puissance mW"
|
||||
echo "Nom : $nom"
|
||||
|
||||
if [ "$mac" = "" ]; then
|
||||
echo "Borne inconnue"
|
||||
ping -c 1 138.231.148.1
|
||||
sleep 120
|
||||
reboot
|
||||
fi
|
||||
|
||||
change=0
|
||||
|
||||
echo -n IP...
|
||||
if [ "$(nvram get lan_ipaddr)" != "$ip" ]; then
|
||||
nvram set lan_ipaddr=$ip
|
||||
change=1
|
||||
fi
|
||||
echo " ok"
|
||||
|
||||
echo -n Canal...
|
||||
if [ "$(nvram get wl_channel)" != "$canal" ]; then
|
||||
nvram set wl_channel=$canal
|
||||
change=1
|
||||
fi
|
||||
echo " ok"
|
||||
|
||||
echo -n Puissance...
|
||||
if [ "$(nvram get txpwr)" != "$puissance" ]; then
|
||||
nvram set txpwr=$puissance
|
||||
change=1
|
||||
fi
|
||||
echo " ok"
|
||||
|
||||
echo -n Nom...
|
||||
if [ "$(nvram get wan_hostname)" != "$nom" ]; then
|
||||
nvram set wan_hostname=$nom
|
||||
change=1
|
||||
fi
|
||||
echo " ok"
|
||||
|
||||
echo -n Désactivation de cron...
|
||||
if [ "$(nvram get cron_enable)" != "0" ]; then
|
||||
nvram set cron_enable=0
|
||||
change=1
|
||||
fi
|
||||
echo " ok"
|
||||
|
||||
echo -n Désactivation de boot wait...
|
||||
if [ "$(nvram get boot_wait)" = "on" ]; then
|
||||
nvram set boot_wait=off
|
||||
if [ $change -eq 0 ]; then
|
||||
# Sinon, on rebootera par la suite
|
||||
nvram commit
|
||||
fi
|
||||
fi
|
||||
echo " ok"
|
||||
|
||||
echo -n Commit des changements...
|
||||
if [ $change -eq 1 ]; then
|
||||
nvram commit
|
||||
sleep 1
|
||||
# On se casse pas la tete
|
||||
reboot
|
||||
fi
|
||||
echo " ok"
|
||||
|
||||
# On place un prompt pour la machine
|
||||
cd /tmp
|
||||
|
||||
ln -s . root
|
||||
cat <<EOF > .profile
|
||||
export PS1="$nom ($ip) # "
|
||||
echo "
|
||||
----------------------------------
|
||||
|
||||
WIFI @ CRANS
|
||||
|
||||
Nom: $nom
|
||||
IP: $ip
|
||||
Puissance: $puissance
|
||||
Canal: $canal
|
||||
|
||||
---------------------------------"
|
||||
EOF
|
||||
|
||||
# Réglage spécial Install Party
|
||||
# vlan0 = switch 4 ports
|
||||
# vlan1 = prise internet
|
||||
# eth1 = wireless
|
||||
# eth0 = switch + internet ? ou tous ? = ne pas utiliser
|
||||
|
||||
# La reconfiguration des services se fait avec les script :
|
||||
# /usr/scripts/install-party/configure_borne
|
||||
|
||||
#if [ "$nom" = "var" ]; then
|
||||
# # Reconfiguration des interfaces réseaux
|
||||
# ifconfig br0 down
|
||||
# brctl delbr br0
|
||||
# ifconfig vlan0 138.231.136.254 netmask 255.255.255.0
|
||||
# ifconfig vlan1 192.168.0.1 netmask 255.255.255.0
|
||||
# ifconfig eth1 down
|
||||
# exit 0
|
||||
#fi
|
||||
|
||||
echo -n Démarrage du firewall...
|
||||
## Firewall
|
||||
|
||||
DHCP=138.231.148.253
|
||||
WEB=138.231.136.6
|
||||
FTP=138.231.136.10
|
||||
WIFI=138.231.148.0/22
|
||||
flt="iptables -A FORWARD -i br0"
|
||||
|
||||
iptables -F FORWARD
|
||||
|
||||
$flt --destination 224.0.0.0/4 -j DROP
|
||||
$flt -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||
|
||||
# DHCP
|
||||
$flt -p udp --sport bootpc --dport bootps --source 0.0.0.0 --destination 255.255.255.255 -j ACCEPT
|
||||
$flt -p udp --sport bootpc --dport bootps --source 0.0.0.0 --destination $DHCP -j ACCEPT
|
||||
$flt -p udp --sport bootpc --dport bootps --source $WIFI --destination 255.255.255.255 -j ACCEPT
|
||||
$flt -p udp --sport bootps --dport bootpc --source $DHCP --destination $WIFI -j ACCEPT
|
||||
$flt -p udp --sport bootps --dport bootpc --source $DHCP --destination 255.255.255.255 -j ACCEPT
|
||||
# Pour compter ce qui ne passe pas (et penser un jour à utiliser tcpdump pour voir ce que c'est)
|
||||
#$flt -p udp --sport bootpc --dport bootps -j LOG # Devrait être 0
|
||||
#$flt -p udp --sport bootps --dport bootpc -j LOG # Devrait être 0
|
||||
#$flt -p udp --sport bootpc --dport bootps -j ACCEPT # Devrait être 0
|
||||
#$flt -p udp --sport bootps --dport bootpc -j ACCEPT # Devrait être 0
|
||||
|
||||
# ISAKMP
|
||||
$flt -p udp --source $WIFI --destination $NECTARIS --dport 500 --sport 500 -j ACCEPT
|
||||
#$flt -p udp --destination $WIFI --source $NECTARIS --dport 500 --sport 500 -j LOG # Doit être 0
|
||||
#$flt -p udp --destination $WIFI --source $NECTARIS --dport 500 --sport 500 -j ACCEPT # Doit être 0
|
||||
|
||||
# DNS + Web vers Zamok + FTP sila
|
||||
$flt -p udp --source $WIFI --destination $NECTARIS --dport 53 --sport 1024: -j ACCEPT
|
||||
$flt -p tcp --source $WIFI --destination $WEB --syn --dport 443 --sport 1024: -j ACCEPT
|
||||
$flt -p tcp --source $WIFI --destination $WEB --syn --dport 80 --sport 1024: -j ACCEPT
|
||||
$flt -p tcp --source $WIFI --destination $FTP --syn --dport 21 --sport 1024: -j ACCEPT
|
||||
|
||||
# ESP
|
||||
$flt -p ESP --source $WIFI --destination $NECTARIS -j ACCEPT # A 0, mais a priori, rien n'empêche d'utiliser cette ligne
|
||||
$flt -p ESP --destination $WIFI --source $NECTARIS -j ACCEPT
|
||||
|
||||
iptables -P FORWARD DROP
|
||||
|
||||
# TODO : un jour utiliser traffic control (tc) pour éviter que les gros
|
||||
# téléchargements pourrissent la bande passante des autres pour
|
||||
# une borne donnée
|
||||
|
||||
echo " ok"
|
||||
|
||||
echo -n "Mise en place du resolv.conf..."
|
||||
|
||||
cat > /tmp/myresolv.conf <<EOF
|
||||
search wifi.crans.org crans.org
|
||||
nameserver $NECTARIS
|
||||
EOF
|
||||
|
||||
cp /tmp/myresolv.conf /tmp/resolv.conf
|
||||
|
||||
echo " ok"
|
||||
|
||||
echo -n "Mise à l'heure..."
|
||||
|
||||
ntpclient -h $NECTARIS -s
|
||||
date
|
||||
|
||||
echo " ok"
|
||||
|
||||
echo -n "Mise en place de cron..."
|
||||
|
||||
killall cron 2> /dev/null
|
||||
|
||||
mkdir /tmp/cron.d 2> /dev/null
|
||||
mkdir /var/spool 2> /dev/null
|
||||
mkdir /var/spool/cron 2> /dev/null
|
||||
chmod 700 /tmp/cron.d /var/spool /var/spool/cron
|
||||
|
||||
cat > /tmp/cron.updatedns <<EOF
|
||||
#! /bin/sh
|
||||
if ! cmp /tmp/myresolv.conf /tmp/resolv.conf; then
|
||||
cp /tmp/myresolv.conf /tmp/resolv.conf
|
||||
rm /etc/cron.d/dns
|
||||
sleep 61 # Sinon, il devient fou
|
||||
fi
|
||||
exit 0
|
||||
EOF
|
||||
chmod +x /tmp/cron.updatedns
|
||||
|
||||
cat > /tmp/cron.ping <<EOF
|
||||
#! /bin/sh
|
||||
/usr/sbin/wl assoclist | grep -c '^assoc' | logger -p local3.info -t "Clients"
|
||||
ping -c 1 $NECTARIS 2> /dev/null
|
||||
sleep 61 # Idem
|
||||
exit 0
|
||||
EOF
|
||||
chmod +x /tmp/cron.ping
|
||||
|
||||
cat > /tmp/cron.uptime <<EOF
|
||||
#! /bin/sh
|
||||
uptime | logger -p local3.info -t "Uptime"
|
||||
sleep 61 # idem
|
||||
exit 0
|
||||
EOF
|
||||
chmod +x /tmp/cron.uptime
|
||||
|
||||
# klogd semble tomber en panne regulierement...
|
||||
# Ou alors, c'est syslog ?
|
||||
cat > /tmp/cron.klogd <<EOF
|
||||
#! /bin/sh
|
||||
killall klogd
|
||||
killall syslogd
|
||||
/sbin/syslogd -R $NECTARIS
|
||||
/sbin/klogd
|
||||
sleep 61 # Idem
|
||||
exit 0
|
||||
EOF
|
||||
chmod +x /tmp/cron.klogd
|
||||
|
||||
# Certaines bornes gardent les associations de ceux qui ne sont plus la
|
||||
cat > /tmp/cron.disassoc <<EOF
|
||||
#! /bin/sh
|
||||
/usr/sbin/wl gmode 0
|
||||
sleep 1
|
||||
/usr/sbin/wl gmode 1
|
||||
exit 0
|
||||
EOF
|
||||
chmod +x /tmp/cron.disassoc
|
||||
|
||||
# Remet en place le plus rapidement possible le resolv.conf (écrasé par la suite du démarrage)
|
||||
cat > /etc/cron.d/dns <<EOF
|
||||
*/2 * * * * root /tmp/cron.updatedns
|
||||
EOF
|
||||
|
||||
# Relance certains services à intervalles réguliers
|
||||
cat > /etc/cron.d/services <<EOF
|
||||
12 * * * * root /tmp/cron.klogd
|
||||
EOF
|
||||
|
||||
# Pingue toutes les 5 minutes egon, cela peut servir un jour...
|
||||
cat > /etc/cron.d/ping <<EOF
|
||||
*/5 * * * * root /tmp/cron.ping
|
||||
29 5 * * * root /tmp/cron.disassoc
|
||||
2 * * * * root /tmp/cron.uptime
|
||||
EOF
|
||||
|
||||
# On lance cron
|
||||
cron
|
||||
|
||||
echo " ok"
|
||||
|
||||
) >> /tmp/autoexec.log 2>> /tmp/autoexec.log
|
||||
# Pas sûr que cela reste ordonné
|
||||
|
||||
|
||||
# On donne le tout à syslog
|
||||
echo "Fin du boot" >> /tmp/autoexec.log
|
||||
cat /tmp/autoexec.log | busybox logger -p local3.info -t "Statut"
|
||||
|
||||
|
||||
"""
|
||||
|
||||
"#" # Ligne ici juste pour avoir un comportement correct de mon éditeur......
|
||||
|
||||
def __str__(self) :
|
||||
return 'bornes wifi'
|
||||
|
||||
|
@ -493,23 +191,20 @@ cat /tmp/autoexec.log | busybox logger -p local3.info -t "Statut"
|
|||
self.bornes = bornes
|
||||
|
||||
def _gen(self) :
|
||||
# Ancien systeme
|
||||
date = time.strftime('%A %d %B %Y %H:%M')
|
||||
bornes = self.db.search('host=*.wifi.crans.org&puissance=*')['machine']
|
||||
if not self.bornes:
|
||||
# Si on n'a pas spécifié de bornes, on va les redémarrer toute !
|
||||
self.bornes = [b.nom() for b in bornes]
|
||||
# Liste des bornes
|
||||
BORNES = u'## Liste des bornes -- source : base LDAP\n'
|
||||
BORNES += u'## MAC - IP - Canal - Puissance - Nom\n'
|
||||
for b in self.db.search('host=*.wifi.crans.org&puissance=*')['machine'] :
|
||||
for b in bornes :
|
||||
self.anim.cycle()
|
||||
BORNES += u'%s %s %s %s %s\n' % ( b.mac(), b.ip(), b.canal(),
|
||||
b.puissance(), b.nom().split(".")[0] )
|
||||
|
||||
BORNES += u'## Fin liste des bornes'
|
||||
|
||||
AUTOEXEC = self.AUTOEXEC
|
||||
fd = self._open_conf(self.AUTOEXEC)
|
||||
fd.write( (self.autoexec % vars()).encode('iso-8859-15') )
|
||||
fd.close()
|
||||
|
||||
# Nouveau systeme
|
||||
fd = self._open_conf(self.GET_CONFIG, '#')
|
||||
fd.write("""
|
||||
|
@ -525,15 +220,22 @@ get_config () {
|
|||
def restart(self) :
|
||||
self.lock()
|
||||
for borne in self.bornes :
|
||||
anim('\treboot de %s' % borne)
|
||||
status, output = commands.getstatusoutput('ssh -i %s -o StrictHostKeyChecking=no root@%s wget ftp://138.231.148.1/autoexec.sh' % ( self.clef, borne ) )
|
||||
if status :
|
||||
print ERREUR
|
||||
if self.debug :
|
||||
print output
|
||||
self.db.services_to_restart('bornes_wifi', [borne])
|
||||
else :
|
||||
status, output = commands.getstatusoutput('ssh -i %s -o StrictHostKeyChecking=no root@%s sh /tmp/autoexec.sh || true' % ( self.clef, borne ) )
|
||||
print OK
|
||||
# Juste pour être sûr
|
||||
if not '.' in borne: borne = borne + ".wifi.crans.org"
|
||||
anim('\treconfiguration de %s' % borne)
|
||||
# Déjà, cette borne a-t-elle un répertoire de configuration ?
|
||||
target = '%s/%s' % (self.WIFI_UPDATE, borne)
|
||||
if not os.path.isdir(target):
|
||||
# On créé le répertoire à l'image du répertoire default
|
||||
os.system("cp -R %s/default %s" % (self.WIFI_UPDATE, target))
|
||||
# Maintenant, on doit refaire quelques liens symboliques
|
||||
os.system("ln -sf ../shared/constants %s/100constants" % target)
|
||||
os.system("ln -sf ../shared/config/get_config %s/101getconfig" % target)
|
||||
os.system("ln -sf ../shared/config/get_clients %s/102getclients" % target)
|
||||
os.system("ln -sf ../shared/config/update-config %s/103update-config" % target)
|
||||
os.system("ln -sf ../shared/firewall/arp-forwarder %s/201firewall-arp" % target)
|
||||
os.system("ln -sf ../shared/firewall/macip %s/202firewall-macip" % target)
|
||||
print OK
|
||||
|
||||
self.unlock()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue