From e3854a803700f9de379e0afb276d68746d69db66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Peters?= Date: Thu, 8 Feb 2018 22:29:06 +0100 Subject: [PATCH] [Dockerapi] Fixes recent chang in exec_run return --- data/Dockerfiles/dockerapi/Dockerfile | 2 +- data/Dockerfiles/dockerapi/server.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/data/Dockerfiles/dockerapi/Dockerfile b/data/Dockerfiles/dockerapi/Dockerfile index a5b3301d..3f205b8b 100644 --- a/data/Dockerfiles/dockerapi/Dockerfile +++ b/data/Dockerfiles/dockerapi/Dockerfile @@ -2,7 +2,7 @@ FROM python:2-alpine LABEL maintainer "Andre Peters " RUN apk add -U --no-cache iptables ip6tables -RUN pip install docker flask flask-restful +RUN pip install docker==3.0.1 flask flask-restful COPY server.py / CMD ["python2", "-u", "/server.py"] diff --git a/data/Dockerfiles/dockerapi/server.py b/data/Dockerfiles/dockerapi/server.py index e0f43ef9..eae472ed 100644 --- a/data/Dockerfiles/dockerapi/server.py +++ b/data/Dockerfiles/dockerapi/server.py @@ -83,11 +83,15 @@ class container_post(Resource): try: for container in docker_client.containers.list(filters={"id": container_id}): hash = container.exec_run(["/bin/bash", "-c", "/usr/bin/rspamadm pw -e -p '" + request.json['raw'].replace("'", "'\\''") + "' 2> /dev/null"], user='_rspamd') - f = open("/access.inc", "w") - f.write('enable_password = "' + re.sub('[^0-9a-zA-Z\$]+', '', hash.rstrip()) + '";\n') - f.close() - container.restart() - return jsonify(type='success', msg='command completed successfully') + if hash.exit_code == 0: + hash = str(hash.output) + f = open("/access.inc", "w") + f.write('enable_password = "' + re.sub('[^0-9a-zA-Z\$]+', '', hash.rstrip()) + '";\n') + f.close() + container.restart() + return jsonify(type='success', msg='command completed successfully') + else: + return jsonify(type='danger', msg='command did not complete, exit code was ' + int(hash.exit_code)) except Exception as e: return jsonify(type='danger', msg=str(e))