check password for 'info' command. display version and load
authorThomasV <thomasv@gitorious>
Mon, 30 Apr 2012 16:10:25 +0000 (20:10 +0400)
committerThomasV <thomasv@gitorious>
Mon, 30 Apr 2012 16:10:25 +0000 (20:10 +0400)
backends/irc/__init__.py
server.py

index 19ed451..099c7c7 100644 (file)
@@ -93,6 +93,17 @@ class ServerProcessor(Processor):
         params = request['params']
         result = None
 
+        if method in ['server.stop', 'server.info']:
+            try:
+                password = request['params'][0]
+            except:
+                password = None
+
+            if password != self.password:
+                response = { 'id':request['id'], 'result':None,  'error':'incorrect password'}
+                self.push_response(response)
+                return
+
         if method == 'server.banner':
             result = self.banner.replace('\\n','\n')
 
@@ -103,17 +114,11 @@ class ServerProcessor(Processor):
             pass
 
         elif method == 'server.stop':
-            print "stopping..."
-            try:
-                password = request['params'][0]
-            except:
-                password = None
-            if password == self.password:
-                self.shared.stop()
-                result = 'ok'
+            self.shared.stop()
+            result = 'ok'
 
         elif method == 'server.info':
-            result = map(lambda s: s.address, self.dispatcher.request_dispatcher.sessions)
+            result = map(lambda s: { "address":s.address, "version":s.version, "subscriptions":len(s.subscriptions)}, self.dispatcher.request_dispatcher.sessions)
 
         else:
             print "unknown method", request
index 09bf816..902153c 100755 (executable)
--- a/server.py
+++ b/server.py
@@ -63,7 +63,11 @@ def run_rpc_command(command, stratum_tcp_port):
     s.send(request + '\n')
     msg = s.recv(1024)
     s.close()
-    print json.loads(msg).get('result')
+    r = json.loads(msg).get('result')
+    if command == 'stop': print r
+    elif command == 'info': 
+        for item in r:
+            print '%15s   %3s  %7s'%( item.get('address'), item.get('subscriptions'), item.get('version') )
 
 if __name__ == '__main__':
     config = create_config()