From 9691a391029a17bce7a628d35773ac3bd5338056 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Thu, 2 May 2013 10:38:44 +0200 Subject: [PATCH] fix setting of default IP/Port (which still used panel_domain's ipandport-field), don't show ssl-enabled IP/Ports for default-ip (wrong default parameter of function getIpPortCombinations()), smaller fixes in bind- and lighttpdcronjob Signed-off-by: Michael Kaufmann (d00p) --- admin_domains.php | 37 ++++++---- .../function.getIpPortCombinations.php | 2 +- .../function.storeSettingDefaultIp.php | 32 ++++---- scripts/jobs/cron_tasks.inc.dns.10.bind.php | 25 ++++--- .../jobs/cron_tasks.inc.http.20.lighttpd.php | 74 ++++++++++--------- 5 files changed, 92 insertions(+), 78 deletions(-) diff --git a/admin_domains.php b/admin_domains.php index 60a418cf..727147fa 100644 --- a/admin_domains.php +++ b/admin_domains.php @@ -1098,23 +1098,24 @@ if($page == 'domains' 'id' => 0 ); - if($aliasdomain != 0) - { - // Overwrite given ipandports with these of the "main" domain - $ipandports = array(); - $origipresult = $db->query("SELECT `id_ipandports` FROM `" . TABLE_DOMAINTOIP ."` WHERE `id_domain` = '" . (int)$aliasdomain . "'"); - while($origip = $db->fetch_array($origipresult)) - { - $ipandports[] = $origip['id_ipandports']; - } + if ($aliasdomain != 0) { + // Overwrite given ipandports with these of the "main" domain + $ipandports = array(); + $origipresult = $db->query("SELECT `id_ipandports` FROM `" . TABLE_DOMAINTOIP ."` WHERE `id_domain` = '" . (int)$aliasdomain . "'"); + while ($origip = $db->fetch_array($origipresult)) { + $ipandports[] = $origip['id_ipandports']; + } + $aliasdomain_check = $db->query_first("SELECT `d`.`id` FROM `" . TABLE_PANEL_DOMAINS . "` `d`, `" . TABLE_PANEL_CUSTOMERS . "` `c` + WHERE `d`.`customerid`='" . (int)$customerid . "' + AND `d`.`aliasdomain` IS NULL AND + `d`.`id` <> `c`.`standardsubdomain` + AND `c`.`customerid`='" . (int)$customerid . "' + AND `d`.`id`='" . (int)$aliasdomain . "'"); + } - $aliasdomain_check = $db->query_first('SELECT `d`.`id` FROM `' . TABLE_PANEL_DOMAINS . '` `d`,`' . TABLE_PANEL_CUSTOMERS . '` `c` WHERE `d`.`customerid`=\'' . (int)$customerid . '\' AND `d`.`aliasdomain` IS NULL AND `d`.`id`<>`c`.`standardsubdomain` AND `c`.`customerid`=\'' . (int)$customerid . '\' AND `d`.`id`=\'' . (int)$aliasdomain . '\''); - } - - if(count($ipandports) == 0) - { - standard_error('noipportgiven'); - } + if (count($ipandports) == 0) { + standard_error('noipportgiven'); + } if($aliasdomain_check['id'] != $aliasdomain) { @@ -1282,6 +1283,10 @@ if($page == 'domains' WHERE `parentdomainid`='" . (int)$id . "' "); + // FIXME check how many we got and if the amount of assigned IP's + // has changed so we can insert a config-rebuild task if only + // the ip's of this domain were changed + // Cleanup domain <-> ip mapping $db->query("DELETE FROM `" . TABLE_DOMAINTOIP . "` WHERE `id_domain` = '" . (int)$id . "'"); diff --git a/lib/functions/froxlor/function.getIpPortCombinations.php b/lib/functions/froxlor/function.getIpPortCombinations.php index 24ba82e4..ee1294e3 100644 --- a/lib/functions/froxlor/function.getIpPortCombinations.php +++ b/lib/functions/froxlor/function.getIpPortCombinations.php @@ -17,7 +17,7 @@ * */ -function getIpPortCombinations($ssl = null) +function getIpPortCombinations($ssl = false) { global $db, $theme; diff --git a/lib/functions/settings/function.storeSettingDefaultIp.php b/lib/functions/settings/function.storeSettingDefaultIp.php index 66b9be4b..83d2fd35 100644 --- a/lib/functions/settings/function.storeSettingDefaultIp.php +++ b/lib/functions/settings/function.storeSettingDefaultIp.php @@ -16,30 +16,34 @@ * @package Functions * */ +function storeSettingDefaultIp($fieldname, $fielddata, $newfieldvalue) { -function storeSettingDefaultIp($fieldname, $fielddata, $newfieldvalue) -{ $returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue); - if($returnvalue !== false && is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'system' && isset($fielddata['varname']) && $fielddata['varname'] == 'defaultip') - { + if ($returnvalue !== false + && is_array($fielddata) + && isset($fielddata['settinggroup']) + && $fielddata['settinggroup'] == 'system' + && isset($fielddata['varname']) + && $fielddata['varname'] == 'defaultip' + ) { global $db, $theme; - - $customerstddomains_result = $db->query('SELECT `standardsubdomain` FROM `' . TABLE_PANEL_CUSTOMERS . '` WHERE `standardsubdomain` <> \'0\''); + + $customerstddomains_result = $db->query("SELECT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `standardsubdomain` <> '0'"); $ids = array(); - while($customerstddomains_row = $db->fetch_array($customerstddomains_result)) - { + while($customerstddomains_row = $db->fetch_array($customerstddomains_result)) { $ids[] = (int)$customerstddomains_row['standardsubdomain']; } - if(count($ids) > 0) - { - $db->query('UPDATE `' . TABLE_PANEL_DOMAINS . '` SET `ipandport`=\'' . (int)$newfieldvalue . '\' WHERE `id` IN (\'' . implode('\',\'', $ids) . '\') AND `ipandport` = \'' . $db->escape(getSetting('system', 'defaultip')) . '\''); + if(count($ids) > 0) { + $db->query("UPDATE `" . TABLE_DOMAINTOIP . "` SET + `id_ipandports`='" . (int)$newfieldvalue . "' + WHERE `id_domain` IN ('" . implode(', ', $ids) . "') + AND `id_ipandports` = '" . $db->escape(getSetting('system', 'defaultip')) . "'" + ); } } - + return $returnvalue; } - -?> diff --git a/scripts/jobs/cron_tasks.inc.dns.10.bind.php b/scripts/jobs/cron_tasks.inc.dns.10.bind.php index 752e33c0..4086b79a 100644 --- a/scripts/jobs/cron_tasks.inc.dns.10.bind.php +++ b/scripts/jobs/cron_tasks.inc.dns.10.bind.php @@ -17,9 +17,6 @@ * */ -/* - * This script creates the php.ini's used by mod_suPHP+php-cgi -*/ if(@php_sapi_name() != 'cli' && @php_sapi_name() != 'cgi' @@ -179,23 +176,24 @@ class bind protected function generateZone($domain) { - /** Array to save all ips needed in the records (already including IN A/AAAA */ + // Array to save all ips needed in the records (already including IN A/AAAA) $ip_a_records = array(); - /** Array to save DNS records */ + // Array to save DNS records $records = array(); $result_ip = $this->db->query("SELECT `p`.`ip` AS `ip` FROM `".TABLE_PANEL_IPSANDPORTS."` `p`, `".TABLE_DOMAINTOIP."` `di` WHERE `di`.`id_domain` = '$domain[id]' AND `p`.`id` = `di`.`id_ipandports` GROUP BY `p`.`ip`;"); while ($ip = $this->db->fetch_array($result_ip)) { - if(filter_var($ip['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) + if (filter_var($ip['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { $ip_a_records[] = "A $ip[ip]"; - - elseif(filter_var($ip['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) + } + elseif (filter_var($ip['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { $ip_a_records[] = "AAAA $ip[ip]"; - - else - return ";Error in at least one IP Adress ($ip[ip]), could not create zonefile!"; + } + else { + return ";Error in at least one IP Adress (".$ip['ip']."), could not create zonefile!"; + } } $date = date('Ymd'); @@ -214,17 +212,20 @@ class bind $zonefile.= ' ' . $bindserial . ' ; serial' . "\n" . ' 8H ; refresh' . "\n" . ' 2H ; retry' . "\n" . ' 1W ; expiry' . "\n" . ' 11h) ; minimum' . "\n"; + // FIXME What is this? there is no $ip_a_record at this stage + /* if(count($this->nameservers) == 0) { $zonefile.= '@ IN NS ns' . "\n" . 'ns IN ' . $ip_a_record . "\n"; } else { + */ foreach($this->nameservers as $nameserver) { $zonefile.= '@ IN NS ' . trim($nameserver['hostname']) . "\n"; } - } + //} if(count($this->mxservers) == 0) { diff --git a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php index 7faafab6..032b6317 100644 --- a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php +++ b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php @@ -198,7 +198,7 @@ class lighttpd * if $this->settings['system']['apacheconf_vhost'] is a folder * refs #70 */ - $vhosts = $this->createLighttpdHosts($row_ipsandports['ip'], $row_ipsandports['port'], $row_ipsandports['ssl'], $vhost_filename); + $vhosts = $this->createLighttpdHosts($row_ipsandports['id'], $row_ipsandports['ssl'], $vhost_filename); if ($vhosts !== null && is_array($vhosts) && isset($vhosts[0])) { // sort vhosts by number (subdomains first!) sort($vhosts); @@ -300,19 +300,35 @@ class lighttpd { } - protected function createLighttpdHosts($ip, $port, $ssl, $vhost_filename) + protected function createLighttpdHosts($ipid, $ssl, $vhost_filename) { - $query = "SELECT * FROM " . TABLE_PANEL_IPSANDPORTS . " WHERE `ip`='" . $ip . "' AND `port`='" . $port . "'"; - $ipandport = $this->db->query_first($query); + $query = "SELECT `d`.*, `pd`.`domain` AS `parentdomain`, `c`.`loginname`, + `d`.`phpsettingid`, `c`.`adminid`, `c`.`guid`, `c`.`email`, + `c`.`documentroot` AS `customerroot`, `c`.`deactivated`, + `c`.`phpenabled` AS `phpenabled`, `d`.`mod_fcgid_starter`, + `d`.`mod_fcgid_maxrequests`, `p`.`ssl` AS `ssl`, + `p`.`ssl_cert_file`, `p`.`ssl_key_file`, `p`.`ssl_ca_file`, `p`.`ssl_cert_chainfile` + FROM `".TABLE_PANEL_DOMAINS."` `d` - if ($ssl == '0') { - $query2 = "SELECT `d`.*, `pd`.`domain` AS `parentdomain`, `c`.`loginname`, `c`.`guid`, `c`.`email`, `c`.`documentroot` AS `customerroot`, `c`.`deactivated`, `c`.`phpenabled` AS `phpenabled` FROM `" . TABLE_PANEL_DOMAINS . "` `d` LEFT JOIN `" . TABLE_PANEL_CUSTOMERS . "` `c` USING(`customerid`) LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` `pd` ON (`pd`.`id` = `d`.`parentdomainid`) WHERE `d`.`ipandport`='" . $ipandport['id'] . "' AND `d`.`aliasdomain` IS NULL AND `d`.`email_only` <> 1 ORDER BY `d`.`parentdomainid` DESC, `d`.`iswildcarddomain`, `d`.`domain` ASC"; - } else { - $query2 = "SELECT `d`.*, `pd`.`domain` AS `parentdomain`, `c`.`loginname`, `c`.`guid`, `c`.`email`, `c`.`documentroot` AS `customerroot`, `c`.`deactivated`, `c`.`phpenabled` AS `phpenabled` FROM `" . TABLE_PANEL_DOMAINS . "` `d` LEFT JOIN `" . TABLE_PANEL_CUSTOMERS . "` `c` USING(`customerid`) LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` `pd` ON (`pd`.`id` = `d`.`parentdomainid`) WHERE `d`.`ssl_ipandport`='" . $ipandport['id'] . "' AND `d`.`aliasdomain` IS NULL AND `d`.`email_only` <> 1 ORDER BY `d`.`parentdomainid` DESC, `d`.`iswildcarddomain`, `d`.`domain` ASC"; - } + LEFT JOIN `".TABLE_PANEL_CUSTOMERS."` `c` USING(`customerid`) + LEFT JOIN `".TABLE_PANEL_DOMAINS."` `pd` ON (`pd`.`id` = `d`.`parentdomainid`) + + INNER JOIN ( + SELECT * FROM ( + SELECT `di`.`id_domain` , `p`.`ssl`, `p`.`ssl_cert_file`, `p`.`ssl_key_file`, `p`.`ssl_ca_file`, `p`.`ssl_cert_chainfile` + FROM `".TABLE_DOMAINTOIP."` `di` , `".TABLE_PANEL_IPSANDPORTS."` `p` + WHERE `p`.`id` = `di`.`id_ipandports` + AND `p`.`id` = '".(int)$ipid."' + ORDER BY `p`.`ssl` DESC + ) AS my_table_tmp + GROUP BY `id_domain` + ) AS p ON p.`id_domain` = `d`.`id` + + WHERE `d`.`aliasdomain` IS NULL + ORDER BY `d`.`parentdomainid` DESC, `d`.`iswildcarddomain`, `d`.`domain` ASC;"; $included_vhosts = array(); - $result_domains = $this->db->query($query2); + $result_domains = $this->db->query($query); while ($domain = $this->db->fetch_array($result_domains)) { if (is_dir($this->settings['system']['apacheconf_vhost'])) { safe_exec('mkdir -p '.escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'].'/vhosts/'))); @@ -368,39 +384,25 @@ class lighttpd $ips_and_ports_index = 'ipandport'; } - $this->lighttpd_data[$vhost_filename].= $this->getVhostContent($domain, $ssl_vhost); - $this->lighttpd_data[$vhost_filename].= isset($this->needed_htpasswds[$domain[$ips_and_ports_index]]) ? $this->needed_htpasswds[$domain[$ips_and_ports_index]] . "\n" : ''; + // FIXME we get duplicate entries of a vhost if it has assigned more than one IP + // checking if the lightt_data for that filename is empty *might* be correct + if ($this->lighttpd_data[$vhost_filename] == '') { + $this->lighttpd_data[$vhost_filename] .= $this->getVhostContent($domain, $ssl_vhost, $ipid); + } + // FIXME did this ever work? + //$this->lighttpd_data[$vhost_filename].= isset($this->needed_htpasswds[$domain[$ips_and_ports_index]]) ? $this->needed_htpasswds[$domain[$ips_and_ports_index]] . "\n" : ''; } } return $included_vhosts; } - protected function getVhostContent($domain, $ssl_vhost = false) + protected function getVhostContent($domain, $ssl_vhost = false, $ipid) { if($ssl_vhost === true - && $domain['ssl'] != '1') - { - return ''; - } - - if ($ssl_vhost === true - && $domain['ssl'] == '1' + && $domain['ssl'] != '1' + && $domain['ssl_redirect'] != '1' ) { - $query = "SELECT * FROM " . TABLE_PANEL_IPSANDPORTS . " WHERE `id`='" . $domain['ssl_ipandport'] . "'"; - } else { - $query = "SELECT * FROM " . TABLE_PANEL_IPSANDPORTS . " WHERE `id`='" . $domain['ipandport'] . "'"; - } - - $ipandport = $this->db->query_first($query); - $domain['ip'] = $ipandport['ip']; - $domain['port'] = $ipandport['port']; - $domain['ssl_cert_file'] = $ipandport['ssl_cert_file']; - $domain['ssl_ca_file'] = $ipandport['ssl_ca_file']; - - if (filter_var($domain['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { - $ipport = '[' . $domain['ip'] . ']:' . $domain['port']; - } else { - $ipport = $domain['ip'] . ':' . $domain['port']; + return ''; } $vhost_content = ''; @@ -440,6 +442,8 @@ class lighttpd $vhost_content.= $domain['specialsettings'] . "\n"; } + $query = "SELECT `default_vhostconf_domain` FROM `".TABLE_PANEL_IPSANDPORTS."` WHERE `id`='".$ipid."';"; + $ipandport = $this->db->query_first($query); if ($ipandport['default_vhostconf_domain'] != '') { $vhost_content.= $ipandport['default_vhostconf_domain'] . "\n"; }