Merge pull request #244 from greybyte/vhost_config_variables

Variable substitution in vhost specialconfig
This commit is contained in:
Michael Kaufmann
2015-07-31 11:45:30 +02:00
committed by Michael Kaufmann (d00p)
parent 8e8c97f7f9
commit 5136824844
6 changed files with 131 additions and 19 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} - evaluates to 'ssl' if domain/ip is ssl, otherwise it is an empty string
* {DOCROOT} - document root for this domain
*
* @param $template
* @return string
*/
protected function processSpecialConfigTemplate($template, $domain, $ip, $port, $is_ssl_vhost) {
$templateVars = array(
'DOMAIN' => $domain['domain'],
'CUSTOMER' => $domain['loginname'],
'IP' => $ip,
'PORT' => $port,
'SCHEME' => ($is_ssl_vhost)?'https':'http',
'DOCROOT' => $domain['documentroot']
);
return replace_variables($template, $templateVars);
}
}

View File

@@ -17,7 +17,9 @@
*
*/
class apache {
require_once(dirname(__FILE__).'/../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;
}
@@ -315,7 +316,12 @@ class apache {
*/
if ($row_ipsandports['specialsettings'] != '') {
$this->virtualhosts_data[$vhosts_filename] .= $row_ipsandports['specialsettings'] . "\n";
$this->virtualhosts_data[$vhosts_filename] .= $this->processSpecialConfigTemplate(
$row_ipsandports['specialsettings'],
$domain,
$row_ipsandports['ip'],
$row_ipsandports['port'],
$row_ipsandports['ssl'] == '1') . "\n";
}
if ($row_ipsandports['ssl'] == '1' && Settings::Get('system.use_ssl') == '1') {
@@ -664,7 +670,6 @@ class apache {
return $vhost_filename;
}
/**
* We compose the virtualhost entry for one domain
*/
@@ -719,7 +724,12 @@ class apache {
}
if ($ipandport['default_vhostconf_domain'] != '') {
$_vhost_content .= $ipandport['default_vhostconf_domain'] . "\n";
$_vhost_content .= $this->processSpecialConfigTemplate(
$ipandport['default_vhostconf_domain'],
$domain,
$domain['ip'],
$domain['port'],
$ssl_vhost) . "\n";
}
$ipportlist .= $ipport;
}
@@ -828,7 +838,12 @@ class apache {
$vhost_content .= $this->getLogfiles($domain);
if ($domain['specialsettings'] != '') {
$vhost_content .= $domain['specialsettings'] . "\n";
$vhost_content .= $this->processSpecialConfigTemplate(
$domain['specialsettings'],
$domain,
$domain['ip'],
$domain['port'],
$ssl_vhost) . "\n";
}
if ($_vhost_content != '') {
@@ -836,7 +851,12 @@ class apache {
}
if (Settings::Get('system.default_vhostconf') != '') {
$vhost_content .= Settings::Get('system.default_vhostconf') . "\n";
$vhost_content .= $this->processSpecialConfigTemplate(
Settings::Get('system.default_vhostconf'),
$domain,
$domain['ip'],
$domain['port'],
$ssl_vhost) . "\n";
}
}

View File

@@ -18,7 +18,9 @@
* @TODO ssl-redirect to non-standard port
*/
class lighttpd {
require_once(dirname(__FILE__).'/../classes/class.HttpConfigBase.php');
class lighttpd extends HttpConfigBase {
private $logger = false;
private $debugHandler = false;
private $idnaConvert = false;
@@ -145,7 +147,13 @@ 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'],
$domain,
$row_ipsandports['ip'],
$row_ipsandports['port'],
$row_ipsandports['ssl'] == '1'
). "\n";
}
$this->lighttpd_data[$vhost_filename].= '}' . "\n";
@@ -453,15 +461,30 @@ class lighttpd {
$vhost_content.= $this->getSslSettings($domain, $ssl_vhost);
if ($domain['specialsettings'] != "") {
$vhost_content.= $domain['specialsettings'] . "\n";
$vhost_content.= $this->processSpecialConfigTemplate(
$domain['specialsettings'],
$domain,
$domain['ip'],
$domain['port'],
$ssl_vhost). "\n";
}
if ($ipandport['default_vhostconf_domain'] != '') {
$vhost_content.= $ipandport['default_vhostconf_domain'] . "\n";
$vhost_content.= $this->processSpecialConfigTemplate(
$ipandport['default_vhostconf_domain'],
$domain,
$domain['ip'],
$domain['port'],
$ssl_vhost) . "\n";
}
if (Settings::Get('system.default_vhostconf') != '') {
$vhost_content.= Settings::Get('system.default_vhostconf') . "\n";
$vhost_content.= $this->processSpecialConfigTemplate(
Settings::Get('system.default_vhostconf'),
$domain,
$domain['ip'],
$domain['port'],
$ssl_vhost). "\n";
}
}
$vhost_content.= $this->getLogFiles($domain);

View File

@@ -15,7 +15,9 @@
*
*/
class nginx {
require_once(dirname(__FILE__).'/../classes/class.HttpConfigBase.php');
class nginx extends HttpConfigBase {
private $logger = false;
private $debugHandler = false;
private $idnaConvert = false;
@@ -187,7 +189,14 @@ 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'],
array('domain'=> Settings::Get('system.hostname'),
'loginname' => Settings::Get('phpfpm.vhost_httpuser'),
'documentroot'=> $mypath),
$row_ipsandports['ip'],
$row_ipsandports['port'],
$row_ipsandports['ssl'] == '1'). "\n";
}
/**
@@ -365,7 +374,12 @@ class nginx {
}
if ($ipandport['default_vhostconf_domain'] != '') {
$_vhost_content .= $ipandport['default_vhostconf_domain'] . "\n";
$_vhost_content .= $this->processSpecialConfigTemplate(
$ipandport['default_vhostconf_domain'],
$domain,
$domain['ip'],
$domain['port'],
$ssl_vhost). "\n";
}
$vhost_content.= "\t" . 'listen ' . $ipport . ($ssl_vhost == true ? ' ssl' : '') . ';' . "\n";
@@ -427,7 +441,13 @@ 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'],
$domain,
$domain['ip'],
$domain['port'],
$ssl_vhost
));
}
if ($_vhost_content != '') {
@@ -435,7 +455,13 @@ 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'),
$domain,
$domain['ip'],
$domain['port'],
$ssl_vhost)."\n");
}
}
}