Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- SleekXMPP: The Sleek XMPP Library
- Copyright (C) 2010 Nathanael C. Fritz
- This file is part of SleekXMPP.
- See the file LICENSE for copying permission.
- """
- import sys
- import subprocess
- import sleekxmpp
- class JabberAdminBot(sleekxmpp.ClientXMPP):
- """
- A simple SleekXMPP bot that will execute your commands on server.
- """
- def __init__(self, jid, password):
- sleekxmpp.ClientXMPP.__init__(self, jid, password)
- # The session_start event will be triggered when
- # the bot establishes its connection with the server
- # and the XML streams are ready for use. We want to
- # listen for this event so that we we can initialize
- # our roster.
- self.add_event_handler("session_start", self.start)
- # The message event is triggered whenever a message
- # stanza is received. Be aware that that includes
- # MUC messages and error messages.
- self.add_event_handler("message", self.message)
- def start(self, event):
- """
- Process the session_start event.
- Typical actions for the session_start event are
- requesting the roster and broadcasting an initial
- presence stanza.
- Arguments:
- event -- An empty dictionary. The session_start
- event does not provide any additional
- data.
- """
- self.send_presence()
- self.get_roster()
- def message(self, msg):
- """
- Process incoming message stanzas. Be aware that this also
- includes MUC messages and error messages. It is usually
- a good idea to check the messages's type before processing
- or sending replies.
- Arguments:
- msg -- The received message stanza. See the documentation
- for stanza objects and the Message stanza to see
- how it may be used.
- """
- if msg['type'] in ('chat', 'normal'):
- # print(msg)
- # command = "echo \"%(body)s\" > /home/vadim/kek" % msg
- # subprocess.call(command, shell=True)
- # command = "lxterminal"
- command = "%(body)s" % msg
- #Паша, тебе сюда. В строке command адекватно приходящая команда. Как бы её выполнить?
- print command
- pipe = subprocess.Popen(command, stdout=subprocess.PIPE)
- print "done"
- out, err = pipe.communicate()
- print out
- msg.reply(out).send()
- # msg.reply("Thanks for sending\n%(body)s" % msg).send()
- jid = "qwerty@127.0.0.1" #raw_input("Username: ")
- password = "qwerty" # raw_input("Password: ")
- xmpp = JabberAdminBot(jid, password)
- xmpp.register_plugin('xep_0030') # Service Discovery
- xmpp.register_plugin('xep_0004') # Data Forms
- xmpp.register_plugin('xep_0060') # PubSub
- xmpp.register_plugin('xep_0199') # XMPP Ping
- if xmpp.connect():
- # If you do not have the dnspython library installed, you will need
- # to manually specify the name of the server if it does not match
- # the one in the JID. For example, to use Google Talk you would
- # need to use:
- #
- # if xmpp.connect(('talk.google.com', 5222)):
- # ...
- xmpp.process(block=True)
- print("Done")
- else:
- print("Unable to connect.")111111111111
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement