[whos] Ajout d'un filtre "serveurs crans" et d'un filtre "adm"

This commit is contained in:
Pierre-Elliott Bécue 2013-03-14 15:55:31 +01:00
parent 62a6272968
commit c7f4fd6cc8

View file

@ -38,6 +38,8 @@ d'historique affichées (défaut %(limit_aff_historique)i)
-d <num> ou --limit-blacklist=<num> : limitation du nombre de lignes -d <num> ou --limit-blacklist=<num> : limitation du nombre de lignes
d'historique des déconnexions affichées (défaut %(limit_aff_blacklist)i) d'historique des déconnexions affichées (défaut %(limit_aff_blacklist)i)
-s ou --ssh : affiche les fingerprint ssh des machines -s ou --ssh : affiche les fingerprint ssh des machines
--servers : limite les résultats aux servers
--adm : limite les résultats aux machines adm
-6 ou --ipv6 : affiche les ipv6 dans l'affichage synthétique -6 ou --ipv6 : affiche les ipv6 dans l'affichage synthétique
""" """
@ -352,30 +354,34 @@ def list_machines(machines) :
largeur = [5, 5, 4, '*', larg, 17, 10], largeur = [5, 5, 4, '*', larg, 17, 10],
alignement = ['d', 'd', 'c', 'c', 'c', 'c', 'c']) alignement = ['d', 'd', 'c', 'c', 'c', 'c', 'c'])
def list_bornes(bornes) : def list_spec(machines) :
""" """
Formatage sous forme d'un tableau des propriétés de la liste de bornes wifi : Formatage sous forme d'un tableau des propriétés de la liste de machines spéciales :
* mid * mid
* rid
* nom * nom
* adresse IP * adresse IPv4/IPv6
* adresse MAC * adresse MAC
Pour les bornes :
* État * État
* puissance * puissance
* canal * canal
* lieu (la première remarque en fait) * lieu (la première remarque en fait)
Pour le reste :
* ??
""" """
data = [] data = []
# Copie locale triée par nom # Copie locale triée par nom
bornes = bornes[:] machines = machines[:]
bornes.sort(lambda x, y: cmp(x.nom(), y.nom())) machines.sort(lambda x, y: cmp(x.nom(), y.nom()))
ok = u'\x1b[1;32mu\x1b[1;0m' for b in machines:
nok = u'\x1b[1;31md\x1b[1;0m'
for b in bornes :
t, bl = __bases_machines(b) t, bl = __bases_machines(b)
# Données # Données
if t == 'borne':
try : try :
l = [x for x in b.info() if not x[0]=='<'][0] l = [x for x in b.info() if not x[0]=='<'][0]
if len(l) > 11 : if len(l) > 11 :
@ -393,11 +399,23 @@ def list_bornes(bornes) :
else: else:
data.append([b.id(), b.rid(), b.nom().split('.')[0], b.ip(), b.mac(), b.canal(), puiss, b.prise(), l]) data.append([b.id(), b.rid(), b.nom().split('.')[0], b.ip(), b.mac(), b.canal(), puiss, b.prise(), l])
return u"Can=canaux, P=puissance, E=état\n" + \ titre = [u'mid', u'rid', u'Nom', u'Adresse IP', u'Adresse MAC', u'Can', u'P', u'Pris', u'Lieu']
tableau(data, largeur = [5, 5, 16, 22, 17, 1, 5, 3, 4, '*']
titre = [u'mid', u'rid', u'Nom', u'Adresse IP', u'Adresse MAC', u'Can', u'P', u'Pris', u'Lieu'], alignement = ['d', 'd', 'c', 'c', 'c', 'c', 'c', 'c', 'g', 'c']
largeur = [5, 5, 16, 22, 17, 1, 5, 3, 4, '*'],
alignement = ['d', 'd', 'c', 'c', 'c', 'c', 'c', 'c', 'g', 'c']) else:
if aff_ipv6:
data.append([b.id(), b.rid(), t, b.nom().split('.')[0], b.ipv6(), b.mac()])
else:
data.append([b.id(), b.rid(), t, b.nom().split('.')[0], b.ip(), b.mac()])
titre = [u'mid', u'rid', u'Type', u'Nom', u'Adresse IP', u'Adresse MAC']
largeur = [5, 5, 10, 20, '*', 17]
alignement = ['d', 'd', 'd', 'c', 'c', 'c']
output = tableau(data, titre=titre, largeur=largeur, alignement=alignement)
return output
def adher_details(adher) : def adher_details(adher) :
""" """
@ -1125,17 +1143,19 @@ def __recherche() :
__usage_brief() __usage_brief()
try : try :
options, arg = getopt.getopt(sys.argv[1:], 'hamcs6tbil:L:d:', [ 'debug', 'help', 'adherent', 'machine', 'club' , 'tech', 'bornes', 'limit=', 'limit-historique=', 'limit-blacklist=', 'ipsec', 'crans', 'ssh', 'ipv6' ]) options, arg = getopt.getopt(sys.argv[1:], 'hamcs6tbil:L:d:', [ 'debug', 'help', 'adherent', 'machine', 'club' , 'tech', 'bornes', 'limit=', 'limit-historique=', 'limit-blacklist=', 'ipsec', 'crans', 'ssh', 'ipv6', 'servers', 'adm' ])
except getopt.error, msg : except getopt.error, msg :
__usage_brief(unicode(msg)) __usage_brief(unicode(msg))
# Traitement des options # Traitement des options
only_adh=0 only_adh = 0
only_mac=0 only_mac = 0
only_club=0 only_club = 0
only_bornes=0 only_bornes = 0
only_crans=0 only_crans = 0
only_servers = 0
only_adm = 0
mtech = 0 mtech = 0
for opt, val in options : for opt, val in options :
@ -1182,6 +1202,20 @@ def __recherche() :
elif arg[0].find('=')!=-1 : elif arg[0].find('=')!=-1 :
# Recherche avec critères # Recherche avec critères
arg += [ '&canal=*' ] arg += [ '&canal=*' ]
elif opt in [ '--servers' ]:
only_servers = 1
cprint(u'Affichage limité aux servers crans')
if not arg:
arg = [ 'ip=138.231.136.*' ]
elif arg[0].find('=') != -1:
arg += [ '&ip=138.231.136.*' ]
elif opt in [ '--adm' ]:
cprint(u'Affichage limité aux machines adm')
only_adm = 1
if not arg:
arg = [ 'host=*.adm.crans.org' ]
elif arg[0].find('=') != -1:
arg += [ '&host=*.adm.crans.org' ]
elif opt in [ '-t', '--tech' ] : elif opt in [ '-t', '--tech' ] :
# Format affichage des machines # Format affichage des machines
mtech = 1 mtech = 1
@ -1240,13 +1274,13 @@ def __recherche() :
cprint(u"Aucun résultat trouvé.") cprint(u"Aucun résultat trouvé.")
sys.exit(3) sys.exit(3)
# L'affichage souhaité a été précisé ? # L'affichage souhaité a été précisé ?
elif only_bornes : elif only_bornes or only_servers or only_adm:
if not res['machine'] : if not res['machine'] :
cprint(u'Aucun résultat à afficher') cprint(u'Aucun résultat à afficher')
sys.exit(4) sys.exit(4)
else : else :
if len(res['machine']) > limit_aff_details : if len(res['machine']) > limit_aff_details :
cprint(list_bornes(res['machine'])) cprint(list_spec(res['machine']))
else : else :
aff(res['machine']) aff(res['machine'])
elif only_adh : elif only_adh :