Skip to content

Commit a6c847e

Browse files
committed
add ipv6-addresses for ispconfig slave-users on the master-server (#5493)
1 parent 5fb17b6 commit a6c847e

File tree

1 file changed

+104
-76
lines changed

1 file changed

+104
-76
lines changed

install/lib/installer_base.lib.php

Lines changed: 104 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -409,80 +409,92 @@ public function add_database_server_record() {
409409

410410

411411
}
412-
412+
413+
public function get_host_ips() {
414+
$out = array();
415+
exec('hostname --all-ip-addresses', $ret, $val);
416+
if($val == 0) {
417+
if(is_array($ret) && !empty($ret)){
418+
$temp = (explode(' ', $ret[0]));
419+
foreach($temp as $ip) {
420+
$out[] = $ip;
421+
}
422+
}
423+
}
424+
425+
return $out;
426+
}
427+
413428
public function detect_ips(){
414429
global $conf;
430+
431+
$output = $this->get_host_ips();
415432

416-
exec("ip addr show | awk '/global/ { print $2 }' | cut -d '/' -f 1", $output, $retval);
417-
418-
if($retval == 0){
419-
if(is_array($output) && !empty($output)){
420-
foreach($output as $line){
421-
$line = trim($line);
422-
$ip_type = '';
423-
if (filter_var($line, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
424-
$ip_type = 'IPv4';
425-
}
426-
if (filter_var($line, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
427-
$ip_type = 'IPv6';
428-
}
429-
if($ip_type == '') continue;
430-
if($this->db->dbHost != $this->dbmaster->dbHost){
431-
$this->dbmaster->query('INSERT INTO server_ip (
432-
sys_userid, sys_groupid, sys_perm_user, sys_perm_group,
433-
sys_perm_other, server_id, client_id, ip_type, ip_address,
434-
virtualhost, virtualhost_port
435-
) VALUES (
436-
1,
437-
1,
438-
"riud",
439-
"riud",
440-
"",
441-
?,
442-
0,
443-
?,
444-
?,
445-
"y",
446-
"80,443"
447-
)', $conf['server_id'], $ip_type, $line);
448-
$server_ip_id = $this->dbmaster->insertID();
449-
$this->db->query('INSERT INTO server_ip (
450-
server_php_id, sys_userid, sys_groupid, sys_perm_user, sys_perm_group,
451-
sys_perm_other, server_id, client_id, ip_type, ip_address,
452-
virtualhost, virtualhost_port
453-
) VALUES (
454-
?,
455-
1,
456-
1,
457-
"riud",
458-
"riud",
459-
"",
460-
?,
461-
0,
462-
?,
463-
?,
464-
"y",
465-
"80,443"
466-
)', $server_ip_id, $conf['server_id'], $ip_type, $line);
467-
} else {
468-
$this->db->query('INSERT INTO server_ip (
469-
sys_userid, sys_groupid, sys_perm_user, sys_perm_group,
470-
sys_perm_other, server_id, client_id, ip_type, ip_address,
471-
virtualhost, virtualhost_port
472-
) VALUES (
473-
1,
474-
1,
475-
"riud",
476-
"riud",
477-
"",
478-
?,
479-
0,
480-
?,
481-
?,
482-
"y",
483-
"80,443"
484-
)', $conf['server_id'], $ip_type, $line);
485-
}
433+
if(is_array($output) && !empty($output)){
434+
foreach($output as $line){
435+
$ip_type = '';
436+
if (filter_var($line, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
437+
$ip_type = 'IPv4';
438+
}
439+
if (filter_var($line, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
440+
$ip_type = 'IPv6';
441+
}
442+
if($ip_type == '') continue;
443+
if($this->db->dbHost != $this->dbmaster->dbHost){
444+
$this->dbmaster->query('INSERT INTO server_ip (
445+
sys_userid, sys_groupid, sys_perm_user, sys_perm_group,
446+
sys_perm_other, server_id, client_id, ip_type, ip_address,
447+
virtualhost, virtualhost_port
448+
) VALUES (
449+
1,
450+
1,
451+
"riud",
452+
"riud",
453+
"",
454+
?,
455+
0,
456+
?,
457+
?,
458+
"y",
459+
"80,443"
460+
)', $conf['server_id'], $ip_type, $line);
461+
$server_ip_id = $this->dbmaster->insertID();
462+
$this->db->query('INSERT INTO server_ip (
463+
server_php_id, sys_userid, sys_groupid, sys_perm_user, sys_perm_group,
464+
sys_perm_other, server_id, client_id, ip_type, ip_address,
465+
virtualhost, virtualhost_port
466+
) VALUES (
467+
?,
468+
1,
469+
1,
470+
"riud",
471+
"riud",
472+
"",
473+
?,
474+
0,
475+
?,
476+
?,
477+
"y",
478+
"80,443"
479+
)', $server_ip_id, $conf['server_id'], $ip_type, $line);
480+
} else {
481+
$this->db->query('INSERT INTO server_ip (
482+
sys_userid, sys_groupid, sys_perm_user, sys_perm_group,
483+
sys_perm_other, server_id, client_id, ip_type, ip_address,
484+
virtualhost, virtualhost_port
485+
) VALUES (
486+
1,
487+
1,
488+
"riud",
489+
"riud",
490+
"",
491+
?,
492+
0,
493+
?,
494+
?,
495+
"y",
496+
"80,443"
497+
)', $conf['server_id'], $ip_type, $line);
486498
}
487499
}
488500
}
@@ -509,15 +521,23 @@ public function grant_master_database_rights($verbose = false) {
509521

510522
//* insert the ispconfig user in the remote server
511523
$from_host = $conf['hostname'];
512-
$from_ip = gethostbyname($conf['hostname']);
513-
514524
$hosts[$from_host]['user'] = $conf['mysql']['master_ispconfig_user'];
515525
$hosts[$from_host]['db'] = $conf['mysql']['master_database'];
516526
$hosts[$from_host]['pwd'] = $conf['mysql']['master_ispconfig_password'];
517527

518-
$hosts[$from_ip]['user'] = $conf['mysql']['master_ispconfig_user'];
519-
$hosts[$from_ip]['db'] = $conf['mysql']['master_database'];
520-
$hosts[$from_ip]['pwd'] = $conf['mysql']['master_ispconfig_password'];
528+
$host_ips = $this->get_host_ips();
529+
if(is_arary($host_ips) && !empty($host_ips)) {
530+
foreach($host_ips as $ip) {
531+
$hosts[$ip]['user'] = $conf['mysql']['master_ispconfig_user'];
532+
$hosts[$ip]['db'] = $conf['mysql']['master_database'];
533+
$hosts[$ip]['pwd'] = $conf['mysql']['master_ispconfig_password'];
534+
}
535+
} else {
536+
$from_ip = gethostbyname($conf['hostname']);
537+
$hosts[$from_ip]['user'] = $conf['mysql']['master_ispconfig_user'];
538+
$hosts[$from_ip]['db'] = $conf['mysql']['master_database'];
539+
$hosts[$from_ip]['pwd'] = $conf['mysql']['master_ispconfig_password'];
540+
}
521541
} else{
522542
/*
523543
* it is NOT a master-slave - Setup so we have to find out all clients and their
@@ -696,6 +716,14 @@ public function grant_master_database_rights($verbose = false) {
696716
$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
697717
}
698718

719+
$query = "GRANT SELECT, INSERT, UPDATE ON ?? TO ?@?";
720+
if ($verbose){
721+
echo $query ."\n";
722+
}
723+
if(!$this->dbmaster->query($query, $value['db'] . '.managed_php', $value['user'], $host)) {
724+
$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
725+
}
726+
699727
}
700728

701729
}

0 commit comments

Comments
 (0)