Skip to content

Commit 5672cd9

Browse files
committed
- Implemented FS#2294.
1 parent 5cf36a8 commit 5672cd9

File tree

8 files changed

+227
-16
lines changed

8 files changed

+227
-16
lines changed

interface/lib/classes/functions.inc.php

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function get_ispconfig_url() {
113113
return $url;
114114
}
115115

116-
function json_encode($data) {
116+
public function json_encode($data) {
117117
if(!function_exists('json_encode')){
118118
if(is_array($data) || is_object($data)){
119119
$islist = is_array($data) && (empty($data) || array_keys($data) === range(0,count($data)-1));
@@ -177,6 +177,105 @@ function json_encode($data) {
177177
return json_encode($data);
178178
}
179179
}
180+
181+
public function suggest_ips($type = 'IPv4'){
182+
global $app;
183+
184+
if($type == 'IPv4'){
185+
$regex = "/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/";
186+
} else {
187+
// IPv6
188+
$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";
189+
}
190+
191+
$ips = array();
192+
$results = $app->db->queryAllRecords("SELECT ip_address AS ip FROM server_ip WHERE ip_type = '".$type."'");
193+
if(!empty($results) && is_array($results)){
194+
foreach($results as $result){
195+
if(preg_match($regex, $result['ip'])) $ips[] = $result['ip'];
196+
}
197+
}
198+
$results = $app->db->queryAllRecords("SELECT ip_address AS ip FROM openvz_ip");
199+
if(!empty($results) && is_array($results)){
200+
foreach($results as $result){
201+
if(preg_match($regex, $result['ip'])) $ips[] = $result['ip'];
202+
}
203+
}
204+
$results = $app->db->queryAllRecords("SELECT data AS ip FROM dns_rr WHERE type = 'A' OR type = 'AAAA'");
205+
if(!empty($results) && is_array($results)){
206+
foreach($results as $result){
207+
if(preg_match($regex, $result['ip'])) $ips[] = $result['ip'];
208+
}
209+
}
210+
$results = $app->db->queryAllRecords("SELECT ns AS ip FROM dns_slave");
211+
if(!empty($results) && is_array($results)){
212+
foreach($results as $result){
213+
if(preg_match($regex, $result['ip'])) $ips[] = $result['ip'];
214+
}
215+
}
216+
217+
$results = $app->db->queryAllRecords("SELECT xfer FROM dns_slave WHERE xfer != ''");
218+
if(!empty($results) && is_array($results)){
219+
foreach($results as $result){
220+
$tmp_ips = explode(',', $result['xfer']);
221+
foreach($tmp_ips as $tmp_ip){
222+
$tmp_ip = trim($tmp_ip);
223+
if(preg_match($regex, $tmp_ip)) $ips[] = $tmp_ip;
224+
}
225+
}
226+
}
227+
$results = $app->db->queryAllRecords("SELECT xfer FROM dns_soa WHERE xfer != ''");
228+
if(!empty($results) && is_array($results)){
229+
foreach($results as $result){
230+
$tmp_ips = explode(',', $result['xfer']);
231+
foreach($tmp_ips as $tmp_ip){
232+
$tmp_ip = trim($tmp_ip);
233+
if(preg_match($regex, $tmp_ip)) $ips[] = $tmp_ip;
234+
}
235+
}
236+
}
237+
$results = $app->db->queryAllRecords("SELECT also_notify FROM dns_soa WHERE also_notify != ''");
238+
if(!empty($results) && is_array($results)){
239+
foreach($results as $result){
240+
$tmp_ips = explode(',', $result['also_notify']);
241+
foreach($tmp_ips as $tmp_ip){
242+
$tmp_ip = trim($tmp_ip);
243+
if(preg_match($regex, $tmp_ip)) $ips[] = $tmp_ip;
244+
}
245+
}
246+
}
247+
$results = $app->db->queryAllRecords("SELECT remote_ips FROM web_database WHERE remote_ips != ''");
248+
if(!empty($results) && is_array($results)){
249+
foreach($results as $result){
250+
$tmp_ips = explode(',', $result['remote_ips']);
251+
foreach($tmp_ips as $tmp_ip){
252+
$tmp_ip = trim($tmp_ip);
253+
if(preg_match($regex, $tmp_ip)) $ips[] = $tmp_ip;
254+
}
255+
}
256+
}
257+
$ips = array_unique($ips);
258+
sort($ips, SORT_NUMERIC);
259+
260+
$result_array = array('cheader' => array(), 'cdata' => array());
261+
262+
if(!empty($ips)){
263+
$result_array['cheader'] = array('title' => 'IPs',
264+
'total' => count($ips),
265+
'limit' => count($ips)
266+
);
267+
268+
foreach($ips as $ip){
269+
$result_array['cdata'][] = array( 'title' => $ip,
270+
'description' => $type,
271+
'onclick' => '',
272+
'fill_text' => $ip
273+
);
274+
}
275+
}
276+
277+
return $result_array;
278+
}
180279

181280

182281

interface/web/dns/ajax_get_json.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,42 +34,45 @@
3434
//* Check permissions for module
3535
$app->auth->check_module_permissions('dns');
3636

37-
$app->uses('tform');
37+
//$app->uses('tform');
3838

3939
$type = $_GET["type"];
4040

4141
//if($_SESSION["s"]["user"]["typ"] == 'admin') {
4242

4343

4444
if($type == 'get_ipv4'){
45-
$q = $app->db->quote(trim($_GET["q"]));
46-
$authsql = " AND ".$app->tform->getAuthSQL('r');
47-
$modules = explode(',', $_SESSION['s']['user']['modules']);
45+
//$q = $app->db->quote(trim($_GET["q"]));
46+
//$authsql = " AND ".$app->tform->getAuthSQL('r');
47+
//$modules = explode(',', $_SESSION['s']['user']['modules']);
4848

4949
$result = array();
5050

5151
// ipv4
52-
$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")");
52+
//$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")");
53+
$result[] = $app->functions->suggest_ips('IPv4');
5354

5455
$json = $app->functions->json_encode($result);
5556
}
5657

5758
if($type == 'get_ipv6'){
58-
$q = $app->db->quote(trim($_GET["q"]));
59-
$authsql = " AND ".$app->tform->getAuthSQL('r');
60-
$modules = explode(',', $_SESSION['s']['user']['modules']);
59+
//$q = $app->db->quote(trim($_GET["q"]));
60+
//$authsql = " AND ".$app->tform->getAuthSQL('r');
61+
//$modules = explode(',', $_SESSION['s']['user']['modules']);
6162

6263
$result = array();
6364

64-
// ipv4
65-
$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")");
66-
65+
// ipv6
66+
//$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")");
67+
$result[] = $app->functions->suggest_ips('IPv6');
68+
6769
$json = $app->functions->json_encode($result);
6870
}
6971

7072
//}
7173

72-
function _search($module, $section, $additional_sql = ''){
74+
/*
75+
function _search($module, $section, $additional_sql = '', $unique = false){
7376
global $app, $q, $authsql, $modules;
7477
7578
$result_array = array('cheader' => array(), 'cdata' => array());
@@ -143,11 +146,16 @@ function _search($module, $section, $additional_sql = ''){
143146
'onclick' => '',
144147
'fill_text' => $result[$title_key]
145148
);
146-
}
149+
}
150+
if($unique === true){
151+
$result_array['cdata'] = array_unique($result_array['cdata']);
152+
$result_array['cheader']['total'] = $result_array['cheader']['limit'] = count($result_array['cdata']);
153+
}
147154
}
148155
}
149156
return $result_array;
150157
}
158+
*/
151159

152160
header('Content-type: application/json');
153161
echo $json;

interface/web/dns/templates/dns_slave_edit.htm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,31 @@ <h2><tmpl_var name="list_head_txt"></h2>
6767
</div>
6868

6969
</div>
70+
<script language="JavaScript" type="text/javascript">
71+
jQuery('#ns').ispconfigSearch({
72+
dataSrc: '/dns/ajax_get_json.php?type=get_ipv4',
73+
resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">',
74+
ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">',
75+
noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">',
76+
noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">',
77+
minChars: 0,
78+
cssPrefix: 'df-',
79+
fillSearchField: true,
80+
fillSearchFieldWith: 'fill_text',
81+
searchFieldWatermark: '',
82+
resultBoxPosition: 'e'
83+
});
84+
jQuery('#xfer').ispconfigSearch({
85+
dataSrc: '/dns/ajax_get_json.php?type=get_ipv4',
86+
resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">',
87+
ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">',
88+
noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">',
89+
noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">',
90+
minChars: 0,
91+
cssPrefix: 'df-',
92+
fillSearchField: true,
93+
fillSearchFieldWith: 'fill_text',
94+
searchFieldWatermark: '',
95+
resultBoxPosition: 'e'
96+
});
97+
</script>

interface/web/dns/templates/dns_soa_edit.htm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,31 @@ <h2><tmpl_var name="list_head_txt"></h2>
101101
</div>
102102

103103
</div>
104+
<script language="JavaScript" type="text/javascript">
105+
jQuery('#xfer').ispconfigSearch({
106+
dataSrc: '/dns/ajax_get_json.php?type=get_ipv4',
107+
resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">',
108+
ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">',
109+
noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">',
110+
noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">',
111+
minChars: 0,
112+
cssPrefix: 'df-',
113+
fillSearchField: true,
114+
fillSearchFieldWith: 'fill_text',
115+
searchFieldWatermark: '',
116+
resultBoxPosition: 'e'
117+
});
118+
jQuery('#also_notify').ispconfigSearch({
119+
dataSrc: '/dns/ajax_get_json.php?type=get_ipv4',
120+
resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">',
121+
ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">',
122+
noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">',
123+
noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">',
124+
minChars: 0,
125+
cssPrefix: 'df-',
126+
fillSearchField: true,
127+
fillSearchFieldWith: 'fill_text',
128+
searchFieldWatermark: '',
129+
resultBoxPosition: 'e'
130+
});
131+
</script>

interface/web/sites/ajax_get_json.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,29 @@
9999
unset($php);
100100
$json .= '"}';
101101
}
102+
103+
if($type == 'get_ipv4'){
104+
$result = array();
105+
106+
// ipv4
107+
//$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv4' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")");
108+
$result[] = $app->functions->suggest_ips('IPv4');
109+
110+
$json = $app->functions->json_encode($result);
111+
}
112+
113+
if($type == 'get_ipv6'){
114+
$result = array();
115+
116+
// ipv6
117+
//$result[] = _search('admin', 'server_ip', "AND ip_type = 'IPv6' AND (client_id = 0 OR client_id=".intval($_SESSION['s']['user']['client_id']).")");
118+
$result[] = $app->functions->suggest_ips('IPv6');
119+
120+
$json = $app->functions->json_encode($result);
121+
}
102122

103123
//}
124+
104125
header('Content-type: application/json');
105126
echo $json;
106127
?>

interface/web/sites/lib/lang/de_database.lng

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ $wb['database_name_change_txt'] = 'Der Datenbankname kann nicht geändert werden
2121
$wb['database_charset_change_txt'] = 'Der Zeichensatz der Datenbank kann nicht geändert werden.';
2222
$wb['password_strength_txt'] = 'Passwortkomplexität';
2323
$wb['database_name_error_len'] = 'Datenbank Name - {db} - zu lang. Die max. Datenbank Namen Länge inkl. Präfix ist 64 Zeichen.';
24-
$wb['database_user_error_len'] = 'Datenbank Benutzername - {user}- zu lang. Die max. Datenbank Benutzernamen Länge inkl. Präfix ist 16 Zeichen.';
24+
$wb['database_user_error_len'] = 'Datenbank Benutzername - {user} - zu lang. Die max. Datenbank Benutzernamen Länge inkl. Präfix ist 16 Zeichen.';
2525
$wb['generate_password_txt'] = 'Passwort erzeugen';
2626
$wb["btn_save_txt"] = 'Speichern';
2727
$wb["btn_cancel_txt"] = 'Abbrechen';
2828
$wb["parent_domain_id_txt"] = 'Website';
2929
$wb["database_site_error_empty"] = 'Wählen Sie ein Website aus, zu der die Datenbank gehört.';
3030
$wb["select_site_txt"] = '- Website wählen -';
31+
$wb['globalsearch_resultslimit_of_txt'] = "von";
32+
$wb['globalsearch_resultslimit_results_txt'] = "Treffern";
33+
$wb['globalsearch_noresults_text_txt'] = "Keine Treffer.";
34+
$wb['globalsearch_noresults_limit_txt'] = "0 Treffer";
35+
$wb['globalsearch_searchfield_watermark_txt'] = "Suche";
36+
$wb['globalsearch_suggestions_text_txt'] = "Vorschläge";
3137
?>

interface/web/sites/lib/lang/en_database.lng

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $wb["limit_database_txt"] = 'The max. number of databases is reached.';
2121
$wb["database_name_change_txt"] = 'The database name can not be changed';
2222
$wb["database_charset_change_txt"] = 'The database charset can not be changed';
2323
$wb["database_name_error_len"] = 'Database name - {db} - too long. The max. database name length incl. prefix is 64 chars.';
24-
$wb["database_user_error_len"] = 'Database username - {user}- too long. The max. database username length incl. prefix is 16 chars.';
24+
$wb["database_user_error_len"] = 'Database username - {user} - too long. The max. database username length incl. prefix is 16 chars.';
2525
$wb["parent_domain_id_txt"] = 'Site';
2626
$wb["database_site_error_empty"] = 'Select the site to which the database belongs.';
2727
$wb["select_site_txt"] = '- Select Site -';
@@ -31,4 +31,10 @@ $wb['generate_password_txt'] = 'Generate Password';
3131
$wb['repeat_password_txt'] = 'Repeat Password';
3232
$wb['password_mismatch_txt'] = 'The passwords do not match.';
3333
$wb['password_match_txt'] = 'The passwords do match.';
34+
$wb['globalsearch_resultslimit_of_txt'] = "of";
35+
$wb['globalsearch_resultslimit_results_txt'] = "results";
36+
$wb['globalsearch_noresults_text_txt'] = "No results.";
37+
$wb['globalsearch_noresults_limit_txt'] = "0 results";
38+
$wb['globalsearch_searchfield_watermark_txt'] = "Search";
39+
$wb['globalsearch_suggestions_text_txt'] = "Suggestions";
3440
?>

interface/web/sites/templates/database_edit.htm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,18 @@ <h2><tmpl_var name="list_head_txt"></h2>
104104
</div>
105105

106106
</div>
107+
<script language="JavaScript" type="text/javascript">
108+
jQuery('#remote_ips').ispconfigSearch({
109+
dataSrc: '/sites/ajax_get_json.php?type=get_ipv4',
110+
resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">',
111+
ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">',
112+
noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">',
113+
noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">',
114+
minChars: 0,
115+
cssPrefix: 'df-',
116+
fillSearchField: true,
117+
fillSearchFieldWith: 'fill_text',
118+
searchFieldWatermark: '',
119+
resultBoxPosition: 'e'
120+
});
121+
</script>

0 commit comments

Comments
 (0)