From 2df08003a9129ebbda0d960b37e0f0ef58e579e4 Mon Sep 17 00:00:00 2001 From: Pascal Dreissen Date: Mon, 26 Feb 2018 11:08:49 +0100 Subject: [PATCH] Modified IP suggestions to only view the IP from the logged in customer. Added hints (description) to A or AAAA records. Fixes #4529, #4386, minor change on web statistics view. --- install/tpl/system.ini.master | 2 + interface/lib/classes/functions.inc.php | 97 ++++++++++++------- .../web/admin/form/system_config.tform.php | 14 +++ .../web/admin/lib/lang/en_system_config.lng | 3 + .../web/admin/lib/lang/nl_system_config.lng | 3 + .../templates/system_config_misc_edit.htm | 9 ++ .../lib/lang/en_web_sites_stats_list.lng | 4 +- .../lib/lang/nl_web_sites_stats_list.lng | 2 +- .../web/sites/list/web_sites_stats.list.php | 2 +- interface/web/sites/web_sites_stats.php | 7 ++ .../default/assets/stylesheets/ispconfig.css | 3 + 11 files changed, 110 insertions(+), 36 deletions(-) diff --git a/install/tpl/system.ini.master b/install/tpl/system.ini.master index 1988762c6c..b5a09ba5ff 100644 --- a/install/tpl/system.ini.master +++ b/install/tpl/system.ini.master @@ -53,6 +53,8 @@ tab_change_discard=n tab_change_warning=n use_loadindicator=y use_combobox=y +use_ipsuggestions=y +ipsuggestions_max=50 maintenance_mode=n admin_dashlets_left= admin_dashlets_right= diff --git a/interface/lib/classes/functions.inc.php b/interface/lib/classes/functions.inc.php index 83ec411d9a..e6f81c6fa6 100644 --- a/interface/lib/classes/functions.inc.php +++ b/interface/lib/classes/functions.inc.php @@ -182,11 +182,25 @@ class functions { } } + + /** + * Function to suggest IP addresses in selectbox with hints, limited to the client logged in. + * + * @access public + * @param string $type (default: 'IPv4') + * @return void + */ public function suggest_ips($type = 'IPv4'){ global $app; + $use_suggestions = $app->getconf->get_global_config('misc')['use_ipsuggestions'] == 'y' ? true : false;; + if(!$use_suggestions) {return array('cheader' => array(), 'cdata' => array());} + + $suggestions_max = $app->getconf->get_global_config('misc')['ipsuggestions_max']; + $groupid = intval($_SESSION["s"]["user"]["default_group"]); + if($type == 'IPv4'){ -// $regex = "/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/"; + // $regex = "/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/"; $regex = "/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/"; } else { // IPv6 @@ -198,58 +212,75 @@ class functions { $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']; + $server_by_id[$server['server_id']] = 'server: ' . $server['server_name'] . ''; } } + $localips = array(); $ips = array(); $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']; + $localips[] = $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"); if(!empty($results) && is_array($results)){ foreach($results as $result){ if(preg_match($regex, $result['ip'])) $ips[] = $result['ip']; } } - $results = $app->db->queryAllRecords("SELECT data AS ip FROM dns_rr WHERE type = 'A' OR type = 'AAAA'"); + $results = $groupid != 1 ? $app->db->queryAllRecords("SELECT rr.data AS server_ip, rr.name as server_name, soa.origin as domain FROM dns_rr as rr, dns_soa as soa WHERE (rr.type = 'A' OR rr.type = 'AAAA') AND soa.id = rr.zone AND rr.sys_groupid = ?", $groupid) : $results = $app->db->queryAllRecords("SELECT rr.data AS server_ip, rr.name as server_name, soa.origin as domain FROM dns_rr as rr, dns_soa as soa WHERE (rr.type = 'A' OR rr.type = 'AAAA') AND soa.id = rr.zone"); + if(!empty($results) && is_array($results)){ foreach($results as $result){ - if(preg_match($regex, $result['ip'])) $ips[] = $result['ip']; + $result['server_name'] = substr($result['server_name'], -1) == '.' ? $result['server_name'] : $result['server_name'] . '.' . $result['domain']; + if (!array_key_exists($result['server_ip'],$server_by_ip)) { + $server_by_ip[$result['server_ip']] = 'dns: ' . $result['server_name']; + if(preg_match($regex, $result['server_ip'])) $ips[] = $result['server_ip']; + } } } - $results = $app->db->queryAllRecords("SELECT ns AS ip FROM dns_slave"); + + $results = $groupid != 1 ? $app->db->queryAllRecords("SELECT ns AS ip FROM dns_slave WHERE sys_groupid = ?", $groupid) : $results = $app->db->queryAllRecords("SELECT ns AS ip FROM dns_slave"); + if(!empty($results) && is_array($results)){ foreach($results as $result){ - if(preg_match($regex, $result['ip'])) $ips[] = $result['ip']; + if (!array_key_exists($result['ip'],$server_by_ip)) { + if(preg_match($regex, $result['ip'])) $ips[] = $result['ip']; + } } } - - $results = $app->db->queryAllRecords("SELECT remote_ips FROM web_database WHERE remote_ips != ''"); + + $results = $groupid != 1 ? $app->db->queryAllRecords("SELECT database_name as name,remote_ips as ip FROM web_database WHERE remote_ips != '' AND sys_groupid = ?", $groupid) : $results = $app->db->queryAllRecords("SELECT database_name as name,remote_ips as ip FROM web_database WHERE remote_ips != ''"); + if(!empty($results) && is_array($results)){ foreach($results as $result){ - $tmp_ips = explode(',', $result['remote_ips']); + $tmp_ips = explode(',', $result['ip']); foreach($tmp_ips as $tmp_ip){ $tmp_ip = trim($tmp_ip); - if(preg_match($regex, $tmp_ip)) $ips[] = $tmp_ip; + if (!array_key_exists($tmp_ip,$server_by_ip)) { + $server_by_ip[$tmp_ip] = 'database: ' . $result['name']; + if(preg_match($regex, $tmp_ip)) $ips[] = $tmp_ip; + } } } } $ips = array_unique($ips); + sort($localips, SORT_NUMERIC); sort($ips, SORT_NUMERIC); - + $ips = array_merge($localips,$ips); + $ips = array_slice($ips, 0, $suggestions_max); $result_array = array('cheader' => array(), 'cdata' => array()); if(!empty($ips)){ $result_array['cheader'] = array('title' => 'IPs', 'total' => count($ips), - 'limit' => count($ips) + 'limit' => count($ips), ); foreach($ips as $ip){ @@ -282,7 +313,7 @@ class functions { */ public function formatBytes($size, $precision = 2) { $suffixes=array('', ' kB', ' MB', ' GB', ' TB'); - if($size != 0 && !is_nan($size)) { + if($size != 0 && !is_nan($size)) { $base=log($size)/log(1024); $tmpoutput = round(pow(1024, $base-floor($base)), $precision).$suffixes[floor($base)]; } else { @@ -371,42 +402,42 @@ class functions { public function is_allowed_user($username, $restrict_names = false) { global $app; - + $name_blacklist = array('root','ispconfig','vmail','getmail'); if(in_array($username,$name_blacklist)) return false; - + if(preg_match('/^[a-zA-Z0-9\.\-_]{1,32}$/', $username) == false) return false; - + if($restrict_names == true && preg_match('/^web\d+$/', $username) == false) return false; - + return true; } - + public function is_allowed_group($groupname, $restrict_names = false) { global $app; - + $name_blacklist = array('root','ispconfig','vmail','getmail'); if(in_array($groupname,$name_blacklist)) return false; - + if(preg_match('/^[a-zA-Z0-9\.\-_]{1,32}$/', $groupname) == false) return false; - + if($restrict_names == true && preg_match('/^client\d+$/', $groupname) == false) return false; - + return true; } - + public function getimagesizefromstring($string){ if (!function_exists('getimagesizefromstring')) { $uri = 'data://application/octet-stream;base64,' . base64_encode($string); return getimagesize($uri); } else { return getimagesizefromstring($string); - } + } } - + public function password($minLength = 10, $special = false){ global $app; - + $iteration = 0; $password = ""; $maxLength = $minLength + 5; @@ -431,7 +462,7 @@ class functions { public function getRandomInt($min, $max){ return floor((mt_rand() / mt_getrandmax()) * ($max - $min + 1)) + $min; } - + public function generate_customer_no(){ global $app; // generate customer no. @@ -439,13 +470,13 @@ class functions { while($app->db->queryOneRecord("SELECT client_id FROM client WHERE customer_no = ?", $customer_no)) { $customer_no = mt_rand(100000, 999999); } - + return $customer_no; } - + public function generate_ssh_key($client_id, $username = ''){ global $app; - + // generate the SSH key pair for the client $id_rsa_file = '/tmp/'.uniqid('',true); $id_rsa_pub_file = $id_rsa_file.'.pub'; @@ -459,7 +490,7 @@ class functions { $app->log("Failed to create SSH keypair for ".$username, LOGLEVEL_WARN); } } - + public function htmlentities($value) { global $conf; @@ -475,7 +506,7 @@ class functions { } else { $out = htmlentities($value, ENT_QUOTES, $conf["html_content_encoding"]); } - + return $out; } } diff --git a/interface/web/admin/form/system_config.tform.php b/interface/web/admin/form/system_config.tform.php index c3c4c969df..f1658a00b2 100644 --- a/interface/web/admin/form/system_config.tform.php +++ b/interface/web/admin/form/system_config.tform.php @@ -602,6 +602,20 @@ $form["tabs"]['misc'] = array ( 'default' => 'y', 'value' => array(0 => 'n', 1 => 'y') ), + 'use_ipsuggestions' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'y', + 'value' => array(0 => 'n', 1 => 'y') + ), + 'ipsuggestions_max' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), 'maintenance_mode' => array ( 'datatype' => 'VARCHAR', 'formtype' => 'CHECKBOX', diff --git a/interface/web/admin/lib/lang/en_system_config.lng b/interface/web/admin/lib/lang/en_system_config.lng index 945d60372f..ca8a3ebe8f 100644 --- a/interface/web/admin/lib/lang/en_system_config.lng +++ b/interface/web/admin/lib/lang/en_system_config.lng @@ -95,4 +95,7 @@ $wb['ca_iodef_txt'] = 'iodef'; $wb['active_txt'] = 'Aktive'; $wb['btn_save_txt'] = 'Save'; $wb['btn_cancel_txt'] = 'Cancel'; +$wb['use_ipsuggestions_txt'] = 'Enable IP suggestions dropdown'; +$wb['use_ipsuggestions_descr_txt'] = 'Shows a dropdown list of IP addresses below a field where an IP address is needed for both IPv4 and IPv6.'; +$wb['ipsuggestions_max_txt'] = 'Max IP suggestions'; ?> diff --git a/interface/web/admin/lib/lang/nl_system_config.lng b/interface/web/admin/lib/lang/nl_system_config.lng index 7b688a2bb8..416f9c0c17 100644 --- a/interface/web/admin/lib/lang/nl_system_config.lng +++ b/interface/web/admin/lib/lang/nl_system_config.lng @@ -91,4 +91,7 @@ $wb['active_txt'] = 'Aktive'; $wb['btn_save_txt'] = 'Save'; $wb['btn_cancel_txt'] = 'Cancel'; $wb['asp_new_package_disabled_txt'] = 'Disable new aps packages'; +$wb['use_ipsuggestions_txt'] = 'IP adres suggesties inschakelen'; +$wb['use_ipsuggestions_descr_txt'] = 'Toont een dropdown box met een lijst van IP adressen voor IPv4 en IPv6 adressen.'; +$wb['ipsuggestions_max_txt'] = 'Max aantal IP suggesties'; ?> diff --git a/interface/web/admin/templates/system_config_misc_edit.htm b/interface/web/admin/templates/system_config_misc_edit.htm index 45bdfcd275..5d35546a3e 100644 --- a/interface/web/admin/templates/system_config_misc_edit.htm +++ b/interface/web/admin/templates/system_config_misc_edit.htm @@ -81,6 +81,15 @@
+ +
+ {tmpl_var name='use_ipsuggestions'}
{tmpl_var name='use_ipsuggestions_descr_txt'} +
+
+
+ +
+
diff --git a/interface/web/sites/lib/lang/en_web_sites_stats_list.lng b/interface/web/sites/lib/lang/en_web_sites_stats_list.lng index 5afde57f6d..6645a3b2e7 100644 --- a/interface/web/sites/lib/lang/en_web_sites_stats_list.lng +++ b/interface/web/sites/lib/lang/en_web_sites_stats_list.lng @@ -6,4 +6,6 @@ $wb["last_month_txt"] = 'Last month'; $wb["this_year_txt"] = 'This year'; $wb["last_year_txt"] = 'Last year'; $wb["sum_txt"] = 'Sum'; -?> \ No newline at end of file +$wb["percentage_txt"] = 'In use %'; +$wb["quota_txt"] = 'Quota'; +?> diff --git a/interface/web/sites/lib/lang/nl_web_sites_stats_list.lng b/interface/web/sites/lib/lang/nl_web_sites_stats_list.lng index c9213dc70e..fa5568418c 100644 --- a/interface/web/sites/lib/lang/nl_web_sites_stats_list.lng +++ b/interface/web/sites/lib/lang/nl_web_sites_stats_list.lng @@ -6,6 +6,6 @@ $wb['last_month_txt'] = 'Vorige maand'; $wb['this_year_txt'] = 'Dit jaar'; $wb['last_year_txt'] = 'Vorig jaar'; $wb['sum_txt'] = 'Som'; -$wb['quota_txt'] = 'Quota'; $wb['percentage_txt'] = 'In gebruik %'; +$wb['quota_txt'] = 'Quota'; ?> diff --git a/interface/web/sites/list/web_sites_stats.list.php b/interface/web/sites/list/web_sites_stats.list.php index de4a062638..24e9eec6e5 100644 --- a/interface/web/sites/list/web_sites_stats.list.php +++ b/interface/web/sites/list/web_sites_stats.list.php @@ -43,7 +43,7 @@ $liste["paging_tpl"] = "templates/paging.tpl.htm"; $liste["auth"] = "yes"; // mark columns for php sorting (no real mySQL columns) -$liste["phpsort"] = array('this_month_sort', 'last_month_sort', 'this_year_sort', 'last_year_sort'); +$liste["phpsort"] = array('this_month_sort', 'last_month_sort', 'this_year_sort', 'last_year_sort', 'percentage', 'quota_sort'); /***************************************************** * Suchfelder diff --git a/interface/web/sites/web_sites_stats.php b/interface/web/sites/web_sites_stats.php index b607465ee8..09295f1579 100644 --- a/interface/web/sites/web_sites_stats.php +++ b/interface/web/sites/web_sites_stats.php @@ -67,7 +67,13 @@ class list_action extends listform_actions { $rec['last_year'] = $app->functions->formatBytes($tmp_rec['t']); $rec['last_year_sort'] = $tmp_rec['t']; $this->sum_last_year += $tmp_rec['t']; + $rec['percentage'] = $rec['traffic_quota'] == '-1' ? -1 : round((($rec['this_month_sort']/($rec['traffic_quota']*1024*1024))*100)); + $rec['progressbar'] = $rec['percentage'] > 100 ? 100 : $rec['percentage']; + $rec['quota_sort'] = $rec['traffic_quota']; + $rec['quota'] = $rec['traffic_quota'] == '-1' ? 'unlimited' : $app->functions->formatBytes($rec['traffic_quota']*1024*1024); + //echo 'quota: ' . $rec['traffic_quota']*1024*1024 . ' - traffic: ' . $rec['this_month_sort'] . ' - percentage: ' . $rec['percentage'] . ' - progressbar: ' . $rec['progressbar'] . '
'; + //var_dump($rec); //* The variable "id" contains always the index variable $rec['id'] = $rec[$this->idx_key]; @@ -97,3 +103,4 @@ $list->onLoad(); ?> + diff --git a/interface/web/themes/default/assets/stylesheets/ispconfig.css b/interface/web/themes/default/assets/stylesheets/ispconfig.css index e6ff41f2ab..9e93bf2308 100644 --- a/interface/web/themes/default/assets/stylesheets/ispconfig.css +++ b/interface/web/themes/default/assets/stylesheets/ispconfig.css @@ -800,3 +800,6 @@ span.pbvaluemargin { margin-left: 5px; } +.ip_suggestion_server { + font-weight: bold; +} -- GitLab