Support des fonctions de whokfet (--all notamment pour les nounous)

This commit is contained in:
Gabriel Detraz 2015-08-18 16:27:34 +02:00
parent 9cb259ea71
commit c0a2697aea

View file

@ -37,6 +37,11 @@ DN_CRANS = 'ou=data,dc=crans,dc=org'
WIFIMAP_DIR = os.getenv('DBG_WIFIMAP_DB', '/usr/scripts/var/wifi_xml') WIFIMAP_DIR = os.getenv('DBG_WIFIMAP_DB', '/usr/scripts/var/wifi_xml')
# Par défaut, l'affichage est limité et on ne prévient pas des machines manquantes
privacy = True
warn = False
def missing_tpe(): def missing_tpe():
"""Envoie un mail si le tpe n'est pas présent avec l'arg --warn-tpe""" """Envoie un mail si le tpe n'est pas présent avec l'arg --warn-tpe"""
dst = 'respbats@crans.org' dst = 'respbats@crans.org'
@ -127,7 +132,7 @@ class WhosThere(object):
if self._ignore_inactive: if self._ignore_inactive:
if unicode(m['objectClass'][0]) == u'machineWifi' or self._ignore_wifi_only: if unicode(m['objectClass'][0]) == u'machineWifi' or self._ignore_wifi_only:
return return
key = 'adh' key = 'adh'
res[key].append(m) res[key].append(m)
else: else:
res['unknown_macs'].append(mac) res['unknown_macs'].append(mac)
@ -265,7 +270,7 @@ class WhoKfet(WhosThere):
] ]
def do_scan(self): def do_scan(self):
self.set_ignore_inactive(False, wifi_only=False) self.set_ignore_inactive(privacy, wifi_only=privacy)
self.populate_from_switch('backbone.adm.crans.org', 21) self.populate_from_switch('backbone.adm.crans.org', 21)
class Who2B(WhosThere): class Who2B(WhosThere):
@ -283,7 +288,7 @@ class Who2B(WhosThere):
def do_scan(self): def do_scan(self):
# Tous les gens au 2B sont supposés actifs (local technique quoi) # Tous les gens au 2B sont supposés actifs (local technique quoi)
# mais on cache quand-même les personnes connectées en WiFi # mais on cache quand-même les personnes connectées en WiFi
self.set_ignore_inactive(True, wifi_only=True) self.set_ignore_inactive(privacy, wifi_only=privacy)
self.populate_from_switch('backbone.adm.crans.org', 33) self.populate_from_switch('backbone.adm.crans.org', 33)
self.tty_server=u"vo" self.tty_server=u"vo"
self.populate_from_tty() self.populate_from_tty()
@ -299,7 +304,7 @@ class WhoDAlembert(WhosThere):
class Who4J(WhosThere): class Who4J(WhosThere):
name = u"4J" name = u"4J"
def do_scan(self): def do_scan(self):
self.set_ignore_inactive(True, wifi_only=True) self.set_ignore_inactive(privacy, wifi_only=privacy)
self.populate_from_switch('batj-3.adm.crans.org', 7) self.populate_from_switch('batj-3.adm.crans.org', 7)
self.tty_server=u"cochon" self.tty_server=u"cochon"
self.populate_from_tty() self.populate_from_tty()
@ -313,12 +318,22 @@ if __name__ == '__main__':
} }
if '--warn-tpe' in sys.argv: if '--warn-tpe' in sys.argv:
warn=['tpe'] warn=['tpe']
else: if '--all' in sys.argv:
warn=False cur_user = os.getenv("SUDO_USER") or os.getenv("USER")
if cur_user:
ldap = shortcuts.lc_ldap_readonly()
user = ldap.search(u'uid=%s' % cur_user)
if u'Nounou' in user[0]['droits']:
privacy = False
else:
cprint("Vous n'avez pas les droits requis, --all ignoré.", 'jaune')
for what in sys.argv[1:]: for what in sys.argv[1:]:
try: try:
name = where[what.lower()] name = where[what.lower()]
except KeyError: except KeyError:
print "Usage: whosthere.py <local>\n Locaux : %s" % (", ".join(where.keys())) if what!='--all' and what!='--warn-tpe':
sys.exit(1) print "Usage: whosthere.py <local>\n Locaux : %s" % (", ".join(where.keys()))
sys.exit(1)
else:
continue
name().summary() name().summary()