- added possibility to set a custom docroot for any ip/port combination, fixes #417

- sort vhosts-file by type (subdomain, sub-of-main, main-domain), fixes #437
This commit is contained in:
Michael Kaufmann (d00p)
2010-10-15 10:41:58 +00:00
parent ceedab3a6e
commit db05ea5f32
10 changed files with 97 additions and 15 deletions

View File

@@ -147,6 +147,7 @@ if($page == 'ipsandports'
$ssl_ca_file = validate($_POST['ssl_ca_file'], 'ssl_ca_file'); $ssl_ca_file = validate($_POST['ssl_ca_file'], 'ssl_ca_file');
$ssl_cert_chainfile = validate($_POST['ssl_cert_chainfile'], 'ssl_cert_chainfile'); $ssl_cert_chainfile = validate($_POST['ssl_cert_chainfile'], 'ssl_cert_chainfile');
$default_vhostconf_domain = validate(str_replace("\r\n", "\n", $_POST['default_vhostconf_domain']), 'default_vhostconf_domain', '/^[^\0]*$/'); $default_vhostconf_domain = validate(str_replace("\r\n", "\n", $_POST['default_vhostconf_domain']), 'default_vhostconf_domain', '/^[^\0]*$/');
$docroot = validate($_POST['docroot'], 'docroot');
if($listen_statement != '1') if($listen_statement != '1')
{ {
@@ -193,6 +194,15 @@ if($page == 'ipsandports'
$ssl_cert_chainfile = makeCorrectFile($ssl_cert_chainfile); $ssl_cert_chainfile = makeCorrectFile($ssl_cert_chainfile);
} }
if(strlen(trim($docroot)) > 0)
{
$docroot = makeCorrectDir($docroot);
}
else
{
$docroot = '';
}
$result_checkfordouble = $db->query_first("SELECT `id` FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `ip`='" . $db->escape($ip) . "' AND `port`='" . (int)$port . "'"); $result_checkfordouble = $db->query_first("SELECT `id` FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `ip`='" . $db->escape($ip) . "' AND `port`='" . (int)$port . "'");
if($result_checkfordouble['id'] != '') if($result_checkfordouble['id'] != '')
@@ -215,7 +225,8 @@ if($page == 'ipsandports'
`ssl_key_file` = '" . $db->escape($ssl_key_file) . "', `ssl_key_file` = '" . $db->escape($ssl_key_file) . "',
`ssl_ca_file` = '" . $db->escape($ssl_ca_file) . "', `ssl_ca_file` = '" . $db->escape($ssl_ca_file) . "',
`ssl_cert_chainfile` = '" . $db->escape($ssl_cert_chainfile) . "', `ssl_cert_chainfile` = '" . $db->escape($ssl_cert_chainfile) . "',
`default_vhostconf_domain` = '" . $db->escape($default_vhostconf_domain) . "'; `default_vhostconf_domain` = '" . $db->escape($default_vhostconf_domain) . "',
`docroot` = '" . $db->escape($docroot) . "';
"); ");
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
@@ -264,6 +275,7 @@ if($page == 'ipsandports'
$ssl_ca_file = validate($_POST['ssl_ca_file'], 'ssl_ca_file'); $ssl_ca_file = validate($_POST['ssl_ca_file'], 'ssl_ca_file');
$ssl_cert_chainfile = validate($_POST['ssl_cert_chainfile'], 'ssl_cert_chainfile'); $ssl_cert_chainfile = validate($_POST['ssl_cert_chainfile'], 'ssl_cert_chainfile');
$default_vhostconf_domain = validate(str_replace("\r\n", "\n", $_POST['default_vhostconf_domain']), 'default_vhostconf_domain', '/^[^\0]*$/'); $default_vhostconf_domain = validate(str_replace("\r\n", "\n", $_POST['default_vhostconf_domain']), 'default_vhostconf_domain', '/^[^\0]*$/');
$docroot = validate($_POST['docroot'], 'docroot');
if($listen_statement != '1') if($listen_statement != '1')
{ {
@@ -310,6 +322,15 @@ if($page == 'ipsandports'
$ssl_cert_chainfile = makeCorrectFile($ssl_cert_chainfile); $ssl_cert_chainfile = makeCorrectFile($ssl_cert_chainfile);
} }
if(strlen(trim($docroot)) > 0)
{
$docroot = makeCorrectDir($docroot);
}
else
{
$docroot = '';
}
if($result['ip'] != $ip if($result['ip'] != $ip
&& $result['ip'] == $settings['system']['ipaddress'] && $result['ip'] == $settings['system']['ipaddress']
&& $result_sameipotherport['id'] == '') && $result_sameipotherport['id'] == '')
@@ -338,7 +359,8 @@ if($page == 'ipsandports'
`ssl_key_file` = '" . $db->escape($ssl_key_file) . "', `ssl_key_file` = '" . $db->escape($ssl_key_file) . "',
`ssl_ca_file` = '" . $db->escape($ssl_ca_file) . "', `ssl_ca_file` = '" . $db->escape($ssl_ca_file) . "',
`ssl_cert_chainfile` = '" . $db->escape($ssl_cert_chainfile) . "', `ssl_cert_chainfile` = '" . $db->escape($ssl_cert_chainfile) . "',
`default_vhostconf_domain` = '" . $db->escape($default_vhostconf_domain) . "' `default_vhostconf_domain` = '" . $db->escape($default_vhostconf_domain) . "',
`docroot` = '" . $db->escape($docroot) . "'
WHERE `id`='" . (int)$id . "' WHERE `id`='" . (int)$id . "'
"); ");

View File

@@ -338,6 +338,7 @@ CREATE TABLE `panel_ipsandports` (
`ssl_ca_file` varchar(255) NOT NULL, `ssl_ca_file` varchar(255) NOT NULL,
`default_vhostconf_domain` text NOT NULL, `default_vhostconf_domain` text NOT NULL,
`ssl_cert_chainfile` varchar(255) NOT NULL, `ssl_cert_chainfile` varchar(255) NOT NULL,
`docroot` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) TYPE=MyISAM ; ) TYPE=MyISAM ;
@@ -461,7 +462,7 @@ INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) V
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (18, 'system', 'vmail_homedir', '/var/customers/mail/'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (18, 'system', 'vmail_homedir', '/var/customers/mail/');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (19, 'system', 'bindconf_directory', '/etc/bind/'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (19, 'system', 'bindconf_directory', '/etc/bind/');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (20, 'system', 'bindreload_command', '/etc/init.d/bind9 reload'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (20, 'system', 'bindreload_command', '/etc/init.d/bind9 reload');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (22, 'panel', 'version', '0.9.14-svn4'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (22, 'panel', 'version', '0.9.14-svn5');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (23, 'system', 'hostname', 'SERVERNAME'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (23, 'system', 'hostname', 'SERVERNAME');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (24, 'login', 'maxloginattempts', '3'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (24, 'login', 'maxloginattempts', '3');
INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (25, 'login', 'deactivatetime', '900'); INSERT INTO `panel_settings` (`settingid`, `settinggroup`, `varname`, `value`) VALUES (25, 'login', 'deactivatetime', '900');

View File

@@ -1139,3 +1139,14 @@ if(isFroxlorVersion('0.9.14-svn3'))
updateToVersion('0.9.14-svn4'); updateToVersion('0.9.14-svn4');
} }
if(isFroxlorVersion('0.9.14-svn4'))
{
showUpdateStep("Updating from 0.9.14-svn4 to 0.9.14-svn5", false);
showUpdateStep("Adding docroot-field to IPs and ports for custom-docroot settings");
$db->query("ALTER TABLE `".TABLE_PANEL_IPSANDPORTS."` ADD `docroot` varchar(255) NOT NULL default '' AFTER `ssl_cert_chainfile`;");
lastStepStatus(0);
updateToVersion('0.9.14-svn5');
}

View File

@@ -72,7 +72,7 @@ define('PACKAGE_ENABLED', 2);
// VERSION INFO // VERSION INFO
$version = '0.9.14-svn4'; $version = '0.9.14-svn5';
$dbversion = '2'; $dbversion = '2';
$branding = ''; $branding = '';

View File

@@ -1506,4 +1506,8 @@ $lng['serversettings']['awstats_icons']['description'] = 'e.g. /usr/share/awstat
// ADDED IN FROXLOR 0.9.14-svn4 // ADDED IN FROXLOR 0.9.14-svn4
$lng['admin']['ipsandports']['ssl_cert_chainfile'] = 'Path to the SSL CertificateChainFile'; $lng['admin']['ipsandports']['ssl_cert_chainfile'] = 'Path to the SSL CertificateChainFile';
// ADDED IN FROXLOR 0.9.14-svn5
$lng['admin']['ipsandports']['docroot']['title'] = 'Custom docroot (empty = point to Froxlor)';
$lng['admin']['ipsandports']['docroot']['description'] = 'You can define a custom document-root (the destination for a request) for this ip/port combination here.<br /><strong>ATTENTION:</strong> Please be careful with what you enter here!';
?> ?>

View File

@@ -1489,4 +1489,8 @@ $lng['serversettings']['awstats_icons']['description'] = 'z.B. /usr/share/awstat
// ADDED IN FROXLOR 0.9.14-svn4 // ADDED IN FROXLOR 0.9.14-svn4
$lng['admin']['ipsandports']['ssl_cert_chainfile'] = 'Pfad zu dem SSL CertificateChainFile'; $lng['admin']['ipsandports']['ssl_cert_chainfile'] = 'Pfad zu dem SSL CertificateChainFile';
// ADDED IN FROXLOR 0.9.14-svn5
$lng['admin']['ipsandports']['docroot']['title'] = 'Benutzerdefinierter Docroot (leer = zeige auf Froxlor)';
$lng['admin']['ipsandports']['docroot']['description'] = 'Hier kann ein benutzerdefinierter Document-Root (der Zeilordner f&uuml;r einen Zugriff) f&uuml;r diese IP/Port Kombination gesetzt werden.<br /><strong>ACHTUNG:</strong> Bitte &uuml;berlege vorher, welchen Pfad du hier angibst!';
?> ?>

View File

@@ -189,6 +189,8 @@ class apache
{ {
$this->virtualhosts_data[$vhosts_filename].= '<VirtualHost ' . $ipport . '>' . "\n"; $this->virtualhosts_data[$vhosts_filename].= '<VirtualHost ' . $ipport . '>' . "\n";
if($row_ipsandports['docroot'] == '')
{
/** /**
* add 'real'-vhost content here, like doc-root :) * add 'real'-vhost content here, like doc-root :)
*/ */
@@ -200,6 +202,13 @@ class apache
{ {
$mypath = makeCorrectDir(dirname(dirname(dirname(dirname(__FILE__))))); $mypath = makeCorrectDir(dirname(dirname(dirname(dirname(__FILE__)))));
} }
}
else
{
// user-defined docroot, #417
$mypath = makeCorrectDir($row_ipsandports['docroot']);
}
$this->virtualhosts_data[$vhosts_filename].= 'DocumentRoot "'.$mypath.'"'."\n"; $this->virtualhosts_data[$vhosts_filename].= 'DocumentRoot "'.$mypath.'"'."\n";
if($row_ipsandports['vhostcontainer_servername_statement'] == '1') if($row_ipsandports['vhostcontainer_servername_statement'] == '1')
@@ -1111,6 +1120,13 @@ class apache
// Save one big file // Save one big file
$vhosts_file = ''; $vhosts_file = '';
// sort by filename so the order is:
// 1. subdomains 20
// 2. subdomains as main-domains 21
// 3. main-domains 22
// #437
ksort($this->virtualhosts_data);
foreach($this->virtualhosts_data as $vhosts_filename => $vhost_content) foreach($this->virtualhosts_data as $vhosts_filename => $vhost_content)
{ {
$vhosts_file.= $vhost_content . "\n\n"; $vhosts_file.= $vhost_content . "\n\n";

View File

@@ -107,6 +107,8 @@ class lighttpd
$this->lighttpd_data[$vhost_filename].= '# Froxlor default vhost' . "\n"; $this->lighttpd_data[$vhost_filename].= '# Froxlor default vhost' . "\n";
$this->lighttpd_data[$vhost_filename].= '$HTTP["host"] =~ "^(?:www\.|)' . $myhost . '$" {' . "\n"; $this->lighttpd_data[$vhost_filename].= '$HTTP["host"] =~ "^(?:www\.|)' . $myhost . '$" {' . "\n";
if($row_ipsandports['docroot'] == '')
{
if($this->settings['system']['froxlordirectlyviahostname']) if($this->settings['system']['froxlordirectlyviahostname'])
{ {
$mypath = makeCorrectDir(dirname(dirname(dirname(__FILE__)))); $mypath = makeCorrectDir(dirname(dirname(dirname(__FILE__))));
@@ -115,6 +117,13 @@ class lighttpd
{ {
$mypath = makeCorrectDir(dirname(dirname(dirname(dirname(__FILE__))))); $mypath = makeCorrectDir(dirname(dirname(dirname(dirname(__FILE__)))));
} }
}
else
{
// user-defined docroot, #417
$mypath = makeCorrectDir($row_ipsandports['docroot']);
}
$this->lighttpd_data[$vhost_filename].= ' server.document-root = "'.$mypath.'"'."\n"; $this->lighttpd_data[$vhost_filename].= ' server.document-root = "'.$mypath.'"'."\n";
/** /**
@@ -855,6 +864,13 @@ class lighttpd
// Save one big file // Save one big file
$vhosts_file = ''; $vhosts_file = '';
// sort by filename so the order is:
// 1. subdomains
// 2. subdomains as main-domains
// 3. main-domains
// #437
ksort($this->lighttpd_data);
foreach($this->lighttpd_data as $vhosts_filename => $vhost_content) foreach($this->lighttpd_data as $vhosts_filename => $vhost_content)
{ {
$vhosts_file.= $vhost_content . "\n\n"; $vhosts_file.= $vhost_content . "\n\n";

View File

@@ -47,6 +47,10 @@ $header
</td> </td>
<td class="main_field_display" nowrap="nowrap">$vhostcontainer</td> <td class="main_field_display" nowrap="nowrap">$vhostcontainer</td>
</tr> </tr>
<tr>
<td class="main_field_name">{$lng['admin']['ipsandports']['docroot']}:</td>
<td class="main_field_display" nowrap="nowrap"><input type="text" class="text" name="docroot" value="" /></td>
</tr>
<tr> <tr>
<td class="main_field_name" valign="top">{$lng['admin']['ownvhostsettings']}:<br /><font size="1">{$lng['serversettings']['default_vhostconf']['description']}</font> <td class="main_field_name" valign="top">{$lng['admin']['ownvhostsettings']}:<br /><font size="1">{$lng['serversettings']['default_vhostconf']['description']}</font>
<if $settings['system']['webserver'] == 'lighttpd'><div style="color:red">{$lng['panel']['not_supported']}lighttpd</div></if> <if $settings['system']['webserver'] == 'lighttpd'><div style="color:red">{$lng['panel']['not_supported']}lighttpd</div></if>

View File

@@ -46,6 +46,10 @@ $header
<td class="main_field_name">{$lng['admin']['ipsandports']['create_vhostcontainer']}:</td> <td class="main_field_name">{$lng['admin']['ipsandports']['create_vhostcontainer']}:</td>
<td class="main_field_display" nowrap="nowrap">$vhostcontainer</td> <td class="main_field_display" nowrap="nowrap">$vhostcontainer</td>
</tr> </tr>
<tr>
<td class="main_field_name">{$lng['admin']['ipsandports']['docroot']}:</td>
<td class="main_field_display" nowrap="nowrap"><input type="text" class="text" name="docroot" value="{$result['docroot']}" /></td>
</tr>
<tr> <tr>
<td class="main_field_name" valign="top">{$lng['admin']['ownvhostsettings']}:<br /><font size="1">{$lng['serversettings']['default_vhostconf']['description']}</font></td> <td class="main_field_name" valign="top">{$lng['admin']['ownvhostsettings']}:<br /><font size="1">{$lng['serversettings']['default_vhostconf']['description']}</font></td>
<td class="main_field_display" nowrap="nowrap"><textarea class="textarea_border" rows="12" cols="60" name="specialsettings">{$result['specialsettings']}</textarea></td> <td class="main_field_display" nowrap="nowrap"><textarea class="textarea_border" rows="12" cols="60" name="specialsettings">{$result['specialsettings']}</textarea></td>