[whos] Ajout d'un filtre "serveurs crans" et d'un filtre "adm"
This commit is contained in:
parent
62a6272968
commit
c7f4fd6cc8
1 changed files with 72 additions and 38 deletions
110
gestion/whos.py
110
gestion/whos.py
|
@ -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'historique des déconnexions affichées (défaut %(limit_aff_blacklist)i)
|
||||
-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
|
||||
"""
|
||||
|
||||
|
@ -352,52 +354,68 @@ def list_machines(machines) :
|
|||
largeur = [5, 5, 4, '*', larg, 17, 10],
|
||||
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
|
||||
* rid
|
||||
* nom
|
||||
* adresse IP
|
||||
* adresse IPv4/IPv6
|
||||
* adresse MAC
|
||||
* État
|
||||
* puissance
|
||||
* canal
|
||||
* lieu (la première remarque en fait)
|
||||
|
||||
Pour les bornes :
|
||||
* État
|
||||
* puissance
|
||||
* canal
|
||||
* lieu (la première remarque en fait)
|
||||
Pour le reste :
|
||||
* ??
|
||||
"""
|
||||
data = []
|
||||
|
||||
# Copie locale triée par nom
|
||||
bornes = bornes[:]
|
||||
bornes.sort(lambda x, y: cmp(x.nom(), y.nom()))
|
||||
machines = machines[:]
|
||||
machines.sort(lambda x, y: cmp(x.nom(), y.nom()))
|
||||
|
||||
ok = u'\x1b[1;32mu\x1b[1;0m'
|
||||
nok = u'\x1b[1;31md\x1b[1;0m'
|
||||
for b in bornes :
|
||||
for b in machines:
|
||||
t, bl = __bases_machines(b)
|
||||
|
||||
# Données
|
||||
try :
|
||||
l = [x for x in b.info() if not x[0]=='<'][0]
|
||||
if len(l) > 11 :
|
||||
l = l[0:11]
|
||||
except :
|
||||
l = u'????'
|
||||
if t == 'borne':
|
||||
try :
|
||||
l = [x for x in b.info() if not x[0]=='<'][0]
|
||||
if len(l) > 11 :
|
||||
l = l[0:11]
|
||||
except :
|
||||
l = u'????'
|
||||
|
||||
if '-' in b.puissance() :
|
||||
puiss = coul(b.puissance(),'rouge')
|
||||
else :
|
||||
puiss = b.puissance()
|
||||
if '-' in b.puissance() :
|
||||
puiss = coul(b.puissance(),'rouge')
|
||||
else :
|
||||
puiss = b.puissance()
|
||||
|
||||
if aff_ipv6:
|
||||
data.append([b.id(), b.rid(), b.nom().split('.')[0], b.ipv6(), b.mac(), b.canal(), puiss, b.prise(), l])
|
||||
else:
|
||||
data.append([b.id(), b.rid(), b.nom().split('.')[0], b.ip(), b.mac(), b.canal(), puiss, b.prise(), l])
|
||||
|
||||
titre = [u'mid', u'rid', u'Nom', u'Adresse IP', u'Adresse MAC', u'Can', u'P', u'Pris', u'Lieu']
|
||||
largeur = [5, 5, 16, 22, 17, 1, 5, 3, 4, '*']
|
||||
alignement = ['d', 'd', 'c', 'c', 'c', 'c', 'c', 'c', 'g', 'c']
|
||||
|
||||
if aff_ipv6:
|
||||
data.append([b.id(), b.rid(), b.nom().split('.')[0], b.ipv6(), b.mac(), b.canal(), puiss, b.prise(), l])
|
||||
else:
|
||||
data.append([b.id(), b.rid(), b.nom().split('.')[0], b.ip(), b.mac(), b.canal(), puiss, b.prise(), l])
|
||||
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()])
|
||||
|
||||
return u"Can=canaux, P=puissance, E=état\n" + \
|
||||
tableau(data,
|
||||
titre = [u'mid', u'rid', u'Nom', u'Adresse IP', u'Adresse MAC', u'Can', u'P', u'Pris', u'Lieu'],
|
||||
largeur = [5, 5, 16, 22, 17, 1, 5, 3, 4, '*'],
|
||||
alignement = ['d', 'd', 'c', 'c', 'c', 'c', 'c', 'c', 'g', 'c'])
|
||||
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) :
|
||||
"""
|
||||
|
@ -1125,17 +1143,19 @@ def __recherche() :
|
|||
__usage_brief()
|
||||
|
||||
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 :
|
||||
__usage_brief(unicode(msg))
|
||||
|
||||
|
||||
# Traitement des options
|
||||
only_adh=0
|
||||
only_mac=0
|
||||
only_club=0
|
||||
only_bornes=0
|
||||
only_crans=0
|
||||
only_adh = 0
|
||||
only_mac = 0
|
||||
only_club = 0
|
||||
only_bornes = 0
|
||||
only_crans = 0
|
||||
only_servers = 0
|
||||
only_adm = 0
|
||||
mtech = 0
|
||||
|
||||
for opt, val in options :
|
||||
|
@ -1182,6 +1202,20 @@ def __recherche() :
|
|||
elif arg[0].find('=')!=-1 :
|
||||
# Recherche avec critères
|
||||
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' ] :
|
||||
# Format affichage des machines
|
||||
mtech = 1
|
||||
|
@ -1240,13 +1274,13 @@ def __recherche() :
|
|||
cprint(u"Aucun résultat trouvé.")
|
||||
sys.exit(3)
|
||||
# L'affichage souhaité a été précisé ?
|
||||
elif only_bornes :
|
||||
elif only_bornes or only_servers or only_adm:
|
||||
if not res['machine'] :
|
||||
cprint(u'Aucun résultat à afficher')
|
||||
sys.exit(4)
|
||||
else :
|
||||
if len(res['machine']) > limit_aff_details :
|
||||
cprint(list_bornes(res['machine']))
|
||||
cprint(list_spec(res['machine']))
|
||||
else :
|
||||
aff(res['machine'])
|
||||
elif only_adh :
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue