changeset 2088:a99ed13fec1e

Introduce a shared secret for wiki-bot communication + some code style fixes.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 03 Jun 2007 19:44:56 +0200
parents a94187915111
children 4ec961fd40d9
files MoinMoin/jabber/main.py MoinMoin/jabber/xmlrpcbot.py MoinMoin/jabber/xmppbot.py wikiconfig.py
diffstat 4 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/jabber/main.py	Sun Jun 03 19:40:58 2007 +0200
+++ b/MoinMoin/jabber/main.py	Sun Jun 03 19:44:56 2007 +0200
@@ -18,6 +18,7 @@
 from xmlrpcbot import XMLRPCServer, XMLRPCClient
 from Queue import Queue
 
+
 def main():
     args = sys.argv
     
@@ -46,5 +47,6 @@
     except KeyboardInterrupt, i:
         print i
         sys.exit(0)
+
         
 if __name__ == "__main__": main()
--- a/MoinMoin/jabber/xmlrpcbot.py	Sun Jun 03 19:40:58 2007 +0200
+++ b/MoinMoin/jabber/xmlrpcbot.py	Sun Jun 03 19:44:56 2007 +0200
@@ -10,9 +10,10 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import time
+import time, xmlrpclib
 from threading import Thread
-from SimpleXMLRPCServer import SimpleXMLRPCServer 
+from SimpleXMLRPCServer import SimpleXMLRPCServer
+
 
 class NotificationCommand:
     """Class representing a notification request"""
@@ -21,6 +22,7 @@
         self.jid = jid
         self.text = text
 
+
 class XMLRPCClient(Thread):
     """XMLRPC Client
     
@@ -40,6 +42,7 @@
         """Starts the server / thread"""
         pass
 
+
 class XMLRPCServer(Thread):
     """XMLRPC Server
     
@@ -54,6 +57,7 @@
         Thread.__init__(self)
         self.commands = commands
         self.verbose = config.verbose
+        self.secret = config.secret
         self.server = SimpleXMLRPCServer((config.xmlrpc_host, config.xmlrpc_port))
         
     def run(self):
@@ -68,9 +72,12 @@
         t = time.localtime( time.time() )
         print time.strftime("%H:%M:%S", t), message
 
-    def send_notification(self, jid, text):
+    def send_notification(self, secret, jid, text):
         """Instructs the XMPP component to send a notification"""
         
+        if secret != self.secret:
+            raise xmlrpclib.Fault(1, "You are not allowed to use this bot!")
+            
         n = NotificationCommand(jid, text)
         self.commands.put_nowait(n)
         return True
--- a/MoinMoin/jabber/xmppbot.py	Sun Jun 03 19:40:58 2007 +0200
+++ b/MoinMoin/jabber/xmppbot.py	Sun Jun 03 19:44:56 2007 +0200
@@ -21,6 +21,7 @@
 
 from xmlrpcbot import NotificationCommand
 
+
 class Contact:
     """Abstraction of a roster item / contact
  
@@ -217,7 +218,7 @@
             contact = self.contacts[bare_jid]
             
             if self.config.verbose:
-                self.log(str(contact) + ", going OFFLINE.")
+                self.log("%s, going OFFLINE." % contact)
             
             try:
                 # Send queued messages now, as we can't guarantee to be 
--- a/wikiconfig.py	Sun Jun 03 19:40:58 2007 +0200
+++ b/wikiconfig.py	Sun Jun 03 19:44:56 2007 +0200
@@ -43,3 +43,9 @@
     
     # Notification  -----------------------------------------------------
     bot_host = u"localhost:8000"
+    
+    # A secret shared with notification bot, must be the same in both
+    # configs for communication to work
+    #
+    # *************** CHANGE THIS! *************** 
+    secret = u"8yFAS(E-,.c-93adj'uff;3AW#(UDJ,.df3OA($HG"