From 391e05cbee6ff84bce60b665be60b4e5f049ee7f Mon Sep 17 00:00:00 2001 From: Falko Timme <ft@falkotimme.com> Date: Tue, 22 Oct 2013 12:48:51 -0400 Subject: [PATCH] - Display hostname next to IP (where available) in the jQuery IP suggestion box. --- interface/lib/classes/functions.inc.php | 139 ++++++++++++++++++++++++++++++---------------- 1 files changed, 90 insertions(+), 49 deletions(-) diff --git a/interface/lib/classes/functions.inc.php b/interface/lib/classes/functions.inc.php index fcb6055..64074d4 100644 --- a/interface/lib/classes/functions.inc.php +++ b/interface/lib/classes/functions.inc.php @@ -129,11 +129,36 @@ return number_format((double)$number, $number_format_decimals, $number_format_dec_point, $number_format_thousands_sep); } + //* convert currency formatted number back to floating number + public function currency_unformat($number) { + global $app; + + $number_format_dec_point = $app->lng('number_format_dec_point'); + $number_format_thousands_sep = $app->lng('number_format_thousands_sep'); + if($number_format_thousands_sep == 'number_format_thousands_sep') $number_format_thousands_sep = ''; + + if($number_format_thousands_sep != '') $number = str_replace($number_format_thousands_sep, '', $number); + if($number_format_dec_point != '.' && $number_format_dec_point != '') $number = str_replace($number_format_dec_point, '.', $number); + + return (double)$number; + } + public function get_ispconfig_url() { + global $app; + $url = (stristr($_SERVER['SERVER_PROTOCOL'],'HTTPS') || stristr($_SERVER['HTTPS'],'on'))?'https':'http'; - $url .= '://'.$_SERVER['SERVER_NAME']; - if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) { - $url .= ':'.$_SERVER['SERVER_PORT']; + if($_SERVER['SERVER_NAME'] != '_') { + $url .= '://'.$_SERVER['SERVER_NAME']; + if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) { + $url .= ':'.$_SERVER['SERVER_PORT']; + } + } else { + $app->uses("getconf"); + $server_config = $app->getconf->get_server_config(1,'server'); + $url .= '://'.$server_config['hostname']; + if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) { + $url .= ':'.$_SERVER['SERVER_PORT']; + } } return $url; } @@ -212,12 +237,24 @@ // IPv6 $regex = "/^(\:\:([a-f0-9]{1,4}\:){0,6}?[a-f0-9]{0,4}|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){0,6}?\:\:|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){1,6}?\:\:([a-f0-9]{1,4}\:){1,6}?[a-f0-9]{1,4})(\/\d{1,3})?$/i"; } + + $server_by_id = array(); + $server_by_ip = array(); + $servers = $app->db->queryAllRecords("SELECT * FROM server"); + if(is_array($servers) && !empty($servers)){ + foreach($servers as $server){ + $server_by_id[$server['server_id']] = $server['server_name']; + } + } $ips = array(); - $results = $app->db->queryAllRecords("SELECT ip_address AS ip FROM server_ip WHERE ip_type = '".$type."'"); + $results = $app->db->queryAllRecords("SELECT ip_address AS ip, server_id FROM server_ip WHERE ip_type = '".$type."'"); if(!empty($results) && is_array($results)){ foreach($results as $result){ - if(preg_match($regex, $result['ip'])) $ips[] = $result['ip']; + if(preg_match($regex, $result['ip'])){ + $ips[] = $result['ip']; + $server_by_ip[$result['ip']] = $server_by_id[$result['server_id']]; + } } } $results = $app->db->queryAllRecords("SELECT ip_address AS ip FROM openvz_ip"); @@ -292,7 +329,7 @@ foreach($ips as $ip){ $result_array['cdata'][] = array( 'title' => $ip, - 'description' => $type, + 'description' => $type.($server_by_ip[$ip] != ''? ' > '.$server_by_ip[$ip] : ''), 'onclick' => '', 'fill_text' => $ip ); @@ -303,7 +340,7 @@ } public function intval($string, $force_numeric = false) { - if(intval($string) == 2147483647) { + if(intval($string) == 2147483647 || ($string > 0 && intval($string) < 0)) { if($force_numeric == true) return floatval($string); elseif(preg_match('/^([-]?)[0]*([1-9][0-9]*)([^0-9].*)*$/', $string, $match)) return $match[1].$match[2]; else return 0; @@ -315,7 +352,7 @@ /** IDN converter wrapper. * all converter classes should be placed in ISPC_CLASS_PATH.'/idn/' */ - public function idn_encode($domain) { + private function _idn_encode_decode($domain, $encode = true) { if($domain == '') return ''; if(preg_match('/^[0-9\.]+$/', $domain)) return $domain; // may be an ip address - anyway does not need to bee encoded @@ -326,56 +363,60 @@ $domain = substr($domain, strrpos($domain, '@') + 1); } - if(function_exists('idn_to_ascii')) { - $domain = idn_to_ascii($domain); - } elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) { - /* use idna class: - * @author Matthias Sommerfeld <mso@phlylabs.de> - * @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de - * @version 0.8.0 2011-03-11 - */ - - if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') { - include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php'); - $this->idn_converter = new idna_convert(array('idn_version' => 2008)); - $this->idn_converter_name = 'idna_convert.class'; + if($encode == true) { + if(function_exists('idn_to_ascii')) { + $domain = idn_to_ascii($domain); + } elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) { + /* use idna class: + * @author Matthias Sommerfeld <mso@phlylabs.de> + * @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de + * @version 0.8.0 2011-03-11 + */ + + if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') { + include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php'); + $this->idn_converter = new idna_convert(array('idn_version' => 2008)); + $this->idn_converter_name = 'idna_convert.class'; + } + $domain = $this->idn_converter->encode($domain); } - $domain = $this->idn_converter->encode($domain); + } else { + if(function_exists('idn_to_utf8')) { + $domain = idn_to_utf8($domain); + } elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) { + /* use idna class: + * @author Matthias Sommerfeld <mso@phlylabs.de> + * @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de + * @version 0.8.0 2011-03-11 + */ + + if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') { + include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php'); + $this->idn_converter = new idna_convert(array('idn_version' => 2008)); + $this->idn_converter_name = 'idna_convert.class'; + } + $domain = $this->idn_converter->decode($domain); + } } if($user_part !== false) return $user_part . '@' . $domain; else return $domain; } + + public function idn_encode($domain) { + $domains = explode("\n", $domain); + for($d = 0; $d < count($domains); $d++) { + $domains[$d] = $this->_idn_encode_decode($domains[$d], true); + } + return implode("\n", $domains); + } public function idn_decode($domain) { - if($domain == '') return ''; - if(preg_match('/^[0-9\.]+$/', $domain)) return $domain; // may be an ip address - anyway does not need to bee decoded - - // get domain and user part if it is an email - $user_part = false; - if(strpos($domain, '@') !== false) { - $user_part = substr($domain, 0, strrpos($domain, '@')); - $domain = substr($domain, strrpos($domain, '@') + 1); + $domains = explode("\n", $domain); + for($d = 0; $d < count($domains); $d++) { + $domains[$d] = $this->_idn_encode_decode($domains[$d], false); } - if(function_exists('idn_to_utf8')) { - $domain = idn_to_utf8($domain); - } elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) { - /* use idna class: - * @author Matthias Sommerfeld <mso@phlylabs.de> - * @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de - * @version 0.8.0 2011-03-11 - */ - - if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') { - include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php'); - $this->idn_converter = new idna_convert(array('idn_version' => 2008)); - $this->idn_converter_name = 'idna_convert.class'; - } - $domain = $this->idn_converter->decode($domain); - } - - if($user_part !== false) return $user_part . '@' . $domain; - else return $domain; + return implode("\n", $domains); } } -- Gitblit v1.9.1