scripts/gestion/gen_confs/squid.py
salles 374978d5e1 Mise en place des blackliste diffrencies pour :
- upload
 - upload rpt
 - p2p
 - p2p rpt

darcs-hash:20060307145443-72cb0-28c846de35d9f194beed5fa2731392fe01776c91.gz
2006-03-07 15:54:43 +01:00

111 lines
3.7 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()
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)
# recherche_bl :
# 1 : search sur champ blacklist et clubs compris
# 2 : search sur champ ablacklist et clubs compris
# 3 : search sur champ mblacklist et clubs compris
# 0 : search plus général et clubs exclus
if self.recherche_bl==1:
liste = self.db.search("paiement=ok&blacklist=*%s*"%self.chaine)
l_proprio = liste["adherent"]+liste["club"]
elif self.recherche_bl==2:
liste = self.db.search("paiement=ok&ablacklist=*%s*"%self.chaine)
l_proprio = liste["adherent"]+liste["club"]
elif self.recherche_bl==3:
liste = self.db.search("paiement=ok&mblacklist=*%s*"%self.chaine)
l_proprio = liste["adherent"]+liste["club"]
else:
l_proprio = self.db.search('paiement=ok&' + self.chaine)["adherent"]
self.anim.iter=len(l_proprio)
for proprio in l_proprio :
self.anim.cycle()
if self.recherche_bl==0 or self.chaine 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()
class squid_upload(squid) :
""" Genère le fichier blacklist-upload pour squid """
FICHIER = "/etc/squid/blacklist_upload"
chaine = "upload"
recherche_bl = 1
class squid_p2p(squid) :
""" Genère le fichier blacklist-p2p pour squid """
FICHIER = "/etc/squid/blacklist_p2p"
chaine = "p2p"
recherche_bl = 2
class squid_autodisc_upload(squid) :
""" Genère le fichier blacklist-autodiscupload pour squid """
FICHIER = "/etc/squid/blacklist_autodisc_upload"
chaine = "autodisc_upload"
recherche_bl = 1
class squid_autodisc_p2p(squid) :
""" Genère le fichier blacklist-autodisc-p2p pour squid """
FICHIER = "/etc/squid/blacklist_autodisc_p2p"
chaine = "autodisc_p2p"
recherche_bl = 2
class squid_virus(squid) :
""" Genère le fichier blacklist-virus pour squid """
FICHIER = "/etc/squid/blacklist_virus"
chaine = "virus"
recherche_bl = 3
class squid_warez(squid) :
""" Genère le fichier blacklist-warez pour squid """
FICHIER = "/etc/squid/blacklist_warez"
chaine = "warez"
recherche_bl = 2
class squid_carte(squid) :
""" Genère le fichier blacklist-carte pour squid """
FICHIER = "/etc/squid/blacklist_carte_et"
chaine = "carteEtudiant!=%i"%ann_scol
recherche_bl = 0
if not bl_carte_et_actif :
# Inutile de relancer squid si la blacklist n'est pas activée
restart_cmd = ''
def _gen(self) :
# Liste vide si la blacklist n'est pas activée
if not bl_carte_et_actif :
fic = self._open_conf(self.FICHIER)
# on vide la blackliste
fic.close()
return
self._mklist()
class squid_chbre(squid) :
""" Genère le fichier blacklist-chbre pour squid """
FICHIER = "/etc/squid/blacklist_chbre"
chaine = "chbre=????"
recherche_bl = 0