diff --git a/circusweb/circushttpd.py b/circusweb/circushttpd.py index 2a47092..ca041ab 100644 --- a/circusweb/circushttpd.py +++ b/circusweb/circushttpd.py @@ -13,6 +13,7 @@ from circusweb import logger, __version__ from circus.exc import CallError from circus.util import LOG_LEVELS, configure_logger +from circus.py3compat import string_types, b from zmq.eventloop import ioloop from circusweb.util import AutoDiscovery, run_command from circusweb.session import (SessionManager, get_controller, @@ -56,6 +57,11 @@ 'session.auto': True } +def encode(s): + return b64encode(s.encode('utf-8')).decode('utf-8') + +def decode(s): + return b64decode(s.encode('utf-8')).decode('utf-8') def require_logged_user(func): @@ -77,7 +83,7 @@ class BaseHandler(tornado.web.RequestHandler): def prepare(self): session_id = self.get_secure_cookie('session_id') if not session_id or not SessionManager.get(session_id): - session_id = uuid4().hex + session_id = b(uuid4().hex) session = SessionManager.new(session_id) self.set_secure_cookie('session_id', session_id) else: @@ -95,7 +101,7 @@ def render_template(self, template_path, **data): server = '%s://%s/' % (self.request.protocol, self.request.host) namespace.update({'controller': get_controller(), 'version': __version__, - 'b64encode': b64encode, + 'b64encode': encode, 'dumps': json.dumps, 'session': self.session, 'messages': messages, 'SERVER': server}) @@ -206,7 +212,7 @@ def post(self, endpoint): 'add_watcher', kwargs=dict((k, v[0]) for k, v in self.request.arguments.iteritems()), - message='added a new watcher', endpoint=b64decode(endpoint), + message='added a new watcher', endpoint=decode(endpoint), redirect_url=self.reverse_url('watcher', self.get_argument('name').lower()), redirect_on_error=self.reverse_url('index')) @@ -220,7 +226,7 @@ class WatcherHandler(BaseHandler): @gen.coroutine def get(self, endpoint, name): controller = get_controller() - endpoint = b64decode(endpoint) + endpoint = decode(endpoint) pids = yield gen.Task(controller.get_pids, name, endpoint) self.finish(self.render_template('watcher.html', pids=pids, name=name, endpoint=endpoint)) @@ -234,7 +240,7 @@ class WatcherSwitchStatusHandler(BaseHandler): def get(self, endpoint, name): url = yield self.run_command(command='switch_status', message='status switched', - endpoint=b64decode(endpoint), + endpoint=decode(endpoint), args=(name,), redirect_url=self.reverse_url('index')) self.redirect(url) @@ -250,7 +256,7 @@ def get(self, endpoint, name, pid): url = yield self.run_command( command='killproc', message=msg.format(pid=pid), - endpoint=b64decode(endpoint), + endpoint=decode(endpoint), args=(name, pid), redirect_url=self.reverse_url('watcher', endpoint, name)) self.redirect(url) @@ -265,7 +271,7 @@ def get(self, endpoint, name): msg = 'removed one process from the {watcher} pool' url = yield self.run_command(command='decrproc', message=msg.format(watcher=name), - endpoint=b64decode(endpoint), + endpoint=decode(endpoint), args=(name,), redirect_url=self.reverse_url('watcher', endpoint, @@ -282,7 +288,7 @@ def get(self, endpoint, name): msg = 'added one process to the {watcher} pool' url = yield self.run_command(command='incrproc', message=msg.format(watcher=name), - endpoint=b64decode(endpoint), + endpoint=decode(endpoint), args=(name,), redirect_url=self.reverse_url('watcher', endpoint, @@ -300,7 +306,7 @@ def get(self, endpoint=None): sockets = {} if endpoint: - endpoint = b64decode(endpoint) + endpoint = decode(endpoint) sockets[endpoint] = yield gen.Task(controller.get_sockets, endpoint=endpoint) else: @@ -324,7 +330,7 @@ class ReloadconfigHandler(BaseHandler): def get(self, endpoint): url = yield self.run_command(command='reloadconfig', message='reload the configuration', - endpoint=b64decode(endpoint), + endpoint=decode(endpoint), args=[], redirect_url=self.reverse_url('index')) self.redirect(url) diff --git a/circusweb/client.py b/circusweb/client.py index 28dc2b8..5896627 100644 --- a/circusweb/client.py +++ b/circusweb/client.py @@ -6,7 +6,7 @@ from zmq.eventloop.zmqstream import ZMQStream from circus.exc import CallError -from circus.py3compat import string_types +from circus.py3compat import string_types, b from circus.util import get_connection from circus.client import CircusClient, make_message @@ -59,7 +59,7 @@ def call(self, cmd, callback): raise CallError(str(e)) socket = self.context.socket(zmq.DEALER) - socket.setsockopt(zmq.IDENTITY, uuid.uuid4().hex) + socket.setsockopt(zmq.IDENTITY, b(uuid.uuid4().hex)) socket.setsockopt(zmq.LINGER, 0) get_connection(socket, self.endpoint, self.ssh_server, self.ssh_keyfile) @@ -84,7 +84,7 @@ def recv_callback(msg): stream.on_recv(recv_callback) try: - socket.send(cmd) + socket.send(b(cmd)) except zmq.ZMQError as e: raise CallError(str(e)) diff --git a/circusweb/templates/index.html b/circusweb/templates/index.html index 460499c..cb5f6a1 100644 --- a/circusweb/templates/index.html +++ b/circusweb/templates/index.html @@ -171,6 +171,6 @@ watchers.push(['${plugin}', ${dumps(b64encode(stat_endpoint))}]); %endfor % endfor - supervise(socket, watchers, undefined, ${dumps(list(endpoints.keys()))}, ${dumps(endpoints.values())}); + supervise(socket, watchers, undefined, ${dumps(list(endpoints.keys()))}, ${dumps(list(endpoints.values()))}); });