Advertisement
Guest User

Untitled

a guest
Mar 13th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. """
  5. SleekXMPP: The Sleek XMPP Library
  6. Copyright (C) 2010 Nathanael C. Fritz
  7. This file is part of SleekXMPP.
  8.  
  9. See the file LICENSE for copying permission.
  10. """
  11.  
  12. import sys
  13. import subprocess
  14. import sleekxmpp
  15.  
  16.  
  17. class JabberAdminBot(sleekxmpp.ClientXMPP):
  18.  
  19. """
  20. A simple SleekXMPP bot that will execute your commands on server.
  21. """
  22.  
  23. def __init__(self, jid, password):
  24. sleekxmpp.ClientXMPP.__init__(self, jid, password)
  25.  
  26. # The session_start event will be triggered when
  27. # the bot establishes its connection with the server
  28. # and the XML streams are ready for use. We want to
  29. # listen for this event so that we we can initialize
  30. # our roster.
  31. self.add_event_handler("session_start", self.start)
  32.  
  33. # The message event is triggered whenever a message
  34. # stanza is received. Be aware that that includes
  35. # MUC messages and error messages.
  36. self.add_event_handler("message", self.message)
  37.  
  38. def start(self, event):
  39. """
  40. Process the session_start event.
  41.  
  42. Typical actions for the session_start event are
  43. requesting the roster and broadcasting an initial
  44. presence stanza.
  45.  
  46. Arguments:
  47. event -- An empty dictionary. The session_start
  48. event does not provide any additional
  49. data.
  50. """
  51. self.send_presence()
  52. self.get_roster()
  53.  
  54. def message(self, msg):
  55. """
  56. Process incoming message stanzas. Be aware that this also
  57. includes MUC messages and error messages. It is usually
  58. a good idea to check the messages's type before processing
  59. or sending replies.
  60.  
  61. Arguments:
  62. msg -- The received message stanza. See the documentation
  63. for stanza objects and the Message stanza to see
  64. how it may be used.
  65. """
  66. if msg['type'] in ('chat', 'normal'):
  67. # print(msg)
  68. # command = "echo \"%(body)s\" > /home/vadim/kek" % msg
  69. # subprocess.call(command, shell=True)
  70. # command = "lxterminal"
  71. command = "%(body)s" % msg
  72. #Паша, тебе сюда. В строке command адекватно приходящая команда. Как бы её выполнить?
  73. print command
  74. pipe = subprocess.Popen(command, stdout=subprocess.PIPE)
  75. print "done"
  76. out, err = pipe.communicate()
  77. print out
  78. msg.reply(out).send()
  79. # msg.reply("Thanks for sending\n%(body)s" % msg).send()
  80.  
  81.  
  82. jid = "qwerty@127.0.0.1" #raw_input("Username: ")
  83. password = "qwerty" # raw_input("Password: ")
  84.  
  85. xmpp = JabberAdminBot(jid, password)
  86. xmpp.register_plugin('xep_0030') # Service Discovery
  87. xmpp.register_plugin('xep_0004') # Data Forms
  88. xmpp.register_plugin('xep_0060') # PubSub
  89. xmpp.register_plugin('xep_0199') # XMPP Ping
  90.  
  91. if xmpp.connect():
  92. # If you do not have the dnspython library installed, you will need
  93. # to manually specify the name of the server if it does not match
  94. # the one in the JID. For example, to use Google Talk you would
  95. # need to use:
  96. #
  97. # if xmpp.connect(('talk.google.com', 5222)):
  98. # ...
  99. xmpp.process(block=True)
  100. print("Done")
  101. else:
  102. print("Unable to connect.")111111111111
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement