From de84419035155b3bdc9e8bdb81e0c75b0c998945 Mon Sep 17 00:00:00 2001 From: Chris Vigelius Date: Mon, 6 Jul 2015 14:15:01 +0200 Subject: [PATCH] add nginx and lighttpd support, refactor into common base class --- scripts/classes/class.HttpConfigBase.php | 38 +++++++++++++ .../jobs/cron_tasks.inc.http.10.apache.php | 53 +++++++------------ .../jobs/cron_tasks.inc.http.20.lighttpd.php | 25 +++++++-- scripts/jobs/cron_tasks.inc.http.30.nginx.php | 28 ++++++++-- 4 files changed, 100 insertions(+), 44 deletions(-) create mode 100644 scripts/classes/class.HttpConfigBase.php diff --git a/scripts/classes/class.HttpConfigBase.php b/scripts/classes/class.HttpConfigBase.php new file mode 100644 index 00000000..2e65e607 --- /dev/null +++ b/scripts/classes/class.HttpConfigBase.php @@ -0,0 +1,38 @@ + $domain['domain'], + 'CUSTOMER' => $domain['loginname'], + 'IP' => $ipandport['ip'], + 'PORT' => $ipandport['port'], + 'IS_SSL' => $domain['ssl'], + 'DOCROOT' => $domain['documentroot'] + ); + return replace_variables($template, $templateVars); + } + +} \ No newline at end of file diff --git a/scripts/jobs/cron_tasks.inc.http.10.apache.php b/scripts/jobs/cron_tasks.inc.http.10.apache.php index d5a7ecd9..3454f39d 100644 --- a/scripts/jobs/cron_tasks.inc.http.10.apache.php +++ b/scripts/jobs/cron_tasks.inc.http.10.apache.php @@ -17,7 +17,9 @@ * */ -class apache { +include('../classes/class.HttpConfigBase.php'); + +class apache extends HttpConfigBase { private $logger = false; private $debugHandler = false; private $idnaConvert = false; @@ -42,7 +44,6 @@ class apache { $this->logger = $logger; $this->debugHandler = $debugHandler; $this->idnaConvert = $idnaConvert; - $this->templateVars = array(); } @@ -315,7 +316,10 @@ class apache { */ if ($row_ipsandports['specialsettings'] != '') { - $this->virtualhosts_data[$vhosts_filename] .= $this->processSpecialConfigTemplate($row_ipsandports['specialsettings']) . "\n"; + $this->virtualhosts_data[$vhosts_filename] .= $this->processSpecialConfigTemplate( + $row_ipsandports['specialsettings'], + $row_ipsandports, + $domain) . "\n"; } if ($row_ipsandports['ssl'] == '1' && Settings::Get('system.use_ssl') == '1') { @@ -629,26 +633,6 @@ class apache { return $vhost_filename; } - /** - * process special config as template, by substituting {VARIABLE} with the - * respective value. - * - * The following variables are known at the moment: - * - * {DOMAIN} - domain name - * {IP} - IP for this domain - * {PORT} - Port for this domain - * {CUSTOMER} - customer name - * {IS_SSL} - '1' if domain/ip is ssl, '' otherwise - * {DOCROOT} - document root for this domain - * - * @param $template - * @return string - */ - protected function processSpecialConfigTemplate($template) { - return replace_variables($template, $this->templateVars); - } - /** * We compose the virtualhost entry for one domain */ @@ -680,14 +664,6 @@ class apache { $_vhost_content = ''; while ($ipandport = $result_stmt->fetch(PDO::FETCH_ASSOC)) { - // set up template variables for specialconfig processing - $this->templateVars['DOMAIN'] = $domain['domain']; - $this->templateVars['CUSTOMER'] = $domain['loginname']; - $this->templateVars['IP'] = $ipandport['ip']; - $this->templateVars['PORT'] = $ipandport['port']; - $this->templateVars['IS_SSL'] = $domain['ssl']; - $this->templateVars['DOCROOT'] = $domain['documentroot']; - $ipport = ''; $domain['ip'] = $ipandport['ip']; $domain['port'] = $ipandport['port']; @@ -711,7 +687,10 @@ class apache { } if ($ipandport['default_vhostconf_domain'] != '') { - $_vhost_content .= $this->processSpecialConfigTemplate($ipandport['default_vhostconf_domain']) . "\n"; + $_vhost_content .= $this->processSpecialConfigTemplate( + $ipandport['default_vhostconf_domain'], + $ipandport, + $domain) . "\n"; } $ipportlist .= $ipport; } @@ -821,7 +800,10 @@ class apache { $vhost_content .= $this->getLogfiles($domain); if ($domain['specialsettings'] != '') { - $vhost_content .= $this->processSpecialConfigTemplate($domain['specialsettings']) . "\n"; + $vhost_content .= $this->processSpecialConfigTemplate( + $domain['specialsettings'], + $ipandport, + $domain) . "\n"; } if ($_vhost_content != '') { @@ -829,7 +811,10 @@ class apache { } if (Settings::Get('system.default_vhostconf') != '') { - $vhost_content .= $this->processSpecialConfigTemplate(Settings::Get('system.default_vhostconf')) . "\n"; + $vhost_content .= $this->processSpecialConfigTemplate( + Settings::Get('system.default_vhostconf'), + $ipandport, + $domain) . "\n"; } } diff --git a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php index f1cf1038..5b5ff41a 100644 --- a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php +++ b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php @@ -18,7 +18,9 @@ * @TODO ssl-redirect to non-standard port */ -class lighttpd { +include('../classes/class.HttpConfigBase.php'); + +class lighttpd extends HttpConfigBase { private $logger = false; private $debugHandler = false; private $idnaConvert = false; @@ -145,7 +147,11 @@ class lighttpd { } if ($row_ipsandports['specialsettings'] != '') { - $this->lighttpd_data[$vhost_filename].= $row_ipsandports['specialsettings'] . "\n"; + $this->lighttpd_data[$vhost_filename].= $this->processSpecialConfigTemplate( + $row_ipsandports['specialsettings'], + $row_ipsandports, + $domain + ). "\n"; } $this->lighttpd_data[$vhost_filename].= '}' . "\n"; @@ -439,15 +445,24 @@ class lighttpd { $vhost_content.= $this->getSslSettings($domain, $ssl_vhost); if ($domain['specialsettings'] != "") { - $vhost_content.= $domain['specialsettings'] . "\n"; + $vhost_content.= $this->processSpecialConfigTemplate( + $domain['specialsettings'], + $ipandport, + $domain). "\n"; } if ($ipandport['default_vhostconf_domain'] != '') { - $vhost_content.= $ipandport['default_vhostconf_domain'] . "\n"; + $vhost_content.= $this->processSpecialConfigTemplate( + $ipandport['default_vhostconf_domain'], + $ipandport, + $domain) . "\n"; } if (Settings::Get('system.default_vhostconf') != '') { - $vhost_content.= Settings::Get('system.default_vhostconf') . "\n"; + $vhost_content.= $this->processSpecialConfigTemplate( + Settings::Get('system.default_vhostconf'), + $ipandport, + $domain). "\n"; } } $vhost_content.= $this->getLogFiles($domain); diff --git a/scripts/jobs/cron_tasks.inc.http.30.nginx.php b/scripts/jobs/cron_tasks.inc.http.30.nginx.php index 758e504a..44c59d70 100644 --- a/scripts/jobs/cron_tasks.inc.http.30.nginx.php +++ b/scripts/jobs/cron_tasks.inc.http.30.nginx.php @@ -15,7 +15,9 @@ * */ -class nginx { +include('../classes/class.HttpConfigBase.php'); + +class nginx extends HttpConfigBase { private $logger = false; private $debugHandler = false; private $idnaConvert = false; @@ -187,7 +189,12 @@ class nginx { $this->nginx_data[$vhost_filename] .= "\t".'}'."\n"; if ($row_ipsandports['specialsettings'] != '') { - $this->nginx_data[$vhost_filename].= $row_ipsandports['specialsettings'] . "\n"; + $this->nginx_data[$vhost_filename].= $this->processSpecialConfigTemplate( + $row_ipsandports['specialsettings'], + $row_ipsandports, + array('domain'=> Settings::Get('system.hostname'), + 'loginname' => Settings::Get('phpfpm.vhost_httpuser'), + 'documentroot'=> $mypath)). "\n"; } /** @@ -363,7 +370,10 @@ class nginx { } if ($ipandport['default_vhostconf_domain'] != '') { - $_vhost_content .= $ipandport['default_vhostconf_domain'] . "\n"; + $_vhost_content .= $this->processSpecialConfigTemplate( + $ipandport['default_vhostconf_domain'], + $ipandport, + $domain). "\n"; } $vhost_content.= "\t" . 'listen ' . $ipport . ($ssl_vhost == true ? ' ssl' : '') . ';' . "\n"; @@ -425,7 +435,11 @@ class nginx { $vhost_content.= isset($this->needed_htpasswds[$domain['id']]) ? $this->needed_htpasswds[$domain['id']] . "\n" : ''; if ($domain['specialsettings'] != "") { - $vhost_content = $this->mergeVhostCustom($vhost_content, $domain['specialsettings']); + $vhost_content = $this->mergeVhostCustom($vhost_content, $this->processSpecialConfigTemplate( + $domain['specialsettings'], + $ipandport, + $domain + )); } if ($_vhost_content != '') { @@ -433,7 +447,11 @@ class nginx { } if (Settings::Get('system.default_vhostconf') != '') { - $vhost_content = $this->mergeVhostCustom($vhost_content, Settings::Get('system.default_vhostconf')."\n"); + $vhost_content = $this->mergeVhostCustom($vhost_content, + $this->processSpecialConfigTemplate( + Settings::Get('system.default_vhostconf'), + $ipandport, + $domain)."\n"); } } }