From 3b2ae0f1c87c13e375da424afa85a3d992cfc4de Mon Sep 17 00:00:00 2001 From: shim_ Date: Tue, 14 Jun 2016 13:16:11 +0200 Subject: [PATCH 1/6] basic user management --- target/addmailuser | 29 +++++++++++++++++++++++++++++ target/delmailuser | 15 +++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 target/addmailuser create mode 100755 target/delmailuser diff --git a/target/addmailuser b/target/addmailuser new file mode 100755 index 00000000..a88062f2 --- /dev/null +++ b/target/addmailuser @@ -0,0 +1,29 @@ +#!/bin/bash + +DATABASE=/tmp/docker-mailserver/postfix-accounts.cf + +function usage { + echo Usage: addmailuser [password] + exit 1 +} + +if [ ! -z "$1" ]; then + USER=$1 + if [ ! -z "$(grep $USER -i $DATABASE)" ]; then + echo "User already exists" + exit 1 + fi + if [ ! -z "$2" ]; then + PASS=$2 + else + read -s -p "Enter Password: " PASS + if [ -z "$PASS" ]; then + echo "Password can't be empty" + exit 1 + fi + fi + ENTRY=$(echo "$USER|$(doveadm pw -s SHA512-CRYPT -u $USER -p $PASS)") + echo $ENTRY >> $DATABASE +else + usage +fi diff --git a/target/delmailuser b/target/delmailuser new file mode 100755 index 00000000..6239cda6 --- /dev/null +++ b/target/delmailuser @@ -0,0 +1,15 @@ +#!/bin/bash + +DATABASE=/tmp/docker-mailserver/postfix-accounts.cf + +function usage { + echo Usage: delmailuser + exit 1 +} + +if [ ! -z "$1" ]; then + ENTRIES=$(grep "$USER" -vi $DATABASE) + echo $ENTRIES > $DATABASE +else + usage +fi From 13b43561f8e6eccc7cbcae986455b400dd438343 Mon Sep 17 00:00:00 2001 From: shim_ Date: Tue, 14 Jun 2016 13:28:15 +0200 Subject: [PATCH 2/6] add quotes --- target/addmailuser | 2 +- target/delmailuser | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/target/addmailuser b/target/addmailuser index a88062f2..c9b1ff78 100755 --- a/target/addmailuser +++ b/target/addmailuser @@ -23,7 +23,7 @@ if [ ! -z "$1" ]; then fi fi ENTRY=$(echo "$USER|$(doveadm pw -s SHA512-CRYPT -u $USER -p $PASS)") - echo $ENTRY >> $DATABASE + echo "$ENTRY" >> $DATABASE else usage fi diff --git a/target/delmailuser b/target/delmailuser index 6239cda6..942b7463 100755 --- a/target/delmailuser +++ b/target/delmailuser @@ -3,13 +3,13 @@ DATABASE=/tmp/docker-mailserver/postfix-accounts.cf function usage { - echo Usage: delmailuser + echo "Usage: delmailuser " exit 1 } if [ ! -z "$1" ]; then ENTRIES=$(grep "$USER" -vi $DATABASE) - echo $ENTRIES > $DATABASE + echo "$ENTRIES" > $DATABASE else usage fi From 2a6d05cab6b971a1e165d85a5e353a3baefc153e Mon Sep 17 00:00:00 2001 From: shim_ Date: Tue, 14 Jun 2016 13:29:55 +0200 Subject: [PATCH 3/6] set user var --- target/delmailuser | 1 + 1 file changed, 1 insertion(+) diff --git a/target/delmailuser b/target/delmailuser index 942b7463..dc471b43 100755 --- a/target/delmailuser +++ b/target/delmailuser @@ -8,6 +8,7 @@ function usage { } if [ ! -z "$1" ]; then + USER=$1 ENTRIES=$(grep "$USER" -vi $DATABASE) echo "$ENTRIES" > $DATABASE else From b9aceb9d6f387ef9241f24e9fbf451a913d4edac Mon Sep 17 00:00:00 2001 From: shim_ Date: Tue, 14 Jun 2016 13:38:34 +0200 Subject: [PATCH 4/6] add relevant files --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e5d6cac5..502a716a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,7 +71,7 @@ RUN curl -s https://letsencrypt.org/certs/lets-encrypt-x1-cross-signed.pem > /et curl -s https://letsencrypt.org/certs/lets-encrypt-x2-cross-signed.pem > /etc/ssl/certs/lets-encrypt-x2-cross-signed.pem # Start-mailserver script -ADD target/bin/generate-ssl-certificate target/bin/generate-dkim-config target/start-mailserver.sh /usr/local/bin/ +ADD target/bin/generate-ssl-certificate target/bin/generate-dkim-config target/start-mailserver.sh target/addmailuser target/delmailuser /usr/local/bin/ RUN chmod +x /usr/local/bin/* EXPOSE 25 587 143 993 110 995 4190 From 7c63d00d77d29953ed135b2ea5770b0e6b170f8d Mon Sep 17 00:00:00 2001 From: shim_ Date: Tue, 14 Jun 2016 16:17:06 +0200 Subject: [PATCH 5/6] added tests for addmailuser delmailuser --- test/tests.bats | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/tests.bats b/test/tests.bats index c12bf711..0685e44c 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -471,3 +471,23 @@ run docker exec mail_pop3 /bin/bash -c "nc -z 0.0.0.0 4190" [ "$status" -ne 0 ] } + +# +# accounts +# + +@test "checking accounts: user3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf" { + docker exec mail /bin/sh -c "addmailuser user3@domain.tld mypassword" + + run docker exec mail /bin/sh -c "grep user3@domain.tld -i /tmp/docker-mailserver/postfix-accounts.cf" + [ "$status" -eq 0 ] + [ ! -z "$output" ] +} + +@test "checking accounts: user3 should have been removed from /tmp/docker-mailserver/postfix-accounts.cf" { + docker exec mail /bin/sh -c "delmailuser user3@domain.tld" + + run docker exec mail /bin/sh -c "grep user3@domain.tld -i /tmp/docker-mailserver/postfix-accounts.cf" + [ "$status" -eq 1 ] + [ -z "$output" ] +} From 94679df291744802706e6350108db87dd384993a Mon Sep 17 00:00:00 2001 From: shim_ Date: Wed, 15 Jun 2016 19:50:01 +0200 Subject: [PATCH 6/6] move addmailuser, delmailuser to target/bin --- Dockerfile | 2 +- target/{ => bin}/addmailuser | 0 target/{ => bin}/delmailuser | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename target/{ => bin}/addmailuser (100%) rename target/{ => bin}/delmailuser (100%) diff --git a/Dockerfile b/Dockerfile index 502a716a..8d45f4ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,7 +71,7 @@ RUN curl -s https://letsencrypt.org/certs/lets-encrypt-x1-cross-signed.pem > /et curl -s https://letsencrypt.org/certs/lets-encrypt-x2-cross-signed.pem > /etc/ssl/certs/lets-encrypt-x2-cross-signed.pem # Start-mailserver script -ADD target/bin/generate-ssl-certificate target/bin/generate-dkim-config target/start-mailserver.sh target/addmailuser target/delmailuser /usr/local/bin/ +ADD target/bin/generate-ssl-certificate target/bin/generate-dkim-config target/bin/addmailuser target/bin/delmailuser target/start-mailserver.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/* EXPOSE 25 587 143 993 110 995 4190 diff --git a/target/addmailuser b/target/bin/addmailuser similarity index 100% rename from target/addmailuser rename to target/bin/addmailuser diff --git a/target/delmailuser b/target/bin/delmailuser similarity index 100% rename from target/delmailuser rename to target/bin/delmailuser