ldap registration added

This commit is contained in:
Volkan Şahin 2016-03-10 09:53:51 +02:00
parent 7ef39c3fd3
commit 077b57a095

View file

@ -37,36 +37,46 @@ class Registration():
message_sender=MessageSender(self.get_registration_request_message(),None)
message_sender.connect_to_server()
def ldap_registration_request(self):
message_sender=MessageSender(self.get_ldap_registration_request_message(),None)
message_sender.connect_to_server()
def confirm_registration(self,reg_reply): #event fire and keep here
j = json.loads(reg_reply)
self.logger.info('[REGISTRATION] register reply: '+j['message'])
status =str(j['status']).lower()
dn=str(j['agentDn']).lower()
if str(status)=='registered':
print("registered")
if self.conf_manager.has_section('CONNECTION') and self.conf_manager.get('REGISTRATION', 'from') is not None:
self.conf_manager.set('CONNECTION', 'uid',self.conf_manager.get('REGISTRATION', 'from'))
self.conf_manager.set('CONNECTION', 'password',self.conf_manager.get('REGISTRATION', 'password'))
self.conf_manager.set('REGISTRATION', 'dn',dn)
self.conf_manager.set('REGISTRATION', 'registered','true')
with open('/etc/ahenk/ahenk.conf', 'w') as configfile:
self.conf_manager.write(configfile)
self.event_manager.register_event('registration_ok',self.reload)
self.logger.info('[REGISTRATION] registered successfully')
elif(status=='registration_error'):
if str(status)=='registered' or str(status)=='registered_without_ldap':
self.update_conf_file()
elif str(status)=='registration_error':
self.logger.info('[REGISTRATION] registration error')
elif(status=='already_registered'):
elif str(status)=='already_registered':
self.logger.info('[REGISTRATION]already registered')
self.re_register()
self.registration_request()
def update_conf_file(self):
if self.conf_manager.has_section('CONNECTION') and self.conf_manager.get('REGISTRATION', 'from') is not None:
self.conf_manager.set('CONNECTION', 'uid',self.conf_manager.get('REGISTRATION', 'from'))
self.conf_manager.set('CONNECTION', 'password',self.conf_manager.get('REGISTRATION', 'password'))
self.conf_manager.set('REGISTRATION', 'dn',dn)
self.conf_manager.set('REGISTRATION', 'registered','true')
with open('/etc/ahenk/ahenk.conf', 'w') as configfile:
self.conf_manager.write(configfile)
def is_registered(self):
if self.conf_manager.has_section('REGISTRATION') and (self.conf_manager.get('REGISTRATION', 'registered')=='true'):
return True
else:
return False
def is_ldap_registered(self):
if self.is_registered() and self.conf_manager.get('REGISTRATION', 'dn')!='' and self.conf_manager.get('REGISTRATION', 'dn') is not None:
return True
else:
return False
def get_registration_request_message(self):
self.logger.debug('[Registration] creating registration message according to parameters of registration')
@ -88,6 +98,27 @@ class Registration():
print("Registration section not found")
return None
def get_ldap_registration_request_message(self):
self.logger.debug('[Registration] creating ldap registration message according to parameters of registration')
if self.conf_manager.has_section('REGISTRATION'):
data = {}
data['type'] = 'REGISTER_LDAP'
data['from'] = str(self.conf_manager.get('REGISTRATION','from'))
data['password'] = str(self.conf_manager.get('REGISTRATION','password'))
data['macAddresses'] = str(self.conf_manager.get('REGISTRATION','macAddresses'))
data['ipAddresses'] = str(self.conf_manager.get('REGISTRATION','ipAddresses'))
data['hostname'] = str(self.conf_manager.get('REGISTRATION','hostname'))
data['timestamp'] = str(self.conf_manager.get('REGISTRATION','timestamp'))
self.logger.debug('[Registration] json of registration message was created')
json_data = json.dumps(data)
self.logger.debug('[Registration] json converted to str')
return json_data
else:
print("Registration section not found")
return None
def register(self,uuid_depend_mac):
self.logger.debug('[Registration] configuration parameters of registration is checking')
if self.conf_manager.has_section('REGISTRATION'):