From c6ed0b63c9a18de1cea97b473b799d02824ce33c Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Wed, 19 Nov 2014 16:29:05 +0100 Subject: [PATCH] fix vhost-block-merging for nginx, fixes #1450 Signed-off-by: Michael Kaufmann (d00p) --- scripts/jobs/cron_tasks.inc.http.30.nginx.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/jobs/cron_tasks.inc.http.30.nginx.php b/scripts/jobs/cron_tasks.inc.http.30.nginx.php index ecc5fda2..dd360de8 100644 --- a/scripts/jobs/cron_tasks.inc.http.30.nginx.php +++ b/scripts/jobs/cron_tasks.inc.http.30.nginx.php @@ -419,7 +419,7 @@ class nginx { ) { $vhost_content.= $this->composeSslSettings($domain); } - $vhost_content.= $this->create_pathOptions($domain); + $vhost_content = $this->mergeVhostCustom($vhost_content, $this->create_pathOptions($domain)); $vhost_content.= $this->composePhpOptions($domain, $ssl_vhost); $vhost_content.= isset($this->needed_htpasswds[$domain['id']]) ? $this->needed_htpasswds[$domain['id']] . "\n" : ''; @@ -429,11 +429,11 @@ class nginx { } if ($_vhost_content != '') { - $vhost_content .= $_vhost_content; + $vhost_content = $this->mergeVhostCustom($vhost_content, $_vhost_content); } if (Settings::Get('system.default_vhostconf') != '') { - $vhost_content .= Settings::Get('system.default_vhostconf') . "\n"; + $vhost_content = $this->mergeVhostCustom($vhost_content, Settings::Get('system.default_vhostconf')."\n"); } } } @@ -445,6 +445,7 @@ class nginx { protected function mergeVhostCustom($vhost_frx, $vhost_usr) { // Clean froxlor defined settings $vhost_frx = explode("\n", preg_replace('/[ \t]+/', ' ', trim(preg_replace('/\t+/', '', $vhost_frx)))); // Break into array items + $vhost_frx = array_map("trim", $vhost_frx); // remove unnecessary whitespaces // Clean user defined settings $vhost_usr = str_replace("\r", "\n", $vhost_usr); // Remove windows linebreaks @@ -476,7 +477,7 @@ class nginx { } while ($vhost_frx[$pos] != "}"); for ($i = 1; $i < count($currentBlock) - 1; $i++) { - array_splice($vhost_frx, $pos + $i - 2, 0, $currentBlock[$i]); + array_splice($vhost_frx, $pos + $i - 1, 0, $currentBlock[$i]); } } else { // Add to end