def main(i_msg, i_plr, i_latency): global payload global msgPaySize global plr global xmpp global latency ###Set global variables and constants### payload = ET.fromstring("<test xmlns = 'test'>%s</test>" % i_msg) msgPaySize = len(i_msg) plr = i_plr latency = i_latency ###Connect to the broker and set handlers### xmpp = sleekxmpp.ClientXMPP(jid, pw) xmpp.add_event_handler("session_start", on_start) xmpp.add_event_handler("message", on_message) xmpp.register_plugin('xep_0004') ###Dataforms xmpp.register_plugin('xep_0060') #PubSub xmpp.connect() xmpp.process(block=True) if flagEnd == 'X': return results
def __init__(self, xmppConf=None): """ Constructor, set up event handlers and register plugins """ self.running = False self.currentHash = 0 self.monitoredBotnets = [] self.foundTrack = False self.password = xmppConf.get("xmpp", "password") self.server = xmppConf.get("xmpp", "server") self.jid = xmppConf.get("xmpp", "jid"); self.sharechannel = xmppConf.get("xmpp", "datashare_channel") + "@conference." + self.server self.coordchannel = xmppConf.get("xmpp", "coordination_channel") + "@conference." + self.server self.port = xmppConf.get("xmpp", "port") self.xmpp = sleekxmpp.ClientXMPP(self.jid, self.password) self.xmpp.registerPlugin("xep_0045") self.xmpp.add_event_handler("session_start", self.handleXMPPConnected) self.xmpp.add_event_handler("disconnected", self.handleXMPPDisconnected) self.xmpp.add_event_handler("groupchat_message", self.handleIncomingGroupChatMessage) self.xmpp.add_event_handler("message", self.handleIncomingMessage) identifier = self.jid md5 = hashlib.new('md5') md5.update(identifier) self.id = md5.hexdigest()
def __init__(self, smarthome, jid, password, logic='XMPP'): self.logger = logging.getLogger(__name__) server = self.get_parameter_value('server') plugins = self.get_parameter_value('plugins') joins = self.get_parameter_value('join') # Check server parameter and default to port 5222 if server is None: self._server = None elif ':' in server: parts = server.split(':') self._server = (parts[0].strip(), parts[1].strip()) else: self._server = (server, 5222) # Enable MUC in case account should join channels if len(joins) and 'xep_0045' not in plugins: plugins.append('xep_0045') self.xmpp = sleekxmpp.ClientXMPP(jid, password) for plugin in plugins: self.xmpp.register_plugin(plugin) self.xmpp.use_ipv6 = self.get_parameter_value('use_ipv6') self.xmpp.add_event_handler("session_start", self.handleXMPPConnected) self.xmpp.add_event_handler("message", self.handleIncomingMessage) self._logic = logic self._sh = smarthome self._join = joins
def main(i_msg, i_plr, i_latency): global payload global msgPaySize global plr global xmpp global results global latency ###Set the CPU measurement### q = Queue.Queue() start_new_thread(measure_cpu, (results, q)) ###Set global variables and constants### payload = ET.fromstring("<test xmlns = 'test'>%s</test>" % i_msg) msgPaySize = len(i_msg) plr = i_plr latency = i_latency ###Connect to the broker and set handlers### xmpp = sleekxmpp.ClientXMPP(jid, pw) xmpp.add_event_handler("session_start", on_start) xmpp.add_event_handler("pubsub_publish", on_receive) xmpp.register_plugin('xep_0004') ###Dataforms xmpp.register_plugin('xep_0060') ###PubSub xmpp.connect() xmpp.process(block=True) if flagEnd == 'X': return results
def run(self): log.info('Connecting to XMPP server.') try: import sleekxmpp except ImportError: log.fatal('Unable to load sleekxmpp!') sys.exit(1) client = sleekxmpp.ClientXMPP(self.config['jid'], self.config['password']) client.register_plugin('xep_0045') client.register_plugin('xep_0030') client.register_plugin( 'xep_0199', pconfig={ 'keepalive': True, 'frequency': 60, 'timeout': 30, }, ) client.resource = 'bot' client.auto_authorize = True client.auto_subscribe = True def start(event): client.send_presence() client.get_roster() for room in self.config['rooms']: client.plugin['xep_0045'].joinMUC(room, self.config['full_name'], wait=True) client.add_event_handler('session_start', start) def message(msg): if msg['type'] in ('normal', 'chat'): log.debug('got message ' + pprint.pformat(msg)) responses = self.bot.proc('friend', msg['body']) for response in responses: if response.strip() != '': msg.reply(response).send() client.add_event_handler('message', message) def room_message(msg): if msg['mucnick'] != self.config['full_name']: log.debug('got MUC message ' + pprint.pformat(msg)) responses = self.bot.proc(msg['mucnick'], msg['body']) for response in responses: if response.strip() != '': client.send_message(mto=msg['from'].bare, mbody=response, mtype='groupchat') # deal with it time.sleep(0.5) client.add_event_handler('groupchat_message', room_message) if client.connect((self.config['server'], self.config['port'])): log.info('Procbot started. Connected to XMPP server.') client.process(block=True) log.info('Procbot exiting')
def __init__(self, config, service_name, service_name_namespace, id="master"): bus.Bus.__init__(self, id) self.config = config self.address = (config.get("DEFAULT", "address"), config.get("DEFAULT", "port")) # As address use mnemonic names self.domain = config.get("DEFAULT", "domain") self.MUC_name = config.get("DEFAULT", "mucService") self.username = config.get("DEFAULT", "user") self.password = config.get("DEFAULT", "password") self.nameSpacePassword = config.get("DEFAULT", "mucServicePassword") self._service_name = service_name self._service_name_namespace = service_name_namespace self._fully_qualified_service_name = self._service_name_namespace + "." + self._service_name self.xmpp = sleekxmpp.ClientXMPP(self._get_JId(), self.password) self.xmpp.register_plugin('xep_0004') # Data forms self.xmpp.register_plugin('xep_0030') # Service Discovery self.xmpp.register_plugin('xep_0045') # MUC self.xmpp.register_plugin('xep_0060') # MUC self.xmpp.register_plugin('xep_0077') # In-band Registration self.xmpp.register_plugin('xep_0078') # Non-SASL Authentication self.xmpp.register_plugin('xep_0199') # XMPP Ping self.xmpp.register_plugin('xep_0249') # Direct MUC invitation self.xmpp.add_event_handler('register', self._register) self.xmpp.add_event_handler('session_start', self._startService) self.xmpp.add_event_handler('message', self._handleXMPPSignal)
def _init_client(self, start_thread): ''' Setup/Start the client. The base class has a function of the same name, which is also called in its constructor. start_thread -- Right now this variable is unused, but is here so it not conflict with its parent's function declaration. ''' # Setup the XMPP Client that we are going to be using self.xmpp_client = sleekxmpp.ClientXMPP(self.user, self.password) self.xmpp_client.add_event_handler('session_start', self.xmpp_session_start) self.xmpp_client.add_event_handler('message', self.xmpp_message) self.xmpp_client.register_plugin('xep_0030') self.xmpp_client.register_plugin('xep_0199', pconfig={ 'keepalive': True, 'frequency': 240 }) self.xmpp_client.register_plugin( 'OpenADR2Plugin', module='oadr2.xmpp', pconfig={'callback': self._handle_oadr_payload}) # Setup system information disco self.xmpp_client['xep_0030'].add_identity(category='system', itype='version', name='OpenADR2 Python VEN') # Connect and thread the client self.xmpp_client.connect((self.server_addr, self.server_port)) self.xmpp_client.process(threaded=True)
def __init__(self, jid, password, backend, url): self.url = url self.xmpp = sleekxmpp.ClientXMPP(jid, password) ## BEGIN NEW for plugin in ["xep_0004", "xep_0030", "xep_0050"]: self.xmpp.registerPlugin(plugin) ## END NEW self.xmpp.add_event_handler("session_start", self.handleXMPPConnected) self.xmpp.add_event_handler("message", self.handleIncomingXMPPEvent) ## BEGIN NEW for event in ["got_online", "got_offline", "changed_status"]: self.xmpp.add_event_handler(event, self.handleIncomingXMPPPresence) ## END NEW self.backend = backend self.backend.addMessageHandler(self.handleMessageAddedToBackend) ## BEGIN NEW configurationForm = self.xmpp.plugin["xep_0004"].makeForm( "form", "Configure") configurationForm.addField(var="monitorPresence", label="Use my status messages", ftype="boolean", required=True, value=True) self.xmpp.plugin["xep_0050"].addCommand( "configure", "Configure", configurationForm, self.handleConfigurationCommand)
def run_bot(self): """ Convenience function to start a bot on the given network, optionally joining some channels """ jid = self.bot.config.xmpp_jid password = self.bot.config.xmpp_password def on_message(msg): """A callback to be called by xmpppy's when new message will arrive. In it's turn, it will call TheBot's callback, to pass request into it. """ if msg['type'] in ('chat', 'normal'): if msg['from'] != msg['to']: request = XMPPRequest(msg['body'], self.bot, unicode(msg['from'])) self.callback(request) def on_start(event): self.xmpp_bot.get_roster() self.xmpp_bot.send_presence() self.xmpp_bot = sleekxmpp.ClientXMPP(jid, password) self.xmpp_bot._use_daemons = True self.xmpp_bot.add_event_handler('session_start', on_start) self.xmpp_bot.add_event_handler('message', on_message) self.xmpp_bot.connect() self.xmpp_bot.process(block=True)
def main(i_msg, i_plr, i_latency): ###Globals### global payload global msgPaySize global plr global xmpp global g_msg global latency payload = ET.fromstring("<test xmlns = 'test'>%s</test>" % i_msg) msgPaySize = len(i_msg) plr = i_plr g_msg = i_msg latency = i_latency ###Connect to the broker and set handlers### xmpp = sleekxmpp.ClientXMPP(jid, pw) xmpp.add_event_handler("session_start", on_start) xmpp.add_event_handler("pubsub_publish", on_receive) xmpp.register_plugin('xep_0004') ###Dataforms xmpp.register_plugin('xep_0060') ###PubSub try: xmpp.connect() except: print('Cannot connect to the broker. Test failed!') sys.exit() xmpp.process(block=True) if flagEnd == 'X': return results
def _handle_action_login(self, account, password, status_, host, port): '''handle Action.ACTION_LOGIN ''' self.my_avatars = self.caches.get_avatar_cache( self.session.account.account) self.client = xmpp.ClientXMPP(account, password) self.client.process(block=False) self.client.register_plugin('xep_0004') # Data Forms self.client.register_plugin('xep_0030') # Service Discovery self.client.register_plugin('xep_0054') # vcard-temp self.client.register_plugin('xep_0060') # PubSub # MSN will kill connections that have been inactive for even # short periods of time. So use pings to keep the session alive; # whitespace keepalives do not work. if not self.session._is_facebook: self.client.register_plugin('xep_0199', { 'keepalive': True, 'frequency': 60 }) self.client.add_event_handler('session_start', self._session_started) self.client.add_event_handler('changed_status', self._on_presence) self.client.add_event_handler('message', self._on_message) self.client.connect((host, port)) self.session.login_started()
def send(self, type, text): self.msg_to_send = text self.client = sleekxmpp.ClientXMPP(self.source, self.password) self.client.add_event_handler("session_start", self._send) self.client.connect(('talk.google.com', 5222)) self.client.process(block=True)
def __init__(self, jid, password, backend, url) : self.url = url self.xmpp = sleekxmpp.ClientXMPP(jid, password) self.xmpp.add_event_handler("session_start", self.handleXMPPConnected) for event in ["message", "got_online", "got_offline", "changed_status"] : self.xmpp.add_event_handler(event, self.handleIncomingXMPPEvent) self.backend = backend self.backend.addMessageHandler(self.handleMessageAddedToBackend)
def __init__(self, jid, password): self.xmpp = sleekxmpp.ClientXMPP(jid, password) self.xmpp.register_plugin('xep_0030') # Service Discovery self.xmpp.register_plugin('xep_0004') # Data Forms self.xmpp.register_plugin('xep_0060') # PubSub self.xmpp.register_plugin('xep_0199') self.xmpp.add_event_handler('session_start', self.handle_connection) self.xmpp.add_event_handler('message', self.handle_incoming_msg)
def main(): global xmpp xmpp = sleekxmpp.ClientXMPP('bob@localhost', 'root') xmpp.add_event_handler("session_start", start) xmpp.add_event_handler("message", message) xmpp.register_plugin('xep_0030') xmpp.register_plugin('xep_0199') xmpp.connect() xmpp.process(block=True)
def register_account(jid, password, name='', email=''): client = sleekxmpp.ClientXMPP(jid, password) client.register_plugin('xep_0077') # In-band Registration return registration_wrapper(client=client, function=register, logger_success="Account created for %s!", logger_error="Could not register account: %s", args=(client, client.boundjid.user, password, name, email), kwargs={})
def send(self, type, text): message_time = time.time() message_timestamp = time.ctime(message_time) self.msg_to_send = text + " Message Sent at: " + message_timestamp if check_time_restriction(self.starttime, self.endtime): self.client = sleekxmpp.ClientXMPP(self.source, self.password) self.client.add_event_handler("session_start", self._send) self.client.connect(('talk.google.com', 5222)) self.client.process(block=True)
def client(): """ A sleekxmpp client with the upload plugin (and its dependencies) loaded. """ c = sleekxmpp.ClientXMPP( '*****@*****.**', 'supersecurepassword' ) c.register_plugin('xep_0030') c.register_plugin('upload', module=upload) return c
def registerXMPPAccount(user, password): responder = sleekxmpp.ClientXMPP(user, password) responder.register_plugin('xep_0030') # Service Discovery responder.register_plugin('xep_0077') responder['feature_mechanisms'].unencrypted_plain = True if responder.connect(("127.0.0.1", 5222)): responder.process(block=False) else: print "connect() failed" sys.exit(1)
def change_password(jid, old_password, new_password): client = sleekxmpp.ClientXMPP(jid, old_password) client.register_plugin('xep_0077') # In-band Registration return registration_wrapper( client=client, function=client['xep_0077'].change_password, logger_success="Password changed for %s!", logger_error="Could not change password for account: %s", args=(new_password, client.boundjid.server, client.boundjid.bare), kwargs=dict(timeout=TIMEOUT))
def start(self): self._xmpp = sleekxmpp.ClientXMPP( self._application.settings['xmpp_bot']['jid'], self._application.settings['xmpp_bot']['password']) self._xmpp.connect((self._application.settings['xmpp_bot']['server'], self._application.settings['xmpp_bot']['port'])) self._xmpp.add_event_handler("session_start", self._on_xmpp_session_start) self._xmpp.add_event_handler("message", self._on_xmpp_message) self._xmpp.process()
def start_client(self): """Start the Jabber client.""" self._client = sleekxmpp.ClientXMPP(self._jabber_id, self._jabber_password) self._client.register_plugin("xep_0045") self._client.add_event_handler("session_start", self._client_startup) self._client.add_event_handler("groupchat_message", self._client_receive) self._client.connect() self._client.process(threaded=True)
def __init__(self, jid, password, room, nick): """ Initialize the sleekxmpp object and register all the event handlers and plugins we're going to be using """ self.xmpp = sleekxmpp.ClientXMPP(jid, password) self.room = room self.nick = nick self.xmpp.add_event_handler( "session_start", self.start ) self.xmpp.add_event_handler( "groupchat_message", self.muc_message ) self.xmpp.register_plugin('xep_0030') # Service Discovery self.xmpp.register_plugin('xep_0045') # Multi-User Chat self.xmpp.register_plugin('xep_0199') # XMPP Ping
def main(): global xmpp xmpp = sleekxmpp.ClientXMPP(jid, pw) xmpp.add_event_handler("session_start", on_start) xmpp.add_event_handler("pubsub_publish", on_receive) xmpp.register_plugin('xep_0004') ###Dataforms xmpp.register_plugin('xep_0060') #PubSub xmpp.connect() xmpp.process(block=True)
def __init__(self, jid, password): self.user = jid self.password = password self.xmpp = sleekxmpp.ClientXMPP(jid, password) self.xmpp.add_event_handler("session_start", self.handleXMPPConnected, threaded=True) self.xmpp.add_event_handler("message", self.handleIncomingMessage, threaded=True) self.xmpp.add_event_handler("presence", self.handleIncomingPresence, threaded=True)
def im2(self, iMessage): """version using sleekxmpp """ self.xmppMessage = iMessage self.xmppClient = sleekxmpp.ClientXMPP(self.imParams.jid, self.imParams.password) self.xmppClient.add_event_handler('session_start', self.startXmpp) self.xmppClient.register_plugin('xep_0030') # Service Discovery self.xmppClient.register_plugin('xep_0199') # XMPP Ping if self.xmppClient.connect(): self.xmppClient.process(block=True) print("sleekxmpp: Done") else: print("sleekxmpp: Unable to connect.")
def initXmpp(self): from .secfg import xmpp_user, xmpp_pass, peer_xmpp_user, xmpp_server self.self_user = xmpp_user self.peer_user = peer_xmpp_user self.xmpp_server = xmpp_server self.xmpp_conference_host = 'conference.' + xmpp_user.split('@')[1] loglevel = logging.DEBUG loglevel = logging.WARNING logging.basicConfig(level=loglevel, format='%(levelname)-8s %(message)s') self.nick_name = 'yatbot0inmuc' self.peer_jid = peer_xmpp_user self.is_connected = False self.fixrooms = defaultdict(list) self.fixstatus = defaultdict(bool) self.xmpp = sleekxmpp.ClientXMPP(jid=xmpp_user, password=xmpp_pass) self.xmpp.auto_authorize = True self.xmpp.auto_subscribe = True self.xmpp.register_plugin('xep_0030') self.xmpp.register_plugin('xep_0045') self.xmpp.register_plugin('xep_0004') self.plugin_muc = self.xmpp.plugin['xep_0045'] self.xmpp.add_event_handler('connected', self.on_connected) self.xmpp.add_event_handler('connection_failed', self.on_connection_failed) self.xmpp.add_event_handler('disconnected', self.on_disconnected) self.xmpp.add_event_handler('session_start', self.on_session_start) self.xmpp.add_event_handler('message', self.on_message) self.xmpp.add_event_handler('groupchat_message', self.on_muc_message) self.xmpp.add_event_handler('groupchat_invite', self.on_groupchat_invite) self.xmpp.add_event_handler('got_online', self.on_muc_online) self.xmpp.add_event_handler('groupchat_presence', self.on_groupchat_presence) self.xmpp.add_event_handler('presence', self.on_presence) self.xmpp.add_event_handler('presence_available', self.on_presence_avaliable) qDebug(str(self.xmpp.boundjid.host) + '...........') self.start() return
def main(): global xmpp xmpp = sleekxmpp.ClientXMPP('bob@raspberrypi', 'root') xmpp.register_plugin('xep_0030') xmpp.register_plugin('xep_0060') #PubSub xmpp.add_event_handler("session_start", session_start) xmpp.add_event_handler("message", message) xmpp.add_event_handler("pubsub_publish", pubsub_publish) xmpp.add_event_handler("pubsub_subscription", pubsub_subscription) if xmpp.connect(): xmpp.process(block=True)
def main(i_msg): global xmpp global payload payload = ET.fromstring("<test xmlns = 'test'>%s</test>" % i_msg) xmpp = sleekxmpp.ClientXMPP(jid, pw) xmpp.add_event_handler("session_start", on_start) xmpp.add_event_handler("pubsub_publish", on_receive) xmpp.register_plugin('xep_0004') ###Dataforms xmpp.register_plugin('xep_0060') ###PubSub print('Connecting') xmpp.connect() xmpp.process(block=True)
def checkPusherServerPresence(domain_url): xmpp = sleekxmpp.ClientXMPP("*****@*****.**", "ei3tseq") conn_address = 'crater.buddycloud.org', 5222 if (not xmpp.connect( conn_address, reattempt=False, use_ssl=False, use_tls=False)): return "XMPP_CONNECTION_PROBLEM" xmpp.process(block=False) try: return xmppServerDiscoItems(domain_url, xmpp) finally: xmpp.disconnect()