From bf371830051244f30c0c063ea9c256c9795be9a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20=C5=9Eahin?= Date: Mon, 15 Aug 2016 11:21:23 +0300 Subject: [PATCH 1/2] resource fixed and code formatted --- .../base/messaging/AnonymousMessenger.py | 15 ++++++++---- opt/ahenk/base/messaging/Messenger.py | 23 ++++++++++++++----- opt/ahenk/base/registration/Registration.py | 4 ++-- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/opt/ahenk/base/messaging/AnonymousMessenger.py b/opt/ahenk/base/messaging/AnonymousMessenger.py index 9b67e8e..300ef00 100644 --- a/opt/ahenk/base/messaging/AnonymousMessenger.py +++ b/opt/ahenk/base/messaging/AnonymousMessenger.py @@ -6,12 +6,12 @@ import json import sys from sleekxmpp import ClientXMPP - -sys.path.append('../..') from base.Scope import Scope +sys.path.append('../..') -class AnonymousMessager(ClientXMPP): + +class AnonymousMessenger(ClientXMPP): def __init__(self, message): # global scope of ahenk scope = Scope().getInstance() @@ -28,7 +28,12 @@ class AnonymousMessager(ClientXMPP): ClientXMPP.__init__(self, self.service, None) self.message = message - self.receiver = self.configuration_manager.get('CONNECTION', 'receiverjid') + '@' + self.configuration_manager.get('CONNECTION', 'servicename') + '/' + self.configuration_manager.get('CONNECTION', 'receiverresource') + self.receiver_resource = self.configuration_manager.get('CONNECTION', 'receiverresource') + self.receiver = self.configuration_manager.get('CONNECTION', + 'receiverjid') + '@' + self.configuration_manager.get( + 'CONNECTION', 'servicename') + if self.receiver_resource: + self.receiver += '/' + self.receiver_resource self.logger.debug('[AnonymousMessenger] XMPP Receiver parameters were set') @@ -72,7 +77,7 @@ class AnonymousMessager(ClientXMPP): return False def recv_direct_message(self, msg): - if msg['type'] in ('normal'): + if msg['type'] in ['normal']: self.logger.debug('[AnonymousMessenger] ---------->Received message: {}'.format(str(msg['body']))) self.logger.debug('[AnonymousMessenger] Disconnecting...') self.disconnect() diff --git a/opt/ahenk/base/messaging/Messenger.py b/opt/ahenk/base/messaging/Messenger.py index d4eac63..edd309b 100644 --- a/opt/ahenk/base/messaging/Messenger.py +++ b/opt/ahenk/base/messaging/Messenger.py @@ -21,7 +21,9 @@ class Messenger(ClientXMPP): self.event_manger = scope.getEventManager() self.execution_manager = scope.getExecutionManager() - self.my_jid = str(self.configuration_manager.get('CONNECTION', 'uid') + '@' + self.configuration_manager.get('CONNECTION', 'servicename')) + self.my_jid = str( + self.configuration_manager.get('CONNECTION', 'uid') + '@' + self.configuration_manager.get('CONNECTION', + 'servicename')) self.my_pass = str(self.configuration_manager.get('CONNECTION', 'password')) ClientXMPP.__init__(self, self.my_jid, self.my_pass) @@ -30,8 +32,15 @@ class Messenger(ClientXMPP): self.auto_subscribe = True self.hostname = self.configuration_manager.get('CONNECTION', 'host') - self.resource_name = self.configuration_manager.get('CONNECTION', 'receiverresource') - self.receiver = self.configuration_manager.get('CONNECTION', 'receiverjid') + '@' + self.configuration_manager.get('CONNECTION', 'servicename') + '/' + self.resource_name + self.receiver_resource = self.configuration_manager.get('CONNECTION', 'receiverresource') + + self.receiver = self.configuration_manager.get('CONNECTION', + 'receiverjid') + '@' + self.configuration_manager.get( + 'CONNECTION', 'servicename') + + if self.receiver_resource: + self.receiver += '/' + self.receiver_resource + self.logger.debug('[Messenger] XMPP Messager parameters were set') self.register_extensions() @@ -79,10 +88,11 @@ class Messenger(ClientXMPP): self.logger.debug('[Messenger] <<--------Sending message: {}'.format(msg)) self.send_message(mto=self.receiver, mbody=msg, mtype='normal') except Exception as e: - self.logger.error('[Messenger] A problem occurred while sending direct message. Error Message: {}'.format(str(e))) + self.logger.error( + '[Messenger] A problem occurred while sending direct message. Error Message: {}'.format(str(e))) def recv_direct_message(self, msg): - if msg['type'] in ('normal'): + if msg['type'] in ['normal']: self.logger.debug('[Messenger] ---------->Received message: {}'.format(str(msg['body']))) try: j = json.loads(str(msg['body'])) @@ -90,4 +100,5 @@ class Messenger(ClientXMPP): self.event_manger.fireEvent(message_type, str(msg['body'])) self.logger.debug('[Messenger] Fired event is: {}'.format(message_type)) except Exception as e: - self.logger.error('[Messenger] A problem occurred while keeping message. Error Message: {}'.format(str(e))) + self.logger.error( + '[Messenger] A problem occurred while keeping message. Error Message: {}'.format(str(e))) diff --git a/opt/ahenk/base/registration/Registration.py b/opt/ahenk/base/registration/Registration.py index 0dddd52..8aa9bd2 100644 --- a/opt/ahenk/base/registration/Registration.py +++ b/opt/ahenk/base/registration/Registration.py @@ -8,7 +8,7 @@ import uuid from uuid import getnode as get_mac from base.Scope import Scope -from base.messaging.AnonymousMessenger import AnonymousMessager +from base.messaging.AnonymousMessenger import AnonymousMessenger from base.system.system import System from base.timer.setup_timer import SetupTimer from base.timer.timer import Timer @@ -35,7 +35,7 @@ class Registration: self.logger.debug('[Registration] Requesting registration') SetupTimer.start(Timer(System.Ahenk.registration_timeout(), timeout_function=self.registration_timeout, checker_func=self.is_registered, kwargs=None)) - anon_messenger = AnonymousMessager(self.message_manager.registration_msg()) + anon_messenger = AnonymousMessenger(self.message_manager.registration_msg()) anon_messenger.connect_to_server() def ldap_registration_request(self): From acf65a2d5bc3f28a4f28c624b660a6e6a1557f30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20=C5=9Eahin?= Date: Mon, 15 Aug 2016 11:22:10 +0300 Subject: [PATCH 2/2] default agreement text fixed --- opt/ahenk/base/agreement/agreement.py | 36 +++++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/opt/ahenk/base/agreement/agreement.py b/opt/ahenk/base/agreement/agreement.py index 98c7d74..7ac2063 100644 --- a/opt/ahenk/base/agreement/agreement.py +++ b/opt/ahenk/base/agreement/agreement.py @@ -24,9 +24,13 @@ class Agreement: self.logger.debug('[Agreement] There is no any contract in database.') contract_id = '-1' - if self.db_service.select_one_result('agreement', 'id', " contract_id='{0}' and username='{1}' and choice='Y' ".format(contract_id, username)) is not None: + if self.db_service.select_one_result('agreement', 'id', + " contract_id='{0}' and username='{1}' and choice='Y' " + .format(contract_id, username)) is not None: return True - elif self.db_service.select_one_result('agreement', 'id', " contract_id='{0}' and username='{1}' and choice='N' ".format(contract_id, username)) is not None: + elif self.db_service.select_one_result('agreement', 'id', + " contract_id='{0}' and username='{1}' and choice='N' ".format( + contract_id, username)) is not None: return False else: return None @@ -42,8 +46,8 @@ class Agreement: content = 'Ahenk kurulu bu bilgisayarda ilk defa oturum açıyorsunuz. ' \ 'Devam ederseniz Lider-Ahenk in bilgisayar üzeride yapacağı ' \ 'tüm işlemlere onay vermiş sayılacaksınız. Kabul ediyor musunuz?' \ - ' \n({} saniye içinde olumlu cevaplandırmadığınız takdirde oturumunuz ' \ - 'sonlandırılacaktır.)'.format(10) + ' \n(Tanımlanmış zaman aralığında olumlu cevaplandırmadığınız takdirde oturumunuz ' \ + 'sonlandırılacaktır.)' title = 'Ahenk Kurulu Bilgisayar Kullanım Anlaşması' contract_id = '-1' else: @@ -54,21 +58,31 @@ class Agreement: agreement_path = System.Ahenk.received_dir_path() + Util.generate_uuid() Util.write_file(agreement_path, content) Util.set_permission(agreement_path, 777) - command = 'export DISPLAY={0};su - {1} -c \'python3 {2} \"$(cat {3})\" \"{4}\"\''.format(display, username, self.ask_path, agreement_path, title) + command = 'export DISPLAY={0};su - {1} -c \'python3 {2} \"$(cat {3})\" \"{4}\"\''.format(display, username, + self.ask_path, + agreement_path, + title) result_code, p_out, p_err = Util.execute(command) pout = str(p_out).replace('\n', '') if pout != 'Error': if pout == 'Y': self.logger.debug('[Agreement] Agreement was accepted by {}.'.format(username)) - self.db_service.update('agreement', self.db_service.get_cols('agreement'), [contract_id, username, Util.timestamp(), 'Y']) + self.db_service.update('agreement', self.db_service.get_cols('agreement'), + [contract_id, username, Util.timestamp(), 'Y']) elif pout == 'N': - self.db_service.update('agreement', self.db_service.get_cols('agreement'), [contract_id, username, Util.timestamp(), 'N']) - self.logger.debug('[Agreement] Agreement was ignored by {}. Session will be closed'.format(username)) + self.db_service.update('agreement', self.db_service.get_cols('agreement'), + [contract_id, username, Util.timestamp(), 'N']) + self.logger.debug( + '[Agreement] Agreement was ignored by {}. Session will be closed'.format(username)) else: - self.logger.error('[Agreement] A problem occurred while executing ask.py. Error Message: {}'.format(str(pout))) + self.logger.error( + '[Agreement] A problem occurred while executing ask.py. Error Message: {}'.format(str(pout))) Util.delete_file(agreement_path) else: - self.logger.error('[Agreement] A problem occurred while executing ask.py (Probably argument fault). Error Message: {}'.format(str(pout))) + self.logger.error( + '[Agreement] A problem occurred while executing ask.py (Probably argument fault). Error Message: {}'.format( + str(pout))) except Exception as e: - self.logger.error('[Agreement] A Problem occurred while displaying agreement. Error Message: {}'.format(str(e))) + self.logger.error( + '[Agreement] A Problem occurred while displaying agreement. Error Message: {}'.format(str(e)))