Dexabification
darcs-hash:20050313135032-d1718-c3377f75daaf3408f5b76e7e3c8d68f56f62ab95.gz
This commit is contained in:
parent
737b40ac89
commit
2b1e681f35
1 changed files with 461 additions and 461 deletions
|
@ -31,56 +31,56 @@ syslog.openlog('firewall')
|
|||
class IptablesError(Exception):
|
||||
""" Gestion des erreurs d'iptables """
|
||||
def __init__(self,cmd,err_code,output):
|
||||
self.cmd=cmd
|
||||
self.err_code=err_code
|
||||
self.output=output
|
||||
syslog.syslog(syslog.LOG_ERR,"%s : status %s,%s" % (cmd,err_code,output))
|
||||
self.cmd=cmd
|
||||
self.err_code=err_code
|
||||
self.output=output
|
||||
syslog.syslog(syslog.LOG_ERR,"%s : status %s,%s" % (cmd,err_code,output))
|
||||
def __str__(self):
|
||||
return "%s\n status : %s\n %s" % (self.cmd,self.err_code,self.output)
|
||||
return "%s\n status : %s\n %s" % (self.cmd,self.err_code,self.output)
|
||||
|
||||
def iptables(cmd):
|
||||
""" Interface à iptables """
|
||||
syslog.syslog(syslog.LOG_INFO,cmd)
|
||||
status,output=getstatusoutput("/sbin/iptables "+cmd)
|
||||
if status:
|
||||
raise IptablesError(cmd,status,output)
|
||||
raise IptablesError(cmd,status,output)
|
||||
return output
|
||||
|
||||
class firewall_komaz :
|
||||
"""
|
||||
Structure du firewall :
|
||||
table nat :
|
||||
PREROUTING (policy par defaut : DROP)
|
||||
1) passage par TEST_VIRUS_FLOOD pour tout ce qui n'est pas dans zone_serveur
|
||||
2) passage dans RESEAUX_NON_ROUTABLES_DST
|
||||
3) passage est paquets venant de l'extérieur dans RESEAUX_NON_ROUTABLES_SRC
|
||||
4) on laisse passer vers filter les paquets suivants :
|
||||
source ou destination les serveurs de serveurs_crans
|
||||
ce qui vient de l'extérieur
|
||||
5) passage par TEST_MAC-IP
|
||||
table nat :
|
||||
PREROUTING (policy par defaut : DROP)
|
||||
1) passage par TEST_VIRUS_FLOOD pour tout ce qui n'est pas dans zone_serveur
|
||||
2) passage dans RESEAUX_NON_ROUTABLES_DST
|
||||
3) passage est paquets venant de l'extérieur dans RESEAUX_NON_ROUTABLES_SRC
|
||||
4) on laisse passer vers filter les paquets suivants :
|
||||
source ou destination les serveurs de serveurs_crans
|
||||
ce qui vient de l'extérieur
|
||||
5) passage par TEST_MAC-IP
|
||||
|
||||
TEST_VIRUS_FLOOD droppe les paquets contenant des virus ou les paquets de flood
|
||||
RESEAUX_NON_ROUTABLES_DST droppe les paquets dont la destination est non routable
|
||||
RESEAUX_NON_ROUTABLES_SRC droppe les paquets dont la source est non routable
|
||||
TEST_MAC-IP envoi les bon paquets vers CRANS_VERS_EXT
|
||||
TEST_VIRUS_FLOOD droppe les paquets contenant des virus ou les paquets de flood
|
||||
RESEAUX_NON_ROUTABLES_DST droppe les paquets dont la destination est non routable
|
||||
RESEAUX_NON_ROUTABLES_SRC droppe les paquets dont la source est non routable
|
||||
TEST_MAC-IP envoi les bon paquets vers CRANS_VERS_EXT
|
||||
|
||||
table filter :
|
||||
FORWARD (policy par defaut : ACCEPT)
|
||||
1) passage par BLACKLIST
|
||||
2) passage pas FILTRE_P2P (REJECT sur tout le trafic p2p)
|
||||
3) ce qui a pour source les serveurs de serveurs_crans est dirigé vers SERVEURS_VERS_EXT
|
||||
4) ce qui a pour destination les serveurs de serveurs_crans est dirigé EXT_VERS_SERVEURS
|
||||
5) tout ce qui vient de l'interface externe est dirigé vers EXT_VERS_CRANS
|
||||
6) ce qui a pour source les serveurs de serveurs_crans est dirigé vers EXT_VERS_CRANS
|
||||
table filter :
|
||||
FORWARD (policy par defaut : ACCEPT)
|
||||
1) passage par BLACKLIST
|
||||
2) passage pas FILTRE_P2P (REJECT sur tout le trafic p2p)
|
||||
3) ce qui a pour source les serveurs de serveurs_crans est dirigé vers SERVEURS_VERS_EXT
|
||||
4) ce qui a pour destination les serveurs de serveurs_crans est dirigé EXT_VERS_SERVEURS
|
||||
5) tout ce qui vient de l'interface externe est dirigé vers EXT_VERS_CRANS
|
||||
6) ce qui a pour source les serveurs de serveurs_crans est dirigé vers EXT_VERS_CRANS
|
||||
|
||||
BLACKLIST fitre des ip blacklistées (reject)
|
||||
FILTRE_P2P filtre le traffic de p2p
|
||||
EXT_VERS_CRANS et CRANS_VERS_EXT
|
||||
ACCEPT pour les paquets vers les machines du crans (test port-ip)
|
||||
REJECT pour le reste
|
||||
EXT_VERS_SERVEURS et SERVEURS_VERS_EXT
|
||||
ACCEPT pour bon mac-ip-port
|
||||
REJECT pour le reste
|
||||
BLACKLIST fitre des ip blacklistées (reject)
|
||||
FILTRE_P2P filtre le traffic de p2p
|
||||
EXT_VERS_CRANS et CRANS_VERS_EXT
|
||||
ACCEPT pour les paquets vers les machines du crans (test port-ip)
|
||||
REJECT pour le reste
|
||||
EXT_VERS_SERVEURS et SERVEURS_VERS_EXT
|
||||
ACCEPT pour bon mac-ip-port
|
||||
REJECT pour le reste
|
||||
"""
|
||||
zone_serveur="138.231.136.0/28"
|
||||
eth_ext = "eth2"
|
||||
|
@ -88,8 +88,8 @@ class firewall_komaz :
|
|||
# Ports ouverts
|
||||
ports_default = { 'tcp_EXT_VERS_CRANS' : [ '22' ],
|
||||
'tcp_CRANS_VERS_EXT': [ ':79', '81:134', '136', '140:444', '446:'],
|
||||
'udp_EXT_VERS_CRANS' : [ ],
|
||||
'udp_CRANS_VERS_EXT': [ ':136','140:'] }
|
||||
'udp_EXT_VERS_CRANS' : [ ],
|
||||
'udp_CRANS_VERS_EXT': [ ':136','140:'] }
|
||||
|
||||
mac_wifi = '00:0c:f1:fa:f1:4b'
|
||||
|
||||
|
@ -127,319 +127,319 @@ class firewall_komaz :
|
|||
debug = 1
|
||||
|
||||
def __exception_catcher(self,tache) :
|
||||
""" Excétute la tache founie en gérant les diverses exceptions
|
||||
pouvant survenir
|
||||
Retoune 1 en cas d'erreur et 0 sinon """
|
||||
try :
|
||||
tache()
|
||||
return 0
|
||||
except IptablesError, c :
|
||||
self.anim.reinit()
|
||||
print ERREUR
|
||||
if self.debug : print c
|
||||
except :
|
||||
self.anim.reinit()
|
||||
print ERREUR
|
||||
import traceback
|
||||
if self.debug : traceback.print_exc()
|
||||
return 1
|
||||
""" Excétute la tache founie en gérant les diverses exceptions
|
||||
pouvant survenir
|
||||
Retoune 1 en cas d'erreur et 0 sinon """
|
||||
try :
|
||||
tache()
|
||||
return 0
|
||||
except IptablesError, c :
|
||||
self.anim.reinit()
|
||||
print ERREUR
|
||||
if self.debug : print c
|
||||
except :
|
||||
self.anim.reinit()
|
||||
print ERREUR
|
||||
import traceback
|
||||
if self.debug : traceback.print_exc()
|
||||
return 1
|
||||
|
||||
def __machines(self) :
|
||||
""" Liste des machines du crans """
|
||||
if not self.machines :
|
||||
self.anim = anim(" Interrogation de la base LDAP")
|
||||
self.machines = crans_ldap().search('ip=*')['machine']
|
||||
print OK
|
||||
return self.machines
|
||||
""" Liste des machines du crans """
|
||||
if not self.machines :
|
||||
self.anim = anim(" Interrogation de la base LDAP")
|
||||
self.machines = crans_ldap().search('ip=*')['machine']
|
||||
print OK
|
||||
return self.machines
|
||||
|
||||
def __init__(self) :
|
||||
""" Pose un lock """
|
||||
make_lock('firewall')
|
||||
""" Pose un lock """
|
||||
make_lock('firewall')
|
||||
|
||||
def __del__(self) :
|
||||
""" Destruction du lock """
|
||||
remove_lock('firewall')
|
||||
""" Destruction du lock """
|
||||
remove_lock('firewall')
|
||||
|
||||
def restart(self):
|
||||
""" Rédémarrage du firewall """
|
||||
cprint('Redémarrage firewall','gras')
|
||||
self.__exception_catcher(self.__stop)
|
||||
self.start(False)
|
||||
""" Rédémarrage du firewall """
|
||||
cprint('Redémarrage firewall','gras')
|
||||
self.__exception_catcher(self.__stop)
|
||||
self.start(False)
|
||||
|
||||
def start(self,aff_txt_intro=True) :
|
||||
""" Construction du firewall
|
||||
aff_txt_intro s'occupe uniquement de l'esthétisme
|
||||
"""
|
||||
if aff_txt_intro : cprint('Démarrage firewall','gras')
|
||||
# Préliminaires
|
||||
if not self.__machines() or self.__exception_catcher(self.__stop) :
|
||||
cprint("Abandon",'rouge')
|
||||
return
|
||||
""" Construction du firewall
|
||||
aff_txt_intro s'occupe uniquement de l'esthétisme
|
||||
"""
|
||||
if aff_txt_intro : cprint('Démarrage firewall','gras')
|
||||
# Préliminaires
|
||||
if not self.__machines() or self.__exception_catcher(self.__stop) :
|
||||
cprint("Abandon",'rouge')
|
||||
return
|
||||
|
||||
# Initialisation
|
||||
self.__exception_catcher(self.__start)
|
||||
# Initialisation
|
||||
self.__exception_catcher(self.__start)
|
||||
|
||||
# Remplisage
|
||||
for tache in [ self.log_chaines, self.test_virus_flood, self.reseaux_non_routables,
|
||||
self.blacklist , self.serveurs_vers_ext, self.ext_vers_serveurs,
|
||||
self.crans_vers_ext, self.ext_vers_crans, self.test_mac_ip, self.filtre_p2p ] :
|
||||
self.__exception_catcher(tache)
|
||||
# Remplisage
|
||||
for tache in [ self.log_chaines, self.test_virus_flood, self.reseaux_non_routables,
|
||||
self.blacklist , self.serveurs_vers_ext, self.ext_vers_serveurs,
|
||||
self.crans_vers_ext, self.ext_vers_crans, self.test_mac_ip, self.filtre_p2p ] :
|
||||
self.__exception_catcher(tache)
|
||||
|
||||
# On peux router
|
||||
self.anim = anim(" Mise en place routage")
|
||||
warn = ''
|
||||
for cmd in [ 'echo 1 > /proc/sys/net/ipv4/ip_forward' ,
|
||||
'echo 65536 > /proc/sys/net/ipv4/ip_conntrack_max' ,
|
||||
'modprobe ip_conntrack_ftp' ,
|
||||
'modprobe ip_conntrack_h323',
|
||||
'modprobe ip_conntrack_irc' ] :
|
||||
status,output=getstatusoutput(cmd)
|
||||
if status :
|
||||
warn += output +'\n'
|
||||
if warn :
|
||||
print WARNING
|
||||
if self.debug :
|
||||
print warn
|
||||
else :
|
||||
print OK
|
||||
# On peux router
|
||||
self.anim = anim(" Mise en place routage")
|
||||
warn = ''
|
||||
for cmd in [ 'echo 1 > /proc/sys/net/ipv4/ip_forward' ,
|
||||
'echo 65536 > /proc/sys/net/ipv4/ip_conntrack_max' ,
|
||||
'modprobe ip_conntrack_ftp' ,
|
||||
'modprobe ip_conntrack_h323',
|
||||
'modprobe ip_conntrack_irc' ] :
|
||||
status,output=getstatusoutput(cmd)
|
||||
if status :
|
||||
warn += output +'\n'
|
||||
if warn :
|
||||
print WARNING
|
||||
if self.debug :
|
||||
print warn
|
||||
else :
|
||||
print OK
|
||||
|
||||
cprint(" -> fin de la procédure de démarrage",'vert')
|
||||
cprint(" -> fin de la procédure de démarrage",'vert')
|
||||
|
||||
def __start(self) :
|
||||
self.anim = anim(' Structure de la table nat')
|
||||
for chaine in [ 'LOG_VIRUS', 'LOG_FLOOD', 'TEST_VIRUS_FLOOD' , 'TEST_MAC-IP' , 'RESEAUX_NON_ROUTABLES_SRC', 'RESEAUX_NON_ROUTABLES_DST' ] :
|
||||
iptables('-t nat -N %s' % chaine)
|
||||
self.anim = anim(' Structure de la table nat')
|
||||
for chaine in [ 'LOG_VIRUS', 'LOG_FLOOD', 'TEST_VIRUS_FLOOD' , 'TEST_MAC-IP' , 'RESEAUX_NON_ROUTABLES_SRC', 'RESEAUX_NON_ROUTABLES_DST' ] :
|
||||
iptables('-t nat -N %s' % chaine)
|
||||
|
||||
iptables("-t nat -P PREROUTING ACCEPT")
|
||||
iptables("-t nat -A PREROUTING -i lo -j ACCEPT")
|
||||
iptables("-t nat -A PREROUTING -d 224.0.0.0/4 -j DROP")
|
||||
iptables("-t nat -A PREROUTING -s ! %s -j TEST_VIRUS_FLOOD" % self.zone_serveur)
|
||||
iptables("-t nat -A PREROUTING -j RESEAUX_NON_ROUTABLES_DST")
|
||||
iptables("-t nat -A PREROUTING -i %s -j RESEAUX_NON_ROUTABLES_SRC" % self.eth_ext )
|
||||
iptables("-t nat -A PREROUTING -d %s -j ACCEPT" % self.zone_serveur )
|
||||
iptables("-t nat -A PREROUTING -s %s -j ACCEPT" % self.zone_serveur )
|
||||
iptables("-t nat -A PREROUTING -i %s -j ACCEPT" % self.eth_ext )
|
||||
iptables("-t nat -A PREROUTING -j TEST_MAC-IP")
|
||||
iptables("-t nat -P PREROUTING DROP")
|
||||
print OK
|
||||
iptables("-t nat -P PREROUTING ACCEPT")
|
||||
iptables("-t nat -A PREROUTING -i lo -j ACCEPT")
|
||||
iptables("-t nat -A PREROUTING -d 224.0.0.0/4 -j DROP")
|
||||
iptables("-t nat -A PREROUTING -s ! %s -j TEST_VIRUS_FLOOD" % self.zone_serveur)
|
||||
iptables("-t nat -A PREROUTING -j RESEAUX_NON_ROUTABLES_DST")
|
||||
iptables("-t nat -A PREROUTING -i %s -j RESEAUX_NON_ROUTABLES_SRC" % self.eth_ext )
|
||||
iptables("-t nat -A PREROUTING -d %s -j ACCEPT" % self.zone_serveur )
|
||||
iptables("-t nat -A PREROUTING -s %s -j ACCEPT" % self.zone_serveur )
|
||||
iptables("-t nat -A PREROUTING -i %s -j ACCEPT" % self.eth_ext )
|
||||
iptables("-t nat -A PREROUTING -j TEST_MAC-IP")
|
||||
iptables("-t nat -P PREROUTING DROP")
|
||||
print OK
|
||||
|
||||
self.anim = anim(' Structure de la table filter')
|
||||
for chaine in [ 'EXT_VERS_SERVEURS', 'SERVEURS_VERS_EXT' , 'EXT_VERS_CRANS', 'CRANS_VERS_EXT', 'BLACKLIST_SRC', 'BLACKLIST_DST' , 'FILTRE_P2P' ] :
|
||||
iptables('-N %s' % chaine)
|
||||
self.anim = anim(' Structure de la table filter')
|
||||
for chaine in [ 'EXT_VERS_SERVEURS', 'SERVEURS_VERS_EXT' , 'EXT_VERS_CRANS', 'CRANS_VERS_EXT', 'BLACKLIST_SRC', 'BLACKLIST_DST' , 'FILTRE_P2P' ] :
|
||||
iptables('-N %s' % chaine)
|
||||
|
||||
iptables("-A FORWARD -i lo -j ACCEPT")
|
||||
iptables("-A FORWARD -p icmp -j ACCEPT")
|
||||
iptables("-A FORWARD -i %s -j BLACKLIST_DST" % self.eth_ext )
|
||||
iptables("-A FORWARD -o %s -j BLACKLIST_SRC" % self.eth_ext )
|
||||
iptables("-A FORWARD -s ! %s -d ! %s -j FILTRE_P2P" % (self.zone_serveur, self.zone_serveur) )
|
||||
iptables("-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT")
|
||||
iptables("-A FORWARD -i %s -d %s -j EXT_VERS_SERVEURS" % (self.eth_ext, self.zone_serveur) )
|
||||
iptables("-A FORWARD -o %s -s %s -j SERVEURS_VERS_EXT" % (self.eth_ext, self.zone_serveur) )
|
||||
iptables("-A FORWARD -i %s -j EXT_VERS_CRANS" % self.eth_ext )
|
||||
iptables("-A FORWARD -o %s -j CRANS_VERS_EXT" % self.eth_ext )
|
||||
print OK
|
||||
iptables("-A FORWARD -i lo -j ACCEPT")
|
||||
iptables("-A FORWARD -p icmp -j ACCEPT")
|
||||
iptables("-A FORWARD -i %s -j BLACKLIST_DST" % self.eth_ext )
|
||||
iptables("-A FORWARD -o %s -j BLACKLIST_SRC" % self.eth_ext )
|
||||
iptables("-A FORWARD -s ! %s -d ! %s -j FILTRE_P2P" % (self.zone_serveur, self.zone_serveur) )
|
||||
iptables("-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT")
|
||||
iptables("-A FORWARD -i %s -d %s -j EXT_VERS_SERVEURS" % (self.eth_ext, self.zone_serveur) )
|
||||
iptables("-A FORWARD -o %s -s %s -j SERVEURS_VERS_EXT" % (self.eth_ext, self.zone_serveur) )
|
||||
iptables("-A FORWARD -i %s -j EXT_VERS_CRANS" % self.eth_ext )
|
||||
iptables("-A FORWARD -o %s -j CRANS_VERS_EXT" % self.eth_ext )
|
||||
print OK
|
||||
|
||||
def log_chaines(self) :
|
||||
""" Construction des chaines de log (LOG_VIRUS et LOG_FLOOD) """
|
||||
self.anim = anim(' Création des chaines de log')
|
||||
for filtre in [ 'VIRUS', 'FLOOD' ] :
|
||||
# Vidage de la chaîne
|
||||
iptables('-t nat -F LOG_%s' % filtre)
|
||||
iptables('-t nat -A LOG_%s %s %s:' % (filtre, self.log_template, filtre.capitalize()) )
|
||||
iptables('-t nat -A LOG_%s -j DROP' % filtre )
|
||||
self.anim.cycle()
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
""" Construction des chaines de log (LOG_VIRUS et LOG_FLOOD) """
|
||||
self.anim = anim(' Création des chaines de log')
|
||||
for filtre in [ 'VIRUS', 'FLOOD' ] :
|
||||
# Vidage de la chaîne
|
||||
iptables('-t nat -F LOG_%s' % filtre)
|
||||
iptables('-t nat -A LOG_%s %s %s:' % (filtre, self.log_template, filtre.capitalize()) )
|
||||
iptables('-t nat -A LOG_%s -j DROP' % filtre )
|
||||
self.anim.cycle()
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
|
||||
def reseaux_non_routables(self) :
|
||||
""" Construction de RESEAUX_NON_ROUTABLES_{DST,SRC} """
|
||||
self.anim = anim(' Filtrage ip non routables',len(self.liste_reseaux_non_routables))
|
||||
for reseau in self.liste_reseaux_non_routables :
|
||||
iptables("-t nat -A RESEAUX_NON_ROUTABLES_DST -d %s -j DROP" % reseau)
|
||||
iptables("-t nat -A RESEAUX_NON_ROUTABLES_SRC -s %s -j DROP" % reseau)
|
||||
self.anim.cycle()
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
""" Construction de RESEAUX_NON_ROUTABLES_{DST,SRC} """
|
||||
self.anim = anim(' Filtrage ip non routables',len(self.liste_reseaux_non_routables))
|
||||
for reseau in self.liste_reseaux_non_routables :
|
||||
iptables("-t nat -A RESEAUX_NON_ROUTABLES_DST -d %s -j DROP" % reseau)
|
||||
iptables("-t nat -A RESEAUX_NON_ROUTABLES_SRC -s %s -j DROP" % reseau)
|
||||
self.anim.cycle()
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
|
||||
def test_virus_flood(self) :
|
||||
""" Construction de la chaîne TEST_VIRUS """
|
||||
iptables('-t nat -F TEST_VIRUS_FLOOD')
|
||||
self.anim = anim(' Filtrage virus et floods')
|
||||
""" Construction de la chaîne TEST_VIRUS """
|
||||
iptables('-t nat -F TEST_VIRUS_FLOOD')
|
||||
self.anim = anim(' Filtrage virus et floods')
|
||||
|
||||
for proto, ports in self.ports_virus.items() :
|
||||
for port in ports :
|
||||
iptables('-t nat -A TEST_VIRUS_FLOOD -p %s --dport %s -j LOG_VIRUS' % (proto, port) )
|
||||
self.anim.cycle()
|
||||
for proto, ports in self.ports_virus.items() :
|
||||
for port in ports :
|
||||
iptables('-t nat -A TEST_VIRUS_FLOOD -p %s --dport %s -j LOG_VIRUS' % (proto, port) )
|
||||
self.anim.cycle()
|
||||
|
||||
iptables('-t nat -A TEST_VIRUS_FLOOD %s -j RETURN' % self.filtre_flood) # Les limites en négatif ca ne marche pas.
|
||||
self.anim.cycle()
|
||||
iptables('-t nat -A TEST_VIRUS_FLOOD -j LOG_FLOOD')
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
iptables('-t nat -A TEST_VIRUS_FLOOD %s -j RETURN' % self.filtre_flood) # Les limites en négatif ca ne marche pas.
|
||||
self.anim.cycle()
|
||||
iptables('-t nat -A TEST_VIRUS_FLOOD -j LOG_FLOOD')
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
|
||||
def stop(self):
|
||||
""" Arrête le firewall """
|
||||
cprint("Arrêt du firewall",'gras')
|
||||
self.anim = anim(" Arrêt routage")
|
||||
status,output=getstatusoutput('echo 0 > /proc/sys/net/ipv4/ip_forward')
|
||||
if status :
|
||||
print ERREUR
|
||||
else :
|
||||
print OK
|
||||
self.__exception_catcher(self.__stop)
|
||||
cprint(" -> fin de la procédure d'arrêt",'vert')
|
||||
self.anim = anim(" Arrêt routage")
|
||||
status,output=getstatusoutput('echo 0 > /proc/sys/net/ipv4/ip_forward')
|
||||
if status :
|
||||
print ERREUR
|
||||
else :
|
||||
print OK
|
||||
self.__exception_catcher(self.__stop)
|
||||
cprint(" -> fin de la procédure d'arrêt",'vert')
|
||||
|
||||
def __stop(self) :
|
||||
self.anim = anim(" Supression règles")
|
||||
iptables("-t nat -P PREROUTING ACCEPT")
|
||||
iptables("-F")
|
||||
iptables("-t nat -F")
|
||||
iptables("-X")
|
||||
iptables("-t nat -X")
|
||||
print OK
|
||||
self.anim = anim(" Supression règles")
|
||||
iptables("-t nat -P PREROUTING ACCEPT")
|
||||
iptables("-F")
|
||||
iptables("-t nat -F")
|
||||
iptables("-X")
|
||||
iptables("-t nat -X")
|
||||
print OK
|
||||
|
||||
def test_mac_ip(self) :
|
||||
""" Reconstruit la correspondance MAC-IP des machines des adhérents """
|
||||
self.anim = anim(' Chaîne TEST_MAC-IP',len(self.__machines())+1)
|
||||
iptables("-t nat -P PREROUTING ACCEPT")
|
||||
iptables("-t nat -F TEST_MAC-IP")
|
||||
self.anim.cycle()
|
||||
""" Reconstruit la correspondance MAC-IP des machines des adhérents """
|
||||
self.anim = anim(' Chaîne TEST_MAC-IP',len(self.__machines())+1)
|
||||
iptables("-t nat -P PREROUTING ACCEPT")
|
||||
iptables("-t nat -F TEST_MAC-IP")
|
||||
self.anim.cycle()
|
||||
|
||||
def procedure() :
|
||||
for machine in self.__machines() :
|
||||
self.__test_mac_ip(machine)
|
||||
self.anim.cycle()
|
||||
iptables("-t nat -P PREROUTING DROP")
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
def procedure() :
|
||||
for machine in self.__machines() :
|
||||
self.__test_mac_ip(machine)
|
||||
self.anim.cycle()
|
||||
iptables("-t nat -P PREROUTING DROP")
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
|
||||
self.__exception_catcher(procedure)
|
||||
self.__exception_catcher(procedure)
|
||||
|
||||
def serveurs_vers_ext(self) :
|
||||
""" Reconstruit la chaine SERVEURS_VERS_EXT """
|
||||
if not self.__build_chaine('SERVEURS_VERS_EXT', self.__serveurs_vers_ext) :
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
""" Reconstruit la chaine SERVEURS_VERS_EXT """
|
||||
if not self.__build_chaine('SERVEURS_VERS_EXT', self.__serveurs_vers_ext) :
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
|
||||
def ext_vers_serveurs(self) :
|
||||
""" Reconstruit la chaine EXT_VERS_SERVEURS """
|
||||
if not self.__build_chaine('EXT_VERS_SERVEURS', self.__ext_vers_serveurs) :
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
""" Reconstruit la chaine EXT_VERS_SERVEURS """
|
||||
if not self.__build_chaine('EXT_VERS_SERVEURS', self.__ext_vers_serveurs) :
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
|
||||
def crans_vers_ext(self) :
|
||||
""" Reconstruit la chaine CRANS_VERS_EXT """
|
||||
self.__build_chaine_adherent('CRANS_VERS_EXT',self.__crans_vers_ext)
|
||||
""" Reconstruit la chaine CRANS_VERS_EXT """
|
||||
self.__build_chaine_adherent('CRANS_VERS_EXT',self.__crans_vers_ext)
|
||||
|
||||
def ext_vers_crans(self) :
|
||||
""" Reconstruit la chaine EXT_VERS_CRANS """
|
||||
self.__build_chaine_adherent('EXT_VERS_CRANS',self.__ext_vers_crans)
|
||||
""" Reconstruit la chaine EXT_VERS_CRANS """
|
||||
self.__build_chaine_adherent('EXT_VERS_CRANS',self.__ext_vers_crans)
|
||||
|
||||
def __build_chaine_adherent(self,chaine,methode):
|
||||
# On construit d'abord les autorisations particulières
|
||||
if not self.__build_chaine(chaine, methode) :
|
||||
# Puis si pas de problèmes les autorisation par défaut
|
||||
self.anim.reinit()
|
||||
for proto in [ 'tcp' , 'udp' ] :
|
||||
for port in self.ports_default["%s_%s" % ( proto, chaine) ] :
|
||||
self.anim.cycle()
|
||||
iptables("-I %s -p %s --dport %s -j ACCEPT" % (chaine, proto,port) )
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
# On construit d'abord les autorisations particulières
|
||||
if not self.__build_chaine(chaine, methode) :
|
||||
# Puis si pas de problèmes les autorisation par défaut
|
||||
self.anim.reinit()
|
||||
for proto in [ 'tcp' , 'udp' ] :
|
||||
for port in self.ports_default["%s_%s" % ( proto, chaine) ] :
|
||||
self.anim.cycle()
|
||||
iptables("-I %s -p %s --dport %s -j ACCEPT" % (chaine, proto,port) )
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
|
||||
def __build_chaine(self,chaine, methode) :
|
||||
self.anim = anim(' Chaîne %s' % chaine,len(self.__machines())+1)
|
||||
iptables("-F %s" % chaine)
|
||||
self.anim.cycle()
|
||||
def procedure() :
|
||||
for machine in self.__machines() :
|
||||
methode(machine)
|
||||
self.anim.cycle()
|
||||
iptables("-A %s -j REJECT" % chaine)
|
||||
self.anim = anim(' Chaîne %s' % chaine,len(self.__machines())+1)
|
||||
iptables("-F %s" % chaine)
|
||||
self.anim.cycle()
|
||||
def procedure() :
|
||||
for machine in self.__machines() :
|
||||
methode(machine)
|
||||
self.anim.cycle()
|
||||
iptables("-A %s -j REJECT" % chaine)
|
||||
|
||||
return self.__exception_catcher(procedure)
|
||||
return self.__exception_catcher(procedure)
|
||||
|
||||
def __serveurs_vers_ext(self,machine):
|
||||
ip=machine.ip()
|
||||
if not AddrInNet(ip,self.zone_serveur):
|
||||
# C'est une machine adhérent, rien à faire ici
|
||||
return
|
||||
ip=machine.ip()
|
||||
if not AddrInNet(ip,self.zone_serveur):
|
||||
# C'est une machine adhérent, rien à faire ici
|
||||
return
|
||||
|
||||
mac = machine.mac()
|
||||
ports = { 'tcp' : machine.portTCPout(),
|
||||
'udp' : machine.portUDPout() }
|
||||
mac = machine.mac()
|
||||
ports = { 'tcp' : machine.portTCPout(),
|
||||
'udp' : machine.portUDPout() }
|
||||
|
||||
for proto in [ 'tcp', 'udp' ] :
|
||||
for port in ports[proto].split() :
|
||||
iptables("-I SERVEURS_VERS_EXT -s %s -p %s --dport %s -m mac --mac-source %s -j ACCEPT" \
|
||||
%(ip,proto,port,mac))
|
||||
for proto in [ 'tcp', 'udp' ] :
|
||||
for port in ports[proto].split() :
|
||||
iptables("-I SERVEURS_VERS_EXT -s %s -p %s --dport %s -m mac --mac-source %s -j ACCEPT" \
|
||||
%(ip,proto,port,mac))
|
||||
|
||||
def __ext_vers_serveurs(self,machine):
|
||||
ip=machine.ip()
|
||||
if not AddrInNet(ip,self.zone_serveur):
|
||||
# C'est une machine adhérent, rien à faire ici
|
||||
return
|
||||
ip=machine.ip()
|
||||
if not AddrInNet(ip,self.zone_serveur):
|
||||
# C'est une machine adhérent, rien à faire ici
|
||||
return
|
||||
|
||||
ports = { 'tcp' : machine.portTCPin(),
|
||||
'udp' : machine.portUDPin() }
|
||||
ports = { 'tcp' : machine.portTCPin(),
|
||||
'udp' : machine.portUDPin() }
|
||||
|
||||
for proto in [ 'tcp', 'udp' ] :
|
||||
for port in ports[proto].split() :
|
||||
iptables("-I EXT_VERS_SERVEURS -d %s -p %s --dport %s -j ACCEPT"\
|
||||
%(ip,proto,port))
|
||||
for proto in [ 'tcp', 'udp' ] :
|
||||
for port in ports[proto].split() :
|
||||
iptables("-I EXT_VERS_SERVEURS -d %s -p %s --dport %s -j ACCEPT"\
|
||||
%(ip,proto,port))
|
||||
|
||||
def __crans_vers_ext(self,machine):
|
||||
ip=machine.ip()
|
||||
if AddrInNet(ip,self.zone_serveur):
|
||||
# C'est un serveur, rien à faire ici
|
||||
return
|
||||
ip=machine.ip()
|
||||
if AddrInNet(ip,self.zone_serveur):
|
||||
# C'est un serveur, rien à faire ici
|
||||
return
|
||||
|
||||
ports = { 'tcp' : machine.portTCPout(),
|
||||
'udp' : machine.portUDPout() }
|
||||
ports = { 'tcp' : machine.portTCPout(),
|
||||
'udp' : machine.portUDPout() }
|
||||
|
||||
for proto in [ 'tcp', 'udp' ] :
|
||||
for port in ports[proto].split() :
|
||||
iptables("-I CRANS_VERS_EXT -s %s -p %s --dport %s -j ACCEPT" \
|
||||
%(ip,proto,port))
|
||||
for proto in [ 'tcp', 'udp' ] :
|
||||
for port in ports[proto].split() :
|
||||
iptables("-I CRANS_VERS_EXT -s %s -p %s --dport %s -j ACCEPT" \
|
||||
%(ip,proto,port))
|
||||
|
||||
def __ext_vers_crans(self,machine):
|
||||
ip=machine.ip()
|
||||
if AddrInNet(ip,self.zone_serveur):
|
||||
# C'est un serveur, rien à faire ici
|
||||
return
|
||||
ip=machine.ip()
|
||||
if AddrInNet(ip,self.zone_serveur):
|
||||
# C'est un serveur, rien à faire ici
|
||||
return
|
||||
|
||||
ports = { 'tcp' : machine.portTCPin(),
|
||||
'udp' : machine.portUDPin() }
|
||||
ports = { 'tcp' : machine.portTCPin(),
|
||||
'udp' : machine.portUDPin() }
|
||||
|
||||
for proto in [ 'tcp', 'udp' ] :
|
||||
for port in ports[proto].split() :
|
||||
iptables("-I EXT_VERS_CRANS -d %s -p %s --dport %s -j ACCEPT" \
|
||||
%(ip,proto,port))
|
||||
for proto in [ 'tcp', 'udp' ] :
|
||||
for port in ports[proto].split() :
|
||||
iptables("-I EXT_VERS_CRANS -d %s -p %s --dport %s -j ACCEPT" \
|
||||
%(ip,proto,port))
|
||||
|
||||
def __test_mac_ip(self,machine):
|
||||
ip=machine.ip()
|
||||
mac=machine.mac()
|
||||
if machine.ipsec():
|
||||
# Machine wifi, c'est la mac de Nectaris
|
||||
iptables("-t nat -A TEST_MAC-IP -s "+\
|
||||
"%s -m mac --mac-source %s -j ACCEPT"%(ip,self.mac_wifi))
|
||||
else:
|
||||
# Machine fixe
|
||||
iptables("-t nat -A TEST_MAC-IP -s "+\
|
||||
"%s -m mac --mac-source %s -j ACCEPT"%(ip,mac))
|
||||
ip=machine.ip()
|
||||
mac=machine.mac()
|
||||
if machine.ipsec():
|
||||
# Machine wifi, c'est la mac de Nectaris
|
||||
iptables("-t nat -A TEST_MAC-IP -s "+\
|
||||
"%s -m mac --mac-source %s -j ACCEPT"%(ip,self.mac_wifi))
|
||||
else:
|
||||
# Machine fixe
|
||||
iptables("-t nat -A TEST_MAC-IP -s "+\
|
||||
"%s -m mac --mac-source %s -j ACCEPT"%(ip,mac))
|
||||
|
||||
def blacklist(self):
|
||||
""" Construit les chaines de blackliste (BLACKLIST_{DST,SRC}) """
|
||||
self.anim = anim(" Blackliste")
|
||||
iptables('-F BLACKLIST_DST')
|
||||
iptables('-F BLACKLIST_SRC')
|
||||
self.anim = anim(" Blackliste")
|
||||
iptables('-F BLACKLIST_DST')
|
||||
iptables('-F BLACKLIST_SRC')
|
||||
|
||||
blacklist=[]
|
||||
search = crans_ldap().search('blacklist=*&paiement=%s'% ann_scol)
|
||||
for entite in search['adherent']+search['club']+search['machine']:
|
||||
self.anim.cycle()
|
||||
self.anim.cycle()
|
||||
sanctions = entite.blacklist_actif()
|
||||
if 'upload' in sanctions or 'warez' in sanctions :
|
||||
if 'upload' in sanctions or 'warez' in sanctions :
|
||||
from ldap_crans import machine
|
||||
if entite.__class__ == machine:
|
||||
blacklist+=[entite]
|
||||
|
@ -450,152 +450,152 @@ class firewall_komaz :
|
|||
iptables("-A BLACKLIST_DST -d %s -j REJECT --reject-with icmp-host-prohibited" % machine.ip())
|
||||
iptables("-A BLACKLIST_SRC -s %s -j REJECT --reject-with icmp-host-prohibited" % machine.ip())
|
||||
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
|
||||
def filtre_p2p(self):
|
||||
""" Construit la chaines de filtrage du p2p (FILTRE_P2P) """
|
||||
self.anim = anim(" Filtrage p2p")
|
||||
iptables('-F FILTRE_P2P')
|
||||
self.anim = anim(" Filtrage p2p")
|
||||
iptables('-F FILTRE_P2P')
|
||||
|
||||
# On ne filtre que ce qui passe sur l'interface externe
|
||||
iptables('-A FILTRE_P2P -i %s -o %s -j RETURN' % (self.eth_int, self.eth_int) )
|
||||
# On ne filtre que ce qui passe sur l'interface externe
|
||||
iptables('-A FILTRE_P2P -i %s -o %s -j RETURN' % (self.eth_int, self.eth_int) )
|
||||
|
||||
for port in self.ports_p2p :
|
||||
iptables('-A FILTRE_P2P -p tcp --dport %s -j REJECT --reject-with icmp-admin-prohibited' % port )
|
||||
iptables('-A FILTRE_P2P -p udp --dport %s -j REJECT --reject-with icmp-admin-prohibited' % port )
|
||||
self.anim.cycle()
|
||||
for port in self.ports_p2p :
|
||||
iptables('-A FILTRE_P2P -p tcp --dport %s -j REJECT --reject-with icmp-admin-prohibited' % port )
|
||||
iptables('-A FILTRE_P2P -p udp --dport %s -j REJECT --reject-with icmp-admin-prohibited' % port )
|
||||
self.anim.cycle()
|
||||
|
||||
for filtre in self.filtres_p2p :
|
||||
iptables('-A FILTRE_P2P %s -j REJECT --reject-with icmp-admin-prohibited' % filtre)
|
||||
self.anim.cycle()
|
||||
for filtre in self.filtres_p2p :
|
||||
iptables('-A FILTRE_P2P %s -j REJECT --reject-with icmp-admin-prohibited' % filtre)
|
||||
self.anim.cycle()
|
||||
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
self.anim.reinit()
|
||||
print OK
|
||||
|
||||
def port_maj(self,ip_list) :
|
||||
""" Mise à jour des ports pour les ip fournies """
|
||||
# Note : système bourrin (on efface les chaines et on refait)
|
||||
# mais rapide et efficace (si qqn veut se casser le cul à
|
||||
# un système aussi délicat que pour la correspondance MAC-IP...)
|
||||
# -- Fred
|
||||
serveur_maj = False
|
||||
adh_maj = False
|
||||
for ip in ip_list :
|
||||
if AddrInNet(ip,self.zone_serveur) :
|
||||
serveur_maj = True
|
||||
else :
|
||||
adh_maj = True
|
||||
if serveur_maj and adh_maj :
|
||||
break
|
||||
to_do=[]
|
||||
if serveur_maj :
|
||||
to_do += [ self.serveurs_vers_ext, self.ext_vers_serveurs ]
|
||||
""" Mise à jour des ports pour les ip fournies """
|
||||
# Note : système bourrin (on efface les chaines et on refait)
|
||||
# mais rapide et efficace (si qqn veut se casser le cul à
|
||||
# un système aussi délicat que pour la correspondance MAC-IP...)
|
||||
# -- Fred
|
||||
serveur_maj = False
|
||||
adh_maj = False
|
||||
for ip in ip_list :
|
||||
if AddrInNet(ip,self.zone_serveur) :
|
||||
serveur_maj = True
|
||||
else :
|
||||
adh_maj = True
|
||||
if serveur_maj and adh_maj :
|
||||
break
|
||||
to_do=[]
|
||||
if serveur_maj :
|
||||
to_do += [ self.serveurs_vers_ext, self.ext_vers_serveurs ]
|
||||
|
||||
if adh_maj :
|
||||
to_do += [ self.crans_vers_ext, self.ext_vers_crans ]
|
||||
if adh_maj :
|
||||
to_do += [ self.crans_vers_ext, self.ext_vers_crans ]
|
||||
|
||||
for tache in to_do :
|
||||
self.__exception_catcher(tache)
|
||||
for tache in to_do :
|
||||
self.__exception_catcher(tache)
|
||||
|
||||
# envoi d'un mail à roots
|
||||
try :
|
||||
from mail import mail_details
|
||||
machines = []
|
||||
db = crans_ldap()
|
||||
for ip in ip_list :
|
||||
machines += db.search('ipHostNumber=%s' % ip)['machine']
|
||||
mail_details(machines, Subject = 'Modification du firewall de komaz concernant une machine')
|
||||
#mail_details(machines, To = ['quenelle'], Subject = 'Modification du firewall du CR@NS', no_ascii = True)
|
||||
except :
|
||||
pass
|
||||
# envoi d'un mail à roots
|
||||
try :
|
||||
from mail import mail_details
|
||||
machines = []
|
||||
db = crans_ldap()
|
||||
for ip in ip_list :
|
||||
machines += db.search('ipHostNumber=%s' % ip)['machine']
|
||||
mail_details(machines, Subject = 'Modification du firewall de komaz concernant une machine')
|
||||
#mail_details(machines, To = ['quenelle'], Subject = 'Modification du firewall du CR@NS', no_ascii = True)
|
||||
except :
|
||||
pass
|
||||
|
||||
def mac_ip_maj(self,ip_list) :
|
||||
""" Mise à jour de la correspondance MAC-IP pour les ip fournies """
|
||||
## Que faut-il faire ?
|
||||
self.anim = anim(' Analyse travail à effectuer')
|
||||
if ip_list == [''] :
|
||||
print OK + ' (rien à faire)'
|
||||
return
|
||||
""" Mise à jour de la correspondance MAC-IP pour les ip fournies """
|
||||
## Que faut-il faire ?
|
||||
self.anim = anim(' Analyse travail à effectuer')
|
||||
if ip_list == [''] :
|
||||
print OK + ' (rien à faire)'
|
||||
return
|
||||
|
||||
mac_ip_maj = {}
|
||||
serveur_maj = False
|
||||
for ip in ip_list :
|
||||
machine = crans_ldap().search('ip=%s'% ip)['machine']
|
||||
if not machine :
|
||||
# Destruction des occurences
|
||||
if AddrInNet(ip,self.zone_serveur) :
|
||||
serveur_maj = True
|
||||
else :
|
||||
mac_ip_maj[ip] = None
|
||||
mac_ip_maj = {}
|
||||
serveur_maj = False
|
||||
for ip in ip_list :
|
||||
machine = crans_ldap().search('ip=%s'% ip)['machine']
|
||||
if not machine :
|
||||
# Destruction des occurences
|
||||
if AddrInNet(ip,self.zone_serveur) :
|
||||
serveur_maj = True
|
||||
else :
|
||||
mac_ip_maj[ip] = None
|
||||
|
||||
elif len(machine) == 1 :
|
||||
# Mise à jour de la machine
|
||||
if AddrInNet(ip,self.zone_serveur) :
|
||||
serveur_maj = True
|
||||
else :
|
||||
# Il faut avoir payé ou être une machine du crans
|
||||
if crans_ldap().search('paiement=ok&ip=%s'% ip)['machine'] or \
|
||||
machine[0].proprietaire().__class__ == crans :
|
||||
mac_ip_maj[ip] = machine[0]
|
||||
else :
|
||||
mac_ip_maj[ip] = None
|
||||
else :
|
||||
print WARNING
|
||||
if debug :
|
||||
sys.stderr.write("Plusieurs machines avec l'IP %s" % ip)
|
||||
elif len(machine) == 1 :
|
||||
# Mise à jour de la machine
|
||||
if AddrInNet(ip,self.zone_serveur) :
|
||||
serveur_maj = True
|
||||
else :
|
||||
# Il faut avoir payé ou être une machine du crans
|
||||
if crans_ldap().search('paiement=ok&ip=%s'% ip)['machine'] or \
|
||||
machine[0].proprietaire().__class__ == crans :
|
||||
mac_ip_maj[ip] = machine[0]
|
||||
else :
|
||||
mac_ip_maj[ip] = None
|
||||
else :
|
||||
print WARNING
|
||||
if debug :
|
||||
sys.stderr.write("Plusieurs machines avec l'IP %s" % ip)
|
||||
|
||||
print OK
|
||||
print OK
|
||||
|
||||
## Traitement
|
||||
# Seveurs
|
||||
if serveur_maj :
|
||||
# Bourrin mais vu la rapidité...
|
||||
self.__exception_catcher(self.serveurs_vers_ext)
|
||||
## Traitement
|
||||
# Seveurs
|
||||
if serveur_maj :
|
||||
# Bourrin mais vu la rapidité...
|
||||
self.__exception_catcher(self.serveurs_vers_ext)
|
||||
|
||||
# Correspondance MAC-IP
|
||||
if mac_ip_maj :
|
||||
def procedure() :
|
||||
warn = ''
|
||||
self.anim = anim(' Actualisation TEST_MAC-IP')
|
||||
for regle in iptables("-t nat -L TEST_MAC-IP -n").split('\n')[2:] :
|
||||
regle = regle.split()
|
||||
ip = regle[3]
|
||||
mac = regle[6].lower()
|
||||
if ip in mac_ip_maj.keys() :
|
||||
# La règle correspond à une ip à mettre à jour
|
||||
machine = mac_ip_maj[ip]
|
||||
try :
|
||||
if not machine :
|
||||
# Il faut détruire cette entrée
|
||||
iptables("-t nat -D TEST_MAC-IP -s %s -m mac --mac-source %s -j ACCEPT" % (ip, mac))
|
||||
else :
|
||||
if ( machine.ipsec() and mac!=self.mac_wifi ) \
|
||||
or ( not machine.ipsec() and mac != machine.mac() ) :
|
||||
# La correspondance MAC-IP est fausse => on ajoute la bonne règle
|
||||
self.__test_mac_ip(machine)
|
||||
# Supression de l'ancienne ligne
|
||||
iptables("-t nat -D TEST_MAC-IP -s %s -m mac --mac-source %s -j ACCEPT" % (ip, mac))
|
||||
# Correspondance MAC-IP
|
||||
if mac_ip_maj :
|
||||
def procedure() :
|
||||
warn = ''
|
||||
self.anim = anim(' Actualisation TEST_MAC-IP')
|
||||
for regle in iptables("-t nat -L TEST_MAC-IP -n").split('\n')[2:] :
|
||||
regle = regle.split()
|
||||
ip = regle[3]
|
||||
mac = regle[6].lower()
|
||||
if ip in mac_ip_maj.keys() :
|
||||
# La règle correspond à une ip à mettre à jour
|
||||
machine = mac_ip_maj[ip]
|
||||
try :
|
||||
if not machine :
|
||||
# Il faut détruire cette entrée
|
||||
iptables("-t nat -D TEST_MAC-IP -s %s -m mac --mac-source %s -j ACCEPT" % (ip, mac))
|
||||
else :
|
||||
if ( machine.ipsec() and mac!=self.mac_wifi ) \
|
||||
or ( not machine.ipsec() and mac != machine.mac() ) :
|
||||
# La correspondance MAC-IP est fausse => on ajoute la bonne règle
|
||||
self.__test_mac_ip(machine)
|
||||
# Supression de l'ancienne ligne
|
||||
iptables("-t nat -D TEST_MAC-IP -s %s -m mac --mac-source %s -j ACCEPT" % (ip, mac))
|
||||
|
||||
# Toutes les autres occurences devront être détruites
|
||||
mac_ip_maj[ip]=None
|
||||
# Toutes les autres occurences devront être détruites
|
||||
mac_ip_maj[ip]=None
|
||||
|
||||
|
||||
except IptablesError, c :
|
||||
warn += c
|
||||
except IptablesError, c :
|
||||
warn += c
|
||||
|
||||
# Ajout des machines qui n'étaient pas dans le firewall
|
||||
for machine in mac_ip_maj.values() :
|
||||
if machine :
|
||||
self.__test_mac_ip(machine)
|
||||
# Ajout des machines qui n'étaient pas dans le firewall
|
||||
for machine in mac_ip_maj.values() :
|
||||
if machine :
|
||||
self.__test_mac_ip(machine)
|
||||
|
||||
if warn :
|
||||
print WARNING
|
||||
sys.stdout.write(warn)
|
||||
else :
|
||||
print OK
|
||||
if warn :
|
||||
print WARNING
|
||||
sys.stdout.write(warn)
|
||||
else :
|
||||
print OK
|
||||
|
||||
self.__exception_catcher(procedure)
|
||||
self.__exception_catcher(procedure)
|
||||
|
||||
if __name__ == '__main__' :
|
||||
# Chaines pouvant être recontruites
|
||||
|
@ -605,9 +605,9 @@ if __name__ == '__main__' :
|
|||
'ext_vers_crans', 'crans_vers_ext' , 'filtre_p2p' ]
|
||||
|
||||
def __usage(txt=None) :
|
||||
if txt!=None : cprint(txt,'gras')
|
||||
if txt!=None : cprint(txt,'gras')
|
||||
|
||||
print """Usage:
|
||||
print """Usage:
|
||||
%(p)s start : Construction du firewall.
|
||||
%(p)s restart : Reconstruction du firewall.
|
||||
%(p)s stop : Arrêt du firewall.
|
||||
|
@ -616,18 +616,18 @@ Les chaines pouvant
|
|||
%(chaines)s
|
||||
Pour reconfiguration d'IPs particulières, utiliser generate. """ % \
|
||||
{ 'p' : sys.argv[0].split('/')[-1] , 'chaines' : '\n '.join(chaines) }
|
||||
sys.exit(-1)
|
||||
sys.exit(-1)
|
||||
|
||||
# Bons arguments ?
|
||||
if len(sys.argv) == 1 :
|
||||
__usage()
|
||||
__usage()
|
||||
for arg in sys.argv[1:] :
|
||||
if arg in [ 'stop', 'restart', 'start' ] and len(sys.argv) != 2 :
|
||||
__usage("L'argument %s ne peut être employé que seul." % arg)
|
||||
if arg in [ 'stop', 'restart', 'start' ] and len(sys.argv) != 2 :
|
||||
__usage("L'argument %s ne peut être employé que seul." % arg)
|
||||
|
||||
if arg not in [ 'stop', 'restart', 'start' ] + chaines :
|
||||
__usage("L'argument %s est inconnu." % arg)
|
||||
if arg not in [ 'stop', 'restart', 'start' ] + chaines :
|
||||
__usage("L'argument %s est inconnu." % arg)
|
||||
|
||||
fw = firewall_komaz()
|
||||
for arg in sys.argv[1:] :
|
||||
eval('fw.%s()' % arg)
|
||||
eval('fw.%s()' % arg)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue