Esempio n. 1
0
 def invite(self, room, jids, reason=None):
     """Invites user to muc.
     Works only if user has permission to invite to muc"""
     NS_MUCUSER = '******'
     mess = Message(to=room)
     for jid in jids:
         invite = simplexml.Node('invite')
         invite.setAttr('to', jid)
         if reason is not None:
             invite.setTagData('reason', reason)
         mess.setTag('x', namespace=NS_MUCUSER).addChild(node=invite)
     self.log.info(mess)
     self.connect().send(mess)
Esempio n. 2
0
 def invite(self, room, jids, reason=None):
     """Invites user to muc.
     Works only if user has permission to invite to muc"""
     NS_MUCUSER = '******'
     mess = Message(to=room)
     for jid in jids:
         invite = simplexml.Node('invite')
         invite.setAttr('to', jid)
         if reason is not None:
             invite.setTagData('reason', reason)
         mess.setTag('x', namespace=NS_MUCUSER).addChild(node=invite)
     self.log.info(mess)
     self.connect().send(mess)
Esempio n. 3
0
 def build_message(self, text):
     """Builds an xhtml message without attributes.
     If input is not valid xhtml-im fallback to normal."""
     try:
         node = XML2Node(text)
         # logging.debug('This message is XML : %s' % text)
         text_plain = xhtml2txt(text)
         logging.debug('Plain Text translation from XHTML-IM:\n%s' % text_plain)
         message = Message(body=text_plain)
         message.addChild(node = node)
     except ExpatError as ee:
         if text.strip(): # avoids keep alive pollution
             logging.debug('Determined that [%s] is not XHTML-IM (%s)' % (text, ee))
         message = Message(body=text)
     return message
Esempio n. 4
0
 def build_message(self, text):
     """Builds an xhtml message without attributes.
     If input is not valid xhtml-im fallback to normal."""
     try:
         text = utf8(text)
         XML2Node(text) # test if is it xml
         # yes, ok epurate it for hipchat
         try:
             hipchat_html = xhtml2hipchat(text)
             node = XML2Node(hipchat_html)
             message = Message(body=xhtml2txt(text))
             message.addChild(node = node)
         except ExpatError as ee:
             logging.error('Error translating to hipchat [%s] Parsing error = [%s]' % (hipchat_html, ee))
     except ExpatError as ee:
         if text.strip(): # avoids keep alive pollution
             logging.debug('Determined that [%s] is not XHTML-IM (%s)' % (text, ee))
         message = Message(body=text)
     return message
Esempio n. 5
0
 def send(self, recipients, message):
     """Send message to recipients via xmpp."""
     jid = JID(self.user)
     if self.server:
         server = self.server
     else:
         server = jid.getDomain()
     cl = Client(server, port=self.port, debug=[])
     if not cl.connect():
         raise IOError("Couldn't connect to xmpp server %s" % server)
     if not cl.auth(jid.getNode(), self.password, resource=self.resource):
         cl.Connection.disconnect()
         raise IOError("Xmpp auth erro using %s to %s", jid, server)
     for recip in recipients:
         cl.send(Message(recip[2], message))
Esempio n. 6
0
 def messageReceived(self, cnx, msg):
     '''Message received, addressed to the component. The command execution
        can raise exceptions, but those will be taken care of by the
        caller (messageHandler())'''
     user = UserAccount(msg.getFrom())
     if user.isRegistered():
         try:
             address = Address(msg.getBody())
             msg = Message(to=msg.getFrom(), frm=address.jid,\
                   body=_(ROSTER, 'address_start_chat').format(address=address), typ='chat')
         except InvalidBitcoinAddressError:
             (action, args) = parseCommand(msg.getBody())
             if action is None:
                 return
             msg = msg.buildReply(Command(action, args).execute(user))
             msg.setType('chat')
             if user.checkBalance() is not None:
                 self.sendBitcoinPresence(cnx, user)
     else:
         error = _(REGISTRATION, 'error_not_registered')
         msg = msg.buildReply(_(COMMANDS, 'error_message').format(message=error))
         msg.setType('error')
     cnx.send(msg)
     raise NodeProcessed
Esempio n. 7
0
 def build_message(self, text):
     """Builds an xhtml message without attributes.
     If input is not valid xhtml-im fallback to normal."""
     try:
         node = XML2Node(text)
         # logging.debug('This message is XML : %s' % text)
         text_plain = xhtml2txt(text)
         logging.debug('Plain Text translation from XHTML-IM:\n%s' %
                       text_plain)
         message = Message(body=text_plain)
         message.addChild(node=node)
     except ExpatError as ee:
         if text.strip():  # avoids keep alive pollution
             logging.debug('Determined that [%s] is not XHTML-IM (%s)' %
                           (text, ee))
         message = Message(body=text)
     return message
Esempio n. 8
0
 def build_message(self, text):
     """Builds an xhtml message without attributes.
     If input is not valid xhtml-im fallback to normal."""
     message = None # keeps the compiler happy
     try:
         text = utf8(text)
         XML2Node(text) # test if is it xml
         # yes, ok epurate it for hipchat
         hipchat_html = xhtml2hipchat(text)
         try:
             node = XML2Node(hipchat_html)
             message = Message(body=xhtml2txt(text))
             message.addChild(node = node)
         except ExpatError as ee:
             logging.error('Error translating to hipchat [%s] Parsing error = [%s]' % (hipchat_html, ee))
     except ExpatError as ee:
         if text.strip(): # avoids keep alive pollution
             logging.debug('Determined that [%s] is not XHTML-IM (%s)' % (text, ee))
         message = Message(body=text)
     return message
Esempio n. 9
0
port = conf.get('xmpp_nagios', 'port')

if len(args) < 1:
    print "xmppsend message [to whom, multiple args]"
    sys.exit(1)

msg = args[0]

msg = msg.replace('\\n', '\n')

c = xmpp.Client(server=server, port=port, debug=[])
con = c.connect()
if not con:
    print "Error: could not connect to server: %s:%s" % (c.Server, c.Port)
    sys.exit(1)

auth = c.auth(user=username, password=password, resource=resource)
if not auth:
    print "Error: Could not authenticate to server: %s:%s" % (c.Server, c.Port)
    sys.exit(1)

if len(args) < 2:
    r = c.getRoster()
    for user in r.keys():
        if user == username:
            continue
        c.send(Message(user, '%s' % msg))
else:
    for user in args[1:]:
        c.send(Message(user, '%s' % msg))
Esempio n. 10
0
 def send_frame(self, jid, frame):
     message = base64.b64encode(repr(frame))
     try:
         self.client.send(Message(to=jid, typ='normal', body=message))
     except:
         self.reconnect()