add nginx and lighttpd support, refactor into common base class

This commit is contained in:
Chris Vigelius
2015-07-06 14:15:01 +02:00
parent d9e0854bb7
commit de84419035
4 changed files with 100 additions and 44 deletions

View File

@@ -0,0 +1,38 @@
<?php
/***
* Class HttpConfigBase
*
* Base class for all HTTP server configs
*
*/
class HttpConfigBase {
/**
* 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, $ipandport, $domain) {
$templateVars = array(
'DOMAIN' => $domain['domain'],
'CUSTOMER' => $domain['loginname'],
'IP' => $ipandport['ip'],
'PORT' => $ipandport['port'],
'IS_SSL' => $domain['ssl'],
'DOCROOT' => $domain['documentroot']
);
return replace_variables($template, $templateVars);
}
}

View File

@@ -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";
}
}

View File

@@ -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);

View File

@@ -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");
}
}
}