[gen_confs/squid.py] On regenere les blacklistes correspondant aux nouvelles IPs
Ca evite qu'un adherent blackliste, creant une nouvelle machine ne soit pas blackliste sur squid ... darcs-hash:20100511202632-ddb99-817464ed5ad86915772768abef6e2985453bdb6e.gz
This commit is contained in:
parent
d8e9d87c34
commit
74fd959a20
2 changed files with 71 additions and 1 deletions
|
@ -39,7 +39,8 @@ make_lock('auto_generate', 'Big lock', nowait=1)
|
||||||
|
|
||||||
class base_reconfigure:
|
class base_reconfigure:
|
||||||
__service_develop = {
|
__service_develop = {
|
||||||
'macip': [ 'rouge-macip', 'zamok-macip', 'sable-macip', 'komaz-macip', 'gordon-macip' ],
|
'macip': [ 'rouge-macip', 'zamok-macip', 'sable-macip', 'komaz-macip', 'gordon-macip',
|
||||||
|
'sable-blacklist_check' ],
|
||||||
# 'droits': [ 'rouge-droits', 'ragnarok-droits' ],
|
# 'droits': [ 'rouge-droits', 'ragnarok-droits' ],
|
||||||
'blacklist_upload': [ 'sable-blacklist_upload', 'komaz-blacklist' ],
|
'blacklist_upload': [ 'sable-blacklist_upload', 'komaz-blacklist' ],
|
||||||
'blacklist_p2p': [ 'sable-blacklist_p2p', 'komaz-blacklist' ],
|
'blacklist_p2p': [ 'sable-blacklist_p2p', 'komaz-blacklist' ],
|
||||||
|
@ -252,6 +253,10 @@ class sable(base_reconfigure):
|
||||||
from gen_confs.bind import dns
|
from gen_confs.bind import dns
|
||||||
self._do(dns(), self._machines())
|
self._do(dns(), self._machines())
|
||||||
|
|
||||||
|
def blacklist_check(self, ips):
|
||||||
|
from gen_confs.squid import squid_check
|
||||||
|
self._do(squid_check(ips))
|
||||||
|
|
||||||
def bl_carte_etudiant(self):
|
def bl_carte_etudiant(self):
|
||||||
from gen_confs.squid import squid_carte
|
from gen_confs.squid import squid_carte
|
||||||
self._do(squid_carte())
|
self._do(squid_carte())
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
sys.path.append('/usr/scripts/gestion')
|
sys.path.append('/usr/scripts/gestion')
|
||||||
|
from affich_tools import *
|
||||||
from gen_confs import gen_config
|
from gen_confs import gen_config
|
||||||
from ldap_crans import crans_ldap, ann_scol
|
from ldap_crans import crans_ldap, ann_scol
|
||||||
from time import localtime
|
from time import localtime
|
||||||
|
@ -56,6 +57,70 @@ class squid(gen_config) :
|
||||||
fic.write( "\n# %s\n%s\n" % (m.Nom(), m.ip()))
|
fic.write( "\n# %s\n%s\n" % (m.Nom(), m.ip()))
|
||||||
fic.close()
|
fic.close()
|
||||||
|
|
||||||
|
class squid_check(gen_config):
|
||||||
|
"""Classe de vérification des blacklistes à regénérer pour une IP."""
|
||||||
|
|
||||||
|
db = crans_ldap()
|
||||||
|
actif = True # la sanction est elle active ?
|
||||||
|
restart_cmd = '/etc/init.d/squid3 reload'
|
||||||
|
|
||||||
|
def __str__(self) :
|
||||||
|
return str(self.__class__).replace('_','-').split('.')[2]
|
||||||
|
|
||||||
|
def __init__(self, ips):
|
||||||
|
self.ips = ips
|
||||||
|
|
||||||
|
def _gen(self):
|
||||||
|
# Regénération des fichiers des blacklistes correspondant aux
|
||||||
|
# nouvelles IPs
|
||||||
|
|
||||||
|
# On regarde pour chaque IP la liste des blacklistes à regénérer
|
||||||
|
to_regen = []
|
||||||
|
for ip in self.ips:
|
||||||
|
s = self.db.search('ipHostNumber=%s' % ip)['machine']
|
||||||
|
if len(s) > 0:
|
||||||
|
m = s[0]
|
||||||
|
p = m.proprietaire()
|
||||||
|
to_regen.extend(m.blacklist_actif())
|
||||||
|
from config import bl_carte_et_actif
|
||||||
|
if (bl_carte_et_actif and ann_scol not in p.carteEtudiant()):
|
||||||
|
to_regen.append('carte')
|
||||||
|
if p.chbre() == '????':
|
||||||
|
to_regen.append('chbre')
|
||||||
|
|
||||||
|
# On ne prend chaque blackliste qu'une seule fois
|
||||||
|
to_regen_uniq = []
|
||||||
|
for item in to_regen:
|
||||||
|
if item == 'mail_invalide':
|
||||||
|
item = 'mail'
|
||||||
|
if item not in to_regen_uniq:
|
||||||
|
to_regen_uniq.append(item)
|
||||||
|
self.anim.reinit()
|
||||||
|
print OK
|
||||||
|
|
||||||
|
# On regénère les fichiers pour chaque blackliste
|
||||||
|
for item in to_regen_uniq:
|
||||||
|
curclass = eval("squid_%s()" % item)
|
||||||
|
curclass.anim = anim('\tgeneration blackliste %s' % item)
|
||||||
|
curclass._gen()
|
||||||
|
curclass.anim.reinit()
|
||||||
|
print OK
|
||||||
|
|
||||||
|
def gen_conf(self) :
|
||||||
|
# Redéfini pour enlever un peu de cosmétique gênante
|
||||||
|
""" Génération des fichiers de conf, retourne False si erreur """
|
||||||
|
self.lock()
|
||||||
|
self.anim = anim('\tverification blacklistes')
|
||||||
|
try :
|
||||||
|
self._gen()
|
||||||
|
self.unlock()
|
||||||
|
return True
|
||||||
|
except :
|
||||||
|
self.anim.reinit()
|
||||||
|
self._restore()
|
||||||
|
self.unlock()
|
||||||
|
return False
|
||||||
|
|
||||||
class squid_upload(squid) :
|
class squid_upload(squid) :
|
||||||
""" Génère le fichier blacklist-upload pour squid """
|
""" Génère le fichier blacklist-upload pour squid """
|
||||||
FICHIER = "/etc/squid3/blacklist_upload"
|
FICHIER = "/etc/squid3/blacklist_upload"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue