#! /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 = '/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_actif() if 'upload' in bl and not 'bloq' in bl : upload.write( '%s:smtp,smtps,pop3,pop3s,imap,imaps,http\n' % machine.nom() ) upload.close()