Feature: Vhost templates

Reworked the initial implementation by hpmewes (https://github.com/Froxlor/Froxlor/pull/233) with
- bugfixes all over
- added support for apache and lighttpd also
- added an update sequence (instead of only modifying froxlor.sql)
- added english language variables
- added missing parts in admin_vhostsettings.php
- added parameter replacements as available since PR 244
This commit is contained in:
Johannes Feichtner
2016-02-11 23:21:43 +01:00
parent 0559f3c4d6
commit abe253bc31
21 changed files with 761 additions and 38 deletions

View File

@@ -261,7 +261,7 @@ class apache extends HttpConfigBase {
if ($row_ipsandports['ssl']) {
$srvName = substr(md5($ipport),0,4).'.ssl-fpm.external';
}
// mod_proxy stuff for apache-2.4
if (Settings::Get('system.apache24') == '1'
&& Settings::Get('phpfpm.use_mod_proxy') == '1'
@@ -269,7 +269,7 @@ class apache extends HttpConfigBase {
$this->virtualhosts_data[$vhosts_filename] .= ' <FilesMatch \.php$>'. "\n";
$this->virtualhosts_data[$vhosts_filename] .= ' SetHandler proxy:unix:' . $php->getInterface()->getSocketFile() . '|fcgi://localhost'. "\n";
$this->virtualhosts_data[$vhosts_filename] .= ' </FilesMatch>' . "\n";
} else {
$this->virtualhosts_data[$vhosts_filename] .= ' FastCgiExternalServer ' . $php->getInterface()->getAliasConfigDir() . $srvName .' -socket ' . $php->getInterface()->getSocketFile() . ' -idle-timeout ' . Settings::Get('phpfpm.idle_timeout') . "\n";
$this->virtualhosts_data[$vhosts_filename] .= ' <Directory "' . $mypath . '">' . "\n";
@@ -868,6 +868,19 @@ class apache extends HttpConfigBase {
}
$vhost_content .= $this->getLogfiles($domain);
// check if vhost config template is set and if so, merge it
if ($domain['vhostsettingid'] != 0) {
$vhostsettings_stmt = Database::prepare("SELECT `description`, `vhostsettings` FROM " . TABLE_PANEL_VHOSTCONFIGS . " WHERE `id` = :id LIMIT 1;");
$vhostconfig = Database::pexecute_first($vhostsettings_stmt, array('id' => $domain['vhostsettingid']));
$vhost_content .= $this->processSpecialConfigTemplate(
$vhostconfig['vhostsettings'],
$domain,
$domain['ip'],
$domain['port'],
$ssl_vhost) . "\n";
}
if ($domain['specialsettings'] != '') {
$vhost_content .= $this->processSpecialConfigTemplate(
$domain['specialsettings'],

View File

@@ -164,7 +164,7 @@ class lighttpd extends HttpConfigBase {
}
if ($row_ipsandports['ssl_cert_file'] != '') {
// check for existence, #1485
if (!file_exists($row_ipsandports['ssl_cert_file'])) {
$this->logger->logAction(CRON_ACTION, LOG_ERR, $ip.':'.$port . ' :: certificate file "'.$row_ipsandports['ssl_cert_file'].'" does not exist! Cannot create ssl-directives');
@@ -175,7 +175,7 @@ class lighttpd extends HttpConfigBase {
$this->lighttpd_data[$vhost_filename].= 'ssl.cipher-list = "' . Settings::Get('system.ssl_cipher_list') . '"' . "\n";
$this->lighttpd_data[$vhost_filename].= 'ssl.honor-cipher-order = "enable"' . "\n";
$this->lighttpd_data[$vhost_filename].= 'ssl.pemfile = "' . makeCorrectFile($row_ipsandports['ssl_cert_file']) . '"' . "\n";
if ($row_ipsandports['ssl_ca_file'] != '') {
// check for existence, #1485
if (!file_exists($row_ipsandports['ssl_ca_file'])) {
@@ -455,6 +455,19 @@ class lighttpd extends HttpConfigBase {
$vhost_content.= $this->getSslSettings($domain, $ssl_vhost);
// check if vhost config template is set and if so, merge it
if ($domain['vhostsettingid'] != 0) {
$vhostsettings_stmt = Database::prepare("SELECT `description`, `vhostsettings` FROM " . TABLE_PANEL_VHOSTCONFIGS . " WHERE `id` = :id LIMIT 1;");
$vhostconfig = Database::pexecute_first($vhostsettings_stmt, array('id' => $domain['vhostsettingid']));
$vhost_content .= $this->processSpecialConfigTemplate(
$vhostconfig['vhostsettings'],
$domain,
$domain['ip'],
$domain['port'],
$ssl_vhost) . "\n";
}
if ($domain['specialsettings'] != "") {
$vhost_content.= $this->processSpecialConfigTemplate(
$domain['specialsettings'],
@@ -508,7 +521,7 @@ class lighttpd extends HttpConfigBase {
}
if ($domain['ssl_cert_file'] != '') {
$ssl_settings.= 'ssl.engine = "enable"' . "\n";
$ssl_settings.= 'ssl.use-sslv2 = "disable"' . "\n";
$ssl_settings.= 'ssl.cipher-list = "' . Settings::Get('system.ssl_cipher_list') . '"' . "\n";

View File

@@ -443,6 +443,24 @@ class nginx extends HttpConfigBase {
$vhost_content.= isset($this->needed_htpasswds[$domain['id']]) ? $this->needed_htpasswds[$domain['id']] . "\n" : '';
// check if vhost config template is set and if so, merge it
if ($domain['vhostsettingid'] != 0) {
$vhostsettings_stmt = Database::prepare("SELECT `description`, `vhostsettings` FROM " . TABLE_PANEL_VHOSTCONFIGS . " WHERE `id` = :id LIMIT 1;");
$vhostconfig = Database::pexecute_first($vhostsettings_stmt, array('id' => $domain['vhostsettingid']));
// replace {SOCKET} var with unix socket
$php = new phpinterface($domain);
$vhostconfig['vhostsettings'] = str_replace("{SOCKET}", $php->getInterface()->getSocketFile(), $vhostconfig['vhostsettings']);
$vhost_content = $this->mergeVhostCustom($vhost_content, $this->processSpecialConfigTemplate(
$vhostconfig['vhostsettings'],
$domain,
$domain['ip'],
$domain['port'],
$ssl_vhost
));
}
if ($domain['specialsettings'] != "") {
$vhost_content = $this->mergeVhostCustom($vhost_content, $this->processSpecialConfigTemplate(
$domain['specialsettings'],
@@ -854,20 +872,23 @@ class nginx extends HttpConfigBase {
$this->_deactivated = false;
}
$webroot_text .= "\t" . 'index index.php index.html index.htm;'."\n";
$webroot_text .= "\n\t".'location / {'."\n";
$webroot_text .= "\t\t" . 'try_files $uri $uri/ @rewrites;'."\n";
// write directives only when vhost_usedefaultlocation is activated in panel domain settings
if ($domain['vhost_usedefaultlocation'] == '1') {
$webroot_text .= "\t" . 'index index.php index.html index.htm;'."\n";
$webroot_text .= "\n\t" . 'location / {' . "\n";
$webroot_text .= "\t\t" . 'try_files $uri $uri/ @rewrites;' . "\n";
if ($this->vhost_root_autoindex) {
$webroot_text .= "\t\t".'autoindex on;'."\n";
$this->vhost_root_autoindex = false;
if ($this->vhost_root_autoindex) {
$webroot_text .= "\t\t" . 'autoindex on;' . "\n";
$this->vhost_root_autoindex = false;
}
$webroot_text .= "\t" . '}' . "\n\n";
$webroot_text .= "\tlocation @rewrites {\n";
$webroot_text .= "\t\trewrite ^ /index.php last;\n";
$webroot_text .= "\t}\n\n";
}
$webroot_text .= "\t".'}'."\n\n";
$webroot_text .= "\tlocation @rewrites {\n";
$webroot_text .= "\t\trewrite ^ /index.php last;\n";
$webroot_text .= "\t}\n\n";
return $webroot_text;
}

View File

@@ -23,24 +23,27 @@ class nginx_phpfpm extends nginx
if ($domain['phpenabled'] == '1') {
$php = new phpinterface($domain);
$phpconfig = $php->getPhpConfig((int)$domain['phpsettingid']);
$php_options_text = "\t" . 'location ~ ^(.+?\.php)(/.*)?$ {' . "\n";
$php_options_text .= "\t\t" . 'try_files ' . $domain['nonexistinguri'] . ' @php;' . "\n";
$php_options_text .= "\t" . '}' . "\n\n";
$php_options_text .= "\t" . 'location @php {' . "\n";
$php_options_text .= "\t\t" . 'try_files $1 = 404;' . "\n\n";
$php_options_text .= "\t\t" . 'include ' . Settings::Get('nginx.fastcgiparams') . ";\n";
$php_options_text .= "\t\t" . 'fastcgi_split_path_info ^(.+\.php)(/.+)\$;' . "\n";
$php_options_text .= "\t\t" . 'fastcgi_param SCRIPT_FILENAME $document_root$1;' . "\n";
$php_options_text .= "\t\t" . 'fastcgi_param PATH_INFO $2;' . "\n";
if ($domain['ssl'] == '1' && $ssl_vhost) {
$php_options_text .= "\t\t" . 'fastcgi_param HTTPS on;' . "\n";
// write directives only when vhost_usedefaultlocation is activated in panel domain settings
if ($domain['vhost_usedefaultlocation'] == '1') {
$php_options_text = "\t" . 'location ~ ^(.+?\.php)(/.*)?$ {' . "\n";
$php_options_text .= "\t\t" . 'try_files ' . $domain['nonexistinguri'] . ' @php;' . "\n";
$php_options_text .= "\t" . '}' . "\n\n";
$php_options_text .= "\t" . 'location @php {' . "\n";
$php_options_text .= "\t\t" . 'try_files $1 = 404;' . "\n\n";
$php_options_text .= "\t\t" . 'include ' . Settings::Get('nginx.fastcgiparams') . ";\n";
$php_options_text .= "\t\t" . 'fastcgi_split_path_info ^(.+\.php)(/.+)\$;' . "\n";
$php_options_text .= "\t\t" . 'fastcgi_param SCRIPT_FILENAME $document_root$1;' . "\n";
$php_options_text .= "\t\t" . 'fastcgi_param PATH_INFO $2;' . "\n";
if ($domain['ssl'] == '1' && $ssl_vhost) {
$php_options_text .= "\t\t" . 'fastcgi_param HTTPS on;' . "\n";
}
$php_options_text .= "\t\t" . 'fastcgi_pass unix:' . $php->getInterface()->getSocketFile() . ";\n";
$php_options_text .= "\t\t" . 'fastcgi_index index.php;' . "\n";
$php_options_text .= "\t}\n\n";
}
$php_options_text .= "\t\t" . 'fastcgi_pass unix:' . $php->getInterface()->getSocketFile() . ";\n";
$php_options_text .= "\t\t" . 'fastcgi_index index.php;' . "\n";
$php_options_text .= "\t}\n\n";
// create starter-file | config-file
$php->getInterface()->createConfig($phpconfig);
@@ -54,7 +57,7 @@ class nginx_phpfpm extends nginx
return $php_options_text;
}
public function createOwnVhostStarter() {
if (Settings::Get('phpfpm.enabled') == '1'