From ac9ecc3bd3fc6c04453f4c135774fc1e3b873464 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Thu, 29 Oct 2020 15:10:11 -0400 Subject: [PATCH] Rename tools/mail.py to management/cli.py --- tools/mail.py => management/cli.py | 38 ++++++++++++++++++------------ management/templates/login.html | 6 ++--- setup/firstuser.sh | 10 ++++---- setup/nextcloud.sh | 2 +- 4 files changed, 32 insertions(+), 24 deletions(-) rename tools/mail.py => management/cli.py (79%) diff --git a/tools/mail.py b/management/cli.py similarity index 79% rename from tools/mail.py rename to management/cli.py index 215f39e..f264fa7 100755 --- a/tools/mail.py +++ b/management/cli.py @@ -1,4 +1,10 @@ #!/usr/bin/python3 +# +# This is a command-line script for calling management APIs +# on the Mail-in-a-Box control panel backend. The script +# reads /var/lib/mailinabox/api.key for the backend's +# root API key. This file is readable only by root, so this +# tool can only be used as root. import sys, getpass, urllib.request, urllib.error, json, re @@ -53,21 +59,23 @@ def setup_key_auth(mgmt_uri): urllib.request.install_opener(opener) if len(sys.argv) < 2: - print("Usage: ") - print(" tools/mail.py user (lists users)") - print(" tools/mail.py user add user@domain.com [password]") - print(" tools/mail.py user password user@domain.com [password]") - print(" tools/mail.py user remove user@domain.com") - print(" tools/mail.py user make-admin user@domain.com") - print(" tools/mail.py user remove-admin user@domain.com") - print(" tools/mail.py user admins (lists admins)") - print(" tools/mail.py alias (lists aliases)") - print(" tools/mail.py alias add incoming.name@domain.com sent.to@other.domain.com") - print(" tools/mail.py alias add incoming.name@domain.com 'sent.to@other.domain.com, multiple.people@other.domain.com'") - print(" tools/mail.py alias remove incoming.name@domain.com") - print() - print("Removing a mail user does not delete their mail folders on disk. It only prevents IMAP/SMTP login.") - print() + print("""Usage: + {cli} user (lists users) + {cli} user add user@domain.com [password] + {cli} user password user@domain.com [password] + {cli} user remove user@domain.com + {cli} user make-admin user@domain.com + {cli} user remove-admin user@domain.com + {cli} user admins (lists admins) + {cli} alias (lists aliases) + {cli} alias add incoming.name@domain.com sent.to@other.domain.com + {cli} alias add incoming.name@domain.com 'sent.to@other.domain.com, multiple.people@other.domain.com' + {cli} alias remove incoming.name@domain.com + +Removing a mail user does not delete their mail folders on disk. It only prevents IMAP/SMTP login. +""".format( + cli="management/cli.py" + )) elif sys.argv[1] == "user" and len(sys.argv) == 2: # Dump a list of users, one per line. Mark admins with an asterisk. diff --git a/management/templates/login.html b/management/templates/login.html index 67cb08d..4c432aa 100644 --- a/management/templates/login.html +++ b/management/templates/login.html @@ -32,13 +32,13 @@

There are no users on this system! To make an administrative user, log into this machine using SSH (like when you first set it up) and run:

cd mailinabox
-sudo tools/mail.py user add me@{{hostname}}
-sudo tools/mail.py user make-admin me@{{hostname}}
+sudo management/cli.py user add me@{{hostname}} +sudo management/cli.py user make-admin me@{{hostname}} {% else %}

There are no administrative users on this system! To make an administrative user, log into this machine using SSH (like when you first set it up) and run:

cd mailinabox
-sudo tools/mail.py user make-admin me@{{hostname}}
+sudo management/cli.py user make-admin me@{{hostname}} {% endif %}
diff --git a/setup/firstuser.sh b/setup/firstuser.sh index f694769..e2d6531 100644 --- a/setup/firstuser.sh +++ b/setup/firstuser.sh @@ -1,6 +1,6 @@ # If there aren't any mail users yet, create one. -if [ -z "`tools/mail.py user`" ]; then - # The outut of "tools/mail.py user" is a list of mail users. If there +if [ -z "`management/cli.py user`" ]; then + # The outut of "management/cli.py user" is a list of mail users. If there # aren't any yet, it'll be empty. # If we didn't ask for an email address at the start, do so now. @@ -47,11 +47,11 @@ if [ -z "`tools/mail.py user`" ]; then fi # Create the user's mail account. This will ask for a password if none was given above. - tools/mail.py user add $EMAIL_ADDR ${EMAIL_PW:-} + management/cli.py user add $EMAIL_ADDR ${EMAIL_PW:-} # Make it an admin. - hide_output tools/mail.py user make-admin $EMAIL_ADDR + hide_output management/cli.py user make-admin $EMAIL_ADDR # Create an alias to which we'll direct all automatically-created administrative aliases. - tools/mail.py alias add administrator@$PRIMARY_HOSTNAME $EMAIL_ADDR > /dev/null + management/cli.py alias add administrator@$PRIMARY_HOSTNAME $EMAIL_ADDR > /dev/null fi diff --git a/setup/nextcloud.sh b/setup/nextcloud.sh index 76c0480..ea1939c 100755 --- a/setup/nextcloud.sh +++ b/setup/nextcloud.sh @@ -324,7 +324,7 @@ rm -f /etc/cron.hourly/mailinabox-owncloud # and there's a lot they could mess up, so we don't make any users admins of Nextcloud. # But if we wanted to, we would do this: # ``` -# for user in $(tools/mail.py user admins); do +# for user in $(management/cli.py user admins); do # sqlite3 $STORAGE_ROOT/owncloud/owncloud.db "INSERT OR IGNORE INTO oc_group_user VALUES ('admin', '$user')" # done # ```