From 51368248446de6e5e12340c70f9959993adf1e63 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Fri, 31 Jul 2015 11:45:30 +0200 Subject: [PATCH] Merge pull request #244 from greybyte/vhost_config_variables Variable substitution in vhost specialconfig --- lng/english.lng.php | 5 ++- lng/german.lng.php | 4 +- scripts/classes/class.HttpConfigBase.php | 38 +++++++++++++++++++ .../jobs/cron_tasks.inc.http.10.apache.php | 34 +++++++++++++---- .../jobs/cron_tasks.inc.http.20.lighttpd.php | 33 +++++++++++++--- scripts/jobs/cron_tasks.inc.http.30.nginx.php | 36 +++++++++++++++--- 6 files changed, 131 insertions(+), 19 deletions(-) create mode 100644 scripts/classes/class.HttpConfigBase.php diff --git a/lng/english.lng.php b/lng/english.lng.php index 72816115..d0366dae 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -1843,9 +1843,12 @@ $lng['admin']['configfiles']['commands'] = 'Commands: T $lng['admin']['configfiles']['files'] = 'Configfiles: This is an example of the contents of a configuration file. The commands before these textfields should open an editor with the target file. Just copy and paste the contents into the editor and save the file.

Please note: The MySQL-password has not been replaced for security reasons. Please replace "MYSQL_PASSWORD" on your own. If you forgot your MySQL-password you\'ll find it in "lib/userdata.inc.php"'; $lng['serversettings']['apache_itksupport']['title'] = 'Use modifications for Apache ITK-MPM'; $lng['serversettings']['apache_itksupport']['description'] = 'ATTENTION: use only if you acutally have apache itk-mpm enabled
otherwise your webserver will not be able to start'; - $lng['integrity_check']['DatabaseCharset'] = 'Characterset of database (should be UTF-8)'; $lng['integrity_check']['DomainIpTable'] = 'IP <‐> domain references'; $lng['integrity_check']['SubdomainSslRedirect'] = 'False SSL-redirect flag for non-ssl domains'; $lng['integrity_check']['FroxlorLocalGroupMemberForFcgidPhpFpm'] = 'froxlor-user in the customer groups (for FCGID/php-fpm)'; $lng['integrity_check']['WebserverGroupMemberForFcgidPhpFpm'] = 'Webserver-user in the customer groups (for FCGID/php-fpm)'; +$lng['admin']['specialsettings_replacements'] = "You can use the following variables:
{DOMAIN}, {DOCROOT}, {CUSTOMER}, {IP}, {PORT}, {SCHEME}
"; +$lng['serversettings']['default_vhostconf']['description'] = 'The content of this field will be included into this ip/port vHost container directly. '.$lng['admin']['specialsettings_replacements'].' Attention: The code won\'t be checked for any errors. If it contains errors, webserver might not start again!'; +$lng['serversettings']['default_vhostconf_domain']['description'] = 'The content of this field will be included into the domain vHost container directly. '.$lng['admin']['specialsettings_replacements'].' Attention: The code won\'t be checked for any errors. If it contains errors, webserver might not start again!'; + diff --git a/lng/german.lng.php b/lng/german.lng.php index 8cc303b2..47430913 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1570,9 +1570,11 @@ $lng['admin']['configfiles']['commands'] = 'Kommandos: $lng['admin']['configfiles']['files'] = 'Konfigurationsdateien: Dies ist der Inhalt einer Konfigurationsdatei. Der Befehl direkt vor dem Textfeld sollte einen Editor mit der Zeildatei öffnen. Der Inhalt kann nun einfach kopiert und in den Editor eingefügt und die Datei gespeichert werden.

Beachten Sie: Das MySQL-Passwort wurde aus Sicherheitsgründen nicht ersetzt. Bitte ersetzen Sie "MYSQL_PASSWORD" manuell durch das entsprechende Passwort. Falls Sie es vergessen haben sollten, finden Sie es in der Datei "lib/userdata.inc.php".'; $lng['serversettings']['apache_itksupport']['title'] = 'Anpassungen für Apache ITK-MPM verwenden'; $lng['serversettings']['apache_itksupport']['description'] = '
Achtung: Bitte nur verwenden, wenn wirklich Apache itk-mpm verwendet wird, ansonsten wird der Webserver nicht starten.
'; - $lng['integrity_check']['DatabaseCharset'] = 'Characterset der Datenbank (sollte UTF-8 sein)'; $lng['integrity_check']['DomainIpTable'] = 'IP <‐> Domain Verknüpfung'; $lng['integrity_check']['SubdomainSslRedirect'] = 'Falsches SSL-redirect Flag bei nicht-ssl Domains'; $lng['integrity_check']['FroxlorLocalGroupMemberForFcgidPhpFpm'] = 'froxlor-Benutzer in Kunden Gruppen (für FCGID/php-fpm)'; $lng['integrity_check']['WebserverGroupMemberForFcgidPhpFpm'] = 'Webserver-Benutzer in Kunden Gruppen (für FCGID/php-fpm)'; +$lng['admin']['specialsettings_replacements'] = "Die folgenden Variablen können verwendet werden:
{DOMAIN}, {DOCROOT}, {CUSTOMER}, {IP}, {PORT}, {SCHEME}
"; +$lng['serversettings']['default_vhostconf']['description'] = 'Der Inhalt dieses Feldes wird direkt in den IP/Port-vHost-Container übernommen. '.$lng['admin']['specialsettings_replacements'].'
ACHTUNG: Der Code wird nicht auf Fehler geprüft. Etwaige Fehler werden also auch übernommen. Der Webserver könnte nicht mehr starten!'; +$lng['serversettings']['default_vhostconf_domain']['description'] = 'Der Inhalt dieses Feldes wird direkt in jeden Domain-vHost-Container übernommen. '. $lng['admin']['specialsettings_replacements'].'ACHTUNG: Der Code wird nicht auf Fehler geprüft. Etwaige Fehler werden also auch übernommen. Der Webserver könnte nicht mehr starten!'; diff --git a/scripts/classes/class.HttpConfigBase.php b/scripts/classes/class.HttpConfigBase.php new file mode 100644 index 00000000..071f43c1 --- /dev/null +++ b/scripts/classes/class.HttpConfigBase.php @@ -0,0 +1,38 @@ + $domain['domain'], + 'CUSTOMER' => $domain['loginname'], + 'IP' => $ip, + 'PORT' => $port, + 'SCHEME' => ($is_ssl_vhost)?'https':'http', + '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 ce59690d..f615065b 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 { +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"; } } diff --git a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php index 787ee383..9d76b428 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 { +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); diff --git a/scripts/jobs/cron_tasks.inc.http.30.nginx.php b/scripts/jobs/cron_tasks.inc.http.30.nginx.php index 012c7abf..fafcefa3 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 { +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"); } } }