From 1880947b7dee5f1f685a71472491d1fe3f497195 Mon Sep 17 00:00:00 2001 From: pauget Date: Mon, 11 Oct 2004 23:25:08 +0200 Subject: [PATCH] Gnration du fichier de blackliste de carte d'tudiant pour squid par Benoit. darcs-hash:20041011212508-41617-940b96361bdce69ef8228fd0a811c77c327a16c8.gz --- gestion/gen_confs/generate.py | 23 ++++++ gestion/gen_confs/squid.py | 137 ++++++++++++++++++---------------- 2 files changed, 95 insertions(+), 65 deletions(-) diff --git a/gestion/gen_confs/generate.py b/gestion/gen_confs/generate.py index d75922a7..3a7269d6 100755 --- a/gestion/gen_confs/generate.py +++ b/gestion/gen_confs/generate.py @@ -209,6 +209,17 @@ if hostname == 'zamok': except: if auto : db.services_to_restart('droits') + if 'upload' in to_do.keys() : + if auto : db.services_to_restart('-upload') + # aussi relancer le firewall (+ tard) + try: + from gen_confs.squid import squid_upload + a = squid_upload() + a.debug = debug + a.reconfigure() + except: + if auto: db.services_to_restart('upload') + if 'switch' in to_do.keys() : if auto : db.services_to_restart('-switch') try: @@ -312,6 +323,18 @@ elif hostname == 'nectaris': if auto : db.services_to_restart('droits-nectaris') sys.stdout.write('Erreur dans la config des droits sur nectaris.\n') +elif hostname == 'sila' : + if 'bl_carte_etudiant' in to_do.keys() : + if auto : db.services_to_restart('-bl_carte_etudiant') + try: + from gen_confs.squid import squid_carte + a = squid_carte() + a.debug = debug + a.reconfigure() + except: + if auto: db.services_to_restart('bl_carte_etudiant') + + if debug : print 'Non traité ici mais signalé dans la base LDAP : \n\t', db.services_to_restart() diff --git a/gestion/gen_confs/squid.py b/gestion/gen_confs/squid.py index 6ca5c1ba..adf48a33 100755 --- a/gestion/gen_confs/squid.py +++ b/gestion/gen_confs/squid.py @@ -1,74 +1,81 @@ #! /usr/bin/env python # -*- coding: iso-8859-15 -*- - -""" Génération de la configuration pour squid """ - + +""" Génération de la configuration pour squid sur sila +""" + +import sys +sys.path.append('/usr/scripts/gestion') from gen_confs import gen_config +from ldap_crans import crans_ldap, adherent, club, machine, ann_scol from time import localtime -class bl_carte_etudiant(gen_config) : - """ Génère le fichier de blackliste pour carte d'étudiant pour squid""" - BL_CARTE = '/tmp/bl_carte_et' - restart_cmd = '/etc/init.d/squid reload' - - def __str__(self) : - return "blackliste cartes d'étudiant" - - def _gen(self) : - fd=self._open_conf(self.BL_CARTE) - - base = self.base.search('paiement=ok') - for adh in ( [ self.crans ] + base['adherent'] + base['club'] ): - for machine in adh.machines() : - self.anim.cycle() - if 'bloq' in machine.blacklist_actif() : continue - if machine.proprietaire().idn != 'aid' : continue - fd.write(machine.nom() + '\n') - - fd.close() - -class bl_upload_squid(gen_config) : - """ Génère le fichier de blackliste d'upload pour squid""" - # Fichier - BL_UPLOAD = '/tmp/bl_upload_squid' - restart_cmd = '/etc/init.d/squid reload' - - def __str__(self) : - return "blackliste upload squid" - - def _gen(self) : - upload = self._open_conf( self.BL_UPLOAD ) - - base = self.base.search('paiement=ok') - for adh in ( [ self.crans ] + base['adherent'] + base['club'] ): - for machine in adh.machines() : - self.anim.cycle() - bl = machine.blacklist_actif() - if 'bl_upload' in bl and not 'bloq' in bl : - upload.write( machine.nom() + '\n' ) - - upload.close() - -class bl_virus(gen_config) : - """ Génère le fichier de blackliste virus pour squid""" - # Fichiers - BL_VIRUS = '/tmp/bl_virus' - - def __str__(self) : - return "blackliste virus" - +class squid(gen_config) : + db = crans_ldap() restart_cmd = '/etc/init.d/squid reload' - description = u'Bloquage accès http vers l\'extérieur, page expliquative' - - def _gen(self) : - virus = self._open_conf( self.BL_VIRUS ) - - base = self.base.search('paiement=ok') - for machine in base['machine'] : + def _mklist(self,quoi,FICHIER) : + bl = self.db.search("blacklist=*%s*"%quoi) + l_proprio = bl["adherent"]+bl["club"] + fic = self._open_conf(self.FICHIER) + self.anim.iter=len(l_proprio) + for proprio in l_proprio : self.anim.cycle() - bl = machine.blacklist_actif() - if 'bl_virus' in bl and not 'bloq' in bl : - virus.write( machine.nom() + '\n') + if quoi in proprio.blacklist_actif(): + # Pas la peine de renvoyer les machines complètement bloqués + for m in proprio.machines(): + if not 'bloq' in m.blacklist_actif(): + fic.write(m.Nom()+'\n') + fic.close() - virus.close() +class squid_upload(squid) : + """ Genère le fichier blacklist-upload pour squid """ + FICHIER = "/tmp/blacklist-upload" + + def __str__(self) : + return "squid-upload" + + def _gen(self) : + self._mklist("upload",self.FICHIER) + +class squid_virus(squid) : + """ Genère le fichier blacklist-virus pour squid """ + FICHIER = "/tmp/blacklist-virus" + + def __str__(self) : + return "squid-virus" + + def _gen(self) : + self._mklist("virus",self.FICHIER) + +class squid_carte(gen_config) : + """ Genère le fichier blacklist-carte pour squid """ + FICHIER = "/etc/squid/blacklist_carte_et" + # Septembre ou octobre + if localtime()[1] in [9,10] : + # Inutile de relancer squid + restart_cmd = '' + else: + restart_cmd = '/etc/init.d/squid reload' + + def __str__(self) : + return "squid-carte" + + def _gen(self) : + fic = self._open_conf(self.FICHIER) + # Pas les mois de septembre ni octobre + if localtime()[1] in [9,10] : + # on vide la blacklist + fic.close() + return + db = crans_ldap() + l_adh = db.search("paiement=ok&carteEtudiant!=%i"%ann_scol)["adherent"] + self.anim.iter=len(l_adh) + for proprio in l_adh : + self.anim.cycle() + # Pas la peine de renvoyer les machines complètement bloqués + for m in proprio.machines(): + if not 'bloq' in m.blacklist_actif(): + fic.write(m.Nom()+'\n') + fic.close() +