From 631fa57aec1296012fb115c4a47f23d38c059e35 Mon Sep 17 00:00:00 2001 From: Bryce Tichit Date: Wed, 27 Aug 2014 22:26:24 +0200 Subject: [PATCH] =?UTF-8?q?Creation=20dossier=20ann=C3=A9e.=20A=20REVERIFI?= =?UTF-8?q?ER?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Brie/brie/controllers/edit.py | 18 ++++++++-- Brie/check_mac_interface.py | 63 ----------------------------------- 2 files changed, 15 insertions(+), 66 deletions(-) delete mode 100644 Brie/check_mac_interface.py diff --git a/Brie/brie/controllers/edit.py b/Brie/brie/controllers/edit.py index 31f4161..7f2d663 100644 --- a/Brie/brie/controllers/edit.py +++ b/Brie/brie/controllers/edit.py @@ -92,15 +92,27 @@ class MemberAddController(AuthenticatedRestController): #end if #endif + def year_directory_exists(year): + search = self.user.ldap_bind.search_s(ldap_config.username_base_dn + residence_dn,ldap.SCOPE_SUBTREE,"(ou="+str(year)+")") + if len(search) == 0: + print "[LOG]Year "+str(year)+" directory does not exist. Creating." + directory_attrs = { + "objectClass" : ["top","organizationalUnit"], + "ou" : str(year).encode("utf-8") + } + directory_dn = "ou="+str(year)+","+ ldap_config.username_base_dn + residence_dn + self.user.ldap_bind.add_entry(directory_dn,directory_attrs) + + member_uid = try_name(member_uid, 0) - - member = Member.entry_attr(member_uid, prenom, nom, mail, phone, -1) + member = Member.entry_attr(member_uid, prenom, nom, mail, phone, -1) year = CotisationComputes.registration_current_year() member_dn = "uid=" + member_uid + ",ou=" + str(year) + "," + ldap_config.username_base_dn + residence_dn - self.user.ldap_bind.add_entry(member_dn, member) + year_directory_exists(year) + self.user.ldap_bind.add_entry(member_dn, member) #preview = member, room diff --git a/Brie/check_mac_interface.py b/Brie/check_mac_interface.py deleted file mode 100644 index 012d6a6..0000000 --- a/Brie/check_mac_interface.py +++ /dev/null @@ -1,63 +0,0 @@ -#from paste.deploy import appconfig -#from pylons import config - -#from brie.config.environment import load_environment - -#conf = appconfig('config:development.ini', relative_to='.') -#load_environment(conf.global_conf, conf.local_conf) - -import os -import sys - -from brie.config import ldap_config -from brie.lib.ldap_helper import * -from brie.lib.camembert_helpers import * - -from brie.model import DBSession -from brie.model.camembert import * - -#interface_name = os.environ["NAS_PORT_ID"] -#switch_ip = os.environ["NAS_IP_ADDRESS"] -#mac = os.environ["USERNAME"] - -#bind = Ldap.connect("uid=roven.gabriel," + ldap_config.username_base_dn, "foobar") -bind = Ldap.connect("uid=admin,ou=Administrators,ou=TopologyManagement,o=netscaperoot", "t734DSSL61") - -rooms_base_dn = "ou=chambres,dc=pacaterie,dc=u-psud,dc=fr" - -interface_name = "FastEthernet0/43" -switch_ip = "172.17.24.2" -mac = "000f1f867189" - -rooms = bind.search(rooms_base_dn, "(&(&(objectClass=pacaterieRoom)(x-switchInterface=" + interface_name + ")(x-switch=" + switch_ip + ")))") - - -def roomOrNone(member): - if member.has("roomNumber"): - return member.roomNumber.first() - return None -#end def - - -def isOk(): - for room in rooms: - print room.get("x-switchInterface").first() - if room.has("x-memberIn"): - print room.get("x-memberIn").first() - associated_member_machine = bind.search_first(room.get("x-memberIn").first(), "(uid=" + mac + ")") - print associated_member_machine.uid.first() - return associated_member_machine is not None - #end if - #end for - - return False -#end def - -ok = isOk() - -if ok: - sys.exit(0) -else: - sys.exit(1) - -