[base, komaz, utils, zamok] Factorisation de code via l'ajout de la methode blacklisted_ips

De plus, on rend le code plus jolie en prenant en compte l'ajout récent de méthodes dans
lc_ldap.
This commit is contained in:
Valentin Samir 2014-02-19 19:35:57 +01:00
parent 63895c98d4
commit cd8ce5c729
4 changed files with 37 additions and 39 deletions

View file

@ -3,7 +3,6 @@
import os
import sys
import socket
import netaddr
import utils
from utils import pretty_print, anim, OK, cprint
@ -96,7 +95,7 @@ class firewall(utils.firewall_tools) :
# for ip in ip_list:
# machine = self.conn.search(u"ipHostNumber=%s" % ip)
# # Est-ce qu'il y a des blacklists hard parmis les blacklists de la machine
# if machine and set([bl.value['type'] for bl in machine[0].blacklist_actif() ]).intersection(config.blacklist_sanctions):
# if machine and set([bl['type'] for bl in machine[0].blacklist_actif() ]).intersection(config.blacklist_sanctions):
# try: self.ipset['blacklist']['hard'].add(ip)
# except IpsetError: pass
# else:
@ -112,15 +111,7 @@ class firewall(utils.firewall_tools) :
if fill_ipset:
anim('\tRestoration de l\'ipset %s' % self.ipset['blacklist']['hard'])
# On récupère la liste de toutes les ips blacklistés hard
bl_hard_ips = set(
str(ip) for ips in
[
machine['ipHostNumber'] for machine in self.blacklisted_machines() if machine['ipHostNumber'] and reduce(lambda x,y: x or y, ( ip.value in netaddr.IPNetwork(n) for n in config.NETs['all'] for ip in machine['ipHostNumber']))
if set([bl.value['type'] for bl in machine.blacklist_actif() ]).intersection(config.blacklist_sanctions)
]
for ip in ips
)
bl_hard_ips = self.blacklisted_ips(config.blacklist_sanctions, config.NETs['all'])
self.ipset['blacklist']['hard'].restore(bl_hard_ips)
print OK