Skip to content

Commit 281ae1f

Browse files
committed
Add nginx webmail template and fix websystem detection
1 parent e6a4687 commit 281ae1f

File tree

8 files changed

+137
-24
lines changed

8 files changed

+137
-24
lines changed

bin/v-add-mail-domain

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@ if [ ! -z "$DNS_SYSTEM" ] && [ "$dkim" = 'yes' ]; then
128128
fi
129129

130130
# Add webmail configuration to mail domain
131-
if [ ! -z "$WEB_SYSTEM" ]; then
132-
add_webmail_config "$WEB_SYSTEM" "default.tpl"
131+
WEBMAIL_TEMPLATE="proxy_system"
132+
if [ "$WEB_SYSTEM" = "nginx" ]; then
133+
WEBMAIL_TEMPLATE="web_system"
133134
fi
135+
add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.tpl"
136+
134137
if [ ! -z "$PROXY_SYSTEM" ]; then
135138
add_webmail_config "$PROXY_SYSTEM" "default.tpl"
136139
fi

bin/v-add-mail-domain-ssl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ is_web_domain_cert_valid
6464
add_mail_ssl_config
6565

6666
# Add webmail configuration to mail domain
67-
if [ ! -z "$WEB_SYSTEM" ]; then
68-
add_webmail_config "$WEB_SYSTEM" "default.stpl"
67+
WEBMAIL_TEMPLATE="proxy_system"
68+
if [ "$WEB_SYSTEM" = "nginx" ]; then
69+
WEBMAIL_TEMPLATE="web_system"
6970
fi
71+
add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.stpl"
72+
7073
if [ ! -z "$PROXY_SYSTEM" ]; then
7174
add_webmail_config "$PROXY_SYSTEM" "default.stpl"
7275
fi

bin/v-add-webmail

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,20 @@ is_object_unsuspended 'mail' 'DOMAIN' "$domain"
5555
#----------------------------------------------------------#
5656

5757
# Add webmail configuration to mail domain
58-
if [ ! -z "$WEB_SYSTEM" ]; then
59-
add_webmail_config "$WEB_SYSTEM" "default.tpl"
58+
WEBMAIL_TEMPLATE="proxy_system"
59+
if [ "$WEB_SYSTEM" = "nginx" ]; then
60+
WEBMAIL_TEMPLATE="web_system"
6061
fi
62+
add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.tpl"
63+
6164
if [ ! -z "$PROXY_SYSTEM" ]; then
6265
add_webmail_config "$PROXY_SYSTEM" "default.tpl"
6366
fi
6467

6568
# Enable SSL for webmail if available
6669
if [ -f $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.crt ] || [ "$SSL" = 'yes' ]; then
67-
if [ ! -z "$WEB_SYSTEM" ]; then
68-
add_webmail_config "$WEB_SYSTEM" "default.stpl"
69-
fi
70+
add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.stpl"
71+
7072
if [ ! -z "$PROXY_SYSTEM" ]; then
7173
add_webmail_config "$PROXY_SYSTEM" "default.stpl"
7274
fi

func/domain.sh

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ del_mail_ssl_certificates(){
671671
add_webmail_config() {
672672
mkdir -p "$HOMEDIR/$user/conf/mail/$domain"
673673
conf="$HOMEDIR/$user/conf/mail/$domain/$1.conf"
674-
if [ "$2" = "default.stpl" ]; then
674+
if [[ "$2" =~ stpl$ ]]; then
675675
conf="$HOMEDIR/$user/conf/mail/$domain/$1.ssl.conf"
676676
fi
677677

@@ -716,19 +716,7 @@ add_webmail_config() {
716716
chown root:$user $conf
717717
chmod 640 $conf
718718

719-
if [ "$2" = "default.tpl" ]; then
720-
if [ ! -z "$WEB_SYSTEM" ]; then
721-
rm -f /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
722-
ln -s $conf /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
723-
fi
724-
if [ ! -z "$PROXY_SYSTEM" ]; then
725-
rm -f /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
726-
ln -s $conf /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
727-
fi
728-
# Clear old configurations
729-
rm -rf $HOMEDIR/$user/conf/mail/$domain.*
730-
fi
731-
if [ "$2" = "default.stpl" ]; then
719+
if [[ "$2" =~ stpl$ ]]; then
732720
if [ ! -z "$WEB_SYSTEM" ]; then
733721
forcessl="$HOMEDIR/$user/conf/mail/$domain/$WEB_SYSTEM.forcessl.conf"
734722
rm -f /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.ssl.conf
@@ -741,7 +729,7 @@ add_webmail_config() {
741729
fi
742730

743731
# Add rewrite rules to force HTTPS/SSL connections
744-
if [ ! -z "$PROXY_SYSTEM" ]; then
732+
if [ ! -z "$PROXY_SYSTEM" ] || [ "$WEB_SYSTEM" = 'nginx' ]; then
745733
echo 'return 301 https://$server_name$request_uri;' > $forcessl
746734
else
747735
echo 'RewriteEngine On' > $forcessl
@@ -752,6 +740,17 @@ add_webmail_config() {
752740
rm -rf $HOMEDIR/$user/conf/mail/$domain.*
753741
rm -rf $HOMEDIR/$user/conf/mail/ssl.$domain.*
754742
rm -rf $HOMEDIR/$user/conf/mail/*nginx.$domain.*
743+
else
744+
if [ ! -z "$WEB_SYSTEM" ]; then
745+
rm -f /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
746+
ln -s $conf /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
747+
fi
748+
if [ ! -z "$PROXY_SYSTEM" ]; then
749+
rm -f /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
750+
ln -s $conf /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
751+
fi
752+
# Clear old configurations
753+
rm -rf $HOMEDIR/$user/conf/mail/$domain.*
755754
fi
756755
}
757756

File renamed without changes.
File renamed without changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
server {
2+
listen %ip%:%web_ssl_port% ssl http2;
3+
server_name %domain% %alias%;
4+
root /var/lib/roundcube;
5+
index index.php;
6+
7+
ssl_certificate %ssl_pem%;
8+
ssl_certificate_key %ssl_key%;
9+
error_log /var/log/%web_system%/domains/%domain%.error.log error;
10+
11+
location / {
12+
try_files $uri $uri/ /index.php?$args;
13+
location ~* ^.+\.(jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls,exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp,rtf,js,mp3,avi,mpeg,flv,html,htm)$ {
14+
alias /var/lib/roundcube/;
15+
expires 15m;
16+
}
17+
}
18+
19+
location /error/ {
20+
alias %home%/%user%/web/%root_domain%/document_errors/;
21+
}
22+
23+
location ~ /(config|temp|logs) {
24+
return 404;
25+
}
26+
27+
location /Microsoft-Server-ActiveSync {
28+
alias /usr/share/z-push/;
29+
30+
location ~ ^/Microsoft-Server-ActiveSync/(.*\.php)$ {
31+
alias /usr/share/z-push/$1;
32+
fastcgi_pass 127.0.0.1:9000;
33+
fastcgi_index index.php;
34+
include fastcgi_params;
35+
fastcgi_param SCRIPT_FILENAME $request_filename;
36+
}
37+
}
38+
39+
location ~ ^/(.*\.php)$ {
40+
alias /var/lib/roundcube/$1;
41+
fastcgi_pass 127.0.0.1:9000;
42+
fastcgi_index index.php;
43+
include fastcgi_params;
44+
fastcgi_param SCRIPT_FILENAME $request_filename;
45+
}
46+
47+
location ~ /\.ht {return 404;}
48+
location ~ /\.svn/ {return 404;}
49+
location ~ /\.git/ {return 404;}
50+
location ~ /\.hg/ {return 404;}
51+
location ~ /\.bzr/ {return 404;}
52+
53+
include %home%/%user%/conf/mail/%root_domain%/%web_system%.ssl.conf_*;
54+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
server {
2+
listen %ip%:%web_port%;
3+
server_name %domain% %alias%;
4+
root /var/lib/roundcube;
5+
index index.php;
6+
7+
include %home%/%user%/conf/mail/%root_domain%/nginx.forcessl.conf*;
8+
9+
location / {
10+
try_files $uri $uri/ /index.php?$args;
11+
location ~* ^.+\.(jpg,jpeg,gif,png,ico,svg,css,zip,tgz,gz,rar,bz2,doc,xls,exe,pdf,ppt,txt,odt,ods,odp,odf,tar,wav,bmp,rtf,js,mp3,avi,mpeg,flv,html,htm)$ {
12+
alias /var/lib/roundcube/;
13+
expires 15m;
14+
}
15+
}
16+
17+
location /error/ {
18+
alias %home%/%user%/web/%root_domain%/document_errors/;
19+
}
20+
21+
location ~ /(config|temp|logs) {
22+
return 404;
23+
}
24+
25+
location /Microsoft-Server-ActiveSync {
26+
alias /usr/share/z-push/;
27+
28+
location ~ ^/Microsoft-Server-ActiveSync/(.*\.php)$ {
29+
alias /usr/share/z-push/$1;
30+
fastcgi_pass 127.0.0.1:9000;
31+
fastcgi_index index.php;
32+
include fastcgi_params;
33+
fastcgi_param SCRIPT_FILENAME $request_filename;
34+
}
35+
}
36+
37+
location ~ ^/(.*\.php)$ {
38+
alias /var/lib/roundcube/$1;
39+
fastcgi_pass 127.0.0.1:9000;
40+
fastcgi_index index.php;
41+
include fastcgi_params;
42+
fastcgi_param SCRIPT_FILENAME $request_filename;
43+
}
44+
45+
location ~ /\.ht {return 404;}
46+
location ~ /\.svn/ {return 404;}
47+
location ~ /\.git/ {return 404;}
48+
location ~ /\.hg/ {return 404;}
49+
location ~ /\.bzr/ {return 404;}
50+
51+
include %home%/%user%/conf/mail/%root_domain%/%web_system%.conf_*;
52+
}

0 commit comments

Comments
 (0)