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 @@ +
+ Adresse mac +
+ + + +
+
+
+ Adresse IP +
+ + + +
+
diff --git a/Brie/brie/templates/search/ip.html b/Brie/brie/templates/search/ip.html new file mode 100644 index 0000000..4d0c385 --- /dev/null +++ b/Brie/brie/templates/search/ip.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + +
membremachine name
${member.cn.first()}${machine.dlzHostName.first()} (${machine.dlzData.first()})
+ + diff --git a/Brie/brie/templates/search/member_global.html b/Brie/brie/templates/search/member_global.html new file mode 100644 index 0000000..f700e4d --- /dev/null +++ b/Brie/brie/templates/search/member_global.html @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
membrerésidencechambredéménager
${member.cn.first()}${mresidence}sdf${room.cn.first()} + + + + +
+ +