diff --git a/utils/list_exempt.py b/utils/list_exempt.py index 34e7d9d4..0d0cac5b 100755 --- a/utils/list_exempt.py +++ b/utils/list_exempt.py @@ -12,12 +12,12 @@ def make_output(ldap): machines_avec_exemption = ldap.search(u"exempt=*") output = [] - for m in machines_avec_exemption: + for machine in machines_avec_exemption: # texte pour la machine - txt = u'' - txt += u'Propriétaire : %s\n' % m.proprio() - txt += u'Machine : %s\n' % m['host'][0] - txt += u'destination : %s\n' % ', '.join([unicode(i) for i in m['exempt']]) + txt = u'' + txt += u'Propriétaire : %s\n' % machine.proprio() + txt += u'Machine : %s\n' % machine['host'][0] + txt += u'destination : %s\n' % ', '.join([unicode(i) for i in machine['exempt']]) output.append(txt.strip()) return output @@ -26,4 +26,4 @@ if __name__ == '__main__': LDAP = shortcuts.lc_ldap_readonly() OUTPUT = make_output(LDAP) - print '\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(OUTPUT).encode(out_encoding) + print u'\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(OUTPUT).encode(out_encoding) diff --git a/utils/list_firewall.py b/utils/list_firewall.py index 8657e022..d4040761 100755 --- a/utils/list_firewall.py +++ b/utils/list_firewall.py @@ -1,32 +1,43 @@ #!/bin/bash /usr/scripts/python.sh # -*- coding: utf-8 -*- +# +# list_firewall.py --- Liste les machines disposant de droits +# particuliers en ce qui concerne leurs ports accessibles. +"""Liste les machines dont certains ports sont whielistés par +le parefeu""" from lc_ldap import shortcuts +from config.encoding import out_encoding -ldap = shortcuts.lc_ldap_readonly() +def make_output(ldap): + """Génère un texte à afficher""" + machines_speciales = ldap.search(u"(|(portTCPin=*)(portTCPout=*)(portUDPin=*)(portUDPout=*))") -machines = ldap.search(u"(|(portTCPin=*)(portTCPout=*)(portUDPin=*)(portUDPout=*))") + output = [] -txts = [] + for machine in machines_speciales: + # On se fiche des machines crans + if machine['objectClass'][0] not in ["machineFixe", "machineWifi"]: + continue -for m in machines : - # On se fiche des machines crans - if m['objectClass'][0] not in ["machineFixe","machineWifi"]: - continue + # texte pour la machine + txt = u'' + txt += u'Propriétaire : %s\n' % machine.proprio() + txt += u'Machine : %s\n' % machine['host'][0] + if machine['portTCPin']: + txt += u'ports TCP in : %s\n' % ' '.join([unicode(port) for port in machine['portTCPin']]) + if machine['portTCPout']: + txt += u'ports TCP out : %s\n' % ' '.join([unicode(port) for port in machine['portTCPout']]) + if machine['portUDPin']: + txt += u'ports UDP in : %s\n' % ' '.join([unicode(port) for port in machine['portUDPin']]) + if machine['portUDPout']: + txt += u'ports UDP out : %s\n' % ' '.join([unicode(port) for port in machine['portTCPout']]) - # texte pour la machine - 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']]) + output.append(txt.strip()) + return output - txts.append(txt.strip()) +if __name__ == '__main__': + LDAP = shortcuts.lc_ldap_readonly() + OUTPUT = make_output(LDAP) -print '\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(txts) + print u'\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(OUTPUT).encode(out_encoding)