71 lines
2.5 KiB
Python
Executable file
71 lines
2.5 KiB
Python
Executable file
#! /usr/bin/env python
|
|
# -*- coding: iso-8859-15 -*-
|
|
|
|
""" Génération de la configuration pour le firewall
|
|
|
|
Copyright (C) Frédéric Pauget
|
|
Licence : GPLv2
|
|
"""
|
|
|
|
from gen_confs import gen_config
|
|
from ldap_crans import crans_ldap
|
|
from time import localtime
|
|
|
|
class firewall(gen_config) :
|
|
""" Génère le fichier de paires MAC-IP """
|
|
# Fichier
|
|
MACIP = '/CRANS/generated/ether/pairesMAC-IP.txt'
|
|
|
|
restart_cmd = '/etc/init.d/firewall macip'
|
|
|
|
def __str__(self) :
|
|
return "firewall"
|
|
|
|
def _gen(self) :
|
|
macip= self._open_conf(self.MACIP)
|
|
|
|
self.anim.iter=len(self.machines)
|
|
for machine in self.machines :
|
|
self.anim.cycle()
|
|
macip.write( "%s %s\n" % ( machine.mac(), machine.ip() ) )
|
|
|
|
macip.close()
|
|
|
|
class bl_upload_fw(gen_config) :
|
|
""" Génère le fichier de blackliste d'upload pour le firewall"""
|
|
# Fichier
|
|
BL_UPLOAD = '/CRANS/confs/blacklist.cf'
|
|
|
|
restart_cmd = 'echo /etc/init.d/firewall blacklist'
|
|
|
|
def __str__(self) :
|
|
return "blackliste upload firewall"
|
|
|
|
def _gen(self) :
|
|
db = crans_ldap()
|
|
upload = self._open_conf( self.BL_UPLOAD, '#' )
|
|
base = db.search('paiement=ok&blacklist=*upload*')
|
|
liste = base['adherent'] + base['club']
|
|
self.anim.iter=len(liste)
|
|
for adh in liste :
|
|
self.anim.cycle()
|
|
for machine in adh.machines() :
|
|
bl = machine.blacklist_all()
|
|
# 0 = présent, 1 = passé
|
|
for i in range(0,2):
|
|
# Si on est dans le passé, on commente la ligne
|
|
if i == 1:
|
|
commentaire = '#'
|
|
else:
|
|
commentaire = ''
|
|
# On regarde s'il y a une sanction d'upload
|
|
if 'upload' in bl[i]:
|
|
# Si on est dans le présent et que le type est bloqué, il n'existe plus
|
|
if i == 1 or not 'bloq' in bl[i] :
|
|
# Pour chaque sanction d'upload, on va écrire une ligne :
|
|
for sanction in bl[i]['upload']:
|
|
upload.write( '%s%s:smtp,smtps,pop3,pop3s,imap,imaps,http # %s:%s:\n' % (commentaire,
|
|
machine.nom(),
|
|
sanction[0].split(" ")[0],
|
|
sanction[1].split(" ")[0]))
|
|
upload.close()
|