logs were added, anonymous connection problem fixed

This commit is contained in:
Volkan Şahin 2016-03-11 17:51:26 +02:00
parent 8f81512560
commit 352073b3f8
3 changed files with 183 additions and 157 deletions

View file

@ -17,106 +17,124 @@ from base.event.EventManager import EventManager
from base.plugin.PluginManager import PluginManager from base.plugin.PluginManager import PluginManager
from base.task.TaskManager import TaskManager from base.task.TaskManager import TaskManager
from multiprocessing import Process from multiprocessing import Process
from threading import Thread import sys
import sys,logging,queue,time,os
class AhenkDeamon(BaseDaemon): class AhenkDeamon(BaseDaemon):
"""docstring for AhenkDeamon""" """docstring for AhenkDeamon"""
def reload(self,msg): def reload(self,msg):
# reload service here # reload service here
pass pass
def run(self): def run(self):
print ("merhaba dunya") print ("Ahenk running...")
globalscope = Scope() globalscope = Scope()
globalscope.setInstance(globalscope) globalscope.setInstance(globalscope)
configFilePath='/etc/ahenk/ahenk.conf' configFilePath='/etc/ahenk/ahenk.conf'
configfileFolderPath='/etc/ahenk/config.d/' configfileFolderPath='/etc/ahenk/config.d/'
#configuration manager must be first load #configuration manager must be first load
configManager = ConfigManager(configFilePath,configfileFolderPath) configManager = ConfigManager(configFilePath,configfileFolderPath)
config = configManager.read() config = configManager.read()
globalscope.setConfigurationManager(config) globalscope.setConfigurationManager(config)
# Logger must be second # Logger must be second
logger = Logger() logger = Logger()
logger.info("this is info log") logger.info("[AhenkDeamon] Log was set")
globalscope.setLogger(logger) globalscope.setLogger(logger)
eventManager = EventManager() eventManager = EventManager()
globalscope.setEventManager(eventManager) globalscope.setEventManager(eventManager)
logger.info("[AhenkDeamon] Event Manager was set")
messageManager = Messaging() messageManager = Messaging()
globalscope.setMessageManager(messageManager) globalscope.setMessageManager(messageManager)
logger.info("[AhenkDeamon] Message Manager was set")
pluginManager = PluginManager() pluginManager = PluginManager()
pluginManager.loadPlugins() pluginManager.loadPlugins()
globalscope.setPluginManager(pluginManager) globalscope.setPluginManager(pluginManager)
logger.info("[AhenkDeamon] Plugin Manager was set")
taskManger = TaskManager() taskManger = TaskManager()
globalscope.setTaskManager(taskManger) globalscope.setTaskManager(taskManger)
logger.info("[AhenkDeamon] Task Manager was set")
registration=Registration() registration=Registration()
globalscope.setRegistration(registration) globalscope.setRegistration(registration)
logger.info("[AhenkDeamon] Registration was set")
execution_manager=ExecutionManager() execution_manager=ExecutionManager()
globalscope.setExecutionManager(execution_manager)
logger.info("[AhenkDeamon] Execution Manager was set")
while registration.is_registered() is False:
registration.registration_request()
print("Receiver OnAir") while registration.is_registered() is False:
message_receiver = MessageReceiver() logger.debug("[AhenkDeamon] Attempting to register")
rec_process = Process(target=message_receiver.connect_to_server) registration.registration_request()
rec_process.start()
logger.info("[AhenkDeamon] Ahenk is registered")
message_receiver = MessageReceiver()
rec_process = Process(target=message_receiver.connect_to_server)
rec_process.start()
logger.info("[AhenkDeamon] Receiver was set")
if registration.is_ldap_registered() is False:
logger.debug("[AhenkDeamon] Attempting to registering ldap")
registration.ldap_registration_request() #TODO bu mesaj daha kısa olabilir
logger.info("[AhenkDeamon] LDAP registration of Ahenk is completed")
#login #login
#message_sender=MessageSender(messageManager.login_msg(),None) logger.info("[AhenkDeamon] Logining...")
#message_sender.connect_to_server() message_sender=MessageSender(messageManager.login_msg(),None)
message_sender.connect_to_server()
#logout
#message_sender=MessageSender(messageManager.logout_msg(),None)
#message_sender.connect_to_server()
#rec_process.terminate() #logout
#message_sender=MessageSender(messageManager.logout_msg(),None)
#message_sender.connect_to_server()
""" #rec_process.terminate()
this is must be created after message services
responseQueue = queue.Queue() """
messageResponseQueue = MessageResponseQueue(responseQueue) this is must be created after message services
messageResponseQueue.setDaemon(True) responseQueue = queue.Queue()
messageResponseQueue.start() messageResponseQueue = MessageResponseQueue(responseQueue)
globalscope.setResponseQueue(responseQueue) messageResponseQueue.setDaemon(True)
""" messageResponseQueue.start()
globalscope.setResponseQueue(responseQueue)
"""
if __name__ == '__main__': if __name__ == '__main__':
pidfilePath='/var/run/ahenk.pid' pidfilePath='/var/run/ahenk.pid'
ahenkdaemon = AhenkDeamon(pidfilePath) ahenkdaemon = AhenkDeamon(pidfilePath)
print (sys.argv) print (sys.argv)
if len(sys.argv) == 2: if len(sys.argv) == 2:
if sys.argv[1] == "start": if sys.argv[1] == "start":
print ("starting") print ("starting")
ahenkdaemon.run() ahenkdaemon.run()
#print (ahenkdaemon.get_pid()) #print (ahenkdaemon.get_pid())
elif sys.argv[1] == 'stop': elif sys.argv[1] == 'stop':
ahenkdaemon.stop() ahenkdaemon.stop()
elif sys.argv[1] == 'restart': elif sys.argv[1] == 'restart':
ahenkdaemon.restart() ahenkdaemon.restart()
elif sys.argv[1] == 'status': elif sys.argv[1] == 'status':
# print (status) # print (status)
pass pass
else: else:
print ('Unknown command. Usage : %s start|stop|restart|status' % sys.argv[0]) print ('Unknown command. Usage : %s start|stop|restart|status' % sys.argv[0])
sys.exit(2) sys.exit(2)
sys.exit(0) sys.exit(0)
else: else:
print ('Usage : %s start|stop|restart|status' % sys.argv[0]) print ('Usage : %s start|stop|restart|status' % sys.argv[0])
sys.exit(2) sys.exit(2)

View file

@ -2,29 +2,22 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com> # Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com> # Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
import sys import json, os, asyncio, slixmpp, sys
sys.path.append('../..') sys.path.append('../..')
import slixmpp
import asyncio
import threading
import json
from threading import Thread
from multiprocessing import Process
from slixmpp.exceptions import IqError, IqTimeout
from base.Scope import Scope from base.Scope import Scope
class MessageReceiver(slixmpp.ClientXMPP): class MessageReceiver(slixmpp.ClientXMPP):
def __init__(self): def __init__(self):
# global scope of ahenk # global scope of ahenk
scope = Scope().getInstance() scope = Scope().getInstance()
# configuration_manager and logger comes from ahenk deamon
self.logger = scope.getLogger() self.logger = scope.getLogger()
self.configurationManager = scope.getConfigurationManager() self.configuration_manager = scope.getConfigurationManager()
self.event_manger=scope.getEventManager() self.event_manger=scope.getEventManager()
self.execution_manager=scope.getExecutionManager()
self.my_jid=self.get_jid_id() self.my_jid=self.get_jid_id()
self.my_pass=self.get_password() self.my_pass=self.get_password()
@ -32,32 +25,33 @@ class MessageReceiver(slixmpp.ClientXMPP):
slixmpp.ClientXMPP.__init__(self, self.my_jid,self.my_pass) slixmpp.ClientXMPP.__init__(self, self.my_jid,self.my_pass)
self.room=None self.room=None
self.receiver=self.configurationManager.get('CONNECTION', 'receiverjid')+'@'+self.configurationManager.get('CONNECTION', 'host')+'/Smack' self.receiver=self.configuration_manager.get('CONNECTION', 'receiverjid')+'@'+self.configuration_manager.get('CONNECTION', 'host')+'/Smack'
self.nick = self.configurationManager.get('CONNECTION', 'nick') self.nick = self.configuration_manager.get('CONNECTION', 'nick')
self.receive_file_path=self.configurationManager.get('CONNECTION', 'receiveFileParam') self.receive_file_path=self.configuration_manager.get('CONNECTION', 'receiveFileParam')
self.logger.debug('[MessageReceiver] XMPP Receiver parameters were set')
#TODO get default folder path from receivefile
#self.file = open('/home/volkan/Desktop/yaz.txt', 'rb')
self.register_extensions() self.register_extensions()
self.add_listeners() self.add_listeners()
self.connect() self.connect()
def get_jid_id(self): def get_jid_id(self):
if self.configurationManager.get('CONNECTION', 'uid') == "" or self.configurationManager.get('CONNECTION', 'uid') is None: if self.configuration_manager.get('CONNECTION', 'uid') == "" or self.configuration_manager.get('CONNECTION', 'uid') is None:
return str(self.configurationManager.get('CONNECTION', 'host')) #is user want to create connection as anonymous self.logger.debug('[MessageReceiver] Parameters were set as anonymous account')
return str(self.configuration_manager.get('CONNECTION', 'host'))
else: else:
return str(self.configurationManager.get('CONNECTION', 'uid')+'@'+self.configurationManager.get('CONNECTION', 'host')+'/receiver') self.logger.debug('[MessageReceiver] Parameters were set as defined account')
return str(self.configuration_manager.get('CONNECTION', 'uid')+'@'+self.configuration_manager.get('CONNECTION', 'host')+'/receiver')
def get_password(self): def get_password(self):
if self.configurationManager.get('CONNECTION', 'password') == "" or self.configurationManager.get('CONNECTION', 'password') is None: if self.configuration_manager.get('CONNECTION', 'password') == "" or self.configuration_manager.get('CONNECTION', 'password') is None:
return None return None
else: else:
return str(self.configurationManager.get('CONNECTION', 'password')) return str(self.configuration_manager.get('CONNECTION', 'password'))
def add_listeners(self): def add_listeners(self):
self.add_event_handler("session_start", self.session_start) self.add_event_handler("session_start", self.session_start)
self.add_event_handler("message", self.recv_direct_message) self.add_event_handler("message", self.recv_direct_message)
self.add_event_handler("socks5_connected", self.stream_opened) self.add_event_handler("socks5_connected", self.stream_opened)
self.add_event_handler("socks5_data", self.stream_data) self.add_event_handler("socks5_data", self.stream_data)
self.add_event_handler("socks5_closed", self.stream_closed) self.add_event_handler("socks5_closed", self.stream_closed)
@ -66,68 +60,68 @@ class MessageReceiver(slixmpp.ClientXMPP):
self.add_event_handler("ibb_stream_data", self.stream_data) self.add_event_handler("ibb_stream_data", self.stream_data)
self.add_event_handler("ibb_stream_end", self.stream_closed) self.add_event_handler("ibb_stream_end", self.stream_closed)
def stream_opened(self, sid): self.logger.debug('[MessageReceiver] Event handlers were added')
print('stream opened')
print('So stream_id:'+str(self.stream_id))
def stream_opened(self, sid):
self.logger.debug('[MessageReceiver] Stream was opened. Stream id: '+str(self.stream_id))
self.file = open(self.receive_file_path+self.stream_id, 'wb') self.file = open(self.receive_file_path+self.stream_id, 'wb')
return self.file return self.file
def stream_data(self, data): def stream_data(self, data):
print('stream data') self.logger.debug('[MessageReceiver] Receiving file...')
self.logger.info('Sd'+self.get_id())
#self.logger.info('Stream data.')
self.file.write(data) self.file.write(data)
def stream_closed(self, exception): def stream_closed(self, exception):
print('stream close') self.logger.debug('[MessageReceiver] Stream was closed')
#self.logger.info('Stream closed. %s', exception)
self.file.close() self.file.close()
self.set_file_name_to_md5()
def session_start(self, event): def session_start(self, event):
self.logger.debug('[MessageReceiver] Session was started')
self.get_roster() self.get_roster()
self.send_presence() self.send_presence()
def send_direct_message(self,msg): def send_direct_message(self,msg):
#need connection control self.logger.debug('[MessageReceiver] Sending message: '+msg)
print("sending...\n"+msg)
self.send_message(mto=self.receiver,mbody=msg,mtype='normal') self.send_message(mto=self.receiver,mbody=msg,mtype='normal')
def invite_auto_accept(self, inv): def invite_auto_accept(self, inv):
self.room=inv['from'] self.room=inv['from']
print("(%s) invite is accepted" % str(self.room)) self.logger.debug('[MessageReceiver] (%s) invite is accepted' % str(self.room))
self.plugin['xep_0045'].joinMUC(self.room,self.nick,wait=True) self.plugin['xep_0045'].joinMUC(self.room,self.nick,wait=True)
self.send_message(mto=self.room.bare,mbody="Hi all!",mtype='groupchat') self.send_message(mto=self.room.bare,mbody="Hi all!",mtype='groupchat')
return self.room return self.room
def recv_muc_message(self, msg):#auto reply def recv_muc_message(self, msg):
if msg['mucnick'] != self.nick: if msg['mucnick'] != self.nick:
print("%s : %s" % (str(msg['from']),str(msg['body'])) ) self.logger.debug('[MessageReceiver] %s : %s' % (str(msg['from']),str(msg['body'])) )
self.send_message(mto=msg['from'].bare,mbody="I got it, %s." % msg['mucnick'],mtype='groupchat') self.send_message(mto=msg['from'].bare,mbody="I got it, %s." % msg['mucnick'],mtype='groupchat')
else: else:
print("%s : %s" % (str(msg['mucnick']),str(msg['body']))) self.logger.debug('[MessageReceiver] %s : %s' % (str(msg['mucnick']),str(msg['body'])))
def recv_direct_message(self, msg): #TODO burada mesajın type ını event olarak fırlat def recv_direct_message(self, msg):
if msg['type'] in ('chat', 'normal'): if msg['type'] in ('chat', 'normal'):
j = json.loads(str(msg['body'])) j = json.loads(str(msg['body']))
type =j['type'] type =j['type']
print ("event will be fired:"+type) self.logger.debug('[MessageReceiver] Fired event is: '+type)
self.event_manger.fireEvent(type,str(msg['body']).lower()) self.event_manger.fireEvent(type,str(msg['body']).lower())
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.
try: try:
self.logger.debug('[MessageReceiver] Connecting to server as thread')
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
loop.run_until_complete(self.process()) loop.run_until_complete(self.process())
self.logger.debug('[MessageReceiver] Connection were established successfully')
#self.logger.info('Connection were established successfully')
return True return True
except Exception as e: except Exception as e:
print('Connection to server is failed (%s)\n' % (e.strerror)) self.logger.error('[MessageReceiver] Connection to server is failed! '+e)
#self.logger.error('Connection to server is failed! '+e)
return False return False
def set_file_name_to_md5(self):
self.logger.debug('[MessageReceiver] Renaming file as md5 hash')
md5_hash=self.execution_manager.get_md5_file(self.file.name)
os.rename(self.file.name,self.receive_file_path+md5_hash)
def register_extensions(self): def register_extensions(self):
try: try:
self.register_plugin('xep_0030') # Service Discovery self.register_plugin('xep_0030') # Service Discovery
@ -136,8 +130,8 @@ class MessageReceiver(slixmpp.ClientXMPP):
self.register_plugin('xep_0065', {'auto_accept': True}) # SOCKS5 Bytestreams self.register_plugin('xep_0065', {'auto_accept': True}) # SOCKS5 Bytestreams
self.register_plugin('xep_0047', {'auto_accept': True}) # In-band Bytestreams self.register_plugin('xep_0047', {'auto_accept': True}) # In-band Bytestreams
#self.logger.info('Extension were registered: xep_0030,xep_0045,xep_0199,xep_0065') self.logger.debug('Extension were registered: xep_0030,xep_0045,xep_0199,xep_0065,xep_0047')
return True return True
except Exception as e: except Exception as e:
#self.logger.error('Extension registration is failed!(%s)\n' % (e.errno, e.strerror)) self.logger.error('Extension registration is failed!(%s)\n' % (e.errno, e.strerror))
return False return False

View file

@ -2,27 +2,21 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com> # Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com> # Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
import sys import slixmpp, asyncio, sys
sys.path.append('../..') sys.path.append('../..')
import slixmpp
import asyncio
import threading
from threading import Thread
from multiprocessing import Process
from slixmpp.exceptions import IqError, IqTimeout from slixmpp.exceptions import IqError, IqTimeout
from base.Scope import Scope from base.Scope import Scope
class MessageSender(slixmpp.ClientXMPP): class MessageSender(slixmpp.ClientXMPP):
def __init__(self,message,file_path):
def __init__(self,message,file_path):
# global scope of ahenk # global scope of ahenk
scope = Scope().getInstance() scope = Scope().getInstance()
# logger comes from ahenk deamon
#configurationManager comes from ahenk deamon
self.logger = scope.getLogger() self.logger = scope.getLogger()
self.configurationManager = scope.getConfigurationManager() self.configuration_manager = scope.getConfigurationManager()
self.registration=scope.getRegistration() self.registration=scope.getRegistration()
self.event_manager = scope.getEventManager() self.event_manager = scope.getEventManager()
@ -34,15 +28,17 @@ class MessageSender(slixmpp.ClientXMPP):
self.message=None self.message=None
self.file=None self.file=None
self.room=None self.room=None
self.receiver=self.configurationManager.get('CONNECTION', 'receiverjid')+'@'+self.configurationManager.get('CONNECTION', 'host')+'/Smack' self.receiver=self.configuration_manager.get('CONNECTION', 'receiverjid')+'@'+self.configuration_manager.get('CONNECTION', 'host')+'/Smack'
self.nick = self.configurationManager.get('CONNECTION', 'nick') self.nick = self.configuration_manager.get('CONNECTION', 'nick')
self.receivefile=self.configurationManager.get('CONNECTION', 'receiveFileParam') self.receivefile=self.configuration_manager.get('CONNECTION', 'receiveFileParam')
if file_path is not None and file_path!='': if file_path is not None and file_path!='':
self.file=open(file_path, 'rb') self.file=open(file_path, 'rb')
if message is not None: if message is not None:
self.message=message self.message=message
self.logger.debug('[MessageSender] XMPP Receiver parameters were set')
self.add_listeners() self.add_listeners()
self.register_extensions() self.register_extensions()
@ -52,41 +48,48 @@ class MessageSender(slixmpp.ClientXMPP):
self.add_event_handler("socks5_connected", self.stream_opened) self.add_event_handler("socks5_connected", self.stream_opened)
self.add_event_handler("socks5_data", self.stream_data) self.add_event_handler("socks5_data", self.stream_data)
self.add_event_handler("socks5_closed", self.stream_closed) self.add_event_handler("socks5_closed", self.stream_closed)
self.logger.debug('[MessageSender] Event handlers were added')
def get_jid_id(self): def get_jid_id(self):
if self.configurationManager.get('CONNECTION', 'uid') == "" or self.configurationManager.get('CONNECTION', 'uid') is None: if self.is_anonymous()==True:
return str(self.configurationManager.get('CONNECTION', 'host')) #is user want to create connection as anonymous self.logger.debug('[MessageSender] Parameters were set as anonymous account')
return str(self.configuration_manager.get('CONNECTION', 'host'))
else: else:
return str(self.configurationManager.get('CONNECTION', 'uid')+'@'+self.configurationManager.get('CONNECTION', 'host')+'/sender') self.logger.debug('[MessageSender] Parameters were set as defined account')
return str(self.configuration_manager.get('CONNECTION', 'uid')+'@'+self.configuration_manager.get('CONNECTION', 'host')+'/sender')
def get_password(self): def get_password(self):
if self.configurationManager.get('CONNECTION', 'password') == "" or self.configurationManager.get('CONNECTION', 'password') is None: if self.configuration_manager.get('CONNECTION', 'password') == "" or self.configuration_manager.get('CONNECTION', 'password') is None:
return None return None
else: else:
return str(self.configurationManager.get('CONNECTION', 'password')) return str(self.configuration_manager.get('CONNECTION', 'password'))
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 ("%s : %s" % (msg['from'], msg['body'])) self.logger.debug("[MessageSender] Received message: %s -> %s" % (msg['from'], msg['body']))
self.disconnect() self.disconnect()
self.event_manager.fireEvent('confirm_registration',str(msg['body'])) #only anonymous account can fire confirm_registration 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
@asyncio.coroutine @asyncio.coroutine
def session_start(self, event): def session_start(self, event):
print("session start") self.logger.debug('[MessageSender] Session was started')
self.get_roster() self.get_roster()
self.send_presence() self.send_presence()
if self.message is not None: if self.message is not None:
self.send_direct_message(self.message) self.send_direct_message(self.message)
print("sent")
if self.file is not None: if self.file is not None:
self.logger.debug('[MessageSender] Sending file: '+self.file.name)
try: try:
self.logger.debug('[MessageSender] Handshaking for file transfering...')
# Open the S5B stream in which to write to. # Open the S5B stream in which to write to.
proxy = yield from self['xep_0065'].handshake(self.receiver) proxy = yield from self['xep_0065'].handshake(self.receiver)
# Send the entire file. # Send the entire file.
self.logger.debug('[MessageSender] Started to streaming file...')
while True: while True:
data = self.file.read(1048576) data = self.file.read(1048576)
if not data: if not data:
@ -95,43 +98,54 @@ class MessageSender(slixmpp.ClientXMPP):
# And finally close the stream. # And finally close the stream.
proxy.transport.write_eof() proxy.transport.write_eof()
except (IqError, IqTimeout): except (IqError, IqTimeout):
print('File transfer errored') self.logger.error('[MessageSender] File transfer errored')
else: else:
print('File transfer finished') self.logger.debug('[MessageSender] File transfer finished successfully')
finally: finally:
self.file.close() self.file.close()
if (self.message is None and self.file is None) or self.get_password() is not None: if (self.message is None and self.file is None) or self.get_password() is not None:#TODO password yerine ???
self.logger.debug('[MessageSender] Disconnecting...')
self.disconnect() self.disconnect()
def stream_opened(self, sid): def stream_opened(self, sid):
#self.logger.info('Stream opened. %s', sid) self.logger.debug('[MessageSender] Stream was opened. Stream id: '+str(self.stream_id))
self.file = open(self.receive_file_path+self.stream_id, 'wb') self.file = open(self.receive_file_path+self.stream_id, 'wb')
return self.file return self.file
def stream_data(self, data): def stream_data(self, data):
#self.logger.info('Stream data.') self.logger.debug('[MessageSender] Receiving file...')
self.file.write(data) self.file.write(data)
def stream_closed(self, exception): def stream_closed(self, exception):
#self.logger.info('Stream closed. %s', exception) self.logger.debug('[MessageSender] Stream was closed')
self.file.close() self.file.close()
self.logger.debug('[MessageSender] Disconnecting...')
self.disconnect() self.disconnect()
def send_direct_message(self,msg): def send_direct_message(self,msg):
#need connection control self.logger.debug('[MessageSender] Sending message: '+msg)
print("sending...\n"+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.
try: try:
self.logger.debug('[MessageSender] Connecting to server...')
self.connect() self.connect()
self.process(forever=True)
#self.logger.info('Connection were established successfully') if self.is_anonymous()==True:
self.process(forever=False)
else:
self.process(forever=True)
self.logger.debug('[MessageSender] Connection were established successfully')
return True return True
except Exception as e: except Exception as e:
print('Connection to server is failed (%s)\n' % (e.strerror)) self.logger.error('[MessageSender] Connection to server is failed! '+e)
#self.logger.error('Connection to server is failed! '+e) return False
def is_anonymous(self):
if self.configuration_manager.get('CONNECTION', 'uid') == "" or self.configuration_manager.get('CONNECTION', 'uid') is None:
return True
else:
return False return False
def register_extensions(self): def register_extensions(self):
@ -142,8 +156,8 @@ class MessageSender(slixmpp.ClientXMPP):
self.register_plugin('xep_0065', {'auto_accept': True}) # SOCKS5 Bytestreams self.register_plugin('xep_0065', {'auto_accept': True}) # SOCKS5 Bytestreams
self.register_plugin('xep_0047', {'auto_accept': True}) # In-band Bytestreams self.register_plugin('xep_0047', {'auto_accept': True}) # In-band Bytestreams
#self.logger.info('Extension were registered: xep_0030,xep_0045,xep_0199,xep_0065') self.logger.debug('[MessageSender] Extension were registered: xep_0030,xep_0045,xep_0199,xep_0065,xep_0047')
return True return True
except Exception as e: except Exception as e:
#self.logger.error('Extension registration is failed!(%s)\n' % (e.errno, e.strerror)) self.logger.error('[MessageSender] Extension registration is failed!(%s)\n' % (e.errno, e.strerror))
return False return False