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