mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 09:42:15 +03:00
Merge branch 'master' of https://github.com/Pardus-Kurumsal/ahenk
This commit is contained in:
commit
a44e7c3ea0
4 changed files with 54 additions and 24 deletions
|
@ -24,9 +24,13 @@ class Agreement:
|
||||||
self.logger.debug('[Agreement] There is no any contract in database.')
|
self.logger.debug('[Agreement] There is no any contract in database.')
|
||||||
contract_id = '-1'
|
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
|
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
|
return False
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
@ -42,8 +46,8 @@ class Agreement:
|
||||||
content = 'Ahenk kurulu bu bilgisayarda ilk defa oturum açıyorsunuz. ' \
|
content = 'Ahenk kurulu bu bilgisayarda ilk defa oturum açıyorsunuz. ' \
|
||||||
'Devam ederseniz Lider-Ahenk in bilgisayar üzeride yapacağı ' \
|
'Devam ederseniz Lider-Ahenk in bilgisayar üzeride yapacağı ' \
|
||||||
'tüm işlemlere onay vermiş sayılacaksınız. Kabul ediyor musunuz?' \
|
'tüm işlemlere onay vermiş sayılacaksınız. Kabul ediyor musunuz?' \
|
||||||
' \n({} saniye içinde olumlu cevaplandırmadığınız takdirde oturumunuz ' \
|
' \n(Tanımlanmış zaman aralığında olumlu cevaplandırmadığınız takdirde oturumunuz ' \
|
||||||
'sonlandırılacaktır.)'.format(10)
|
'sonlandırılacaktır.)'
|
||||||
title = 'Ahenk Kurulu Bilgisayar Kullanım Anlaşması'
|
title = 'Ahenk Kurulu Bilgisayar Kullanım Anlaşması'
|
||||||
contract_id = '-1'
|
contract_id = '-1'
|
||||||
else:
|
else:
|
||||||
|
@ -54,21 +58,31 @@ class Agreement:
|
||||||
agreement_path = System.Ahenk.received_dir_path() + Util.generate_uuid()
|
agreement_path = System.Ahenk.received_dir_path() + Util.generate_uuid()
|
||||||
Util.write_file(agreement_path, content)
|
Util.write_file(agreement_path, content)
|
||||||
Util.set_permission(agreement_path, 777)
|
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)
|
result_code, p_out, p_err = Util.execute(command)
|
||||||
pout = str(p_out).replace('\n', '')
|
pout = str(p_out).replace('\n', '')
|
||||||
if pout != 'Error':
|
if pout != 'Error':
|
||||||
if pout == 'Y':
|
if pout == 'Y':
|
||||||
self.logger.debug('[Agreement] Agreement was accepted by {}.'.format(username))
|
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':
|
elif pout == 'N':
|
||||||
self.db_service.update('agreement', self.db_service.get_cols('agreement'), [contract_id, username, Util.timestamp(), 'N'])
|
self.db_service.update('agreement', self.db_service.get_cols('agreement'),
|
||||||
self.logger.debug('[Agreement] Agreement was ignored by {}. Session will be closed'.format(username))
|
[contract_id, username, Util.timestamp(), 'N'])
|
||||||
|
self.logger.debug(
|
||||||
|
'[Agreement] Agreement was ignored by {}. Session will be closed'.format(username))
|
||||||
else:
|
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)
|
Util.delete_file(agreement_path)
|
||||||
else:
|
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:
|
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)))
|
||||||
|
|
|
@ -6,12 +6,12 @@ import json
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from sleekxmpp import ClientXMPP
|
from sleekxmpp import ClientXMPP
|
||||||
|
|
||||||
sys.path.append('../..')
|
|
||||||
from base.Scope import Scope
|
from base.Scope import Scope
|
||||||
|
|
||||||
|
sys.path.append('../..')
|
||||||
|
|
||||||
class AnonymousMessager(ClientXMPP):
|
|
||||||
|
class AnonymousMessenger(ClientXMPP):
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
# global scope of ahenk
|
# global scope of ahenk
|
||||||
scope = Scope().getInstance()
|
scope = Scope().getInstance()
|
||||||
|
@ -28,7 +28,12 @@ class AnonymousMessager(ClientXMPP):
|
||||||
ClientXMPP.__init__(self, self.service, None)
|
ClientXMPP.__init__(self, self.service, None)
|
||||||
|
|
||||||
self.message = message
|
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')
|
self.logger.debug('[AnonymousMessenger] XMPP Receiver parameters were set')
|
||||||
|
|
||||||
|
@ -72,7 +77,7 @@ class AnonymousMessager(ClientXMPP):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def recv_direct_message(self, msg):
|
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] ---------->Received message: {}'.format(str(msg['body'])))
|
||||||
self.logger.debug('[AnonymousMessenger] Disconnecting...')
|
self.logger.debug('[AnonymousMessenger] Disconnecting...')
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
|
@ -21,7 +21,9 @@ class Messenger(ClientXMPP):
|
||||||
self.event_manger = scope.getEventManager()
|
self.event_manger = scope.getEventManager()
|
||||||
self.execution_manager = scope.getExecutionManager()
|
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'))
|
self.my_pass = str(self.configuration_manager.get('CONNECTION', 'password'))
|
||||||
|
|
||||||
ClientXMPP.__init__(self, self.my_jid, self.my_pass)
|
ClientXMPP.__init__(self, self.my_jid, self.my_pass)
|
||||||
|
@ -30,8 +32,15 @@ class Messenger(ClientXMPP):
|
||||||
self.auto_subscribe = True
|
self.auto_subscribe = True
|
||||||
|
|
||||||
self.hostname = self.configuration_manager.get('CONNECTION', 'host')
|
self.hostname = self.configuration_manager.get('CONNECTION', 'host')
|
||||||
self.resource_name = 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') + '/' + self.resource_name
|
|
||||||
|
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.logger.debug('[Messenger] XMPP Messager parameters were set')
|
||||||
|
|
||||||
self.register_extensions()
|
self.register_extensions()
|
||||||
|
@ -79,10 +88,11 @@ class Messenger(ClientXMPP):
|
||||||
self.logger.debug('[Messenger] <<--------Sending message: {}'.format(msg))
|
self.logger.debug('[Messenger] <<--------Sending message: {}'.format(msg))
|
||||||
self.send_message(mto=self.receiver, mbody=msg, mtype='normal')
|
self.send_message(mto=self.receiver, mbody=msg, mtype='normal')
|
||||||
except Exception as e:
|
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):
|
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'])))
|
self.logger.debug('[Messenger] ---------->Received message: {}'.format(str(msg['body'])))
|
||||||
try:
|
try:
|
||||||
j = json.loads(str(msg['body']))
|
j = json.loads(str(msg['body']))
|
||||||
|
@ -90,4 +100,5 @@ class Messenger(ClientXMPP):
|
||||||
self.event_manger.fireEvent(message_type, str(msg['body']))
|
self.event_manger.fireEvent(message_type, str(msg['body']))
|
||||||
self.logger.debug('[Messenger] Fired event is: {}'.format(message_type))
|
self.logger.debug('[Messenger] Fired event is: {}'.format(message_type))
|
||||||
except Exception as e:
|
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)))
|
||||||
|
|
|
@ -8,7 +8,7 @@ import uuid
|
||||||
from uuid import getnode as get_mac
|
from uuid import getnode as get_mac
|
||||||
|
|
||||||
from base.Scope import Scope
|
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.system.system import System
|
||||||
from base.timer.setup_timer import SetupTimer
|
from base.timer.setup_timer import SetupTimer
|
||||||
from base.timer.timer import Timer
|
from base.timer.timer import Timer
|
||||||
|
@ -35,7 +35,7 @@ class Registration:
|
||||||
self.logger.debug('[Registration] Requesting registration')
|
self.logger.debug('[Registration] Requesting registration')
|
||||||
SetupTimer.start(Timer(System.Ahenk.registration_timeout(), timeout_function=self.registration_timeout,
|
SetupTimer.start(Timer(System.Ahenk.registration_timeout(), timeout_function=self.registration_timeout,
|
||||||
checker_func=self.is_registered, kwargs=None))
|
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()
|
anon_messenger.connect_to_server()
|
||||||
|
|
||||||
def ldap_registration_request(self):
|
def ldap_registration_request(self):
|
||||||
|
|
Loading…
Reference in a new issue