Skip to content

Commit 3c24081

Browse files
author
Kristan Kenney
committed
Update v-change-sys-webmail to support new configuration
1 parent d8584c5 commit 3c24081

File tree

1 file changed

+29
-44
lines changed

1 file changed

+29
-44
lines changed

bin/v-change-sys-webmail

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,69 +16,54 @@ WEBMAIL=$1
1616
source $HESTIA/func/main.sh
1717
source $HESTIA/conf/hestia.conf
1818

19+
# Get existing system webmail alias
20+
export $WEBMAIL_ALIAS
21+
22+
# Define aliases
23+
OLD_ALIAS=$WEBMAIL_ALIAS
24+
NEW_ALIAS=$1
1925

2026
#----------------------------------------------------------#
2127
# Verifications #
2228
#----------------------------------------------------------#
2329

2430
check_args '1' "$#" 'WEBMAIL'
2531

26-
# Check if string has leading /
27-
if [[ ! ${WEBMAIL:0:1} == "/" ]]; then
28-
WEBMAIL="/$WEBMAIL"
29-
fi
30-
3132
#----------------------------------------------------------#
3233
# Action #
3334
#----------------------------------------------------------#
3435

35-
# Get existing apache2 webmail alias
36-
if [ -f /etc/apache2/conf.d/roundcube.conf ]; then
37-
apache_webmail=$(tail -n+3 /etc/apache2/conf.d/roundcube.conf | grep "Alias" | { IFS=' '; read -r -a array; echo "${array[1]}"; })
38-
fi
39-
40-
# Get existing nginx webmail alias
41-
if [ -f /etc/nginx/conf.d/webmail.inc ]; then
42-
nginx_webmail=$(cat /etc/nginx/conf.d/webmail.inc | grep "location" | { IFS=' '; read -r -a array; echo "${array[1]}"; })
43-
fi
44-
45-
# Check if alias is different for apache2
46-
if [ ! -z "$apache_webmail" ]; then
47-
if [ ! "$apache_webmail" = "$WEBMAIL" ]; then
48-
# Replace webmail alias in config files.
49-
sed -i "s|Alias $apache_webmail|Alias $WEBMAIL|" /etc/apache2/conf.d/roundcube.conf
36+
# Delete old webmail configuration
37+
for user in `ls /usr/local/hestia/data/users/`; do
38+
for domain in $($BIN/v-list-web-domains $user plain |cut -f 1); do
39+
v-delete-webmail $user $domain
40+
done
41+
done
5042

51-
# Replace in Backend UI
52-
sed -i "s|$apache_webmail/|$WEBMAIL/|" /usr/local/hestia/web/templates/admin/list_mail.html
53-
sed -i "s|$apache_webmail/|$WEBMAIL/|" /usr/local/hestia/web/templates/user/list_mail.html
43+
# Set new webmail alias
44+
sed -i "s|WEBMAIL_ALIAS='$OLD_ALIAS'|WEBMAIL_ALIAS='$NEW_ALIAS'|gI" $HESTIA/conf/hestia.conf
5445

55-
# Restart services
56-
$HESTIA/bin/v-restart-service apache2
57-
fi
58-
fi
59-
60-
# Check if alias is different for nginx
61-
if [ ! -z "$nginx_webmail" ]; then
62-
if [ ! "$nginx_webmail" = "$WEBMAIL" ]; then
63-
# Replace webmail alias in config files.
64-
sed -i "s|$nginx_webmail|$WEBMAIL|" /etc/nginx/conf.d/webmail.inc
65-
sed -i "s|/var/lib$WEBMAIL|/var/lib/roundcube|" /etc/nginx/conf.d/webmail.inc
66-
67-
# Replace in Backend UI
68-
sed -i "s|$nginx_webmail/|$WEBMAIL/|" /usr/local/hestia/web/templates/admin/list_mail.html
69-
sed -i "s|$nginx_webmail/|$WEBMAIL/|" /usr/local/hestia/web/templates/user/list_mail.html
70-
71-
# Restart services
72-
$HESTIA/bin/v-restart-service nginx
73-
fi
74-
fi
46+
for user in `ls /usr/local/hestia/data/users/`; do
47+
for domain in $($BIN/v-list-web-domains $user plain |cut -f 1); do
48+
echo "Changing webmail alias for $domain"
49+
v-add-webmail $user $domain
50+
done
51+
done
7552

53+
# Update alias (non-subdomain) configuration to match
54+
sed -i "s|Alias \/webmail|Alias \/$NEW_ALIAS|gI" /etc/apache2/conf.d/roundcube.conf
55+
sed -i "s|location \/webmail|location \/$NEW_ALIAS|gI" /etc/nginx/conf.d/webmail.inc
7656

7757
#----------------------------------------------------------#
7858
# Hestia #
7959
#----------------------------------------------------------#
8060

61+
# Restart services
62+
$BIN/v-restart-web $restart
63+
$BIN/v-restart-proxy $restart
64+
8165
# Logging
82-
#log_event "$OK" "$ARGUMENTS"
66+
log_history "changed system webmail alias to $NEW_ALIAS"
67+
log_event "$OK" "$ARGUMENTS"
8368

8469
exit

0 commit comments

Comments
 (0)