diff --git a/Brie/brie/controllers/search.py b/Brie/brie/controllers/search.py index 6c052a0..c595a6a 100644 --- a/Brie/brie/controllers/search.py +++ b/Brie/brie/controllers/search.py @@ -76,6 +76,83 @@ class SearchController(AuthenticatedBaseController): #end def + @expose("brie.templates.search.member") + def mac(self, residence, mac): + residence_dn = Residences.get_dn_by_name(self.user, residence) + machine = Machine.get_dhcp_by_mac(self.user, residence_dn, mac) + + if machine is None: + return self.error_no_entry() + + machine = machine.dn.split(',') + + i = 0 + member_dn = "" + for sub in machine: + if i >= 3: + if member_dn != "": + member_dn += "," + #end if + member_dn += sub + #end if + i += 1 + #end for + + member = Member.get_by_dn(self.user, member_dn) + + if member is None: + return self.error_no_entry() + #end if + + redirect("/show/member/"+ residence +"/" + member.uid.first()) + #end def + + + @expose("brie.templates.search.ip") + def ip(self, residence, ip): + residence_dn = Residences.get_dn_by_name(self.user, residence) + machines = Machine.get_dns_by_ip(self.user, residence_dn, ip) + + if len(machines) == 0: + return self.error_no_entry() + + results = [] + + for machine in machines: + membre_dn = machine.dn.split(',') + + i = 0 + member_dn = "" + for sub in membre_dn: + if i >= 3: + if member_dn != "": + member_dn += "," + #end if + member_dn += sub + #end if + i += 1 + #end for + + member = Member.get_by_dn(self.user, member_dn) + if member is None: + return self.error_no_entry() + #end if + + if len(machines) == 1: + redirect("/show/member/"+ residence +"/"+ member.uid.first()) + #end if + + results.append((member, machine)) + #end for + + return { + "residence" : residence, + "user" : self.user, + "results" : results + } + #end def + + @expose("brie.templates.search.member_global") def member_global(self, myresidence, name): residences = Residences.get_residences(self.user) diff --git a/Brie/brie/model/ldap.py b/Brie/brie/model/ldap.py index e7e1478..e039947 100644 --- a/Brie/brie/model/ldap.py +++ b/Brie/brie/model/ldap.py @@ -221,6 +221,11 @@ class Machine(object): return user_session.ldap_bind.search_first(machine_dn, "(objectClass=dlzAbstractRecord)") #end def + @staticmethod + def get_dns_by_ip(user_session, search_dn, ip): + return user_session.ldap_bind.search(search_dn, "(dlzData="+ ip +")") + #end def + @staticmethod def get_dhcps(user_session, machine_dn): return user_session.ldap_bind.search(machine_dn, "(objectClass=dhcpHost)") diff --git a/Brie/brie/templates/index.html b/Brie/brie/templates/index.html index c33a8e1..1af18cc 100644 --- a/Brie/brie/templates/index.html +++ b/Brie/brie/templates/index.html @@ -55,6 +55,22 @@ +