From 607b1c44d9e26d848f538d7b461aa77e9d5b395a Mon Sep 17 00:00:00 2001 From: bernat Date: Fri, 31 Dec 2004 16:20:41 +0100 Subject: [PATCH] Nouveau systeme de configuration des bornes Les "anciennes" ne seront donc plus mises a jour... darcs-hash:20041231152041-d1718-d44fa18330d720707a108a78c60b8fffc0644b9c.gz --- gestion/gen_confs/generate.py | 7 +- gestion/gen_confs/wifi.py | 352 +++------------------------------- 2 files changed, 33 insertions(+), 326 deletions(-) diff --git a/gestion/gen_confs/generate.py b/gestion/gen_confs/generate.py index a8c0ef3c..82476a32 100755 --- a/gestion/gen_confs/generate.py +++ b/gestion/gen_confs/generate.py @@ -340,6 +340,8 @@ elif hostname == 'nectaris': a = conf_wifi() a.debug = debug a.reconfigure() + # On va aussi demander la reconfiguration de toutes les bornes + to_do['bornes_wifi'] = [] except: if auto : db.services_to_restart('conf_wifi') sys.stdout.write('Erreur dans la config du wifi.\n') @@ -352,7 +354,10 @@ elif hostname == 'nectaris': if auto : db.services_to_restart('-bornes_wifi') try: from gen_confs.wifi import bornes_wifi - a = bornes_wifi(to_do['bornes_wifi']) + if to_do['bornes_wifi']==['all']: + a = bornes_wifi() + else: + a = bornes_wifi(to_do['bornes_wifi']) a.debug = debug a.reconfigure() except: diff --git a/gestion/gen_confs/wifi.py b/gestion/gen_confs/wifi.py index 73ec4761..19b836e6 100755 --- a/gestion/gen_confs/wifi.py +++ b/gestion/gen_confs/wifi.py @@ -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 < /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 < .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 < /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 < /tmp/cron.ping < /dev/null -sleep 61 # Idem -exit 0 -EOF -chmod +x /tmp/cron.ping - -cat > /tmp/cron.uptime < /tmp/cron.klogd < /tmp/cron.disassoc < /etc/cron.d/dns < /etc/cron.d/services < /etc/cron.d/ping <> /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() +