Gnration des fichiers de conf de squid.

darcs-hash:20041017142032-41617-5e9b037884233c2835fc0c68080f1210a1936742.gz
This commit is contained in:
pauget 2004-10-17 16:20:32 +02:00
parent 3ca42aa431
commit 1481c22db1
2 changed files with 98 additions and 51 deletions

View file

@ -25,9 +25,11 @@ import config
args_autorises = ['quiet', 'remove=', 'list' ,'help'] args_autorises = ['quiet', 'remove=', 'list' ,'help']
if hostname == 'zamok' : if hostname == 'zamok' :
args_autorises += [ 'home=', 'mail_bienvenue=', 'ML-ENS=', 'droits', 'switch=' , 'dhcp', 'dns', 'firewall' , 'del_user='] args_autorises += [ 'home=', 'mail_bienvenue=', 'ML-ENS=', 'droits', 'switch=' , 'dhcp', 'dns', 'firewall' , 'del_user=', 'blacklist_upload' ]
elif hostname == 'nectaris' : elif hostname == 'nectaris' :
args_autorises += [ 'conf_wifi', 'bornes_wifi=' , 'droits-nectaris'] args_autorises += [ 'conf_wifi', 'bornes_wifi=' , 'droits-nectaris']
elif hostname == 'sila' :
args_autorises += [ 'bl_squid_upload', 'blacklist_virus' , 'blacklist_warez' , 'bl_chbre_invalide', 'bl_carte_etudiant' ]
# On vérifie que l'on est root # On vérifie que l'on est root
if os.getuid() != 0: if os.getuid() != 0:
@ -209,17 +211,17 @@ if hostname == 'zamok':
except: except:
if auto : db.services_to_restart('droits') if auto : db.services_to_restart('droits')
if 'upload' in to_do.keys() : if 'blacklist_upload' in to_do.keys() :
if auto : db.services_to_restart('-upload') if auto : db.services_to_restart('-blacklist_upload')
# aussi relancer le firewall (+ tard) db.services_to_restart('bl_squid_upload')
try: try:
from gen_confs.squid import squid_upload from gen_confs.firewall import bl_upload_fw
a = squid_upload() a = bl_upload_fw()
a.debug = debug a.debug = debug
a.reconfigure() a.reconfigure()
except: except:
if auto: db.services_to_restart('upload') if auto: db.services_to_restart('blacklist_upload')
if 'switch' in to_do.keys() : if 'switch' in to_do.keys() :
if auto : db.services_to_restart('-switch') if auto : db.services_to_restart('-switch')
try: try:
@ -334,7 +336,46 @@ elif hostname == 'sila' :
except: except:
if auto: db.services_to_restart('bl_carte_etudiant') if auto: db.services_to_restart('bl_carte_etudiant')
if 'blacklist_virus' in to_do.keys() :
if auto : db.services_to_restart('-blacklist_virus')
try:
from gen_confs.squid import squid_virus
a = squid_virus()
a.debug = debug
a.reconfigure()
except:
if auto: db.services_to_restart('blacklist_virus')
if 'blacklist_warez' in to_do.keys() :
if auto : db.services_to_restart('-blacklist_warez')
try:
from gen_confs.squid import squid_warez
a = squid_warez()
a.debug = debug
a.reconfigure()
except:
if auto: db.services_to_restart('blacklist_warez')
if 'bl_squid_upload' in to_do.keys() :
if auto : db.services_to_restart('-bl_squid_upload')
try:
from gen_confs.squid import squid_upload
a = squid_upload()
a.debug = debug
a.reconfigure()
except:
if auto: db.services_to_restart('bl_squid_upload')
if 'bl_chbre_invalide' in to_do.keys() :
if auto : db.services_to_restart('-bl_chbre_invalide')
try:
from gen_confs.squid import squid_chbre
a = squid_chbre()
a.debug = debug
a.reconfigure()
except:
if auto: db.services_to_restart('bl_chbre_invalide')
if debug : if debug :
print 'Non traité ici mais signalé dans la base LDAP : \n\t', db.services_to_restart() print 'Non traité ici mais signalé dans la base LDAP : \n\t', db.services_to_restart()

View file

@ -1,81 +1,87 @@
#! /usr/bin/env python #! /usr/bin/env python
# -*- coding: iso-8859-15 -*- # -*- 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 import sys
sys.path.append('/usr/scripts/gestion') sys.path.append('/usr/scripts/gestion')
from gen_confs import gen_config 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 from time import localtime
class squid(gen_config) : class squid(gen_config) :
db = crans_ldap() db = crans_ldap()
restart_cmd = '/etc/init.d/squid reload' restart_cmd = '/etc/init.d/squid reload'
def _mklist(self,quoi,FICHIER) : def __str__(self) :
bl = self.db.search("blacklist=*%s*"%quoi) return str(self.__class__).replace('_','-').split('.')[2]
l_proprio = bl["adherent"]+bl["club"]
def _gen(self) :
self._mklist()
def _mklist(self) :
fic = self._open_conf(self.FICHIER) 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) self.anim.iter=len(l_proprio)
for proprio in l_proprio : for proprio in l_proprio :
self.anim.cycle() 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 # Pas la peine de renvoyer les machines complètement bloqués
for m in proprio.machines(): for m in proprio.machines():
if not 'bloq' in m.blacklist_actif(): if not 'bloq' in m.blacklist_actif():
fic.write(m.Nom()+'\n') fic.write(m.Nom()+'\n')
fic.close() fic.close()
class squid_upload(squid) : class squid_upload(squid) :
""" Genère le fichier blacklist-upload pour squid """ """ Genère le fichier blacklist-upload pour squid """
FICHIER = "/tmp/blacklist-upload" FICHIER = "/etc/squid/blacklist_upload"
chaine = "upload"
def __str__(self) : recherche_bl = 1
return "squid-upload"
def _gen(self) :
self._mklist("upload",self.FICHIER)
class squid_virus(squid) : class squid_virus(squid) :
""" Genère le fichier blacklist-virus pour squid """ """ Genère le fichier blacklist-virus pour squid """
FICHIER = "/tmp/blacklist-virus" #FICHIER = "/etc/squid/blacklist_infectes"
# on ne fait rien pour l'instant, non géré par LDAP
def __str__(self) : chaine = "virus"
return "squid-virus"
def _gen(self) : 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 """ """ Genère le fichier blacklist-carte pour squid """
FICHIER = "/etc/squid/blacklist_carte_et" FICHIER = "/etc/squid/blacklist_carte_et"
# Septembre ou octobre chaine = "carteEtudiant!=%i"%ann_scol
recherche_bl = 0
if localtime()[1] in [9,10] : if localtime()[1] in [9,10] :
# Inutile de relancer squid # Inutile de relancer squid en septembre et octobre
restart_cmd = '' restart_cmd = ''
else:
restart_cmd = '/etc/init.d/squid reload'
def __str__(self) :
return "squid-carte"
def _gen(self) : def _gen(self) :
fic = self._open_conf(self.FICHIER) # Liste vide les mois de septembre et octobre
# Pas les mois de septembre ni octobre
if localtime()[1] in [9,10] : if localtime()[1] in [9,10] :
# on vide la blacklist fic = self._open_conf(self.FICHIER)
# on vide la blackliste
fic.close() fic.close()
return return
db = crans_ldap() self._mklist()
l_adh = db.search("paiement=ok&carteEtudiant!=%i"%ann_scol)["adherent"]
self.anim.iter=len(l_adh) class squid_chbre(squid) :
for proprio in l_adh : """ Genère le fichier blacklist-chbre pour squid """
self.anim.cycle() FICHIER = "/etc/squid/blacklist_chbre"
# Pas la peine de renvoyer les machines complètement bloqués chaine = "chbre=????"
for m in proprio.machines(): recherche_bl = 0
if not 'bloq' in m.blacklist_actif():
fic.write(m.Nom()+'\n')
fic.close()