diff --git a/gestion/tools/whosthere.py b/gestion/tools/whosthere.py index 006da5a4..882af1a9 100755 --- a/gestion/tools/whosthere.py +++ b/gestion/tools/whosthere.py @@ -9,7 +9,8 @@ import collections import os import xml.dom.minidom -from gestion.ldap_crans import crans_ldap, AssociationCrans +from lc_ldap import shortcuts + from gestion.hptools import hpswitch, ConversationError from gestion.affich_tools import cprint import gestion.affichage as affichage @@ -28,6 +29,7 @@ STATE_DESCR = collections.OrderedDict([ DN_CLUB_CRANS = 'cid=35,' DN_CLUB_BDE = 'cid=1,' +DN_CRANS = 'ou=data,dc=crans,dc=org' WIFIMAP_DIR = os.getenv('DBG_WIFIMAP_DB', '/usr/scripts/var/wifi_xml') @@ -35,10 +37,13 @@ def pretty_name(item): """Affiche un joli nom pour un objet ldap (adh ou machine)""" v = "" - if hasattr(item, 'nom'): - v = item.nom() - if hasattr(item, 'prenom'): - v = item.prenom() + " " + v + try: + nom = unicode(item['nom'][0]) + prenom = unicode(item['prenom'][0]) + v = prenom + u" " + nom + except KeyError: + nom = unicode(item['host'][0]) + v = nom v = v.replace('.wifi.crans.org', ' (WiFi)') v = v.replace('.adm.crans.org', '') v = v.replace('.crans.org', '') @@ -50,7 +55,7 @@ def show_liste_by_prop(liste): by_owner = dict() for machine in liste: - # ldap_crans or lc_ldap + # ldapcrans(déprécié) or lc_ldap owner = (getattr(machine, 'proprietaire', None) or \ getattr(machine, 'proprio', None))() if owner.dn not in by_owner: @@ -90,26 +95,29 @@ class WhosThere(object): def populate_from_mac(self, mac): """Rempli à partir de la mac""" - fm = self.db.search("mac=%s" % mac) + fm = self.db.search(u"macAddress=%s" % mac) res = self._res if mac in self.expected: return - if fm['machine']: - m = fm['machine'][0] - if m.nom() in self.expected: - return - proprio = m.proprietaire() - if isinstance(proprio, AssociationCrans) or proprio.dn.startswith(DN_CLUB_CRANS): + if fm: + m = fm[0] + proprio = m.proprio() + if proprio.dn == DN_CRANS or proprio.dn.startswith(DN_CLUB_CRANS): key = 'crans' - elif hasattr(proprio, 'droits') and proprio.droits(): - key = 'ma' elif proprio.dn.startswith(DN_CLUB_BDE): key = 'bde' else: - if self._ignore_inactive: - if fm['machineWifi'] or self._ignore_wifi_only: - return - key = 'adh' + try: + droits = proprio['droits'] + except KeyError: + droits = False + if droits: + key = 'ma' + else: + if self._ignore_inactive: + if unicode(m['objectClass'][0]) == u'machineWifi' or self._ignore_wifi_only: + return + key = 'adh' res[key].append(m) else: res['unknown_macs'].append(mac) @@ -151,7 +159,7 @@ class WhosThere(object): 'unknown_macs': [], 'ttyfound': 0, } - self.db = crans_ldap() + self.db = shortcuts.lc_ldap_readonly() self.do_scan() return self._res