From: ThomasV Date: Mon, 30 Apr 2012 16:10:25 +0000 (+0400) Subject: check password for 'info' command. display version and load X-Git-Url: https://git.novaco.in/?p=electrum-server.git;a=commitdiff_plain;h=443e0d6f7086ce661874fa100e1412ece33fac19 check password for 'info' command. display version and load --- diff --git a/backends/irc/__init__.py b/backends/irc/__init__.py index 19ed451..099c7c7 100644 --- a/backends/irc/__init__.py +++ b/backends/irc/__init__.py @@ -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 diff --git a/server.py b/server.py index 09bf816..902153c 100755 --- 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()