aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config.py1
-rw-r--r--rmq.py1
-rw-r--r--snekbox.py6
-rw-r--r--snekweb.py2
4 files changed, 8 insertions, 2 deletions
diff --git a/config.py b/config.py
index 5ca23bb..5e4f648 100644
--- a/config.py
+++ b/config.py
@@ -6,6 +6,7 @@ from docker.errors import NotFound
def autodiscover():
"""Search for the snekbox container and return its IPv4 address."""
+
container_names = ["rmq", "pdrmq", "snekbox_pdrmq_1"]
client = docker.from_env()
diff --git a/rmq.py b/rmq.py
index b4cb90a..919ef19 100644
--- a/rmq.py
+++ b/rmq.py
@@ -25,6 +25,7 @@ class Rmq:
def consume(self, queue=QUEUE, callback=None, thread_ws=None, run_once=False):
"""Subscribe to read from a RMQ channel."""
+
while True:
try:
connection = pika.BlockingConnection(self.con_params)
diff --git a/snekbox.py b/snekbox.py
index a5cebde..f8d7c31 100644
--- a/snekbox.py
+++ b/snekbox.py
@@ -12,8 +12,7 @@ class Snekbox:
def __init__(self,
nsjail_binary='nsjail',
- python_binary=os.path.dirname(sys.executable)+os.sep+'python3.6'):
-
+ python_binary=os.path.dirname(sys.executable) + os.sep + 'python3.6'):
self.nsjail_binary = nsjail_binary
self.python_binary = python_binary
self._nsjail_workaround()
@@ -46,6 +45,7 @@ class Snekbox:
Returns the output of executing the command (stdout) if
successful, or a error message if the execution failed.
"""
+
args = [self.nsjail_binary, '-Mo',
'--rlimit_as', '700',
'--chroot', '/',
@@ -108,6 +108,7 @@ class Snekbox:
to RMQ. Once published, the system exits, since the snekboxes
are created and disposed of per-execution.
"""
+
msg = body.decode('utf-8')
result = ''
snek_msg = json.loads(msg)
@@ -124,6 +125,7 @@ class Snekbox:
def message_handler(self, ch, method, properties, body, thread_ws=None):
"""Spawns a daemon process that handles RMQ messages."""
+
p = multiprocessing.Process(target=self.execute, args=(body,))
p.daemon = True
p.start()
diff --git a/snekweb.py b/snekweb.py
index 3e20fda..ff1a72c 100644
--- a/snekweb.py
+++ b/snekweb.py
@@ -22,12 +22,14 @@ log = app.logger
@app.route('/')
def index():
"""Root path returns standard index.html."""
+
return render_template('index.html')
@sockets.route('/ws/<snekboxid>')
def websocket_route(ws, snekboxid):
"""Opens a websocket that spawns and connects to a snekbox daemon."""
+
localdata = threading.local()
localdata.thread_ws = ws