Gnration des fichiers de conf de squid.
darcs-hash:20041017142032-41617-5e9b037884233c2835fc0c68080f1210a1936742.gz
This commit is contained in:
parent
3ca42aa431
commit
1481c22db1
2 changed files with 98 additions and 51 deletions
|
@ -1,81 +1,87 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: iso-8859-15 -*-
|
||||
|
||||
""" Génération de la configuration pour squid sur sila
|
||||
"""
|
||||
""" 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 ldap_crans import crans_ldap, ann_scol
|
||||
from time import localtime
|
||||
|
||||
class squid(gen_config) :
|
||||
db = crans_ldap()
|
||||
restart_cmd = '/etc/init.d/squid reload'
|
||||
|
||||
def _mklist(self,quoi,FICHIER) :
|
||||
bl = self.db.search("blacklist=*%s*"%quoi)
|
||||
l_proprio = bl["adherent"]+bl["club"]
|
||||
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
|
||||
# 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"]
|
||||
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 quoi in proprio.blacklist_actif():
|
||||
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 = "/tmp/blacklist-upload"
|
||||
|
||||
def __str__(self) :
|
||||
return "squid-upload"
|
||||
|
||||
def _gen(self) :
|
||||
self._mklist("upload",self.FICHIER)
|
||||
FICHIER = "/etc/squid/blacklist_upload"
|
||||
chaine = "upload"
|
||||
recherche_bl = 1
|
||||
|
||||
class squid_virus(squid) :
|
||||
""" Genère le fichier blacklist-virus pour squid """
|
||||
FICHIER = "/tmp/blacklist-virus"
|
||||
|
||||
def __str__(self) :
|
||||
return "squid-virus"
|
||||
|
||||
#FICHIER = "/etc/squid/blacklist_infectes"
|
||||
# on ne fait rien pour l'instant, non géré par LDAP
|
||||
chaine = "virus"
|
||||
def _gen(self) :
|
||||
self._mklist("virus",self.FICHIER)
|
||||
pass
|
||||
recherche_bl = 1
|
||||
|
||||
class squid_warez(squid) :
|
||||
""" Genère le fichier blacklist-warez pour squid """
|
||||
FICHIER = "/etc/squid/blacklist_warez"
|
||||
chaine = "warez"
|
||||
recherche_bl = 1
|
||||
|
||||
class squid_carte(gen_config) :
|
||||
class squid_carte(squid) :
|
||||
""" Genère le fichier blacklist-carte pour squid """
|
||||
FICHIER = "/etc/squid/blacklist_carte_et"
|
||||
# Septembre ou octobre
|
||||
chaine = "carteEtudiant!=%i"%ann_scol
|
||||
recherche_bl = 0
|
||||
|
||||
if localtime()[1] in [9,10] :
|
||||
# Inutile de relancer squid
|
||||
# Inutile de relancer squid en septembre et octobre
|
||||
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
|
||||
# Liste vide les mois de septembre et octobre
|
||||
if localtime()[1] in [9,10] :
|
||||
# on vide la blacklist
|
||||
fic = self._open_conf(self.FICHIER)
|
||||
# on vide la blackliste
|
||||
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()
|
||||
|
||||
self._mklist()
|
||||
|
||||
class squid_chbre(squid) :
|
||||
""" Genère le fichier blacklist-chbre pour squid """
|
||||
FICHIER = "/etc/squid/blacklist_chbre"
|
||||
chaine = "chbre=????"
|
||||
recherche_bl = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue