From 09a720b8277747121047bdfd8e7f6ae8f50ff2ac Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 17 Aug 2015 13:24:28 +0200 Subject: [PATCH] =?UTF-8?q?list=5Ffirewall=20passe=20=C3=A0=20lc=5Fldap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestion/tools/list_exempt.py | 2 +- gestion/tools/list_firewall.py | 44 +++++++++++++++------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/gestion/tools/list_exempt.py b/gestion/tools/list_exempt.py index c7411fa0..777e59c9 100755 --- a/gestion/tools/list_exempt.py +++ b/gestion/tools/list_exempt.py @@ -13,7 +13,7 @@ for m in machines : # texte pour la machine txt = u'' - txt += u'Propriétaire : %s\n' % m.proprio() + txt += u'Propriétaire : %s\n' % str(m.proprio()).decode('utf8') txt += u'Machine : %s\n' % m['host'][0] txt += u'destination : %s\n' % ', '.join([unicode(i) for i in m['exempt']]) diff --git a/gestion/tools/list_firewall.py b/gestion/tools/list_firewall.py index 39488fdc..8657e022 100755 --- a/gestion/tools/list_firewall.py +++ b/gestion/tools/list_firewall.py @@ -1,38 +1,32 @@ -#! /usr/bin/env python +#!/bin/bash /usr/scripts/python.sh # -*- coding: utf-8 -*- -import sys -sys.path.append('/usr/scripts/gestion') +from lc_ldap import shortcuts -from ldap_crans import crans_ldap, decode, AssociationCrans +ldap = shortcuts.lc_ldap_readonly() -db = crans_ldap() -machines = db.search('portTCPin=*')['machine'] + db.search('portTCPout=*')['machine'] + db.search('portUDPin=*')['machine'] + db.search('portUDPout=*')['machine'] +machines = ldap.search(u"(|(portTCPin=*)(portTCPout=*)(portUDPin=*)(portUDPout=*))") -done = [] txts = [] for m in machines : - # on vérifie qu'on l'a pas encore traité - if m.ip() in done : + # On se fiche des machines crans + if m['objectClass'][0] not in ["machineFixe","machineWifi"]: continue - if m.proprietaire().__class__ == AssociationCrans : - continue - done.append(m.ip()) - + # texte pour la machine - txt = u'' - txt += u'Propriétaire : %s\n' % m.proprietaire().Nom() - txt += u'Machine : %s\n' % m.nom() - if m.portTCPin() : - txt += u'ports TCP in : %s\n' % ' '.join(m.portTCPin()) - if m.portTCPout() : - txt += u'ports TCP out : %s\n' % ' '.join(m.portTCPout()) - if m.portUDPin() : - txt += u'ports UDP in : %s\n' % ' '.join(m.portUDPin()) - if m.portUDPout() : - txt += u'ports UDP out : %s\n' % ' '.join(m.portUDPout()) - + txt = u'' + txt += u'Propriétaire : %s\n' % str(m.proprio()).decode('utf8') + txt += u'Machine : %s\n' % m['host'][0] + if m['portTCPin']: + txt += u'ports TCP in : %s\n' % ' '.join([unicode(port) for port in m['portTCPin']]) + if m['portTCPout']: + txt += u'ports TCP out : %s\n' % ' '.join([unicode(port) for port in m['portTCPout']]) + if m['portUDPin']: + txt += u'ports UDP in : %s\n' % ' '.join([unicode(port) for port in m['portUDPin']]) + if m['portUDPout']: + txt += u'ports UDP out : %s\n' % ' '.join([unicode(port) for port in m['portTCPout']]) + txts.append(txt.strip()) print '\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(txts)