Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions circusweb/circushttpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):

Expand All @@ -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:
Expand All @@ -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})
Expand Down Expand Up @@ -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'))
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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:
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions circusweb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion circusweb/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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()))});
});
</script>