fix vhost(parts)-merging in nginx cron, fixes #669

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2019-06-03 11:59:56 +02:00
parent 6806f896d6
commit b7a10fdeda

View File

@@ -574,27 +574,39 @@ class Nginx extends HttpConfigBase
return $vhost_content; return $vhost_content;
} }
protected function mergeVhostCustom($vhost_frx, $vhost_usr) private function cleanVhostStruct($vhost = null)
{ {
// Clean froxlor defined settings // Remove windows linebreaks
$vhost_frx = explode("\n", preg_replace('/[ \t]+/', ' ', trim(preg_replace('/\t+/', '', $vhost_frx)))); // Break into array items $vhost = str_replace("\r", "\n", $vhost);
$vhost_frx = array_map("trim", $vhost_frx); // remove unnecessary whitespaces // Break blocks into lines
$vhost = str_replace(array(
// Clean user defined settings
$vhost_usr = str_replace("\r", "\n", $vhost_usr); // Remove windows linebreaks
$vhost_usr = str_replace(array(
"{", "{",
"}" "}"
), array( ), array(
" {\n", " {\n",
"\n}" "\n}"
), $vhost_usr); // Break blocks into lines ), $vhost);
$vhost_usr = explode("\n", preg_replace('/[ \t]+/', ' ', trim(preg_replace('/\t+/', '', $vhost_usr)))); // Break into array items // Break into array items
$vhost = explode("\n", preg_replace('/[ \t]+/', ' ', trim(preg_replace('/\t+/', '', $vhost))));
// Remove empty lines // Remove empty lines
$vhost_usr = array_filter($vhost_usr, function ($a) { $vhost = array_filter($vhost, function ($a) {
return preg_match("#\S#", $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 = $this->cleanVhostStruct($vhost_frx);
// Clean user defined settings
$vhost_usr = $this->cleanVhostStruct($vhost_usr);
// Cycle through the user defined settings // Cycle through the user defined settings
$currentBlock = array(); $currentBlock = array();
$blockLevel = 0; $blockLevel = 0;