From 5672cd94d3ce6504b97792c9594190f56cef40e3 Mon Sep 17 00:00:00 2001 From: ftimme <ft@falkotimme.com> Date: Wed, 27 Jun 2012 19:34:40 -0400 Subject: [PATCH] - Implemented FS#2294. --- interface/web/dns/templates/dns_soa_edit.htm | 28 +++++ interface/web/sites/lib/lang/de_database.lng | 8 + interface/web/sites/lib/lang/en_database.lng | 8 + interface/web/dns/templates/dns_slave_edit.htm | 28 +++++ interface/web/sites/templates/database_edit.htm | 15 +++ interface/web/dns/ajax_get_json.php | 34 ++++-- interface/web/sites/ajax_get_json.php | 21 ++++ interface/lib/classes/functions.inc.php | 101 ++++++++++++++++++++ 8 files changed, 227 insertions(+), 16 deletions(-) diff --git a/interface/lib/classes/functions.inc.php b/interface/lib/classes/functions.inc.php index 2b11427..fe02f14 100644 --- a/interface/lib/classes/functions.inc.php +++ b/interface/lib/classes/functions.inc.php @@ -113,7 +113,7 @@ return $url; } - function json_encode($data) { + public function json_encode($data) { if(!function_exists('json_encode')){ if(is_array($data) || is_object($data)){ $islist = is_array($data) && (empty($data) || array_keys($data) === range(0,count($data)-1)); @@ -177,6 +177,105 @@ return json_encode($data); } } + + public function suggest_ips($type = 'IPv4'){ + global $app; + + if($type == 'IPv4'){ + $regex = "/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/"; + } else { + // 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"; + } + + $ips = array(); + $results = $app->db->queryAllRecords("SELECT ip_address AS ip 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']; + } + } + $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'"); + if(!empty($results) && is_array($results)){ + foreach($results as $result){ + if(preg_match($regex, $result['ip'])) $ips[] = $result['ip']; + } + } + $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']; + } + } + + $results = $app->db->queryAllRecords("SELECT xfer FROM dns_slave WHERE xfer != ''"); + if(!empty($results) && is_array($results)){ + foreach($results as $result){ + $tmp_ips = explode(',', $result['xfer']); + foreach($tmp_ips as $tmp_ip){ + $tmp_ip = trim($tmp_ip); + if(preg_match($regex, $tmp_ip)) $ips[] = $tmp_ip; + } + } + } + $results = $app->db->queryAllRecords("SELECT xfer FROM dns_soa WHERE xfer != ''"); + if(!empty($results) && is_array($results)){ + foreach($results as $result){ + $tmp_ips = explode(',', $result['xfer']); + foreach($tmp_ips as $tmp_ip){ + $tmp_ip = trim($tmp_ip); + if(preg_match($regex, $tmp_ip)) $ips[] = $tmp_ip; + } + } + } + $results = $app->db->queryAllRecords("SELECT also_notify FROM dns_soa WHERE also_notify != ''"); + if(!empty($results) && is_array($results)){ + foreach($results as $result){ + $tmp_ips = explode(',', $result['also_notify']); + foreach($tmp_ips as $tmp_ip){ + $tmp_ip = trim($tmp_ip); + if(preg_match($regex, $tmp_ip)) $ips[] = $tmp_ip; + } + } + } + $results = $app->db->queryAllRecords("SELECT remote_ips FROM web_database WHERE remote_ips != ''"); + if(!empty($results) && is_array($results)){ + foreach($results as $result){ + $tmp_ips = explode(',', $result['remote_ips']); + foreach($tmp_ips as $tmp_ip){ + $tmp_ip = trim($tmp_ip); + if(preg_match($regex, $tmp_ip)) $ips[] = $tmp_ip; + } + } + } + $ips = array_unique($ips); + sort($ips, SORT_NUMERIC); + + $result_array = array('cheader' => array(), 'cdata' => array()); + + if(!empty($ips)){ + $result_array['cheader'] = array('title' => 'IPs', + 'total' => count($ips), + 'limit' => count($ips) + ); + + foreach($ips as $ip){ + $result_array['cdata'][] = array( 'title' => $ip, + 'description' => $type, + 'onclick' => '', + 'fill_text' => $ip + ); + } + } + + return $result_array; + } diff --git a/interface/web/dns/ajax_get_json.php b/interface/web/dns/ajax_get_json.php index 410bc77..3be847c 100644 --- a/interface/web/dns/ajax_get_json.php +++ b/interface/web/dns/ajax_get_json.php @@ -34,7 +34,7 @@ //* Check permissions for module $app->auth->check_module_permissions('dns'); -$app->uses('tform'); +//$app->uses('tform'); $type = $_GET["type"]; @@ -42,34 +42,37 @@ if($type == 'get_ipv4'){ - $q = $app->db->quote(trim($_GET["q"])); - $authsql = " AND ".$app->tform->getAuthSQL('r'); - $modules = explode(',', $_SESSION['s']['user']['modules']); + //$q = $app->db->quote(trim($_GET["q"])); + //$authsql = " AND ".$app->tform->getAuthSQL('r'); + //$modules = explode(',', $_SESSION['s']['user']['modules']); $result = array(); // ipv4 - $result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")"); + //$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")"); + $result[] = $app->functions->suggest_ips('IPv4'); $json = $app->functions->json_encode($result); } if($type == 'get_ipv6'){ - $q = $app->db->quote(trim($_GET["q"])); - $authsql = " AND ".$app->tform->getAuthSQL('r'); - $modules = explode(',', $_SESSION['s']['user']['modules']); + //$q = $app->db->quote(trim($_GET["q"])); + //$authsql = " AND ".$app->tform->getAuthSQL('r'); + //$modules = explode(',', $_SESSION['s']['user']['modules']); $result = array(); - // ipv4 - $result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")"); - + // ipv6 + //$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")"); + $result[] = $app->functions->suggest_ips('IPv6'); + $json = $app->functions->json_encode($result); } //} -function _search($module, $section, $additional_sql = ''){ +/* +function _search($module, $section, $additional_sql = '', $unique = false){ global $app, $q, $authsql, $modules; $result_array = array('cheader' => array(), 'cdata' => array()); @@ -143,11 +146,16 @@ 'onclick' => '', 'fill_text' => $result[$title_key] ); - } + } + if($unique === true){ + $result_array['cdata'] = array_unique($result_array['cdata']); + $result_array['cheader']['total'] = $result_array['cheader']['limit'] = count($result_array['cdata']); + } } } return $result_array; } +*/ header('Content-type: application/json'); echo $json; diff --git a/interface/web/dns/templates/dns_slave_edit.htm b/interface/web/dns/templates/dns_slave_edit.htm index 4cc0fde..52e0af2 100644 --- a/interface/web/dns/templates/dns_slave_edit.htm +++ b/interface/web/dns/templates/dns_slave_edit.htm @@ -67,3 +67,31 @@ </div> </div> +<script language="JavaScript" type="text/javascript"> + jQuery('#ns').ispconfigSearch({ + dataSrc: '/dns/ajax_get_json.php?type=get_ipv4', + resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">', + ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">', + noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">', + noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">', + minChars: 0, + cssPrefix: 'df-', + fillSearchField: true, + fillSearchFieldWith: 'fill_text', + searchFieldWatermark: '', + resultBoxPosition: 'e' + }); + jQuery('#xfer').ispconfigSearch({ + dataSrc: '/dns/ajax_get_json.php?type=get_ipv4', + resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">', + ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">', + noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">', + noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">', + minChars: 0, + cssPrefix: 'df-', + fillSearchField: true, + fillSearchFieldWith: 'fill_text', + searchFieldWatermark: '', + resultBoxPosition: 'e' + }); +</script> \ No newline at end of file diff --git a/interface/web/dns/templates/dns_soa_edit.htm b/interface/web/dns/templates/dns_soa_edit.htm index fa83123..6b7ced0 100644 --- a/interface/web/dns/templates/dns_soa_edit.htm +++ b/interface/web/dns/templates/dns_soa_edit.htm @@ -101,3 +101,31 @@ </div> </div> +<script language="JavaScript" type="text/javascript"> + jQuery('#xfer').ispconfigSearch({ + dataSrc: '/dns/ajax_get_json.php?type=get_ipv4', + resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">', + ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">', + noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">', + noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">', + minChars: 0, + cssPrefix: 'df-', + fillSearchField: true, + fillSearchFieldWith: 'fill_text', + searchFieldWatermark: '', + resultBoxPosition: 'e' + }); + jQuery('#also_notify').ispconfigSearch({ + dataSrc: '/dns/ajax_get_json.php?type=get_ipv4', + resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">', + ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">', + noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">', + noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">', + minChars: 0, + cssPrefix: 'df-', + fillSearchField: true, + fillSearchFieldWith: 'fill_text', + searchFieldWatermark: '', + resultBoxPosition: 'e' + }); +</script> \ No newline at end of file diff --git a/interface/web/sites/ajax_get_json.php b/interface/web/sites/ajax_get_json.php index 887f5da..14eb440 100644 --- a/interface/web/sites/ajax_get_json.php +++ b/interface/web/sites/ajax_get_json.php @@ -99,8 +99,29 @@ unset($php); $json .= '"}'; } + + if($type == 'get_ipv4'){ + $result = array(); + + // ipv4 + //$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")"); + $result[] = $app->functions->suggest_ips('IPv4'); + + $json = $app->functions->json_encode($result); + } + + if($type == 'get_ipv6'){ + $result = array(); + + // ipv6 + //$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")"); + $result[] = $app->functions->suggest_ips('IPv6'); + + $json = $app->functions->json_encode($result); + } //} + header('Content-type: application/json'); echo $json; ?> \ No newline at end of file diff --git a/interface/web/sites/lib/lang/de_database.lng b/interface/web/sites/lib/lang/de_database.lng index 0e10a09..f919586 100644 --- a/interface/web/sites/lib/lang/de_database.lng +++ b/interface/web/sites/lib/lang/de_database.lng @@ -21,11 +21,17 @@ $wb['database_charset_change_txt'] = 'Der Zeichensatz der Datenbank kann nicht geändert werden.'; $wb['password_strength_txt'] = 'Passwortkomplexität'; $wb['database_name_error_len'] = 'Datenbank Name - {db} - zu lang. Die max. Datenbank Namen Länge inkl. Präfix ist 64 Zeichen.'; -$wb['database_user_error_len'] = 'Datenbank Benutzername - {user}- zu lang. Die max. Datenbank Benutzernamen Länge inkl. Präfix ist 16 Zeichen.'; +$wb['database_user_error_len'] = 'Datenbank Benutzername - {user} - zu lang. Die max. Datenbank Benutzernamen Länge inkl. Präfix ist 16 Zeichen.'; $wb['generate_password_txt'] = 'Passwort erzeugen'; $wb["btn_save_txt"] = 'Speichern'; $wb["btn_cancel_txt"] = 'Abbrechen'; $wb["parent_domain_id_txt"] = 'Website'; $wb["database_site_error_empty"] = 'Wählen Sie ein Website aus, zu der die Datenbank gehört.'; $wb["select_site_txt"] = '- Website wählen -'; +$wb['globalsearch_resultslimit_of_txt'] = "von"; +$wb['globalsearch_resultslimit_results_txt'] = "Treffern"; +$wb['globalsearch_noresults_text_txt'] = "Keine Treffer."; +$wb['globalsearch_noresults_limit_txt'] = "0 Treffer"; +$wb['globalsearch_searchfield_watermark_txt'] = "Suche"; +$wb['globalsearch_suggestions_text_txt'] = "Vorschläge"; ?> diff --git a/interface/web/sites/lib/lang/en_database.lng b/interface/web/sites/lib/lang/en_database.lng index 3d21df9..8a470c7 100644 --- a/interface/web/sites/lib/lang/en_database.lng +++ b/interface/web/sites/lib/lang/en_database.lng @@ -21,7 +21,7 @@ $wb["database_name_change_txt"] = 'The database name can not be changed'; $wb["database_charset_change_txt"] = 'The database charset can not be changed'; $wb["database_name_error_len"] = 'Database name - {db} - too long. The max. database name length incl. prefix is 64 chars.'; -$wb["database_user_error_len"] = 'Database username - {user}- too long. The max. database username length incl. prefix is 16 chars.'; +$wb["database_user_error_len"] = 'Database username - {user} - too long. The max. database username length incl. prefix is 16 chars.'; $wb["parent_domain_id_txt"] = 'Site'; $wb["database_site_error_empty"] = 'Select the site to which the database belongs.'; $wb["select_site_txt"] = '- Select Site -'; @@ -31,4 +31,10 @@ $wb['repeat_password_txt'] = 'Repeat Password'; $wb['password_mismatch_txt'] = 'The passwords do not match.'; $wb['password_match_txt'] = 'The passwords do match.'; +$wb['globalsearch_resultslimit_of_txt'] = "of"; +$wb['globalsearch_resultslimit_results_txt'] = "results"; +$wb['globalsearch_noresults_text_txt'] = "No results."; +$wb['globalsearch_noresults_limit_txt'] = "0 results"; +$wb['globalsearch_searchfield_watermark_txt'] = "Search"; +$wb['globalsearch_suggestions_text_txt'] = "Suggestions"; ?> diff --git a/interface/web/sites/templates/database_edit.htm b/interface/web/sites/templates/database_edit.htm index 558e311..01dfe03 100644 --- a/interface/web/sites/templates/database_edit.htm +++ b/interface/web/sites/templates/database_edit.htm @@ -104,3 +104,18 @@ </div> </div> +<script language="JavaScript" type="text/javascript"> + jQuery('#remote_ips').ispconfigSearch({ + dataSrc: '/sites/ajax_get_json.php?type=get_ipv4', + resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">', + ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">', + noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">', + noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">', + minChars: 0, + cssPrefix: 'df-', + fillSearchField: true, + fillSearchFieldWith: 'fill_text', + searchFieldWatermark: '', + resultBoxPosition: 'e' + }); +</script> \ No newline at end of file -- Gitblit v1.9.1