81 lines
2.2 KiB
Python
Executable file
81 lines
2.2 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, adherent, club, machine, 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"]
|
|
fic = self._open_conf(self.FICHIER)
|
|
self.anim.iter=len(l_proprio)
|
|
for proprio in l_proprio :
|
|
self.anim.cycle()
|
|
if quoi 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)
|
|
|
|
class squid_virus(squid) :
|
|
""" Genère le fichier blacklist-virus pour squid """
|
|
FICHIER = "/tmp/blacklist-virus"
|
|
|
|
def __str__(self) :
|
|
return "squid-virus"
|
|
|
|
def _gen(self) :
|
|
self._mklist("virus",self.FICHIER)
|
|
|
|
class squid_carte(gen_config) :
|
|
""" Genère le fichier blacklist-carte pour squid """
|
|
FICHIER = "/etc/squid/blacklist_carte_et"
|
|
# Septembre ou octobre
|
|
if localtime()[1] in [9,10] :
|
|
# Inutile de relancer squid
|
|
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
|
|
if localtime()[1] in [9,10] :
|
|
# on vide la blacklist
|
|
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()
|
|
|