allow private-network ip-addresses for database-connection, fixes #1489
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -264,7 +264,7 @@ class Database {
|
||||
'charset' => 'utf8'
|
||||
);
|
||||
|
||||
if (!validateLocalHostname($host) && !validate_ip2($host, true, 'invalidip', true)) {
|
||||
if (!validateLocalHostname($host) && !validate_ip2($host, true, 'invalidip', true, true)) {
|
||||
$dbconf["dsn"]['unix_socket'] = makeCorrectFile($host);
|
||||
} else {
|
||||
$dbconf["dsn"]['host'] = $host;
|
||||
|
||||
@@ -23,7 +23,7 @@ function checkMysqlAccessHost($fieldname, $fielddata, $newfieldvalue, $allnewfie
|
||||
|
||||
foreach ($mysql_access_host_array as $host_entry) {
|
||||
|
||||
if (validate_ip2($host_entry, true, 'invalidip', true) == false
|
||||
if (validate_ip2($host_entry, true, 'invalidip', true, true) == false
|
||||
&& validateDomain($host_entry) == false
|
||||
&& validateLocalHostname($host_entry) == false
|
||||
&& $host_entry != '%'
|
||||
|
||||
@@ -44,13 +44,21 @@ function validate_ip($ip, $return_bool = false, $lng = 'invalidip') {
|
||||
/**
|
||||
* Checks whether it is a valid ip
|
||||
*
|
||||
* @return mixed ip address on success, false on failure
|
||||
* @param string $ip ip-address to check
|
||||
* @param bool $return_bool whether to return bool or call standard_error()
|
||||
* @param string $lng index for error-message (if $return_bool is false)
|
||||
* @param bool $allow_localhost whether to allow 127.0.0.1
|
||||
* @param bool $allow_priv whether to allow private network addresses
|
||||
*
|
||||
* @return string|bool ip address on success, false on failure
|
||||
*/
|
||||
function validate_ip2($ip, $return_bool = false, $lng = 'invalidip', $allow_localhost = false) {
|
||||
function validate_ip2($ip, $return_bool = false, $lng = 'invalidip', $allow_localhost = false, $allow_priv = false) {
|
||||
|
||||
$filter_lan = $allow_priv ? FILTER_FLAG_NO_RES_RANGE : (FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_NO_PRIV_RANGE);
|
||||
|
||||
if ((filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)
|
||||
|| filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))
|
||||
&& filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_NO_PRIV_RANGE)
|
||||
&& filter_var($ip, FILTER_VALIDATE_IP, $filter_lan)
|
||||
) {
|
||||
return $ip;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user