From 9b5c51bcc9843575b7fa4eb86b29b5660a06ece6 Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Fri, 19 Mar 2021 11:58:35 -0700 Subject: [PATCH] user permissions checks --- bin/vmail-aliases-add.sh | 2 +- bin/vmail-aliases-del.sh | 2 +- bin/vmail-aliases-get.sh | 2 +- bin/vmail-deploy.sh | 2 +- bin/vmail-dkim-add.sh | 2 +- bin/vmail-dkim-del.sh | 2 +- bin/vmail-domains-add.sh | 2 +- bin/vmail-domains-del.sh | 2 +- bin/vmail-domains-get.sh | 2 +- bin/vmail-domains-mod.sh | 2 +- bin/vmail-forwards-add.sh | 2 +- bin/vmail-forwards-del.sh | 2 +- bin/vmail-forwards-get.sh | 2 +- bin/vmail-mboxes-add.sh | 2 +- bin/vmail-mboxes-del.sh | 2 +- bin/vmail-mboxes-get.sh | 2 +- bin/vmail-purge-dirs.sh | 2 +- bin/webmail-disable.sh | 2 +- bin/webmail-enable.sh | 2 +- etc/vmail.conf | 7 ++++++- 20 files changed, 25 insertions(+), 20 deletions(-) diff --git a/bin/vmail-aliases-add.sh b/bin/vmail-aliases-add.sh index 9ea6f7b..c9d821b 100755 --- a/bin/vmail-aliases-add.sh +++ b/bin/vmail-aliases-add.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit help() { diff --git a/bin/vmail-aliases-del.sh b/bin/vmail-aliases-del.sh index c506282..dd22342 100755 --- a/bin/vmail-aliases-del.sh +++ b/bin/vmail-aliases-del.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit help() { diff --git a/bin/vmail-aliases-get.sh b/bin/vmail-aliases-get.sh index 9ccdd08..3a5daef 100755 --- a/bin/vmail-aliases-get.sh +++ b/bin/vmail-aliases-get.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit help() { diff --git a/bin/vmail-deploy.sh b/bin/vmail-deploy.sh index dc22a00..eed2930 100755 --- a/bin/vmail-deploy.sh +++ b/bin/vmail-deploy.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit # check for and set virtualhost if [ -n "$1" ]; then diff --git a/bin/vmail-dkim-add.sh b/bin/vmail-dkim-add.sh index 347d2e3..242dff0 100755 --- a/bin/vmail-dkim-add.sh +++ b/bin/vmail-dkim-add.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit # check for and set virtualhost if [ -n "$1" ]; then diff --git a/bin/vmail-dkim-del.sh b/bin/vmail-dkim-del.sh index ae69798..fa4064b 100755 --- a/bin/vmail-dkim-del.sh +++ b/bin/vmail-dkim-del.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit # check for and set virtualhost if [ -n "$1" ]; then diff --git a/bin/vmail-domains-add.sh b/bin/vmail-domains-add.sh index 41a5ba1..7f790be 100755 --- a/bin/vmail-domains-add.sh +++ b/bin/vmail-domains-add.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit help() { diff --git a/bin/vmail-domains-del.sh b/bin/vmail-domains-del.sh index cdd16d7..7077675 100755 --- a/bin/vmail-domains-del.sh +++ b/bin/vmail-domains-del.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit help() { diff --git a/bin/vmail-domains-get.sh b/bin/vmail-domains-get.sh index 0519cf3..5c2671c 100755 --- a/bin/vmail-domains-get.sh +++ b/bin/vmail-domains-get.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit help() { diff --git a/bin/vmail-domains-mod.sh b/bin/vmail-domains-mod.sh index 074028b..0190586 100755 --- a/bin/vmail-domains-mod.sh +++ b/bin/vmail-domains-mod.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit help() { diff --git a/bin/vmail-forwards-add.sh b/bin/vmail-forwards-add.sh index 8b07fe1..9542b6a 100755 --- a/bin/vmail-forwards-add.sh +++ b/bin/vmail-forwards-add.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit help() { diff --git a/bin/vmail-forwards-del.sh b/bin/vmail-forwards-del.sh index 06cb16d..5bfbf6b 100755 --- a/bin/vmail-forwards-del.sh +++ b/bin/vmail-forwards-del.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit help() { diff --git a/bin/vmail-forwards-get.sh b/bin/vmail-forwards-get.sh index 660fa07..9398de4 100755 --- a/bin/vmail-forwards-get.sh +++ b/bin/vmail-forwards-get.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit help() { diff --git a/bin/vmail-mboxes-add.sh b/bin/vmail-mboxes-add.sh index fe63c6b..8f9e3ac 100755 --- a/bin/vmail-mboxes-add.sh +++ b/bin/vmail-mboxes-add.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit help() { diff --git a/bin/vmail-mboxes-del.sh b/bin/vmail-mboxes-del.sh index 18f586d..a86ae4c 100755 --- a/bin/vmail-mboxes-del.sh +++ b/bin/vmail-mboxes-del.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit help() { diff --git a/bin/vmail-mboxes-get.sh b/bin/vmail-mboxes-get.sh index 1f3b533..24be9bd 100755 --- a/bin/vmail-mboxes-get.sh +++ b/bin/vmail-mboxes-get.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit help() { diff --git a/bin/vmail-purge-dirs.sh b/bin/vmail-purge-dirs.sh index 9accc20..0525caf 100755 --- a/bin/vmail-purge-dirs.sh +++ b/bin/vmail-purge-dirs.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /usr/local/etc/vmail.conf +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit # only continue if vmail dir exists if [ -d $VMAIL_DIR ]; then diff --git a/bin/webmail-disable.sh b/bin/webmail-disable.sh index 6cd6337..f80bed4 100755 --- a/bin/webmail-disable.sh +++ b/bin/webmail-disable.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /opt/stack/include/config.inc +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit # check for and set virtualhost if [ -n "$1" ]; then diff --git a/bin/webmail-enable.sh b/bin/webmail-enable.sh index 4497f48..7f74a85 100755 --- a/bin/webmail-enable.sh +++ b/bin/webmail-enable.sh @@ -5,7 +5,7 @@ # MIT License Copyright (c) 2021 Matthew Saunders Brown # load config -source /opt/stack/include/config.inc +source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit # check for and set virtualhost if [ -n "$1" ]; then diff --git a/etc/vmail.conf b/etc/vmail.conf index e5ad255..4591661 100644 --- a/etc/vmail.conf +++ b/etc/vmail.conf @@ -6,11 +6,16 @@ if [ "$USER" != "vmail" ]; then fi # constants - readonly MYSQL_CONNECTION_INFO_FILE=/usr/local/etc/vmail-db-info.conf readonly VMAIL_DIR=/var/vmail readonly VMAIL_DB=vmail +# check that MYSQL_CONNECTION_INFO_FILE exists and is readable +if [ ! -f "$MYSQL_CONNECTION_INFO_FILE" ]; then + echo "ERROR: MySQL connection info file ($MYSQL_CONNECTION_INFO_FILE) does not exist or is not readable." + exit +fi + # functions # crude but good enough domain name format validation