From 944b91a4b85635b62db14a2c9f5d6c6aada0560e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Peters?= Date: Thu, 22 Feb 2018 09:21:37 +0100 Subject: [PATCH] [Dockerapi] Add du command, push version --- data/Dockerfiles/dockerapi/server.py | 17 +++++++++++++++-- docker-compose.yml | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/data/Dockerfiles/dockerapi/server.py b/data/Dockerfiles/dockerapi/server.py index eae472ed..57ed3570 100644 --- a/data/Dockerfiles/dockerapi/server.py +++ b/data/Dockerfiles/dockerapi/server.py @@ -67,10 +67,23 @@ class container_post(Resource): if not request.json or not 'cmd' in request.json: return jsonify(type='danger', msg='cmd is missing') - if request.json['cmd'] == 'sieve_list' and request.json['username']: + if request.json['cmd'] == 'df' and request.json['dir']: try: for container in docker_client.containers.list(filters={"id": container_id}): - return container.exec_run(["/bin/bash", "-c", "/usr/local/bin/doveadm sieve list -u '" + request.json['username'].replace("'", "'\\''") + "'"], user='vmail') + # Should be changed to be able to validate a path + directory = re.sub('[^0-9a-zA-Z/]+', '', request.json['dir']) + df_return = container.exec_run(["/bin/bash", "-c", "/bin/df -H " + directory + " | /usr/bin/tail -n1 | /usr/bin/tr -s [:blank:] | /usr/bin/tr ' ' ','"], user='nobody') + if df_return.exit_code == 0: + return df_return.output.rstrip() + else: + return "0,0,0,0,0,0" + except Exception as e: + return jsonify(type='danger', msg=str(e)) + elif request.json['cmd'] == 'sieve_list' and request.json['username']: + try: + for container in docker_client.containers.list(filters={"id": container_id}): + sieve_return = container.exec_run(["/bin/bash", "-c", "/usr/local/bin/doveadm sieve list -u '" + request.json['username'].replace("'", "'\\''") + "'"], user='vmail') + return sieve_return.output except Exception as e: return jsonify(type='danger', msg=str(e)) elif request.json['cmd'] == 'sieve_print' and request.json['script_name'] and request.json['username']: diff --git a/docker-compose.yml b/docker-compose.yml index 2f443e79..5e167164 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -369,7 +369,7 @@ services: - watchdog dockerapi-mailcow: - image: mailcow/dockerapi:1.8 + image: mailcow/dockerapi:1.9 restart: always build: ./data/Dockerfiles/dockerapi sysctls: