Просмотр исходного кода

Add nginx webmail template and fix websystem detection

Robert Zollner 6 лет назад
Родитель
Сommit
281ae1f25c

+ 5 - 2
bin/v-add-mail-domain

@@ -128,9 +128,12 @@ if [ ! -z "$DNS_SYSTEM" ] && [ "$dkim" = 'yes' ]; then
 fi
 
 # Add webmail configuration to mail domain
-if [ ! -z "$WEB_SYSTEM" ]; then
-    add_webmail_config "$WEB_SYSTEM" "default.tpl"
+WEBMAIL_TEMPLATE="proxy_system"
+if [ "$WEB_SYSTEM" = "nginx" ]; then
+    WEBMAIL_TEMPLATE="web_system"
 fi
+add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.tpl"
+
 if [ ! -z "$PROXY_SYSTEM" ]; then
     add_webmail_config "$PROXY_SYSTEM" "default.tpl"
 fi

+ 5 - 2
bin/v-add-mail-domain-ssl

@@ -64,9 +64,12 @@ is_web_domain_cert_valid
 add_mail_ssl_config
 
 # Add webmail configuration to mail domain
-if [ ! -z "$WEB_SYSTEM" ]; then
-    add_webmail_config "$WEB_SYSTEM" "default.stpl"
+WEBMAIL_TEMPLATE="proxy_system"
+if [ "$WEB_SYSTEM" = "nginx" ]; then
+    WEBMAIL_TEMPLATE="web_system"
 fi
+add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.stpl"
+
 if [ ! -z "$PROXY_SYSTEM" ]; then
     add_webmail_config "$PROXY_SYSTEM" "default.stpl"
 fi

+ 7 - 5
bin/v-add-webmail

@@ -55,18 +55,20 @@ is_object_unsuspended 'mail' 'DOMAIN' "$domain"
 #----------------------------------------------------------#
 
 # Add webmail configuration to mail domain
-if [ ! -z "$WEB_SYSTEM" ]; then
-    add_webmail_config "$WEB_SYSTEM" "default.tpl"
+WEBMAIL_TEMPLATE="proxy_system"
+if [ "$WEB_SYSTEM" = "nginx" ]; then
+    WEBMAIL_TEMPLATE="web_system"
 fi
+add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.tpl"
+
 if [ ! -z "$PROXY_SYSTEM" ]; then
     add_webmail_config "$PROXY_SYSTEM" "default.tpl"
 fi
 
 # Enable SSL for webmail if available
 if [ -f $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.crt ] || [ "$SSL" = 'yes' ]; then
-    if [ ! -z "$WEB_SYSTEM" ]; then
-        add_webmail_config "$WEB_SYSTEM" "default.stpl"
-    fi
+    add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.stpl"
+
     if [ ! -z "$PROXY_SYSTEM" ]; then
         add_webmail_config "$PROXY_SYSTEM" "default.stpl"
     fi

+ 14 - 15
func/domain.sh

@@ -671,7 +671,7 @@ del_mail_ssl_certificates(){
 add_webmail_config() {
     mkdir -p "$HOMEDIR/$user/conf/mail/$domain"
     conf="$HOMEDIR/$user/conf/mail/$domain/$1.conf"
-    if [ "$2" = "default.stpl" ]; then
+    if [[ "$2" =~ stpl$ ]]; then
         conf="$HOMEDIR/$user/conf/mail/$domain/$1.ssl.conf"
     fi
 
@@ -716,19 +716,7 @@ add_webmail_config() {
     chown root:$user $conf
     chmod 640 $conf
 
-    if [ "$2" = "default.tpl" ]; then
-        if [ ! -z "$WEB_SYSTEM" ]; then
-            rm -f /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
-            ln -s $conf /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
-        fi
-        if [ ! -z "$PROXY_SYSTEM" ]; then
-            rm -f /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
-            ln -s $conf /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
-        fi
-        # Clear old configurations
-        rm -rf $HOMEDIR/$user/conf/mail/$domain.*
-    fi
-    if [ "$2" = "default.stpl" ]; then
+    if [[ "$2" =~ stpl$ ]]; then
         if [ ! -z "$WEB_SYSTEM" ]; then
             forcessl="$HOMEDIR/$user/conf/mail/$domain/$WEB_SYSTEM.forcessl.conf"
             rm -f /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.ssl.conf
@@ -741,7 +729,7 @@ add_webmail_config() {
         fi
 
         # Add rewrite rules to force HTTPS/SSL connections
-        if [ ! -z "$PROXY_SYSTEM" ]; then
+        if [ ! -z "$PROXY_SYSTEM" ] || [ "$WEB_SYSTEM" = 'nginx' ]; then
             echo 'return 301 https://$server_name$request_uri;' > $forcessl
         else
             echo 'RewriteEngine On' > $forcessl
@@ -752,6 +740,17 @@ add_webmail_config() {
         rm -rf $HOMEDIR/$user/conf/mail/$domain.*
         rm -rf $HOMEDIR/$user/conf/mail/ssl.$domain.*
         rm -rf $HOMEDIR/$user/conf/mail/*nginx.$domain.*
+    else
+        if [ ! -z "$WEB_SYSTEM" ]; then
+            rm -f /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
+            ln -s $conf /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
+        fi
+        if [ ! -z "$PROXY_SYSTEM" ]; then
+            rm -f /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
+            ln -s $conf /etc/$1/conf.d/domains/$WEBMAIL_ALIAS.$domain.conf
+        fi
+        # Clear old configurations
+        rm -rf $HOMEDIR/$user/conf/mail/$domain.*
     fi
 }
 

+ 0 - 0
install/deb/templates/mail/nginx/default.stpl → install/deb/templates/mail/nginx/proxy_system.stpl


+ 0 - 0
install/deb/templates/mail/nginx/default.tpl → install/deb/templates/mail/nginx/proxy_system.tpl


+ 54 - 0
install/deb/templates/mail/nginx/web_system.stpl

@@ -0,0 +1,54 @@
+server {
+    listen      %ip%:%web_ssl_port% ssl http2;
+    server_name %domain% %alias%;
+    root /var/lib/roundcube;
+    index index.php;
+
+    ssl_certificate      %ssl_pem%;
+    ssl_certificate_key  %ssl_key%;
+    error_log  /var/log/%web_system%/domains/%domain%.error.log error;
+
+    location / {
+        try_files      $uri $uri/ /index.php?$args;
+        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)$ {
+            alias          /var/lib/roundcube/;
+            expires        15m;
+        }
+    }
+
+    location /error/ {
+        alias   %home%/%user%/web/%root_domain%/document_errors/;
+    }
+
+    location ~ /(config|temp|logs) {
+        return 404;
+    }
+
+    location /Microsoft-Server-ActiveSync {
+        alias /usr/share/z-push/;
+
+        location ~ ^/Microsoft-Server-ActiveSync/(.*\.php)$ {
+            alias /usr/share/z-push/$1;
+            fastcgi_pass 127.0.0.1:9000;
+            fastcgi_index index.php;
+            include fastcgi_params;
+            fastcgi_param SCRIPT_FILENAME $request_filename;
+        }
+    }
+
+    location ~ ^/(.*\.php)$ {
+        alias /var/lib/roundcube/$1;
+        fastcgi_pass 127.0.0.1:9000;
+        fastcgi_index index.php;
+        include fastcgi_params;
+        fastcgi_param SCRIPT_FILENAME $request_filename;
+    }
+    
+    location ~ /\.ht    {return 404;}
+    location ~ /\.svn/  {return 404;}
+    location ~ /\.git/  {return 404;}
+    location ~ /\.hg/   {return 404;}
+    location ~ /\.bzr/  {return 404;}
+
+    include %home%/%user%/conf/mail/%root_domain%/%web_system%.ssl.conf_*;
+}

+ 52 - 0
install/deb/templates/mail/nginx/web_system.tpl

@@ -0,0 +1,52 @@
+server {
+    listen      %ip%:%web_port%;
+    server_name %domain% %alias%;
+    root /var/lib/roundcube;
+    index index.php;
+
+    include %home%/%user%/conf/mail/%root_domain%/nginx.forcessl.conf*;
+
+    location / {
+        try_files      $uri $uri/ /index.php?$args;
+        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)$ {
+            alias          /var/lib/roundcube/;
+            expires        15m;
+        }
+    }
+
+    location /error/ {
+        alias   %home%/%user%/web/%root_domain%/document_errors/;
+    }
+
+    location ~ /(config|temp|logs) {
+        return 404;
+    }
+
+    location /Microsoft-Server-ActiveSync {
+        alias /usr/share/z-push/;
+
+        location ~ ^/Microsoft-Server-ActiveSync/(.*\.php)$ {
+            alias /usr/share/z-push/$1;
+            fastcgi_pass 127.0.0.1:9000;
+            fastcgi_index index.php;
+            include fastcgi_params;
+            fastcgi_param SCRIPT_FILENAME $request_filename;
+        }
+    }
+    
+    location ~ ^/(.*\.php)$ {
+        alias /var/lib/roundcube/$1;
+        fastcgi_pass 127.0.0.1:9000;
+        fastcgi_index index.php;
+        include fastcgi_params;
+        fastcgi_param SCRIPT_FILENAME $request_filename;
+    }
+    
+    location ~ /\.ht    {return 404;}
+    location ~ /\.svn/  {return 404;}
+    location ~ /\.git/  {return 404;}
+    location ~ /\.hg/   {return 404;}
+    location ~ /\.bzr/  {return 404;}
+
+    include %home%/%user%/conf/mail/%root_domain%/%web_system%.conf_*;
+}