Skip to content

Commit e9ea753

Browse files
authored
Merge pull request hestiacp#1994 from jaapmarcus/fix/issues-with-webmail
Fix hestiacp#1986 and Webmail client reset to disabled after ssl enabled
2 parents 7e25540 + d4af46e commit e9ea753

File tree

9 files changed

+99
-106
lines changed

9 files changed

+99
-106
lines changed

bin/v-add-mail-domain-ssl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fi
7878
# Call routine to add SSL configuration to mail domain
7979
add_mail_ssl_config
8080

81-
if [ "$webmail" == "roundcube" ]; then
81+
if [ "$WEBMAIL" == "roundcube" ]; then
8282
WEBMAIL_TEMPLATE="default"
8383
if [ ! -z "$PROXY_SYSTEM" ]; then
8484
PROXY_TEMPLATE="default"
@@ -88,7 +88,7 @@ if [ "$webmail" == "roundcube" ]; then
8888
if [ "$WEB_SYSTEM" = "nginx" ]; then
8989
WEBMAIL_TEMPLATE="web_system"
9090
fi
91-
elif [ "$webmail" == "rainloop" ]; then
91+
elif [ "$WEBMAIL" == "rainloop" ]; then
9292
WEBMAIL_TEMPLATE="rainloop"
9393
if [ ! -z "$PROXY_SYSTEM" ]; then
9494
PROXY_TEMPLATE="default_rainloop"

bin/v-add-mail-domain-webmail

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ webmail=$3
2020
restart="$4"
2121
quiet=$5
2222

23+
if [ -z "$restart" ]; then
24+
restart="yes"
25+
fi
26+
2327
# Additional argument formatting
2428
if [[ "$domain" =~ [[:upper:]] ]]; then
2529
domain=$(echo "$domain" |tr '[:upper:]' '[:lower:]')

func/domain.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,9 +802,7 @@ add_webmail_config() {
802802
fi
803803

804804
# Remove old configurations
805-
rm -rf $HOMEDIR/$user/conf/mail/$domain.*
806-
rm -rf $HOMEDIR/$user/conf/mail/ssl.$domain.*
807-
rm -rf $HOMEDIR/$user/conf/mail/*nginx.$domain.*
805+
find $HOMEDIR/$user/conf/mail/ -maxdepth 1 -type f \( -name "$domain.*" -o -name "ssl.$domain.*" -o -name "*nginx.$domain.*" \) -exec rm {} \;
808806
else
809807
if [ ! -z "$WEB_SYSTEM" ]; then
810808
rm -f /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
@@ -815,7 +813,7 @@ add_webmail_config() {
815813
ln -s $conf /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
816814
fi
817815
# Clear old configurations
818-
rm -rf $HOMEDIR/$user/conf/mail/$domain.*
816+
find $HOMEDIR/$user/conf/mail/ -maxdepth 1 -type f \( -name "$domain.*" \) -exec rm {} \;
819817
fi
820818
}
821819

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
<VirtualHost %ip%:%web_ssl_port%>
22
ServerName %domain_idn%
33
ServerAlias %alias_idn%
4-
Alias / /var/www/html/
5-
Alias /error/ %home%/%user%/web/%root_domain%/document_errors/
6-
#SuexecUserGroup %user% %group%
4+
DocumentRoot /var/www/html/
5+
Alias /error/ /var/www/document_errors/
76

87
SSLEngine on
98
SSLVerifyClient none
109
SSLCertificateFile %home%/%user%/conf/mail/%root_domain%/ssl/%root_domain%.crt
1110
SSLCertificateKeyFile %home%/%user%/conf/mail/%root_domain%/ssl/%root_domain%.key
12-
13-
<Directory /var/www/html>
14-
Options +FollowSymLinks
15-
AllowOverride All
16-
order allow,deny
17-
allow from all
18-
</Directory>
1911

20-
IncludeOptional %home%/%user%/conf/mail/%root_domain%/%web_system%.conf_*
2112
</VirtualHost>
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
<VirtualHost %ip%:%web_port%>
22
ServerName %domain_idn%
33
ServerAlias %alias_idn%
4-
Alias / /var/www/html
5-
Alias /error/ %home%/%user%/web/%root_domain%/document_errors/
4+
DocumentRoot /var/www/html/
5+
Alias /error/ /var/www/document_errors/
66
#SuexecUserGroup %user% %group%
7-
8-
IncludeOptional %home%/%user%/conf/mail/%root_domain%/apache2.forcessl.conf*
9-
10-
<Directory /var/www/html>
11-
Options +FollowSymLinks
12-
AllowOverride All
13-
order allow,deny
14-
allow from all
15-
</Directory>
16-
17-
IncludeOptional %home%/%user%/conf/mail/%root_domain%/%web_system%.conf_*
187
</VirtualHost>
Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
11
server {
2-
listen %ip%:%proxy_ssl_port% ssl http2;
3-
server_name %domain_idn% %alias_idn%;
4-
root /var/lib/roundcube;
2+
listen %ip%:%proxy_ssl_port% ssl http2;
3+
server_name %domain_idn% %alias_idn%;
54
index index.php index.html index.htm;
65
access_log /var/log/nginx/domains/%domain%.log combined;
76
error_log /var/log/nginx/domains/%domain%.error.log error;
8-
7+
98
ssl_certificate %ssl_pem%;
109
ssl_certificate_key %ssl_key%;
1110
ssl_stapling on;
1211
ssl_stapling_verify on;
13-
12+
1413
location ~ /\.(?!well-known\/) {
1514
deny all;
1615
return 404;
1716
}
18-
17+
1918
location / {
20-
try_files $uri $uri/ =404;
21-
alias /var/www/html;
19+
proxy_pass http://%ip%:%web_port%;
2220
}
23-
24-
location /error/ {
25-
alias /var/www/document_errors/;
26-
}
27-
28-
location @fallback {
29-
proxy_pass https://%ip%:%web_ssl_port%;
30-
}
31-
32-
include %home%/%user%/conf/mail/%root_domain%/%proxy_system%.conf_*;
33-
}
21+
}
Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
server {
2-
listen %ip%:%proxy_ssl_port% ssl http2;
3-
server_name %domain_idn% %alias_idn%;
4-
root /var/lib/roundcube;
5-
index index.php index.html index.htm;
6-
access_log /var/log/nginx/domains/%domain%.log combined;
7-
error_log /var/log/nginx/domains/%domain%.error.log error;
8-
9-
ssl_certificate %ssl_pem%;
10-
ssl_certificate_key %ssl_key%;
11-
ssl_stapling on;
12-
ssl_stapling_verify on;
13-
2+
listen %ip%:%proxy_port%;
3+
server_name %domain_idn% %alias_idn%;
4+
index index.php index.html index.htm;
5+
access_log /var/log/nginx/domains/%domain%.log combined;
6+
error_log /var/log/nginx/domains/%domain%.error.log error;
7+
8+
include %home%/%user%/conf/mail/%root_domain%/nginx.forcessl.conf*;
9+
1410
location ~ /\.(?!well-known\/) {
1511
deny all;
1612
return 404;
1713
}
18-
14+
1915
location / {
20-
try_files $uri $uri/ =404;
21-
alias /var/www/html;
16+
proxy_pass http://%ip%:%web_port%;
2217
}
23-
24-
location /error/ {
25-
alias /var/www/document_errors/;
26-
}
27-
28-
location @fallback {
29-
proxy_pass https://%ip%:%web_ssl_port%;
30-
}
31-
32-
include %home%/%user%/conf/mail/%root_domain%/%proxy_system%.conf_*;
33-
}
18+
}

test/test.bats

Lines changed: 67 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function setup() {
2323
echo 'userpass2=t3st-p4ssw0rd' >> /tmp/hestia-test-env.sh
2424
echo 'HESTIA=/usr/local/hestia' >> /tmp/hestia-test-env.sh
2525
echo 'domain=test-5285.hestiacp.com' >> /tmp/hestia-test-env.sh
26+
echo 'domainuk=test-5285.hestiacp.com.uk' >> /tmp/hestia-test-env.sh
2627
echo 'rootdomain=testhestiacp.com' >> /tmp/hestia-test-env.sh
2728
echo 'subdomain=cdn.testhestiacp.com' >> /tmp/hestia-test-env.sh
2829
echo 'database=test-5285_database' >> /tmp/hestia-test-env.sh
@@ -121,26 +122,38 @@ function validate_webmail_domain() {
121122
if [ ! -z "$webpath" ]; then
122123
assert_file_exist /var/lib/roundcube/$webpath
123124
fi
124-
125-
# Test HTTP
126-
run curl --location --silent --show-error --insecure --resolve "webmail.${domain}:80:${domain_ip}" "http://webmail.${domain}/${webpath}"
127-
assert_success
128-
assert_output --partial "$webproof"
129-
130-
# Test HTTP
131-
run curl --location --silent --show-error --insecure --resolve "mail.${domain}:80:${domain_ip}" "http://mail.${domain}/${webpath}"
132-
assert_success
133-
assert_output --partial "$webproof"
125+
126+
if [ "$SSL" = "no" ]; then
127+
# Test HTTP
128+
run curl --location --silent --show-error --insecure --resolve "webmail.${domain}:80:${domain_ip}" "http://webmail.${domain}/${webpath}"
129+
assert_success
130+
assert_output --partial "$webproof"
131+
132+
# Test HTTP
133+
run curl --location --silent --show-error --insecure --resolve "mail.${domain}:80:${domain_ip}" "http://mail.${domain}/${webpath}"
134+
assert_success
135+
assert_output --partial "$webproof"
136+
fi
134137

135138
# Test HTTPS
136139
if [ "$SSL" = "yes" ]; then
137-
run v-list-mail-domain-ssl $user $domain
140+
# Test HTTP with 301 redirect for some reasons due to 301 redirect it fails
141+
run curl --silent --show-error --insecure --resolve "webmail.${domain}:80:${domain_ip}" "http://webmail.${domain}/${webpath}"
138142
assert_success
143+
assert_output --partial "301 Moved Permanently"
139144

145+
# Test HTTP with 301 redirect for some reasons due to 301 redirect it fails
146+
run curl --silent --show-error --insecure --resolve "mail.${domain}:80:${domain_ip}" "http://mail.${domain}/${webpath}"
147+
assert_success
148+
assert_output --partial "301 Moved Permanently"
149+
150+
run v-list-mail-domain-ssl $user $domain
151+
assert_success
152+
140153
run curl --location --silent --show-error --insecure --resolve "webmail.${domain}:443:${domain_ip}" "https://webmail.${domain}/${webpath}"
141154
assert_success
142155
assert_output --partial "$webproof"
143-
156+
144157
run curl --location --silent --show-error --insecure --resolve "mail.${domain}:443:${domain_ip}" "https://mail.${domain}/${webpath}"
145158
assert_success
146159
assert_output --partial "$webproof"
@@ -183,17 +196,6 @@ function validate_database(){
183196
rm -f "$tmpfile"
184197
}
185198

186-
#----------------------------------------------------------#
187-
# MAIN #
188-
#----------------------------------------------------------#
189-
190-
@test "Add new userXXX" {
191-
skip
192-
run v-add-user $user $user $user@hestiacp.com default "Super Test"
193-
assert_success
194-
refute_output
195-
}
196-
197199
#----------------------------------------------------------#
198200
# IP #
199201
#----------------------------------------------------------#
@@ -918,20 +920,52 @@ function validate_database(){
918920
run v-add-mail-domain $user $domain
919921
assert_success
920922
refute_output
923+
924+
validate_mail_domain $user $domain
921925
}
922926

923-
@test "MAIL: Add mail domain webmail client" {
924-
skip
925-
run v-add-mail-domain-webmail $user $domain "rouncube"
927+
@test "MAIL: Add mail domain webmail client (Roundcube)" {
928+
run v-add-mail-domain-webmail $user $domain "roundcube" "yes"
926929
assert_success
927930
refute_output
928-
validate_mail_domain $user $domain
929931

930932
# echo -e "<?php\necho 'Server: ' . \$_SERVER['SERVER_SOFTWARE'];" > /var/lib/roundcube/check_server.php
931933
validate_webmail_domain $user $domain 'Welcome to Roundcube Webmail'
932934
# rm /var/lib/roundcube/check_server.php
933935
}
934936

937+
@test "Mail: Add SSL to mail domain" {
938+
cp -f $HESTIA/ssl/certificate.crt /tmp/$domain.crt
939+
cp -f $HESTIA/ssl/certificate.key /tmp/$domain.key
940+
941+
run v-add-mail-domain-ssl $user $domain /tmp
942+
assert_success
943+
refute_output
944+
945+
validate_webmail_domain $user $domain 'Welcome to Roundcube Webmail'
946+
}
947+
948+
@test "MAIL: Add mail domain webmail client (Rainloop)" {
949+
if [ -z "$(echo $WEBMAIL_SYSTEM | grep -w "rainloop")" ]; then
950+
skip "Webmail client Rainloop not installed"
951+
fi
952+
run v-add-mail-domain-webmail $user $domain "rainloop" "yes"
953+
assert_success
954+
refute_output
955+
validate_mail_domain $user $domain
956+
957+
validate_webmail_domain $user $domain 'RainLoop Webmail'
958+
}
959+
960+
@test "MAIL: Disable webmail client" {
961+
run v-add-mail-domain-webmail $user $domain "disabled" "yes"
962+
assert_success
963+
refute_output
964+
validate_mail_domain $user $domain
965+
966+
validate_webmail_domain $user $domain 'Success!'
967+
}
968+
935969
@test "MAIL: Add domain (duplicate)" {
936970
run v-add-mail-domain $user $domain
937971
assert_failure $E_EXISTS
@@ -959,6 +993,12 @@ function validate_database(){
959993
assert_failure $E_NOTEXIST
960994
}
961995

996+
@test "MAIL: Rebuild mail domain" {
997+
run v-rebuild-mail-domains $user
998+
assert_success
999+
refute_output
1000+
}
1001+
9621002
#----------------------------------------------------------#
9631003
# Limit possibilities adding different owner domain #
9641004
#----------------------------------------------------------#
@@ -1066,8 +1106,6 @@ function validate_database(){
10661106
refute_output
10671107
}
10681108

1069-
1070-
10711109
#----------------------------------------------------------#
10721110
# DB #
10731111
#----------------------------------------------------------#

web/templates/pages/edit_mail.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@
7676
<select class="vst-list" name="v_webmail" tabindex="6">
7777
<?php foreach ($webmail_clients as $client){
7878
echo "\t\t\t\t<option value=\"".htmlentities($client)."\"";
79-
if (( $v_webmail == $client )) {
79+
if (( htmlentities(trim($v_webmail,"'")) == $client )) {
8080
echo ' selected' ;
8181
}
8282
echo ">".htmlentities(ucfirst($client))."</option>\n";
8383
}
8484
?>
85-
<option value="disabled" <?php if ( empty($v_webmail) || ($v_webmail == 'disabled')) { echo "selected";}?>><?=_('Disabled');?></option>
85+
<option value="disabled" <?php if (htmlentities(trim($v_webmail,"'")) == 'disabled') { echo "selected";}?>><?=_('Disabled');?></option>
8686
</select>
8787
</td>
8888
</tr>

0 commit comments

Comments
 (0)