normalize ipv6 addresses to avoid possible comparison problems; fixes #965
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -721,7 +721,7 @@ opcache.interned_strings_buffer'),
|
|||||||
('panel', 'logo_overridetheme', '0'),
|
('panel', 'logo_overridetheme', '0'),
|
||||||
('panel', 'logo_overridecustom', '0'),
|
('panel', 'logo_overridecustom', '0'),
|
||||||
('panel', 'version', '0.10.27'),
|
('panel', 'version', '0.10.27'),
|
||||||
('panel', 'db_version', '202107210');
|
('panel', 'db_version', '202107260');
|
||||||
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `panel_tasks`;
|
DROP TABLE IF EXISTS `panel_tasks`;
|
||||||
|
|||||||
@@ -687,7 +687,7 @@ class FroxlorInstall
|
|||||||
if (version_compare($db_root->getAttribute(\PDO::ATTR_SERVER_VERSION), '8.0.11', '>=')) {
|
if (version_compare($db_root->getAttribute(\PDO::ATTR_SERVER_VERSION), '8.0.11', '>=')) {
|
||||||
// create user
|
// create user
|
||||||
$stmt = $db_root->prepare("
|
$stmt = $db_root->prepare("
|
||||||
CREATE USER '" . $username . "'@'" . $access_host . "' IDENTIFIED BY :password
|
CREATE USER '" . $username . "'@'" . $access_host . "' IDENTIFIED WITH mysql_native_password BY :password
|
||||||
");
|
");
|
||||||
$stmt->execute(array(
|
$stmt->execute(array(
|
||||||
"password" => $password
|
"password" => $password
|
||||||
@@ -1310,10 +1310,12 @@ class FroxlorInstall
|
|||||||
// from form
|
// from form
|
||||||
if (! empty($_POST['serverip'])) {
|
if (! empty($_POST['serverip'])) {
|
||||||
$this->_data['serverip'] = $_POST['serverip'];
|
$this->_data['serverip'] = $_POST['serverip'];
|
||||||
|
$this->_data['serverip'] = inet_ntop(inet_pton($this->_data['serverip']));
|
||||||
return;
|
return;
|
||||||
// from $_SERVER
|
// from $_SERVER
|
||||||
} elseif (! empty($_SERVER['SERVER_ADDR'])) {
|
} elseif (! empty($_SERVER['SERVER_ADDR'])) {
|
||||||
$this->_data['serverip'] = $_SERVER['SERVER_ADDR'];
|
$this->_data['serverip'] = $_SERVER['SERVER_ADDR'];
|
||||||
|
$this->_data['serverip'] = inet_ntop(inet_pton($this->_data['serverip']));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// empty
|
// empty
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
use Froxlor\Database\Database;
|
use Froxlor\Database\Database;
|
||||||
use Froxlor\Settings;
|
use Froxlor\Settings;
|
||||||
|
use Froxlor\Validate\Validate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file is part of the Froxlor project.
|
* This file is part of the Froxlor project.
|
||||||
@@ -882,3 +883,23 @@ if (\Froxlor\Froxlor::isDatabaseVersion('202107200')) {
|
|||||||
lastStepStatus(0);
|
lastStepStatus(0);
|
||||||
\Froxlor\Froxlor::updateToDbVersion('202107210');
|
\Froxlor\Froxlor::updateToDbVersion('202107210');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\Froxlor\Froxlor::isDatabaseVersion('202107210')) {
|
||||||
|
showUpdateStep("Normalizing ipv6 for correct comparison", true);
|
||||||
|
$result_stmt = Database::prepare("
|
||||||
|
SELECT `id`, `ip` FROM `" . TABLE_PANEL_IPSANDPORTS . "`"
|
||||||
|
);
|
||||||
|
Database::pexecute($result_stmt);
|
||||||
|
$upd_stmt = Database::prepare("UPDATE `" . TABLE_PANEL_IPSANDPORTS . "` SET `ip` = :ip WHERE `id` = :id");
|
||||||
|
while ($iprow = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||||
|
if (Validate::is_ipv6($iprow['ip'])) {
|
||||||
|
$ip = inet_ntop(inet_pton($iprow['ip']));
|
||||||
|
Database::pexecute($upd_stmt, [
|
||||||
|
'ip' => $ip,
|
||||||
|
'id' => $iprow['id']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastStepStatus(0);
|
||||||
|
\Froxlor\Froxlor::updateToDbVersion('202107260');
|
||||||
|
}
|
||||||
|
|||||||
@@ -247,6 +247,9 @@ class IpsAndPorts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
|||||||
$docroot = '';
|
$docroot = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// always use compressed ipv6 format
|
||||||
|
$ip = inet_ntop(inet_pton($ip));
|
||||||
|
|
||||||
$result_checkfordouble_stmt = Database::prepare("
|
$result_checkfordouble_stmt = Database::prepare("
|
||||||
SELECT `id` FROM `" . TABLE_PANEL_IPSANDPORTS . "`
|
SELECT `id` FROM `" . TABLE_PANEL_IPSANDPORTS . "`
|
||||||
WHERE `ip` = :ip AND `port` = :port");
|
WHERE `ip` = :ip AND `port` = :port");
|
||||||
@@ -462,6 +465,9 @@ class IpsAndPorts extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resour
|
|||||||
$docroot = '';
|
$docroot = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// always use compressed ipv6 format
|
||||||
|
$ip = inet_ntop(inet_pton($ip));
|
||||||
|
|
||||||
if ($result['ip'] != $ip && $result['ip'] == Settings::Get('system.ipaddress') && $result_sameipotherport == false) {
|
if ($result['ip'] != $ip && $result['ip'] == Settings::Get('system.ipaddress') && $result_sameipotherport == false) {
|
||||||
\Froxlor\UI\Response::standard_error('cantchangesystemip', '', true);
|
\Froxlor\UI\Response::standard_error('cantchangesystemip', '', true);
|
||||||
} elseif ($result_checkfordouble && $result_checkfordouble['id'] != '' && $result_checkfordouble['id'] != $id) {
|
} elseif ($result_checkfordouble && $result_checkfordouble['id'] != '' && $result_checkfordouble['id'] != $id) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ final class Froxlor
|
|||||||
const VERSION = '0.10.27';
|
const VERSION = '0.10.27';
|
||||||
|
|
||||||
// Database version (YYYYMMDDC where C is a daily counter)
|
// Database version (YYYYMMDDC where C is a daily counter)
|
||||||
const DBVERSION = '202107210';
|
const DBVERSION = '202107260';
|
||||||
|
|
||||||
// Distribution branding-tag (used for Debian etc.)
|
// Distribution branding-tag (used for Debian etc.)
|
||||||
const BRANDING = '';
|
const BRANDING = '';
|
||||||
|
|||||||
@@ -241,10 +241,14 @@ class PhpHelper
|
|||||||
$ips = array();
|
$ips = array();
|
||||||
foreach ($dns as $record) {
|
foreach ($dns as $record) {
|
||||||
if ($record["type"] == "A") {
|
if ($record["type"] == "A") {
|
||||||
$ips[] = $record["ip"];
|
// always use compressed ipv6 format
|
||||||
|
$ip = inet_ntop(inet_pton($record["ip"]));
|
||||||
|
$ips[] = $ip;
|
||||||
}
|
}
|
||||||
if ($record["type"] == "AAAA") {
|
if ($record["type"] == "AAAA") {
|
||||||
$ips[] = $record["ipv6"];
|
// always use compressed ipv6 format
|
||||||
|
$ip = inet_ntop(inet_pton($record["ipv6"]));
|
||||||
|
$ips[] = $ip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count($ips) < 1) {
|
if (count($ips) < 1) {
|
||||||
|
|||||||
@@ -72,12 +72,12 @@ class IpsAndPortsTest extends TestCase
|
|||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
$data = [
|
$data = [
|
||||||
'ip' => '2a01:440:1:12:82:149:225:46',
|
'ip' => '2a01:0440:0000:0012:0082:0149:0225:0046',
|
||||||
'docroot' => '/var/www/html'
|
'docroot' => '/var/www/html'
|
||||||
];
|
];
|
||||||
$json_result = IpsAndPorts::getLocal($admin_userdata, $data)->add();
|
$json_result = IpsAndPorts::getLocal($admin_userdata, $data)->add();
|
||||||
$result = json_decode($json_result, true)['data'];
|
$result = json_decode($json_result, true)['data'];
|
||||||
$this->assertEquals(4, $result['id']);
|
$this->assertEquals('2a01:440:0:12:82:149:225:46', $result['ip']);
|
||||||
$this->assertEquals('/var/www/html/', $result['docroot']);
|
$this->assertEquals('/var/www/html/', $result['docroot']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user