mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-12-23 13:22:17 +03:00
registartion process fixed
This commit is contained in:
parent
77455de1dd
commit
85395033d4
4 changed files with 38 additions and 25 deletions
|
@ -118,10 +118,15 @@ class AhenkDeamon(BaseDaemon):
|
|||
|
||||
def check_registration(self):
|
||||
# TODO restrict number of attemption
|
||||
while Scope.getInstance().getRegistration().is_registered() is False:
|
||||
print('registration need')
|
||||
Scope.getInstance().getLogger().debug('[AhenkDeamon] Attempting to register')
|
||||
Scope.getInstance().getRegistration().registration_request()
|
||||
try:
|
||||
while Scope.getInstance().getRegistration().is_registered() is False:
|
||||
print('registration need')
|
||||
Scope.getInstance().getLogger().debug('[AhenkDeamon] Attempting to register')
|
||||
Scope.getInstance().getRegistration().registration_request()
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
raise
|
||||
|
||||
|
||||
|
||||
def reload_plugins(self):
|
||||
|
@ -176,13 +181,13 @@ class AhenkDeamon(BaseDaemon):
|
|||
self.init_task_manager()
|
||||
logger.info('[AhenkDeamon] Task Manager was set')
|
||||
|
||||
#self.init_registration()
|
||||
self.init_registration()
|
||||
logger.info('[AhenkDeamon] Registration was set')
|
||||
|
||||
self.init_execution_manager()
|
||||
logger.info('[AhenkDeamon] Execution Manager was set')
|
||||
|
||||
#self.check_registration()
|
||||
self.check_registration()
|
||||
logger.info('[AhenkDeamon] Ahenk is registered')
|
||||
|
||||
messager = self.init_messager()
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import asyncio
|
||||
import slixmpp
|
||||
import sys
|
||||
import json
|
||||
|
||||
sys.path.append('../..')
|
||||
from slixmpp.exceptions import IqError, IqTimeout
|
||||
|
@ -49,12 +50,13 @@ class AnonymousMessager(slixmpp.ClientXMPP):
|
|||
|
||||
def recv_direct_message(self, msg):
|
||||
if msg['type'] in ('chat', 'normal'):
|
||||
print('ANON<---'+ msg['body'])
|
||||
self.logger.debug("[MessageSender] Received message: %s -> %s" % (msg['from'], msg['body']))
|
||||
self.disconnect()
|
||||
self.logger.debug('[MessageSender] Disconnecting...')
|
||||
self.logger.debug('[MessageSender] Fired event is: confirm_registration')
|
||||
self.event_manager.fireEvent('confirm_registration', str(msg['body']))
|
||||
##TODO type fire -- only anonymous account can fire confirm_registration
|
||||
j = json.loads(str(msg['body']))
|
||||
message_type = j['type']
|
||||
self.event_manager.fireEvent(message_type, str(msg['body']))
|
||||
|
||||
@asyncio.coroutine
|
||||
def session_start(self, event):
|
||||
|
@ -104,6 +106,7 @@ class AnonymousMessager(slixmpp.ClientXMPP):
|
|||
|
||||
def send_direct_message(self, msg):
|
||||
self.logger.debug('[MessageSender] Sending message: ' + msg)
|
||||
print('ANON-->'+msg)
|
||||
self.send_message(mto=self.receiver, mbody=msg, mtype='normal')
|
||||
|
||||
def connect_to_server(self): # Connect to the XMPP server and start processing XMPP stanzas.
|
||||
|
|
|
@ -100,12 +100,14 @@ class Messaging(object):
|
|||
def registration_msg(self):
|
||||
data = {}
|
||||
data['type'] = 'REGISTER'
|
||||
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(datetime.datetime.now().strftime("%d-%m-%Y %I:%M"))
|
||||
data['from'] = self.db_service.select_one_result('registration','jid',' 1=1')#str(self.conf_manager.get('REGISTRATION', 'from'))
|
||||
data['password'] = self.db_service.select_one_result('registration','password',' 1=1')
|
||||
params = self.db_service.select_one_result('registration','params',' 1=1')
|
||||
json_params = json.loads(str(params))
|
||||
data['macAddresses'] = json_params['macAddresses']
|
||||
data['ipAddresses'] = json_params['ipAddresses']
|
||||
data['hostname'] = json_params['hostname']
|
||||
data['timestamp'] = self.db_service.select_one_result('registration','timestamp',' 1=1')
|
||||
json_data = json.dumps(data)
|
||||
self.logger.debug('[Messaging] Registration message was created')
|
||||
return json_data
|
||||
|
|
|
@ -20,8 +20,11 @@ class Registration():
|
|||
self.message_manager = scope.getMessageManager()
|
||||
self.event_manager = scope.getEventManager()
|
||||
self.messager = scope.getMessager()
|
||||
self.conf_manager = scope.getConfigurationManager()
|
||||
self.db_service = scope.getDbService()
|
||||
|
||||
self.event_manager.register_event('REGISTRATION_RESPONSE', self.registration_process)
|
||||
|
||||
if self.is_registered():
|
||||
self.logger.debug('[Registration] Ahenk already registered')
|
||||
else:
|
||||
|
@ -36,33 +39,33 @@ class Registration():
|
|||
self.logger.debug('[Registration] Requesting LDAP registration')
|
||||
self.messager.send_Direct_message(self.message_manager.ldap_registration_msg())
|
||||
|
||||
def confirm_registration(self, reg_reply):
|
||||
def registration_process(self, reg_reply):
|
||||
self.logger.debug('[Registration] Reading registration reply')
|
||||
j = json.loads(reg_reply)
|
||||
self.logger.debug('[Registration]' + j['message'])
|
||||
status = str(j['status']).lower()
|
||||
dn = str(j['agentDn']).lower()
|
||||
|
||||
self.logger.debug('[Registration] Registration status: ' + str(status))
|
||||
|
||||
if 'registered' == str(status) or 'registered_without_ldap' == str(status):
|
||||
if 'already_exists' == str(status) or 'registered' == str(status) or 'registered_without_ldap' == str(status):
|
||||
self.logger.debug('dn:' + dn)
|
||||
self.update_conf_file(dn)
|
||||
self.update_registration_attrs(dn)
|
||||
elif 'registration_error' == str(status):
|
||||
self.logger.info('[Registration] Registration is failed. New registration request will send')
|
||||
self.re_register()
|
||||
self.registration_request()
|
||||
elif 'already_exists' == str(status):
|
||||
self.update_conf_file(dn)
|
||||
self.logger.info('[Registration] Ahenk already registered')
|
||||
else:
|
||||
self.logger.error('[Registration] Bad message type of registration response ')
|
||||
|
||||
def update_conf_file(self, dn=None):
|
||||
def update_registration_attrs(self, dn=None):
|
||||
self.logger.debug('[Registration] Registration configuration is updating...')
|
||||
self.db_service.update('registration', ['dn', 'registered'], [dn, 1], ' registered = 0')
|
||||
|
||||
if self.conf_manager.has_section('CONNECTION'):
|
||||
self.conf_manager.set('CONNECTION', 'uid',self.conf_manager.get('REGISTRATION', 'from'))
|
||||
self.conf_manager.set('CONNECTION', 'password',self.conf_manager.get('REGISTRATION', 'password'))
|
||||
#TODO get file path?
|
||||
self.conf_manager.set('CONNECTION', 'uid', self.db_service.select_one_result('registration', 'jid', ' registered=1'))
|
||||
self.conf_manager.set('CONNECTION', 'password', self.db_service.select_one_result('registration', 'password', ' registered=1'))
|
||||
# TODO get file path?
|
||||
with open('/etc/ahenk/ahenk.conf', 'w') as configfile:
|
||||
self.conf_manager.write(configfile)
|
||||
self.logger.debug('[Registration] Registration configuration file is updated')
|
||||
|
|
Loading…
Reference in a new issue