webmail scripts must be run as root

This commit is contained in:
Matthew Saunders Brown 2021-03-19 11:59:41 -07:00
parent 9b5c51bcc9
commit 33471972e5
2 changed files with 12 additions and 4 deletions

View File

@ -4,8 +4,10 @@
# https://git.stack-source.com/msb/vmail-stack # https://git.stack-source.com/msb/vmail-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown # MIT License Copyright (c) 2021 Matthew Saunders Brown
# load config # must be root to disable apache config
source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit if [ "$USER" != "root" ]; then
exec su "$0" -- "$@"
fi
# check for and set virtualhost # check for and set virtualhost
if [ -n "$1" ]; then if [ -n "$1" ]; then
@ -15,10 +17,12 @@ else
exit 1 exit 1
fi fi
# disable webmail vhost & restart apache
if [ -h "/etc/apache2/sites-enabled/mail.$virtualhost.conf" ]; then if [ -h "/etc/apache2/sites-enabled/mail.$virtualhost.conf" ]; then
/usr/sbin/a2dissite --quiet mail.$virtualhost /usr/sbin/a2dissite --quiet mail.$virtualhost
/usr/bin/systemctl --quiet reload apache2 /usr/bin/systemctl --quiet reload apache2
fi fi
if [ -f "/etc/apache2/sites-available/mail.$virtualhost.conf" ]; then if [ -f "/etc/apache2/sites-available/mail.$virtualhost.conf" ]; then
rm /etc/apache2/sites-available/mail.$virtualhost.conf rm /etc/apache2/sites-available/mail.$virtualhost.conf
fi fi

View File

@ -4,8 +4,10 @@
# https://git.stack-source.com/msb/vmail-stack # https://git.stack-source.com/msb/vmail-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown # MIT License Copyright (c) 2021 Matthew Saunders Brown
# load config # must be root to enable apache config
source /usr/local/etc/vmail.conf || echo "ERROR: Either you do not have vmail user permissions or the config file is missing." && exit if [ "$USER" != "root" ]; then
exec su "$0" -- "$@"
fi
# check for and set virtualhost # check for and set virtualhost
if [ -n "$1" ]; then if [ -n "$1" ]; then
@ -15,6 +17,7 @@ else
exit 1 exit 1
fi fi
# check that letsencrypt cert exists
if [ ! -f /etc/ssl/letsencrypt/mail.$virtualhost.pem ]; then if [ ! -f /etc/ssl/letsencrypt/mail.$virtualhost.pem ]; then
echo "Let's Encrypt cert for mail.$virtualhost does not exist, create that first:" echo "Let's Encrypt cert for mail.$virtualhost does not exist, create that first:"
exit 1 exit 1
@ -24,6 +27,7 @@ fi
if [ ! -f "/etc/apache2/sites-available/mail.$virtualhost.conf" ]; then if [ ! -f "/etc/apache2/sites-available/mail.$virtualhost.conf" ]; then
echo "Use VHostMAIL $virtualhost" > /etc/apache2/sites-available/mail.$virtualhost.conf echo "Use VHostMAIL $virtualhost" > /etc/apache2/sites-available/mail.$virtualhost.conf
fi fi
if [ ! -h "/etc/apache2/sites-enabled/mail.$virtualhost.conf" ]; then if [ ! -h "/etc/apache2/sites-enabled/mail.$virtualhost.conf" ]; then
/usr/sbin/a2ensite --quiet mail.$virtualhost /usr/sbin/a2ensite --quiet mail.$virtualhost
/usr/bin/systemctl --quiet is-active apache2 && systemctl --quiet reload apache2 /usr/bin/systemctl --quiet is-active apache2 && systemctl --quiet reload apache2