From befdfb2ae5e9d33c90a1584c3be0fd055bcd0687 Mon Sep 17 00:00:00 2001
From: Marius Burkard <m.burkard@pixcept.de>
Date: Mon, 12 Aug 2019 15:01:31 +0200
Subject: [PATCH] - added missing rspamd lines in apps vhost template on
 install

---
 install/lib/installer_base.lib.php   | 11 ++++++++++-
 install/tpl/apache_apps.vhost.master | 18 ++++++++++++++++++
 install/tpl/nginx_apps.vhost.master  | 24 ++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php
index b60300e2b1..c7f955d945 100644
--- a/install/lib/installer_base.lib.php
+++ b/install/lib/installer_base.lib.php
@@ -2226,7 +2226,10 @@ class installer_base {
 				$tpl->setVar('logging','yes');
 			}
 
-
+			if($conf['rspamd']['installed'] == true) {
+				$tpl->setVar('use_rspamd', 'yes');
+			}
+			
 			// comment out the listen directive if port is 80 or 443
 			if($conf['web']['apps_vhost_ip'] == 80 or $conf['web']['apps_vhost_ip'] == 443) {
 				$tpl->setVar('vhost_port_listen','#');
@@ -2294,6 +2297,12 @@ class installer_base {
 				$apps_vhost_ip = $conf['web']['apps_vhost_ip'].':';
 			}
 
+			if($conf['rspamd']['installed'] == true) {
+				$content = str_replace('{use_rspamd}', '', $content);
+			} else {
+				$content = str_replace('{use_rspamd}', '# ', $content);
+			}
+			
 			$socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']);
 			if(substr($socket_dir, -1) != '/') $socket_dir .= '/';
 			if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir);
diff --git a/install/tpl/apache_apps.vhost.master b/install/tpl/apache_apps.vhost.master
index ee1b693097..9cccf8d38e 100644
--- a/install/tpl/apache_apps.vhost.master
+++ b/install/tpl/apache_apps.vhost.master
@@ -19,6 +19,12 @@
 	RequestHeader unset Proxy early
   </IfModule>
   
+  {tmpl_if name="enable_spdy" op="==" value="y"}
+  <IfModule spdy_module>
+	SpdyEnabled on
+  </IfModule>
+  {/tmpl_if}
+
   <IfModule mod_php5.c>
     DocumentRoot {tmpl_var name='apps_vhost_dir'}
     AddType application/x-httpd-php .php
@@ -68,6 +74,18 @@
     </Directory>
   </IfModule>
 
+{tmpl_if name="use_rspamd"}
+  <Location /rspamd>
+        Order allow,deny
+        Allow from all
+  </Location>
+  RewriteEngine On
+  RewriteRule ^/rspamd$ /rspamd/ [R,L]
+  RewriteRule ^/rspamd/(.*) http://127.0.0.1:11334/$1 [P]
+{/tmpl_if}
+
+
+
 </VirtualHost>
 
 
diff --git a/install/tpl/nginx_apps.vhost.master b/install/tpl/nginx_apps.vhost.master
index 3d00d11106..871dff8c57 100644
--- a/install/tpl/nginx_apps.vhost.master
+++ b/install/tpl/nginx_apps.vhost.master
@@ -208,4 +208,28 @@ server {
                alias /var/lib/mailman/archives/public;
                autoindex on;
         }
+
+        {use_rspamd}location /rspamd/ {
+                {use_rspamd}proxy_pass http://127.0.0.1:11334/;
+                {use_rspamd}rewrite ^//(.*) /$1;
+                {use_rspamd}proxy_set_header X-Forwarded-Proto $scheme;
+                {use_rspamd}proxy_set_header Host $host;
+                {use_rspamd}proxy_set_header X-Real-IP $remote_addr;
+                {use_rspamd}proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+                {use_rspamd}proxy_pass_header Authorization;
+                {use_rspamd}client_max_body_size 0;
+                {use_rspamd}client_body_buffer_size 1m;
+                {use_rspamd}proxy_intercept_errors on;
+                {use_rspamd}proxy_buffering on;
+                {use_rspamd}proxy_buffer_size 128k;
+                {use_rspamd}proxy_buffers 256 16k;
+                {use_rspamd}proxy_busy_buffers_size 256k;
+                {use_rspamd}proxy_temp_file_write_size 256k;
+                {use_rspamd}proxy_max_temp_file_size 0;
+                {use_rspamd}proxy_read_timeout 300;
+                {use_rspamd}
+                {use_rspamd}location ~* ^/rspamd/(.+\.(jpg|jpeg|gif|css|png|js|ico|html?|xml|txt))$ {
+                       {use_rspamd}alias /usr/share/rspamd/www/$1;
+                {use_rspamd}}
+        {use_rspamd}}
 }
-- 
GitLab