From f5221581ec8f2f268653b2d4210cf2534b8235cc Mon Sep 17 00:00:00 2001 From: Romain Beuque Date: Sat, 30 Mar 2013 20:55:55 +0100 Subject: [PATCH] ajout des restrict mac + dns-name + debut changement room membre --- Brie/brie/controllers/edit.py | 81 ++++++++++++++++--- Brie/brie/model/ldap.py | 9 +++ Brie/brie/templates/edit/member.html | 2 +- .../member_room_interface_edit_views.html | 31 ++++++- Brie/brie/templates/edit/room.html | 2 +- .../show/member_room_interface_views.html | 2 +- 6 files changed, 109 insertions(+), 18 deletions(-) diff --git a/Brie/brie/controllers/edit.py b/Brie/brie/controllers/edit.py index 49413bb..837e7c1 100644 --- a/Brie/brie/controllers/edit.py +++ b/Brie/brie/controllers/edit.py @@ -17,7 +17,7 @@ from operator import itemgetter from datetime import datetime import uuid - +import re #root = tg.config['application_root_module'].RootController @@ -42,7 +42,37 @@ class EditController(AuthenticatedBaseController): """ Affiche les détails éditables du membre et de la chambre """ @expose("brie.templates.edit.member") def member(self, residence, uid): - return self.show.member(residence, uid) + + residence_dn = Residences.get_dn_by_name(self.user, residence) + if residence_dn is None: + raise Exception("unknown residence") + #end if + + member = Member.get_by_uid(self.user, residence_dn, uid) + + if member is None: + return self.error_no_entry() + + room = Room.get_by_member_dn(self.user, residence_dn, member.dn) + + machines = Machine.get_machine_tuples_of_member(self.user, member.dn) + + groups = Groupes.get_by_user_dn(self.user, residence_dn, member.dn) + + rooms = Room.get_rooms(self.user, residence_dn) + if rooms is None: + raise Exception("unable to retrieve rooms") + #end if + rooms = sorted(rooms, key=lambda t:t.cn.first()) + return { + "residence" : residence, + "user" : self.user, + "member_ldap" : member, + "room_ldap" : room, + "machines" : machines, + "groups" : groups, + "rooms" : rooms + } #end def """ Affiche les détails éditables de la chambre """ @@ -79,24 +109,53 @@ class MachineAddController(AuthenticatedRestController): def post(self, residence, member_uid, name, mac): residence_dn = Residences.get_dn_by_name(self.user, residence) - #TODO : néttoyer mac (utiliser deux-points) et vérifier (regex) - # XX:XX:XX:XX:XX + #Vérification que l'adresse mac soit correcte + mac_match = re.match('^([0-9A-Fa-f]{2}[:-]?){5}([0-9A-Fa-f]{2})$', mac) + if mac_match is None: + #TODO : changer l'exception en une page d'erreur + raise Exception("mac non valide") + #endif + + #Remplacement de l'adresse mac non séparée + mac_match = re.match('^([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})$', mac) + if mac_match is not None: + mac = mac_match.group(1) + ":" + mac_match.group(2) + ":" + mac_match.group(3) + ":" + mac_match.group(4) + ":" + mac_match.group(5) + ":" + mac_match.group(6) + #endif + + #Remplacement de l'adresse mac séparée par des tirets + mac_match = re.match('^([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})$', mac) + if mac_match is not None: + mac = mac_match.group(1) + ":" + mac_match.group(2) + ":" + mac_match.group(3) + ":" + mac_match.group(4) + ":" + mac_match.group(5) + ":" + mac_match.group(6) + #endif + + #Passage au format lowercase + mac = mac.lower() + # Vérification que le membre existe member = Member.get_by_uid(self.user, residence_dn, member_uid) if member is None: #TODO : membre inexistant pass - + #endif + + + # Vérification que l'adresse mac de la machine n'existe pas déjà + # Note : on cherche sur toute la résidence (residence_dn) + machine = Machine.get_dhcp_by_mac(self.user, residence_dn, mac) + if machine is not None: + #TODO : gérer l'exception + raise Exception("mac address already exist") + #endif + # Vérification que le nom de machine n'existe pas déjà # Note : on cherche sur toute la résidence (residence_dn) - - # TODO : - # machine = Machine.get_machine_by_name(self.user, residence_dn, name) - machine = None + machine = Machine.get_dns_by_name(self.user, residence_dn, name) if machine is not None: - #TODO : erreur machine existe déjà - pass + #TODO : gérer l'exception + raise Exception("dns name already exist") + #endif + # Génération de l'id de la machine et recherche d'une ip libre machine_id = str(uuid.uuid4()) ip = IpReservation.get_first_free(self.user, residence_dn) diff --git a/Brie/brie/model/ldap.py b/Brie/brie/model/ldap.py index 9ea1354..e3499ef 100644 --- a/Brie/brie/model/ldap.py +++ b/Brie/brie/model/ldap.py @@ -179,6 +179,15 @@ class Machine(object): return user_session.ldap_bind.search_first(machine_dn, "(objectClass=dlzAbstractRecord)") #end def + @staticmethod + def get_dhcp_by_mac(user_session, residence_dn, mac): + return user_session.ldap_bind.search_first(residence_dn, "(dhcpHWAddress=ethernet "+mac+")") + #end def + + @staticmethod + def get_dns_by_name(user_session, residence_dn, name): + return user_session.ldap_bind.search_first(residence_dn, "(dlzHostName="+name+")") + #end def #end class class Groupes(object): diff --git a/Brie/brie/templates/edit/member.html b/Brie/brie/templates/edit/member.html index 88bb4de..6d3a71e 100644 --- a/Brie/brie/templates/edit/member.html +++ b/Brie/brie/templates/edit/member.html @@ -15,7 +15,7 @@
Pas de chambre associée -
${room_view(room_ldap)}
+
${room_view(room_ldap,rooms)}
diff --git a/Brie/brie/templates/edit/member_room_interface_edit_views.html b/Brie/brie/templates/edit/member_room_interface_edit_views.html index ff054b3..ac3105d 100644 --- a/Brie/brie/templates/edit/member_room_interface_edit_views.html +++ b/Brie/brie/templates/edit/member_room_interface_edit_views.html @@ -14,6 +14,14 @@
${member_ldap.cn.first()}
+
+ Prénom + +
+
+ Nom + +
Fin de connexion @@ -66,8 +74,8 @@
- - + + @@ -76,14 +84,29 @@
- +
CHAMBRE ${room.cn.first()}
+
+ Changer de chambre + + + Sauvegarder le changement de chambre
diff --git a/Brie/brie/templates/edit/room.html b/Brie/brie/templates/edit/room.html index d62f400..86a1cd8 100644 --- a/Brie/brie/templates/edit/room.html +++ b/Brie/brie/templates/edit/room.html @@ -9,7 +9,7 @@ ${edit_banner()} - ${back_show("room", room_ldap.uid.first())} + ${back_show("room", None, room_ldap.uid.first())}
Pas de chambre associée
${room_view(room_ldap, member_ldap)}
diff --git a/Brie/brie/templates/show/member_room_interface_views.html b/Brie/brie/templates/show/member_room_interface_views.html index 22ddfc0..63fd9b8 100644 --- a/Brie/brie/templates/show/member_room_interface_views.html +++ b/Brie/brie/templates/show/member_room_interface_views.html @@ -5,7 +5,7 @@