Skip to content

Commit 3ff36ab

Browse files
author
Marius Burkard
committed
Merge branch 'master' into 'master'
Modified IP suggestions to only view the IP from the logged in customer. Added… Closes #4529 and #4386 See merge request ispconfig/ispconfig3!751
2 parents 19f37d3 + 2c9d574 commit 3ff36ab

File tree

11 files changed

+110
-36
lines changed

11 files changed

+110
-36
lines changed

install/tpl/system.ini.master

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ tab_change_discard=n
5353
tab_change_warning=n
5454
use_loadindicator=y
5555
use_combobox=y
56+
use_ipsuggestions=y
57+
ipsuggestions_max=50
5658
maintenance_mode=n
5759
admin_dashlets_left=
5860
admin_dashlets_right=

interface/lib/classes/functions.inc.php

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,25 @@ public function json_encode($data) {
182182
}
183183
}
184184

185+
186+
/**
187+
* Function to suggest IP addresses in selectbox with hints, limited to the client logged in.
188+
*
189+
* @access public
190+
* @param string $type (default: 'IPv4')
191+
* @return void
192+
*/
185193
public function suggest_ips($type = 'IPv4'){
186194
global $app;
187195

196+
$use_suggestions = $app->getconf->get_global_config('misc')['use_ipsuggestions'] == 'y' ? true : false;;
197+
if(!$use_suggestions) {return array('cheader' => array(), 'cdata' => array());}
198+
199+
$suggestions_max = $app->getconf->get_global_config('misc')['ipsuggestions_max'];
200+
$groupid = intval($_SESSION["s"]["user"]["default_group"]);
201+
188202
if($type == 'IPv4'){
189-
// $regex = "/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/";
203+
// $regex = "/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/";
190204
$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]?)$/";
191205
} else {
192206
// IPv6
@@ -198,58 +212,75 @@ public function suggest_ips($type = 'IPv4'){
198212
$servers = $app->db->queryAllRecords("SELECT * FROM server");
199213
if(is_array($servers) && !empty($servers)){
200214
foreach($servers as $server){
201-
$server_by_id[$server['server_id']] = $server['server_name'];
215+
$server_by_id[$server['server_id']] = '<span class="ip_suggestion_server">server: ' . $server['server_name'] . '</span>';
202216
}
203217
}
204218

219+
$localips = array();
205220
$ips = array();
206221
$results = $app->db->queryAllRecords("SELECT ip_address AS ip, server_id FROM server_ip WHERE ip_type = ?", $type);
207222
if(!empty($results) && is_array($results)){
208223
foreach($results as $result){
209224
if(preg_match($regex, $result['ip'])){
210-
$ips[] = $result['ip'];
225+
$localips[] = $result['ip'];
211226
$server_by_ip[$result['ip']] = $server_by_id[$result['server_id']];
212227
}
213228
}
214229
}
230+
215231
$results = $app->db->queryAllRecords("SELECT ip_address AS ip FROM openvz_ip");
216232
if(!empty($results) && is_array($results)){
217233
foreach($results as $result){
218234
if(preg_match($regex, $result['ip'])) $ips[] = $result['ip'];
219235
}
220236
}
221-
$results = $app->db->queryAllRecords("SELECT data AS ip FROM dns_rr WHERE type = 'A' OR type = 'AAAA'");
237+
$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");
238+
222239
if(!empty($results) && is_array($results)){
223240
foreach($results as $result){
224-
if(preg_match($regex, $result['ip'])) $ips[] = $result['ip'];
241+
$result['server_name'] = substr($result['server_name'], -1) == '.' ? $result['server_name'] : $result['server_name'] . '.' . $result['domain'];
242+
if (!array_key_exists($result['server_ip'],$server_by_ip)) {
243+
$server_by_ip[$result['server_ip']] = 'dns: ' . $result['server_name'];
244+
if(preg_match($regex, $result['server_ip'])) $ips[] = $result['server_ip'];
245+
}
225246
}
226247
}
227-
$results = $app->db->queryAllRecords("SELECT ns AS ip FROM dns_slave");
248+
249+
$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");
250+
228251
if(!empty($results) && is_array($results)){
229252
foreach($results as $result){
230-
if(preg_match($regex, $result['ip'])) $ips[] = $result['ip'];
253+
if (!array_key_exists($result['ip'],$server_by_ip)) {
254+
if(preg_match($regex, $result['ip'])) $ips[] = $result['ip'];
255+
}
231256
}
232257
}
233-
234-
$results = $app->db->queryAllRecords("SELECT remote_ips FROM web_database WHERE remote_ips != ''");
258+
259+
$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 != ''");
260+
235261
if(!empty($results) && is_array($results)){
236262
foreach($results as $result){
237-
$tmp_ips = explode(',', $result['remote_ips']);
263+
$tmp_ips = explode(',', $result['ip']);
238264
foreach($tmp_ips as $tmp_ip){
239265
$tmp_ip = trim($tmp_ip);
240-
if(preg_match($regex, $tmp_ip)) $ips[] = $tmp_ip;
266+
if (!array_key_exists($tmp_ip,$server_by_ip)) {
267+
$server_by_ip[$tmp_ip] = 'database: ' . $result['name'];
268+
if(preg_match($regex, $tmp_ip)) $ips[] = $tmp_ip;
269+
}
241270
}
242271
}
243272
}
244273
$ips = array_unique($ips);
274+
sort($localips, SORT_NUMERIC);
245275
sort($ips, SORT_NUMERIC);
246-
276+
$ips = array_merge($localips,$ips);
277+
$ips = array_slice($ips, 0, $suggestions_max);
247278
$result_array = array('cheader' => array(), 'cdata' => array());
248279

249280
if(!empty($ips)){
250281
$result_array['cheader'] = array('title' => 'IPs',
251282
'total' => count($ips),
252-
'limit' => count($ips)
283+
'limit' => count($ips),
253284
);
254285

255286
foreach($ips as $ip){
@@ -282,7 +313,7 @@ public function intval($string, $force_numeric = false) {
282313
*/
283314
public function formatBytes($size, $precision = 2) {
284315
$suffixes=array('', ' kB', ' MB', ' GB', ' TB');
285-
if($size != 0 && !is_nan($size)) {
316+
if($size != 0 && !is_nan($size)) {
286317
$base=log($size)/log(1024);
287318
$tmpoutput = round(pow(1024, $base-floor($base)), $precision).$suffixes[floor($base)];
288319
} else {
@@ -371,42 +402,42 @@ public function idn_decode($domain) {
371402

372403
public function is_allowed_user($username, $restrict_names = false) {
373404
global $app;
374-
405+
375406
$name_blacklist = array('root','ispconfig','vmail','getmail');
376407
if(in_array($username,$name_blacklist)) return false;
377-
408+
378409
if(preg_match('/^[a-zA-Z0-9\.\-_]{1,32}$/', $username) == false) return false;
379-
410+
380411
if($restrict_names == true && preg_match('/^web\d+$/', $username) == false) return false;
381-
412+
382413
return true;
383414
}
384-
415+
385416
public function is_allowed_group($groupname, $restrict_names = false) {
386417
global $app;
387-
418+
388419
$name_blacklist = array('root','ispconfig','vmail','getmail');
389420
if(in_array($groupname,$name_blacklist)) return false;
390-
421+
391422
if(preg_match('/^[a-zA-Z0-9\.\-_]{1,32}$/', $groupname) == false) return false;
392-
423+
393424
if($restrict_names == true && preg_match('/^client\d+$/', $groupname) == false) return false;
394-
425+
395426
return true;
396427
}
397-
428+
398429
public function getimagesizefromstring($string){
399430
if (!function_exists('getimagesizefromstring')) {
400431
$uri = 'data://application/octet-stream;base64,' . base64_encode($string);
401432
return getimagesize($uri);
402433
} else {
403434
return getimagesizefromstring($string);
404-
}
435+
}
405436
}
406-
437+
407438
public function password($minLength = 10, $special = false){
408439
global $app;
409-
440+
410441
$iteration = 0;
411442
$password = "";
412443
$maxLength = $minLength + 5;
@@ -431,21 +462,21 @@ public function password($minLength = 10, $special = false){
431462
public function getRandomInt($min, $max){
432463
return floor((mt_rand() / mt_getrandmax()) * ($max - $min + 1)) + $min;
433464
}
434-
465+
435466
public function generate_customer_no(){
436467
global $app;
437468
// generate customer no.
438469
$customer_no = mt_rand(100000, 999999);
439470
while($app->db->queryOneRecord("SELECT client_id FROM client WHERE customer_no = ?", $customer_no)) {
440471
$customer_no = mt_rand(100000, 999999);
441472
}
442-
473+
443474
return $customer_no;
444475
}
445-
476+
446477
public function generate_ssh_key($client_id, $username = ''){
447478
global $app;
448-
479+
449480
// generate the SSH key pair for the client
450481
$id_rsa_file = '/tmp/'.uniqid('',true);
451482
$id_rsa_pub_file = $id_rsa_file.'.pub';
@@ -459,7 +490,7 @@ public function generate_ssh_key($client_id, $username = ''){
459490
$app->log("Failed to create SSH keypair for ".$username, LOGLEVEL_WARN);
460491
}
461492
}
462-
493+
463494
public function htmlentities($value) {
464495
global $conf;
465496

@@ -475,7 +506,7 @@ public function htmlentities($value) {
475506
} else {
476507
$out = htmlentities($value, ENT_QUOTES, $conf["html_content_encoding"]);
477508
}
478-
509+
479510
return $out;
480511
}
481512
}

interface/web/admin/form/system_config.tform.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,20 @@
602602
'default' => 'y',
603603
'value' => array(0 => 'n', 1 => 'y')
604604
),
605+
'use_ipsuggestions' => array (
606+
'datatype' => 'VARCHAR',
607+
'formtype' => 'CHECKBOX',
608+
'default' => 'y',
609+
'value' => array(0 => 'n', 1 => 'y')
610+
),
611+
'ipsuggestions_max' => array (
612+
'datatype' => 'INTEGER',
613+
'formtype' => 'TEXT',
614+
'default' => '',
615+
'value' => '',
616+
'width' => '30',
617+
'maxlength' => '255'
618+
),
605619
'maintenance_mode' => array (
606620
'datatype' => 'VARCHAR',
607621
'formtype' => 'CHECKBOX',

interface/web/admin/lib/lang/en_system_config.lng

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,7 @@ $wb['ca_iodef_txt'] = 'iodef';
9595
$wb['active_txt'] = 'Aktive';
9696
$wb['btn_save_txt'] = 'Save';
9797
$wb['btn_cancel_txt'] = 'Cancel';
98+
$wb['use_ipsuggestions_txt'] = 'Enable IP suggestions dropdown';
99+
$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.';
100+
$wb['ipsuggestions_max_txt'] = 'Max IP suggestions';
98101
?>

interface/web/admin/lib/lang/nl_system_config.lng

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,7 @@ $wb['active_txt'] = 'Aktive';
9191
$wb['btn_save_txt'] = 'Save';
9292
$wb['btn_cancel_txt'] = 'Cancel';
9393
$wb['asp_new_package_disabled_txt'] = 'Disable new aps packages';
94+
$wb['use_ipsuggestions_txt'] = 'IP adres suggesties inschakelen';
95+
$wb['use_ipsuggestions_descr_txt'] = 'Toont een dropdown box met een lijst van IP adressen voor IPv4 en IPv6 adressen.';
96+
$wb['ipsuggestions_max_txt'] = 'Max aantal IP suggesties';
9497
?>

interface/web/admin/templates/system_config_misc_edit.htm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ <h1><tmpl_var name="list_head_txt"></h1>
8181
</div>
8282
</div>
8383
<div class="form-group">
84+
<label class="col-sm-3 control-label">{tmpl_var name='use_ipsuggestions_txt'}</label>
85+
<div class="col-sm-9">
86+
{tmpl_var name='use_ipsuggestions'}<br/>{tmpl_var name='use_ipsuggestions_descr_txt'}
87+
</div>
88+
</div>
89+
<div class="form-group">
90+
<label for="ipsuggestions_max" class="col-sm-3 control-label">{tmpl_var name='ipsuggestions_max_txt'}</label>
91+
<div class="col-sm-9"><input type="text" name="ipsuggestions_max" id="ipsuggestions_max" value="{tmpl_var name='ipsuggestions_max'}" class="form-control" /></div></div>
92+
<div class="form-group">
8493
<label for="customer_no_template" class="col-sm-3 control-label">{tmpl_var name='customer_no_template_txt'}</label>
8594
<div class="col-sm-9"><input type="text" name="customer_no_template" id="customer_no_template" value="{tmpl_var name='customer_no_template'}" class="form-control" /></div></div>
8695
<div class="form-group">

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ $wb["last_month_txt"] = 'Last month';
66
$wb["this_year_txt"] = 'This year';
77
$wb["last_year_txt"] = 'Last year';
88
$wb["sum_txt"] = 'Sum';
9-
?>
9+
$wb["percentage_txt"] = 'In use %';
10+
$wb["quota_txt"] = 'Quota';
11+
?>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ $wb['last_month_txt'] = 'Vorige maand';
66
$wb['this_year_txt'] = 'Dit jaar';
77
$wb['last_year_txt'] = 'Vorig jaar';
88
$wb['sum_txt'] = 'Som';
9-
$wb['quota_txt'] = 'Quota';
109
$wb['percentage_txt'] = 'In gebruik %';
10+
$wb['quota_txt'] = 'Quota';
1111
?>

interface/web/sites/list/web_sites_stats.list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
$liste["auth"] = "yes";
4444

4545
// mark columns for php sorting (no real mySQL columns)
46-
$liste["phpsort"] = array('this_month_sort', 'last_month_sort', 'this_year_sort', 'last_year_sort');
46+
$liste["phpsort"] = array('this_month_sort', 'last_month_sort', 'this_year_sort', 'last_year_sort', 'percentage', 'quota_sort');
4747

4848
/*****************************************************
4949
* Suchfelder

interface/web/sites/web_sites_stats.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ function prepareDataRow($rec)
6767
$rec['last_year'] = $app->functions->formatBytes($tmp_rec['t']);
6868
$rec['last_year_sort'] = $tmp_rec['t'];
6969
$this->sum_last_year += $tmp_rec['t'];
70+
$rec['percentage'] = $rec['traffic_quota'] == '-1' ? -1 : round((($rec['this_month_sort']/($rec['traffic_quota']*1024*1024))*100));
71+
$rec['progressbar'] = $rec['percentage'] > 100 ? 100 : $rec['percentage'];
72+
$rec['quota_sort'] = $rec['traffic_quota'];
73+
$rec['quota'] = $rec['traffic_quota'] == '-1' ? 'unlimited' : $app->functions->formatBytes($rec['traffic_quota']*1024*1024);
74+
//echo 'quota: ' . $rec['traffic_quota']*1024*1024 . ' - traffic: ' . $rec['this_month_sort'] . ' - percentage: ' . $rec['percentage'] . ' - progressbar: ' . $rec['progressbar'] . '<br/>';
7075

76+
//var_dump($rec);
7177
//* The variable "id" contains always the index variable
7278
$rec['id'] = $rec[$this->idx_key];
7379

@@ -97,3 +103,4 @@ function onShowEnd()
97103

98104

99105
?>
106+

0 commit comments

Comments
 (0)