diff --git a/lib/Froxlor/Cron/Http/Nginx.php b/lib/Froxlor/Cron/Http/Nginx.php index ff6f3669..e38c9a6f 100644 --- a/lib/Froxlor/Cron/Http/Nginx.php +++ b/lib/Froxlor/Cron/Http/Nginx.php @@ -250,7 +250,7 @@ class Nginx extends HttpConfigBase $aliases = ""; $froxlor_aliases = Settings::Get('system.froxloraliases'); - if (!empty($froxlor_aliases)) { + if (! empty($froxlor_aliases)) { $froxlor_aliases = explode(",", $froxlor_aliases); foreach ($froxlor_aliases as $falias) { if (\Froxlor\Validate\Validate::validateDomain(trim($falias))) { @@ -574,26 +574,38 @@ class Nginx extends HttpConfigBase return $vhost_content; } + private function cleanVhostStruct($vhost = null) + { + // Remove windows linebreaks + $vhost = str_replace("\r", "\n", $vhost); + // Break blocks into lines + $vhost = str_replace(array( + "{", + "}" + ), array( + " {\n", + "\n}" + ), $vhost); + // Break into array items + $vhost = explode("\n", preg_replace('/[ \t]+/', ' ', trim(preg_replace('/\t+/', '', $vhost)))); + // Remove empty lines + $vhost = array_filter($vhost, function ($a) { + return preg_match("#\S#", $a); + }); + + // remove unnecessary whitespaces + $vhost = array_map("trim", $vhost); + // re-number array keys + $vhost = array_values($vhost); + return $vhost; + } + 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 - + $vhost_frx = $this->cleanVhostStruct($vhost_frx); // Clean user defined settings - $vhost_usr = str_replace("\r", "\n", $vhost_usr); // Remove windows linebreaks - $vhost_usr = str_replace(array( - "{ ", - " }" - ), array( - "{\n", - "\n}" - ), $vhost_usr); // Break blocks into lines - $vhost_usr = explode("\n", preg_replace('/[ \t]+/', ' ', trim(preg_replace('/\t+/', '', $vhost_usr)))); // Break into array items - // Remove empty lines - $vhost_usr = array_filter($vhost_usr, function ($a) { - return preg_match("#\S#", $a); - }); + $vhost_usr = $this->cleanVhostStruct($vhost_usr); // Cycle through the user defined settings $currentBlock = array();