mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 15:32:19 +03:00
ldap registration added
This commit is contained in:
parent
7ef39c3fd3
commit
077b57a095
1 changed files with 44 additions and 13 deletions
|
@ -37,36 +37,46 @@ class Registration():
|
||||||
message_sender=MessageSender(self.get_registration_request_message(),None)
|
message_sender=MessageSender(self.get_registration_request_message(),None)
|
||||||
message_sender.connect_to_server()
|
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
|
def confirm_registration(self,reg_reply): #event fire and keep here
|
||||||
j = json.loads(reg_reply)
|
j = json.loads(reg_reply)
|
||||||
self.logger.info('[REGISTRATION] register reply: '+j['message'])
|
self.logger.info('[REGISTRATION] register reply: '+j['message'])
|
||||||
status =str(j['status']).lower()
|
status =str(j['status']).lower()
|
||||||
dn=str(j['agentDn']).lower()
|
dn=str(j['agentDn']).lower()
|
||||||
|
|
||||||
if str(status)=='registered':
|
if str(status)=='registered' or str(status)=='registered_without_ldap':
|
||||||
print("registered")
|
self.update_conf_file()
|
||||||
if self.conf_manager.has_section('CONNECTION') and self.conf_manager.get('REGISTRATION', 'from') is not None:
|
elif str(status)=='registration_error':
|
||||||
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'):
|
|
||||||
self.logger.info('[REGISTRATION] registration error')
|
self.logger.info('[REGISTRATION] registration error')
|
||||||
elif(status=='already_registered'):
|
elif str(status)=='already_registered':
|
||||||
self.logger.info('[REGISTRATION]already registered')
|
self.logger.info('[REGISTRATION]already registered')
|
||||||
self.re_register()
|
self.re_register()
|
||||||
self.registration_request()
|
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):
|
def is_registered(self):
|
||||||
if self.conf_manager.has_section('REGISTRATION') and (self.conf_manager.get('REGISTRATION', 'registered')=='true'):
|
if self.conf_manager.has_section('REGISTRATION') and (self.conf_manager.get('REGISTRATION', 'registered')=='true'):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
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):
|
def get_registration_request_message(self):
|
||||||
self.logger.debug('[Registration] creating registration message according to parameters of registration')
|
self.logger.debug('[Registration] creating registration message according to parameters of registration')
|
||||||
|
|
||||||
|
@ -88,6 +98,27 @@ class Registration():
|
||||||
print("Registration section not found")
|
print("Registration section not found")
|
||||||
return None
|
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):
|
def register(self,uuid_depend_mac):
|
||||||
self.logger.debug('[Registration] configuration parameters of registration is checking')
|
self.logger.debug('[Registration] configuration parameters of registration is checking')
|
||||||
if self.conf_manager.has_section('REGISTRATION'):
|
if self.conf_manager.has_section('REGISTRATION'):
|
||||||
|
|
Loading…
Reference in a new issue