indépendance par rapport à la pacaterie

This commit is contained in:
Roven Gabriel 2013-02-16 09:32:02 +01:00
parent 6305e1c9cc
commit 3d415a9347
22 changed files with 238 additions and 542 deletions

View File

@ -2,14 +2,10 @@
uri = "ldaps://172.17.31.4" uri = "ldaps://172.17.31.4"
base_dn = "dc=pacaterie,dc=u-psud,dc=fr" username_base_dn = "ou=membres,"
room_base_dn = "ou=chambres,"
group_base_dn = "ou=groupes,"
username_base_dn = "ou=membres," + base_dn aurore_dn = "dc=aurore,dc=u-psud,dc=fr"
parametres_aurore_dn = "ou=parametres," + aurore_dn
room_base_dn = "ou=chambres," + base_dn liste_residence_dn = "cn=residences," + parametres_aurore_dn
group_base_dn = "ou=groupes," + base_dn
area_filter = "(objectClass=pacateriearea)"
floor_filter = "(objectClass=pacateriefloor)"
room_filter = "(objectClass=pacaterieRoom)"

View File

@ -4,12 +4,8 @@ from tg import session
from tg.controllers import redirect from tg.controllers import redirect
from tg.decorators import expose, validate from tg.decorators import expose, validate
from brie.lib.camembert_helpers import *
from brie.config import ldap_config from brie.config import ldap_config
from brie.lib.ldap_helper import * from brie.lib.ldap_helper import *
from brie.model import DBSession
from brie.model.camembert import Interface
from brie.model.ldap import * from brie.model.ldap import *
from brie.controllers import auth from brie.controllers import auth
@ -22,13 +18,13 @@ class GroupAddMemberController(AuthenticatedRestController):
@expose() @expose()
def post(self, group_cn, user_dn): def post(self, group_cn, user_dn):
groups_of_user = Groupes.get_by_user_dn(self.user, user_dn) groups_of_user = Groupes.get_by_user_dn(self.user, self.user.residence_dn, user_dn)
if group_cn in groups_of_user: if group_cn in groups_of_user:
redirect("/administration/") redirect("/administration/")
#end if #end if
target_group = Groupes.get_by_cn(self.user, group_cn) target_group = Groupes.get_by_cn(self.user, self.user.residence_dn, group_cn)
if target_group is None: if target_group is None:
redirect("/administration/") redirect("/administration/")
@ -47,10 +43,10 @@ class GroupController(AuthenticatedBaseController):
@expose() @expose()
def delete_member(self, group_cn, user_dn): def delete_member(self, group_cn, user_dn):
groups_of_user = Groupes.get_by_user_dn(self.user, user_dn) groups_of_user = Groupes.get_by_user_dn(self.user, self.user.residence_dn, user_dn)
if group_cn in groups_of_user: if group_cn in groups_of_user:
target_group = Groupes.get_by_cn(self.user, group_cn) target_group = Groupes.get_by_cn(self.user, self.user.residence_dn, group_cn)
attr = Groupes.unique_member_attr(user_dn) attr = Groupes.unique_member_attr(user_dn)
self.user.ldap_bind.delete_attr(target_group.dn, attr) self.user.ldap_bind.delete_attr(target_group.dn, attr)
@ -71,8 +67,8 @@ class AdministrationController(AuthenticatedBaseController):
@expose("brie.templates.administration.index") @expose("brie.templates.administration.index")
def index(self): def index(self):
groups = Groupes.get_all(self.user) groups = Groupes.get_all(self.user, self.user.residence_dn)
all_users = sorted(Member.get_all(self.user), key=lambda u: u.cn.first()) all_users = sorted(Member.get_all(self.user, self.user.residence_dn), key=lambda u: u.cn.first())
return { "user" : self.user, "groups_ldap" : groups, "all_users" : all_users } return { "user" : self.user, "groups_ldap" : groups, "all_users" : all_users }
#end def #end def

View File

@ -7,6 +7,7 @@ from tg.decorators import expose, validate
from brie.lib.base import BaseController from brie.lib.base import BaseController
from brie.config import ldap_config from brie.config import ldap_config
from brie.lib.ldap_helper import * from brie.lib.ldap_helper import *
from brie.lib.aurore_helper import *
from brie.model.ldap import Groupes from brie.model.ldap import Groupes
class Groups(object): class Groups(object):
@ -30,14 +31,18 @@ class User(object):
ldap_bind = None ldap_bind = None
attrs = None attrs = None
groups = None groups = None
residence_dn = None
def __init__(self, ldap_bind, attrs): def __init__(self, ldap_bind, attrs, residence_dn = None):
self.ldap_bind = ldap_bind self.ldap_bind = ldap_bind
self.attrs = attrs self.attrs = attrs
self.residence_dn = residence_dn
groups = Groupes.get_by_user_dn(self, self.attrs.dn) if attrs is not None:
groups = Groupes.get_by_user_dn(self, residence_dn, self.attrs.dn)
self.groups = Groups(groups) self.groups = Groups(groups)
#end if
#end def #end def
#end class #end class
@ -55,11 +60,16 @@ class AuthHandler(object):
#end if #end if
#end def #end def
def login(self, username, password): def get_anon_user(self):
return User(self.get_anon_bind(), None)
#end def
def login(self, residence_dn, username, password):
if self.get_anon_bind() is None: if self.get_anon_bind() is None:
return False return False
actual_user = self.get_anon_bind().search_first(ldap_config.username_base_dn, "(uid=" + username + ")") user_base_dn = ldap_config.username_base_dn + residence_dn
actual_user = self.get_anon_bind().search_first(user_base_dn, "(uid=" + username + ")")
if actual_user is None: if actual_user is None:
return False return False
@ -72,7 +82,7 @@ class AuthHandler(object):
attributes = bind.search_first(username_dn, "(uid=" + username + ")") attributes = bind.search_first(username_dn, "(uid=" + username + ")")
user = User(bind, attributes) user = User(bind, attributes, residence_dn)
AuthHandler.__users[username] = user AuthHandler.__users[username] = user
@ -153,17 +163,38 @@ class LoginRestController(RestController):
@expose("brie.templates.auth.login") @expose("brie.templates.auth.login")
def get(self): def get(self):
return dict(login = "", error = "") residences = Residences.get_residences(current.get_anon_user())
return dict(residences = residences, login = "", error = "")
#end def
@expose("brie.templates.auth.login") @expose("brie.templates.auth.login")
def post(self, username, password): def post(self, residence, username, password):
success = current.login(username, password) anon_user = current.get_anon_user()
residence_dn = Residences.get_dn_by_name(anon_user, residence)
if residence_dn is None:
return dict(
login = username,
error = "erreur de résidence"
)
#end if
success = current.login(residence_dn, username, password)
if success: if success:
redirect("/") redirect("/")
#end if #end if
return dict(login = username, error = "erreur de connexion") residences = Residences.get_residences(anon_user)
return dict(
residences = residences,
login = username,
residence = residence,
error = "erreur de connexion"
)
#end def #end def

View File

@ -4,17 +4,13 @@ from tg import session
from tg.controllers import redirect from tg.controllers import redirect
from tg.decorators import expose, validate from tg.decorators import expose, validate
from brie.lib.camembert_helpers import *
from brie.config import ldap_config from brie.config import ldap_config
from brie.config import groups_enum from brie.config import groups_enum
from brie.lib.ldap_helper import * from brie.lib.ldap_helper import *
from brie.model import DBSession
from brie.model.ldap import * from brie.model.ldap import *
from brie.controllers import auth from brie.controllers import auth
from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRestController from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRestController
from brie.controllers.import_actions import *
from operator import itemgetter from operator import itemgetter
@ -43,25 +39,6 @@ class EditController(AuthenticatedBaseController):
return self.show.room(room_number) return self.show.room(room_number)
#end def #end def
@expose("brie.templates.edit.interface")
def interface(self, interface_id):
return self.show.interface(interface_id)
#end def
@expose("brie.templates.edit.import_from")
def import_from(self, room_number):
success = True
message = ""
# try:
Migration.import_all(self.user.ldap_bind, room_number)
# except Exception as ex:
# success = False
# message = str(ex)
#end try
return { "room_number" : room_number, "success" : success, "message" : message }
#end def
#end class #end class
class WifiRestController(AuthenticatedRestController): class WifiRestController(AuthenticatedRestController):
@ -74,7 +51,7 @@ class WifiRestController(AuthenticatedRestController):
@expose("brie.templates.edit.wifi") @expose("brie.templates.edit.wifi")
def get(self, uid): def get(self, uid):
member = Member.get_by_uid(self.user, uid) member = Member.get_by_uid(self.user, self.user.residence_dn, uid)
if member is None: if member is None:
self.show.error_no_entry() self.show.error_no_entry()
@ -86,7 +63,7 @@ class WifiRestController(AuthenticatedRestController):
@expose("brie.templates.edit.wifi") @expose("brie.templates.edit.wifi")
def post(self, uid, password): def post(self, uid, password):
member = Member.get_by_uid(self.user, uid) member = Member.get_by_uid(self.user, self.user.residence_dn, uid)
if member is None: if member is None:
self.show.error_no_entry() self.show.error_no_entry()

View File

@ -4,12 +4,10 @@ from tg import session
from tg.controllers import redirect from tg.controllers import redirect
from tg.decorators import expose, validate from tg.decorators import expose, validate
from brie.lib.camembert_helpers import *
from brie.config import ldap_config from brie.config import ldap_config
from brie.lib.ldap_helper import * from brie.lib.ldap_helper import *
from brie.model import DBSession from brie.model import DBSession
from brie.model.camembert import Interface
from brie.model.ldap import * from brie.model.ldap import *
from brie.controllers import auth from brie.controllers import auth

View File

@ -1,151 +0,0 @@
# -*- coding: utf-8 -*-
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 *
from brie.model.ldap import Machine, Member
class Migration:
@staticmethod
def first(target_list, default = None):
for item in target_list:
return item
#end for
return default
#end def
@staticmethod
def import_all(bind, target_id):
Migration.delete_room_member(bind, target_id)
Migration.import_member(bind, target_id)
Migration.import_machines(bind, target_id)
#end def
@staticmethod
def delete_room_member(bind, target_id):
results = DBSession.query(Room).filter(Room.idroom == target_id)
room = Migration.first(results)
if not room is None:
ldap_room = bind.search_first(ldap_config.room_base_dn, "(cn=" + room.name + ")")
print room.name
member_of = {
"x-memberIn" : None
}
try:
bind.delete_attr(ldap_room.dn, member_of)
except:
pass
#end try
#end if
#end def
@staticmethod
def import_member(bind, target_id):
results = DBSession.query(UserPacaterie, Room).filter(UserPacaterie.idroom == Room.idroom).filter(Room.idroom == target_id)
user, room = Migration.first(results)
if user is not None and room is not None:
uid = Translations.to_uid(user.prenom, user.nom)
member = bind.search_first(ldap_config.username_base_dn, "(uid=" + uid + ")")
member_dn = ""
if member is None:
member_dn = "uid=" + uid + ",ou=2012," + ldap_config.username_base_dn
print member_dn
mail = user.mail
if mail is None:
mail = ""
attributes = Member.entry_attr(uid, user.prenom, user.nom, mail, str(-1))
bind.add_entry(member_dn, attributes)
else:
member_dn = member.dn
#end if
ldap_room = bind.search_first(ldap_config.room_base_dn, "(cn=" + room.name + ")")
new_member_of = {
"x-memberIn" : str(member_dn)
}
bind.replace_attr(ldap_room.dn, new_member_of)
#end if
#end def
@staticmethod
def import_machines(bind, target_id):
print target_id
results = DBSession.query(UserPacaterie, Room).filter(UserPacaterie.idroom == Room.idroom).filter(Room.idroom == target_id)
user, room = Migration.first(results)
print room.idroom
print user.idroom
if user is None: return
uid = Translations.to_uid(user.prenom, user.nom)
member = bind.search_first(ldap_config.username_base_dn, "(uid=" + uid + ")")
print member.dn
machines = DBSession.query(Computer).filter(Computer.iduser == user.iduser)
machine_id = 1
for machine in machines:
print machine_id
print machine.name
print machine.mac
print machine.ip
machine_dn = "cn=" + str(machine_id) + "," + member.dn
existant = bind.search_first(machine_dn, "(objectClass=*)")
if existant is not None:
bind.delete_entry_subtree(existant.dn)
print "deleted : " + existant.dn
machine_attributes = Machine.entry_attr(machine_id)
bind.add_entry(machine_dn, machine_attributes)
dhcp_dn = "cn=" + str(machine.name) + "," + machine_dn
dhcp_attributes = Machine.dhcp_attr(machine.name, machine.mac)
bind.add_entry(dhcp_dn, dhcp_attributes)
mac_auth_dn = "cn=mac," + machine_dn
flat_mac = str(machine.mac).replace(":", "")
mac_auth_attributes = Machine.auth_attr(flat_mac)
bind.add_entry(mac_auth_dn, mac_auth_attributes)
dns_dn = "dlzHostName=" + machine.name + "," + machine_dn
dns_attributes = Machine.dns_attr(machine.name, machine.ip)
bind.add_entry(dns_dn, dns_attributes)
machine_id = 1 + machine_id
#end for machine
#end def
#end class

View File

@ -3,13 +3,10 @@ from tg.controllers import redirect
from tg.decorators import expose, validate from tg.decorators import expose, validate
from brie.lib.base import BaseController from brie.lib.base import BaseController
from brie.lib.camembert_helpers import *
from brie.config import ldap_config from brie.config import ldap_config
from brie.config import groups_enum from brie.config import groups_enum
from brie.lib.ldap_helper import * from brie.lib.ldap_helper import *
from brie.model import DBSession from brie.lib.aurore_helper import *
from brie.model.camembert import *
from brie.model.ldap import * from brie.model.ldap import *
from brie.controllers import auth from brie.controllers import auth
@ -47,54 +44,54 @@ class RoomsController(AuthenticatedBaseController):
return sorted(name_items, key=itemgetter(0)) return sorted(name_items, key=itemgetter(0))
@expose("brie.templates.rooms.index") @expose("brie.templates.rooms.index")
def index(self): def index(self, residence_name):
result = DBSession.query(Interface)
interfaces_dict = dict()
for interface in result:
interfaces_dict[str(interface.idinterface)] = interface
stats = dict() stats = dict()
areas = dict() areas = dict()
rooms = self.user.ldap_bind.search(ldap_config.room_base_dn, ldap_config.room_filter) residence_dn = Residences.get_dn_by_name(self.user, residence_name)
if residence_dn is None:
raise Exception("unknown residence")
#end if
rooms = sorted(rooms, key = lambda a: a.cn.first()) for area in Room.get_areas(self.user, residence_dn):
for room in rooms: areas[area] = dict()
interface = interfaces_dict[room.get("x-switchInterface").first()]
color = self.color_picker(interface.ifdescription) for floor in Room.get_floors(self.user, area.dn):
areas[area][floor] = list()
for room in Room.get_rooms_of_floor(self.user, floor.dn):
areas[area][floor].append(room)
color = self.color_picker("foobar")
if color in stats: if color in stats:
stats[color] = stats[color] + 1 stats[color] = stats[color] + 1
else: else:
stats[color] = 0 stats[color] = 0
#end if #end if
room_id = int(room.uid.first()) #end for room
floor = Translations.floor_of_room(room_id) #end for floor
area = Translations.area_of_room(room_id) #end for area
if area not in areas:
areas[area] = dict()
#end if
if floor not in areas[area]: return {
areas[area][floor] = [] "areas" : areas,
#end if "color_picker" : self.color_picker,
"reverse_sorted_name" : self.reverse_sort_name,
areas[area][floor].append((room, interface)) "sorted_name" : self.sort_name,
#end for "stats" : stats,
"residence" : residence_name
return { "areas" : areas, "color_picker" : self.color_picker, "reverse_sorted_name" : self.reverse_sort_name, "sorted_name" : self.sort_name, "stats" : stats} }
#end def #end def
@expose("brie.templates.rooms.index") @expose("brie.templates.rooms.index")
def preview(self, number): def preview(self, residence, number):
if not number.isdigit(): redirect("/rooms/") if not number.isdigit(): redirect("/rooms/" + residence)
index_result = self.index() index_result = self.index(residence)
room = Room.get_by_uid(self.user, number) room = Room.get_by_uid(self.user, self.user.residence_dn, number)
member = None member = None
@ -102,13 +99,7 @@ class RoomsController(AuthenticatedBaseController):
member = Member.get_by_dn(self.user, room.get("x-memberIn").first()) member = Member.get_by_dn(self.user, room.get("x-memberIn").first())
interface = ( preview = member, room
DBSession.query(Interface)
.filter(Interface.idinterface == room.get("x-switchInterface").first())
.first()
)
preview = member, room, interface
index_result["preview"] = preview index_result["preview"] = preview
return index_result return index_result

View File

@ -7,8 +7,9 @@ from catwalk.tg2 import Catwalk
from repoze.what import predicates from repoze.what import predicates
from brie.lib.base import BaseController from brie.lib.base import BaseController
from brie.model import DBSession, metadata from brie.lib.aurore_helper import *
from brie import model from brie import model
#from brie.controllers.secure import SecureController #from brie.controllers.secure import SecureController
import brie.controllers.auth as auth_handler import brie.controllers.auth as auth_handler
from brie.controllers.auth import AuthRestController from brie.controllers.auth import AuthRestController
@ -18,7 +19,6 @@ from brie.controllers.edit import EditController
from brie.controllers.administration import AdministrationController from brie.controllers.administration import AdministrationController
from brie.controllers.error import ErrorController from brie.controllers.error import ErrorController
from brie.model.camembert import Materiel
__all__ = ['RootController'] __all__ = ['RootController']
@ -48,10 +48,13 @@ class RootController(BaseController):
@expose('brie.templates.index') @expose('brie.templates.index')
def index(self): def index(self):
"""Handle the front-page."""
materiel = DBSession.query(Materiel)
user = auth_handler.current.get_user() user = auth_handler.current.get_user()
residence = None
return { "user" : user, "materiel" : materiel } if user is not None:
residence = Residences.get_name_by_dn(user, user.residence_dn)
#end if
return { "user" : user, "residence" : residence }
#end def #end def
#end class #end class

View File

@ -3,13 +3,9 @@
from tg import session from tg import session
from tg.controllers import redirect from tg.controllers import redirect
from tg.decorators import expose, validate from tg.decorators import expose, validate
from brie.lib.camembert_helpers import *
from brie.config import ldap_config from brie.config import ldap_config
from brie.lib.ldap_helper import * from brie.lib.ldap_helper import *
from brie.model import DBSession from brie.lib.aurore_helper import *
from brie.model.camembert import Interface
from brie.model.ldap import * from brie.model.ldap import *
from brie.controllers import auth from brie.controllers import auth
@ -26,64 +22,50 @@ class ShowController(AuthenticatedBaseController):
""" Affiche les détails du membre, de la chambre et de l'interface """ """ Affiche les détails du membre, de la chambre et de l'interface """
@expose("brie.templates.show.member") @expose("brie.templates.show.member")
def member(self, uid): def member(self, residence, uid):
member = Member.get_by_uid(self.user, uid) residence_dn = Residences.get_dn_by_name(self.user, residence)
member = Member.get_by_uid(self.user, residence_dn, uid)
if member is None: if member is None:
return self.error_no_entry() return self.error_no_entry()
room = Room.get_by_member_dn(self.user, member.dn) room = Room.get_by_member_dn(self.user, residence_dn, member.dn)
interface = None
if room is not None:
interface = (
DBSession.query(Interface)
.filter(Interface.idinterface == room.get("x-switchInterface").first())
.first()
)
#end if
machines = Machine.get_machines_of_member(self.user, member.dn) machines = Machine.get_machines_of_member(self.user, member.dn)
groups = Groupes.get_by_user_dn(self.user, member.dn) groups = Groupes.get_by_user_dn(self.user, residence_dn, member.dn)
return { "user" : self.user, "member_ldap" : member, "interface" : interface, "room_ldap" : room, "machines" : machines, "groups" : groups} return {
"residence" : residence,
"user" : self.user,
"member_ldap" : member,
"room_ldap" : room,
"machines" : machines,
"groups" : groups
}
#end def #end def
@expose("brie.templates.show.room") @expose("brie.templates.show.room")
def room(self, room_id): def room(self, residence, room_id):
room = Room.get_by_uid(self.user, room_id) residence_dn = Residences.get_dn_by_name(self.user, residence)
room = Room.get_by_uid(self.user, residence_dn, room_id)
if room is None: if room is None:
return self.error_no_entry() return self.error_no_entry()
interface = (
DBSession.query(Interface)
.filter(Interface.idinterface == room.get("x-switchInterface").first())
.first()
)
member = None member = None
if room.has("x-memberIn"): if room.has("x-memberIn"):
member = Member.get_by_dn(self.user, room.get("x-memberIn").first()) member = Member.get_by_dn(self.user, room.get("x-memberIn").first())
return { "user" : self.user, "interface" : interface, "room_ldap" : room, "member_ldap" : member } return {
"residence" : residence,
"user" : self.user,
"room_ldap" : room,
"member_ldap" : member
}
#end def #end def
@expose("brie.templates.show.interface")
def interface(self, interface_id):
interface = (
DBSession.query(Interface)
.filter(Interface.idinterface == interface_id)
.first()
)
if interface is None:
return self.error_no_entry()
room = Room.get_by_interface(self.user, interface.idinterface)
return { "user" : self.user, "interface" : interface, "room_ldap" : room }
#end def
#end class #end class

View File

@ -0,0 +1,32 @@
from brie.config import ldap_config
class Residences:
@staticmethod
def get_dn_by_name(user_session, name):
result = user_session.ldap_bind.search_first(ldap_config.liste_residence_dn, "(cn=" + name + ")")
if result is None:
return None
#end if
return result.uniqueMember.first()
#end def
@staticmethod
def get_name_by_dn(user_session, dn):
result = user_session.ldap_bind.search_first(ldap_config.liste_residence_dn, "(uniqueMember=" + dn + ")")
if result is None:
return None
#end if
return result.cn.first()
#end def
@staticmethod
def get_residences(user_session):
return user_session.ldap_bind.search(ldap_config.liste_residence_dn, "(objectClass=groupOfUniqueNames)")
#end def
#end class

View File

@ -1,42 +0,0 @@
# -*- coding: utf-8 -*-
import unicodedata
class Translations(object):
@staticmethod
def to_uid(name, surname):
clean_name = Translations.strip_accents(name.replace(" ", "")).lower()[:15]
clean_surname = Translations.strip_accents(surname.replace(" ", "")).lower()[:15]
return clean_name + "." + clean_surname
#end def
@staticmethod
def floor_of_room(room):
return room / 100
#end def
@staticmethod
def area_of_room(room):
if Translations.floor_of_room(room) == 5:
return "crous"
floor_number = room % 100
if floor_number <= 33:
return "sud"
else:
return "nord"
#end if
#end def
#end class
# http://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-in-a-python-unicode-string
@staticmethod
def strip_accents(s):
return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn'))
#end def

View File

@ -27,13 +27,13 @@ class Member(object):
#end def #end def
@staticmethod @staticmethod
def get_by_uid(user_session, uid): def get_by_uid(user_session, residence_dn, uid):
return user_session.ldap_bind.search_first(ldap_config.username_base_dn, "(uid=" + uid + ")") return user_session.ldap_bind.search_first(ldap_config.username_base_dn + residence_dn, "(uid=" + uid + ")")
#end def #end def
@staticmethod @staticmethod
def get_all(user_session): def get_all(user_session, residence_dn):
return user_session.ldap_bind.search(ldap_config.username_base_dn, "(objectClass=pacatnetMember)") return user_session.ldap_bind.search(ldap_config.username_base_dn + residence_dn, "(objectClass=pacatnetMember)")
#end def #end def
#end class #end class
@ -41,23 +41,39 @@ class Member(object):
class Room(object): class Room(object):
@staticmethod @staticmethod
def get_by_name(user_session, name): def get_by_name(user_session, residence_dn, name):
return user_session.ldap_bind.search_first(ldap_config.room_base_dn, "(&" + ldap_config.room_filter + "(cn=" + name + "))") return user_session.ldap_bind.search_first(ldap_config.room_base_dn + residence_dn, "(&(objectClass=pacaterieRoom)(cn=" + name + "))")
#end def #end def
@staticmethod @staticmethod
def get_by_uid(user_session, uid): def get_by_uid(user_session, residence_dn, uid):
return user_session.ldap_bind.search_first(ldap_config.room_base_dn, "(&" + ldap_config.room_filter + "(uid=" + uid + "))") return user_session.ldap_bind.search_first(ldap_config.room_base_dn + residence_dn, "(&(objectClass=pacaterieRoom)(uid=" + uid + "))")
#end def #end def
@staticmethod @staticmethod
def get_by_member_dn(user_session, dn): def get_by_member_dn(user_session, residence_dn, dn):
return user_session.ldap_bind.search_first(ldap_config.room_base_dn, "(&" + ldap_config.room_filter + "(x-memberIn=" + dn + "))") return user_session.ldap_bind.search_first(ldap_config.room_base_dn + residence_dn, "(&(objectClass=pacaterieRoom)(x-memberIn=" + dn + "))")
#end def #end def
@staticmethod @staticmethod
def get_by_interface(user_session, interface_id): def get_areas(user_session, residence_dn):
return user_session.ldap_bind.search_first(ldap_config.room_base_dn, "(&" + ldap_config.room_filter + "(x-switchInterface=" + str(interface_id) + "))") return user_session.ldap_bind.search(ldap_config.room_base_dn + residence_dn, "(objectClass=pacaterieArea)")
#end def
@staticmethod
def get_floors(user_session, area_dn):
return user_session.ldap_bind.search(area_dn, "(objectClass=pacaterieFloor)")
#end def
@staticmethod
def get_rooms_of_floor(user_session, floor_dn):
return user_session.ldap_bind.search(floor_dn, "(objectClass=pacaterieRoom)")
#end def
@staticmethod
def get_rooms(user_session, residence_dn):
return user_session.ldap_bind.search(ldap_config.room_base_dn + residence_dn, "(objectClass=pacaterieRoom)")
#end def
#end class #end class
@ -151,8 +167,8 @@ class Machine(object):
class Groupes(object): class Groupes(object):
@staticmethod @staticmethod
def get_by_user_dn(user_session, user_dn): def get_by_user_dn(user_session, residence_dn, user_dn):
results = user_session.ldap_bind.search(ldap_config.group_base_dn, "(&(objectClass=groupOfUniqueNames)(uniqueMember=" + user_dn + "))") results = user_session.ldap_bind.search(ldap_config.group_base_dn + residence_dn, "(&(objectClass=groupOfUniqueNames)(uniqueMember=" + user_dn + "))")
groups = list() groups = list()
@ -165,15 +181,15 @@ class Groupes(object):
#end def #end def
@staticmethod @staticmethod
def get_by_cn(user_session, cn): def get_by_cn(user_session, residence_dn, cn):
results = user_session.ldap_bind.search_first(ldap_config.group_base_dn, "(&(objectClass=groupOfUniqueNames)(cn=" + cn + "))") results = user_session.ldap_bind.search_first(ldap_config.group_base_dn + residence_dn, "(&(objectClass=groupOfUniqueNames)(cn=" + cn + "))")
return results return results
#end def #end def
@staticmethod @staticmethod
def get_all(user_session): def get_all(user_session, residence_dn):
results = user_session.ldap_bind.search(ldap_config.group_base_dn, "(objectClass=groupOfUniqueNames)") results = user_session.ldap_bind.search(ldap_config.group_base_dn + residence_dn, "(objectClass=groupOfUniqueNames)")
return results return results
#end def #end def

View File

@ -1,4 +1,7 @@
<html> <html
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
>
<head> <head>
<link type="text/css" rel="Stylesheet" href="/css/common.css" /> <link type="text/css" rel="Stylesheet" href="/css/common.css" />
<link type="text/css" rel="Stylesheet" href="/css/show.css" /> <link type="text/css" rel="Stylesheet" href="/css/show.css" />
@ -8,6 +11,22 @@
<span class="section_name show_section_name">CONNEXION</span> <span class="section_name show_section_name">CONNEXION</span>
<form action="/auth/login" method="post"> <form action="/auth/login" method="post">
<p class="error">${error}</p> <p class="error">${error}</p>
<div>
<span class="item_name">Résidence</span>
<select name="residence">
<option value=""></option>
<py:for each="residence in residences">
<py:choose test="residence.cn.first() == residence">
<option py:when="True" selected="selected" value="${residence.cn.first()}">
${residence.cn.first()}
</option>
<option py:otherwise="" value="${residence.cn.first()}">
${residence.cn.first()}
</option>
</py:choose>
</py:for>
</select>
</div>
<div> <div>
<span class="item_name">Utilisateur</span> <span class="item_name">Utilisateur</span>
<input name="username" type="text" value="${login}" /> <input name="username" type="text" value="${login}" />

View File

@ -17,9 +17,5 @@
<span class="section_name" py:when="None">Pas de chambre associée</span> <span class="section_name" py:when="None">Pas de chambre associée</span>
<div py:otherwise="">${room_view(room)}</div> <div py:otherwise="">${room_view(room)}</div>
</div> </div>
<div py:choose="interface">
<span class="section_name" py:when="None">Pas d'interface associée</span>
<div py:otherwise="">${interface_view(interface)}</div>
</div>
</body> </body>
</html> </html>

View File

@ -80,72 +80,5 @@
</div> </div>
</div> </div>
</py:def> </py:def>
<py:def function="interface_view(interface, room_attached = None)">
<div class="section">
<span class="section_name show_section_name">INFOS INTERFACE</span>
<div>
<div>
<span class="item_name">Nombre de mac max</span>
<span>${interface.portsecmaxmac}</span>
</div>
<div>
<span class="item_name">Violation</span>
<span>${interface.portsecviolation}</span>
</div>
</div>
</div>
<div class="section">
<span class="section_name show_section_name">INFOS AVANCÉES</span>
<div>
<div>
<span class="item_name">ifNumber</span>
<span>${interface.ifnumber}</span>
</div>
<div>
<span class="item_name">ifAddress</span>
<span>${interface.ifaddress}</span>
</div>
<div>
<span class="item_name">ifType</span>
<span>${interface.iftype}</span>
</div>
<div>
<span class="item_name">Description</span>
<span>${interface.ifdescription}</span>
</div>
<div>
<span class="item_name">Etat</span>
<span py:choose="interface.ifoperstatus">
<span py:when="1">Up</span>
<span py:when="0">Down</span>
<span py:when="2">Error</span>
<span py:otherwise="">Inconnu</span>
</span>
</div>
<div>
<span class="item_name">Vitesse</span>
<span py:choose="interface.ifspeed">
<span py:when="10000000">10 Mb/s</span>
<span py:when="100000000">100 Mb/s</span>
<span py:when="1000000000">1 Gb/s</span>
<span py:otherwise="">interface.ifspeed</span>
</span>
</div>
<div>
<span class="item_name">Vlan</span>
<span>${interface.ifvlan}</span>
</div>
<div>
<span class="item_name">Native Vlan</span>
<span>${interface.ifnativevlan}</span>
</div>
<div>
<span class="item_name">SpanningTree Portfast</span>
<span>${interface.portfast}</span>
</div>
</div>
</div>
</py:def>
</html> </html>

View File

@ -14,9 +14,5 @@
<span class="section_name" py:when="None">Pas de chambre associée</span> <span class="section_name" py:when="None">Pas de chambre associée</span>
<div py:otherwise="">${room_view(room_ldap, member_ldap)}</div> <div py:otherwise="">${room_view(room_ldap, member_ldap)}</div>
</div> </div>
<div py:choose="interface">
<span class="section_name" py:when="None">Pas d'interface associée</span>
<div py:otherwise="">${interface_view(interface)}</div>
</div>
</body> </body>
</html> </html>

View File

@ -10,7 +10,7 @@
<div py:if="user is not None"> <div py:if="user is not None">
<div class="section"> <div class="section">
<span class="section_name show_section_name"></span> <span class="section_name show_section_name"></span>
<a py:if="user.groups.admin" class="button" href="/rooms/" >CHAMBRES</a> <a py:if="user.groups.admin" class="button" href="/rooms/index/${residence}/" >CHAMBRES</a>
<a py:if="user.groups.responsablereseau" class="button" href="/administration/" >ADMINISTRATION</a> <a py:if="user.groups.responsablereseau" class="button" href="/administration/" >ADMINISTRATION</a>
</div> </div>
<div class="section" > <div class="section" >

View File

@ -6,6 +6,8 @@
<link rel="stylesheet" type="text/css" href="/css/rooms.css" /> <link rel="stylesheet" type="text/css" href="/css/rooms.css" />
<link rel="stylesheet" type="text/css" href="/css/common.css" /> <link rel="stylesheet" type="text/css" href="/css/common.css" />
</head> </head>
<!--
<div class="rooms_legend"> <div class="rooms_legend">
<py:def function="display_stat(name)"> <py:def function="display_stat(name)">
<div class="room_number ${name}">${"%03d" % stats[name]}</div> <div class="room_number ${name}">${"%03d" % stats[name]}</div>
@ -27,33 +29,28 @@
<span>chambres vides</span> <span>chambres vides</span>
</div> </div>
</div> </div>
-->
<div class="area section"> <div class="area section">
<span class="section_name">PREVIEW</span> <span class="section_name">PREVIEW</span>
<div py:if="defined('preview')"> <div py:if="defined('preview')">
<py:with vars="member_ldap, room_preview, interface_preview = preview"> <py:with vars="member_ldap, room_preview = preview">
<div class="room_number ${color_picker(interface_preview.ifdescription)}"> <div class="room_number">
<span><a href="/show/room/${room_preview.uid.first()}">${room_preview.cn.first()}</a></span> <span><a href="/show/room/${residence}/${room_preview.uid.first()}">${room_preview.cn.first()}</a></span>
</div> </div>
<div class="preview_part preview_name" py:choose="member_ldap is not None"> <div class="preview_part preview_name" py:choose="member_ldap is not None">
<span py:when="True"><a href="/show/member/${member_ldap.uid.first()}">${member_ldap.cn.first()}</a></span> <span py:when="True"><a href="/show/member/${residence}/${member_ldap.uid.first()}">${member_ldap.cn.first()}</a></span>
<span py:otherwise=""><a href="/show/room/${room_preview.uid.first()}">Chambre Vide</a></span> <span py:otherwise=""><a href="/show/room/${residence}/${room_preview.uid.first()}">Chambre Vide</a></span>
</div>
<div class="preview_part" py:choose="">
<span py:when="interface_preview.ifoperstatus == 1" class="interface_status ok_color">Ordinateur branché</span>
<span py:when="interface_preview.portsecviolation == 1" class="interface_status violation_color">Violation mac</span>
<span py:when="interface_preview.ifoperstatus == 0" class="interface_status shut_color">Ordinateur débranché</span>
<span py:when="interface_preview.portsecstatus == 3" class="interface_status violation_color">Inteface éteinte</span>
</div> </div>
</py:with> </py:with>
</div> </div>
</div> </div>
<div py:for="area_name, floors in sorted_name(areas.iteritems())" class="area section"> <div py:for="area, floors in sorted_name(areas.iteritems())" class="area section">
<div> <div>
<span class="section_name">${("Aile " + area_name).upper()}</span> <span class="section_name">${("Aile " + area.cn.first()).upper()}</span>
<div py:for="floor_name, rooms in reverse_sorted_name(floors.iteritems())" class="floor"> <div py:for="floor, rooms in reverse_sorted_name(floors.iteritems())" class="floor">
<span class="floor_name">étage ${floor_name}</span> <span class="floor_name">étage ${floor.cn.first()}</span>
<div py:for="room, interface in rooms" class="room_number ${color_picker(interface.ifdescription)}"> <div py:for="room in rooms" class="room_number">
<a href="/rooms/preview/${room.uid.first()}"><span>${room.cn.first()}</span></a> <a href="/rooms/preview/${residence}/${room.uid.first()}"><span>${room.cn.first()}</span></a>
</div> </div>
</div> </div>
</div> </div>

View File

@ -16,9 +16,5 @@
<span class="section_name" py:when="None">Pas de chambre associée</span> <span class="section_name" py:when="None">Pas de chambre associée</span>
<div py:otherwise="">${room_view(room_ldap)}</div> <div py:otherwise="">${room_view(room_ldap)}</div>
</div> </div>
<div py:choose="interface">
<span class="section_name" py:when="None">Pas d'interface associée</span>
<div py:otherwise="">${interface_view(interface)}</div>
</div>
</body> </body>
</html> </html>

View File

@ -4,8 +4,8 @@
py:strip=""> py:strip="">
<py:def function="back_rooms(preview_room_ldap = None)"> <py:def function="back_rooms(preview_room_ldap = None)">
<div py:choose="preview_room_ldap"> <div py:choose="preview_room_ldap">
<a py:when="None" href="/rooms/" class="button">RETOUR LIST</a> <a py:when="None" href="/rooms/index/${residence}/" class="button">RETOUR LIST</a>
<a py:otherwise="" href="/rooms/preview/${preview_room_ldap.cn.first()}" class="button">RETOUR PREVIEW</a> <a py:otherwise="" href="/rooms/preview/${residence}/${preview_room_ldap.cn.first()}" class="button">RETOUR PREVIEW</a>
</div> </div>
</py:def> </py:def>
<py:def function="member_view(member_ldap)"> <py:def function="member_view(member_ldap)">
@ -51,7 +51,7 @@
</div> </div>
</div> </div>
<div class="section"> <div class="section">
<span class="section_name show_section_name">SALLE INFO + DIVERS</span> <span class="section_name show_section_name">DIVERS</span>
<div> <div>
<span class="item_name">Identifiant</span> <span class="item_name">Identifiant</span>
<span>${member_ldap.uid.first()}</span> <span>${member_ldap.uid.first()}</span>
@ -86,83 +86,17 @@
<py:def function="room_view(room, member_in = None)"> <py:def function="room_view(room, member_in = None)">
<div class="section"> <div class="section">
<span class="section_name show_section_name">CHAMBRE ${room.cn.first()}</span> <span class="section_name show_section_name">CHAMBRE ${room.cn.first()}</span>
<a class="link_button some_margin" href="/edit/room/${room.uid.first()}/">éditer</a> <a class="link_button some_margin" href="/edit/room/${residence}/${room.uid.first()}/">éditer</a>
<div> <div>
<div py:if="member_in is not None"> <div py:if="member_in is not None">
<span class="item_name">Membre</span> <span class="item_name">Membre</span>
<span> <span>
<a href="/show/member/${member_in.uid.first()}">${member_in.cn.first()}</a> <a href="/show/member/${residence}/${member_in.uid.first()}">${member_in.cn.first()}</a>
</span> </span>
</div> </div>
</div> </div>
</div> </div>
</py:def> </py:def>
<py:def function="interface_view(interface, room_attached = None)">
<div class="section">
<span class="section_name show_section_name">INFOS INTERFACE</span>
<div>
<div>
<span class="item_name">Nombre de mac max</span>
<span>${interface.portsecmaxmac}</span>
</div>
<div>
<span class="item_name">Violation</span>
<span>${interface.portsecviolation}</span>
</div>
</div>
</div>
<div class="section">
<span class="section_name show_section_name">INFOS AVANCÉES</span>
<div>
<div>
<span class="item_name">ifNumber</span>
<span>${interface.ifnumber}</span>
</div>
<div>
<span class="item_name">ifAddress</span>
<span>${interface.ifaddress}</span>
</div>
<div>
<span class="item_name">ifType</span>
<span>${interface.iftype}</span>
</div>
<div>
<span class="item_name">Description</span>
<span>${interface.ifdescription}</span>
</div>
<div>
<span class="item_name">Etat</span>
<span py:choose="interface.ifoperstatus">
<span py:when="1">Up</span>
<span py:when="0">Down</span>
<span py:when="2">Error</span>
<span py:otherwise="">Inconnu</span>
</span>
</div>
<div>
<span class="item_name">Vitesse</span>
<span py:choose="interface.ifspeed">
<span py:when="10000000">10 Mb/s</span>
<span py:when="100000000">100 Mb/s</span>
<span py:when="1000000000">1 Gb/s</span>
<span py:otherwise="">interface.ifspeed</span>
</span>
</div>
<div>
<span class="item_name">Vlan</span>
<span>${interface.ifvlan}</span>
</div>
<div>
<span class="item_name">Native Vlan</span>
<span>${interface.ifnativevlan}</span>
</div>
<div>
<span class="item_name">SpanningTree Portfast</span>
<span>${interface.portfast}</span>
</div>
</div>
</div>
</py:def>
</html> </html>

View File

@ -14,9 +14,5 @@
<span class="section_name" py:when="None">Pas de chambre associée</span> <span class="section_name" py:when="None">Pas de chambre associée</span>
<div py:otherwise="">${room_view(room_ldap, member_ldap)}</div> <div py:otherwise="">${room_view(room_ldap, member_ldap)}</div>
</div> </div>
<div py:choose="interface">
<span class="section_name" py:when="None">Pas d'interface associée</span>
<div py:otherwise="">${interface_view(interface)}</div>
</div>
</body> </body>
</html> </html>

View File

@ -17,7 +17,7 @@ error_email_from = paste@localhost
[server:main] [server:main]
use = egg:Paste#http use = egg:Paste#http
host = 0.0.0.0 host = 0.0.0.0
port = 9000 port = 9001
[app:main] [app:main]
use = egg:Brie use = egg:Brie
@ -36,14 +36,14 @@ beaker.session.secret = somesecret
# pick the form for your database # pick the form for your database
# %(here) may include a ':' character on Windows environments; this can # %(here) may include a ':' character on Windows environments; this can
# invalidate the URI when specifying a SQLite db via path name # invalidate the URI when specifying a SQLite db via path name
sqlalchemy.url=postgresql://camembert:CamembertDB%40Pacat@172.17.22.7:5432/camembert #sqlalchemy.url=postgresql://camembert:CamembertDB%40Pacat@172.17.22.7:5432/camembert
# sqlalchemy.url=mysql://username:password@hostname:port/databasename # sqlalchemy.url=mysql://username:password@hostname:port/databasename
# If you have sqlite, here's a simple default to get you started # If you have sqlite, here's a simple default to get you started
# in development # in development
#sqlalchemy.url = sqlite:///%(here)s/devdata.db sqlalchemy.url = sqlite:///%(here)s/devdata.db
#echo shouldn't be used together with the logging module. #echo shouldn't be used together with the logging module.
#sqlalchemy.echo = false #sqlalchemy.echo = false
#sqlalchemy.echo_pool = false #sqlalchemy.echo_pool = false