96 lines
2.3 KiB
Python
96 lines
2.3 KiB
Python
from nameko.events import EventDispatcher, event_handler
|
|
from nameko.rpc import rpc
|
|
from configparser import ConfigParser
|
|
import ldap3
|
|
|
|
config = ConfigParser()
|
|
config.read('nameko.conf')
|
|
|
|
try:
|
|
mult_server = int(config['LDAP']['SERVERMULTIPLE'])
|
|
except:
|
|
exit("[LDAP] SERVERMULTIPLE has to be an integer >= 1")
|
|
if mult_server < 1:
|
|
exit("[LDAP] SERVERMULTIPLE has to be an integer >= 1")
|
|
|
|
class UserLookUp(object):
|
|
name = "userlookup"
|
|
dispatch = EventDispatcher()
|
|
|
|
@rpc
|
|
def lookup(self, user):
|
|
LDAP_UID = 'uid=%s' % user
|
|
LDAP_USER_SEARCH = LDAP_UID + config['LDAP']['LDAPDATA']
|
|
|
|
|
|
class CreateUser(object):
|
|
name = "createuser"
|
|
dispatch = EventDispatcher()
|
|
|
|
@rpc
|
|
def create_user(self, user, password, firstname, lastname, email):
|
|
return "To be done"
|
|
|
|
|
|
class GetUserData(object):
|
|
name = "getuserdata"
|
|
dispatch = EventDispatcher()
|
|
|
|
@rpc
|
|
def get_data(self, user):
|
|
return "To be done"
|
|
|
|
class ChangeUserData(object):
|
|
name = "changeuserdata"
|
|
dispatch = EventDispatcher()
|
|
|
|
@rpc
|
|
def change_data(self, user, firstname, lastname, email):
|
|
return "To be done"
|
|
|
|
|
|
class PasswordResetRequest(object):
|
|
name = "passwordresetrequest"
|
|
dispatch = EventDispatcher()
|
|
|
|
@rpc
|
|
def send_request(self, user):
|
|
return "To be done"
|
|
|
|
|
|
class ChangePassword(object):
|
|
name = "changepassword"
|
|
dispatch = EventDispatcher()
|
|
|
|
@rpc
|
|
def change_password(self, user, oldpassword, newpassword):
|
|
return "To be done"
|
|
|
|
|
|
class DeleteUser(object):
|
|
name = "deleteuser"
|
|
dispatch = EventDispatcher()
|
|
|
|
@rpc
|
|
def delete_user(self, user):
|
|
return "To be done"
|
|
|
|
|
|
class Log(object):
|
|
name = "log"
|
|
ldaplog = config['System']['LOGDIR'] + '/ldap.log'
|
|
|
|
|
|
# Gets all the dispatches with 'ldap' and writes them into the ldap.log
|
|
@event_handler('userlookup', 'ldap')
|
|
@event_handler('createuser', 'ldap')
|
|
@event_handler('getuserdata', 'ldap')
|
|
@event_handler('changeuserdata', 'ldap')
|
|
@event_handler('passwordresetrequest', 'ldap')
|
|
@event_handler('changepassword', 'ldap')
|
|
@event_handler('deleteuser', 'ldap')
|
|
def event_handler_ldap(self, payload):
|
|
f = open(self.ldaplog, mode='a', encoding='utf-8')
|
|
f.write(payload)
|
|
f.close
|
|
|