scripts/gestion/gen_confs/squid.py
chove b03c53eeae on met en place la sanction bloq
- bloquage total du firewall de komaz
 - refus d'authentification radius
 - bloquage sur squid (le temps que le switch jette la machine)
     => délai de réauthentification de radius

darcs-hash:20060609134849-4ec08-97373756f9c143adc33ea5b08d228fc1f0a3ca97.gz
2006-06-09 15:48:49 +02:00

104 lines
3.4 KiB
Python
Executable file

#! /usr/bin/env python
# -*- coding: iso-8859-15 -*-
""" 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, ann_scol
from time import localtime
from config import bl_carte_et_actif
class squid(gen_config) :
db = crans_ldap()
actif = True # la sanction est elle active ?
restart_cmd = '/etc/init.d/squid reload'
def __str__(self) :
return str(self.__class__).replace('_','-').split('.')[2]
def _gen(self) :
self._mklist()
def _mklist(self) :
fic = self._open_conf(self.FICHIER)
if not self.actif:
return
# recherche dans la base LDAP
if '=' in self.chaine:
# chaine de tri spéciale
liste = self.db.search("paiement=ok&%s"%self.chaine)
l_proprio = liste["adherent"] + liste["club"]
l_machine = liste["machine"]
else:
# recherche dans les adhérents blacklistés
liste = self.db.search("paiement=ok&ablacklist=*%s*"%self.chaine)
l_proprio = liste["adherent"] + liste["club"]
l_proprio = [ x for x in l_proprio if self.chaine in x.blacklist_actif() ]
# recherche dans les machines blacklistés
liste = self.db.search("paiement=ok&mblacklist=*%s*"%self.chaine)
l_machine = liste["machine"]
l_machine = [ m for m in l_machine if self.chaine in m.blacklist_actif() ]
# on ajoute les machines des proprios aux autres machines
for proprio in l_proprio :
l_machine += proprio.machines()
# on colle toutes les machines dans le fichier
self.anim.iter=len(l_machine)
for m in l_machine:
self.anim.cycle()
fic.write( m.Nom() + '\n' )
fic.close()
class squid_upload(squid) :
""" Genère le fichier blacklist-upload pour squid """
FICHIER = "/etc/squid/blacklist_upload"
chaine = "upload"
class squid_p2p(squid) :
""" Genère le fichier blacklist-p2p pour squid """
FICHIER = "/etc/squid/blacklist_p2p"
chaine = "p2p"
class squid_autodisc_upload(squid) :
""" Genère le fichier blacklist-autodiscupload pour squid """
FICHIER = "/etc/squid/blacklist_autodisc_upload"
chaine = "autodisc_upload"
class squid_autodisc_p2p(squid) :
""" Genère le fichier blacklist-autodisc-p2p pour squid """
FICHIER = "/etc/squid/blacklist_autodisc_p2p"
chaine = "autodisc_p2p"
class squid_virus(squid) :
""" Genère le fichier blacklist-virus pour squid """
FICHIER = "/etc/squid/blacklist_virus"
chaine = "virus"
class squid_warez(squid) :
""" Genère le fichier blacklist-warez pour squid """
FICHIER = "/etc/squid/blacklist_warez"
chaine = "warez"
class squid_bloq(squid) :
""" Genère le fichier blacklist-bloq pour squid """
FICHIER = "/etc/squid/blacklist_bloq"
chaine = "bloq"
class squid_carte(squid) :
""" Genère le fichier blacklist-carte pour squid """
actif = bl_carte_et_actif
if not actif : restart_cmd = ''
FICHIER = "/etc/squid/blacklist_carte_et"
chaine = "carteEtudiant!=%i"%ann_scol
class squid_chbre(squid) :
""" Genère le fichier blacklist-chbre pour squid """
FICHIER = "/etc/squid/blacklist_chbre"
chaine = "chbre=????"