def omegleCaptchaRequired(self, url): if not self.connected: presence = Presence(to=self.muc + '/' + self.nick) presence.setTag('x', namespace=xmpp.NS_MUC).setTagData('password', '') presence.getTag('x').addChild('history', {'maxchars': '0', 'maxstanzas': '0'}); self.xmppClient.send(presence) #~ print '[o:' + self.nick + '] captcha: ' + url self.sendToXMPP('.* CAPTCHA: ' + url)
def addAddressToRoster(self, address, user): '''Add the JID corresponding to a given bitcoin address to user's roster. The suggested name is the bitcoin address.''' debug("Adding address %s to %s's roster") msg = _(ROSTER, 'new_address_message') pres = Presence(typ='subscribe', status=msg, frm=address.jid, to=user.jid) pres.addChild('nick', payload=[address.address], namespace=NS_NICK) self.send(pres)
def declineSubscription(self, jid): ''' Declines the subscription request from 'jid' ''' msg = Presence(to=jid, typ="unsubscribed") self.myAgent.send(msg) self.myAgent.DEBUG("I have declined the " + str(jid) + "'s request of subscription to me")
def acceptSubscription(self, jid): ''' Accepts the subscription request from 'jid' ''' msg = Presence(to=jid, typ="subscribed") self.myAgent.send(msg) self.myAgent.DEBUG("I have accepted the " + str(jid) + "'s request of subscription to me")
def sendPresence(self, typ=None, priority=None, show=None, status=None): ''' Updates your presence to all your contacts typ - your presence type (available, unavailable,...) default='available' priority - the priority of the resource you are connected from show - The message shown to your contacts status - a brief description of your status ''' jid = self.myAgent.getName() + self.myAgent.resource self.myAgent.jabber.send( Presence(jid, typ=typ, priority=priority, show=show, status=status))
def connect(self): if not self.client.connect(): print 'Failed to connect to the XMPP server.\nExiting...' return False auth = self.client.auth(self.jid.getNode(), self.password, self.jid.getResource()) if not auth: print 'Failed to authenticate you.\nExiting...' return False self.client.RegisterHandler('message', self.handle_message) self.client.RegisterHandler('presence', self.handle_presence) self.client.send(Presence(status=self.status)) return True
def setStatus(self, status): self.myAgent.jabber.send(Presence(status=status))
def setShow(self, show): self.myAgent.jabber.send(Presence(show=show))
def setPriority(self, prio): self.myAgent.jabber.send(Presence(priority=prio))
def omegleJoin(self): presence = Presence(to=self.muc + '/' + self.nick) presence.setTag('x', namespace=xmpp.NS_MUC).setTagData('password', '') presence.getTag('x').addChild('history', {'maxchars': '0', 'maxstanzas': '0'}); self.xmppClient.send(presence) self.connected = True
def _try_register(client, jid, account, use_data_form): '''Try to register and unregister as specified on XEP-0100''' # TODO: Managing this with exceptions should be cleaner # Perform registration if use_data_form: reg_iq = Iq(to=jid, typ='set', queryNS='jabber:iq:register') data_form = DataForm('submit', account) reg_iq.getTag('query').addChild(node=data_form) node = client.Dispatcher.SendAndWaitForResponse(reg_iq) else: if features.register(client, jid, info=account) == 1: # Success logging.debug('Registered on %s gateway', jid) else: #print client.lastErrCode.encode('utf-8'), ' ', client.lastErr.encode('utf-8') logging.debug('Can not register on %s gateway (%s: %s)', jid, client.lastErrCode, client.lastErr) return False roster = client.getRoster() # Seconds to wait # A openfire gtalk gateway on localhost can take 21 seconds on inform of a # invalid username/password max_wait = 30 # Wait for a error message (Openfire gateways send messages) for time in range(0, max_wait): if (MESSAGES.has_key(jid) and MESSAGES[jid].has_key('error') and len(MESSAGES[jid]['error']) > 0): for message in MESSAGES[jid]['error']: logging.warning('Error message received from %s gateway: %s', jid, message) MESSAGES[jid]['error'] = [] _unregister(client, roster, jid) return False #break client.Process(1) if time < max_wait - 1: _unregister(client, roster, jid) return False # Perform subscriptions # Wait subscrition request for time in range(0, max_wait): if jid in roster.keys( ) and roster.getSubscriptionFromStatus(jid) != None: break client.Process(1) if time >= max_wait - 1: # The gateway didn't requested subscription logging.debug('Subcription request from %s gateway not received', jid) _unregister(client, roster, jid) return False if roster.getSubscriptionFromStatus(jid) == 'pending': roster.Authorize(jid) if roster.getSubscriptionToStatus(jid) == None: roster.Subscribe(jid) for time in range(0, max_wait): if roster.getSubscriptionToStatus(jid) == 'subscribed': break client.Process(1) if time >= max_wait - 1: # The gateway rejected our subscription request logging.debug('Subcription request rejected by %s gateway', jid) _unregister(client, roster, jid) return False # Try to login client.Dispatcher.send(Presence(jid)) full_client_jid = "%s@%s/%s" % (client.User, client.Server, client.Resource) for time in range(0, max_wait): if len(roster.getResources(jid)) > 0: full_gw_jid = "%s/%s" % (jid, roster.getResources(jid)[0]) if (roster.getShow(full_gw_jid) == 'unavailable' and roster.getStatus(full_gw_jid) == 'error'): # Error in login, was the account data correct? time = max_wait break elif roster.getShow(full_gw_jid) == 'xa': # J2J Transport (http://JRuDevels.org) Twisted-version uses 'xa' show # and 'Logging in...' status while trying to login pass elif ( roster.getShow(full_gw_jid) == 'available' or (roster.getShow(full_gw_jid) == roster.getShow(full_client_jid) and roster.getStatus(full_gw_jid) == roster.getStatus(full_client_jid))): # Transport seems to have logged in break client.Process(1) if time >= max_wait - 1: # Login failed logging.debug('Can not login on %s gateway', jid) _unregister(client, roster, jid) return False logging.debug('Successfull login on %s gateway', jid) # Successfull registration, now unregister _unregister(client, roster, jid) return True