#! /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 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 = '/tmp/bl_upload_fw' restart_cmd = '/etc/init.d/firewall blacklist' def __str__(self) : return "blackliste upload firewall" def _gen(self) : upload = self._open_conf( self.BL_UPLOAD, '#' ) if localtime()[1] == 9: # On est en septembre, on autorise ceux qui ont payé l'an dernier et cette année base = self.base.search('(paiement=%d|paiement=%d)' % (int(self.ann_scol), int(self.ann_scol) - 1)) else: base = self.base.search('paiement=%s' % self.ann_scol) for adh in ( [ self.crans ] + base['adherent'] + base['club'] ): for machine in adh.machines() : self.anim.cycle() bl = machine.blacklist_actif() if 'bl_upload' in bl and not 'bloq' in bl : upload.write( '%s:smtp,smtps,pop3,pop3s,imap,imaps,http\n' % machine.nom() ) upload.close()