Gnration du fichier de blackliste de carte d'tudiant pour squid par Benoit.

darcs-hash:20041011212508-41617-940b96361bdce69ef8228fd0a811c77c327a16c8.gz
This commit is contained in:
pauget 2004-10-11 23:25:08 +02:00
parent 5af2c8f33e
commit 1880947b7d
2 changed files with 95 additions and 65 deletions

View file

@ -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()

View file

@ -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()