allow CIDR values in AXFR setting, fixes #1672
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -122,7 +122,7 @@ function validateFormFieldString($fieldname, $fielddata, $newfieldvalue)
|
|||||||
$newfieldvalue = '';
|
$newfieldvalue = '';
|
||||||
$returnvalue = 'stringmustntbeempty';
|
$returnvalue = 'stringmustntbeempty';
|
||||||
} else {
|
} else {
|
||||||
$newfieldvalue = validate_ip2($newfieldvalue, true, true, true);
|
$newfieldvalue = validate_ip2($newfieldvalue, true, 'invalidip', true, true, true);
|
||||||
$returnvalue = ($newfieldvalue !== false ? true : 'invalidip');
|
$returnvalue = ($newfieldvalue !== false ? true : 'invalidip');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,23 +49,43 @@ function validate_ip($ip, $return_bool = false, $lng = 'invalidip') {
|
|||||||
* @param string $lng index for error-message (if $return_bool is false)
|
* @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_localhost whether to allow 127.0.0.1
|
||||||
* @param bool $allow_priv whether to allow private network addresses
|
* @param bool $allow_priv whether to allow private network addresses
|
||||||
|
* @param bool $allow_cidr whether to allow CIDR values e.g. 10.10.10.10/16
|
||||||
*
|
*
|
||||||
* @return string|bool ip address on success, false on failure
|
* @return string|bool ip address on success, false on failure
|
||||||
*/
|
*/
|
||||||
function validate_ip2($ip, $return_bool = false, $lng = 'invalidip', $allow_localhost = false, $allow_priv = false) {
|
function validate_ip2($ip, $return_bool = false, $lng = 'invalidip', $allow_localhost = false, $allow_priv = false, $allow_cidr = false) {
|
||||||
|
|
||||||
$filter_lan = $allow_priv ? FILTER_FLAG_NO_RES_RANGE : (FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_NO_PRIV_RANGE);
|
$cidr = "";
|
||||||
|
if ($allow_cidr) {
|
||||||
|
$org_ip = $ip;
|
||||||
|
$ip_cidr = explode("/", $ip);
|
||||||
|
if (count($ip_cidr) == 2) {
|
||||||
|
$ip = $ip_cidr[0];
|
||||||
|
$cidr = "/".$ip_cidr[1];
|
||||||
|
} else {
|
||||||
|
$ip = $org_ip;
|
||||||
|
}
|
||||||
|
} elseif (strpos($ip, "/") !== false) {
|
||||||
|
if ($return_bool) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
standard_error($lng, $ip);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$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)
|
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_IPV4))
|
||||||
&& filter_var($ip, FILTER_VALIDATE_IP, $filter_lan)
|
&& filter_var($ip, FILTER_VALIDATE_IP, $filter_lan)
|
||||||
) {
|
) {
|
||||||
return $ip;
|
return $ip.$cidr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// special case where localhost ip is allowed (mysql-access-hosts for example)
|
// special case where localhost ip is allowed (mysql-access-hosts for example)
|
||||||
if ($allow_localhost && $ip == '127.0.0.1') {
|
if ($allow_localhost && $ip == '127.0.0.1') {
|
||||||
return $ip;
|
return $ip.$cidr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($return_bool) {
|
if ($return_bool) {
|
||||||
|
|||||||
@@ -129,9 +129,7 @@ class bind extends DnsBase
|
|||||||
// AXFR server #100
|
// AXFR server #100
|
||||||
if (count($this->_axfr) > 0) {
|
if (count($this->_axfr) > 0) {
|
||||||
foreach ($this->_axfr as $axfrserver) {
|
foreach ($this->_axfr as $axfrserver) {
|
||||||
if (validate_ip($axfrserver, true) !== false) {
|
$bindconf_file .= ' ' . $axfrserver . ';' . "\n";
|
||||||
$bindconf_file .= ' ' . $axfrserver . ';' . "\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// close allow-transfer
|
// close allow-transfer
|
||||||
|
|||||||
@@ -194,10 +194,8 @@ class pdns extends DnsBase
|
|||||||
// AXFR server #100
|
// AXFR server #100
|
||||||
if (count($this->_axfr) > 0) {
|
if (count($this->_axfr) > 0) {
|
||||||
foreach ($this->_axfr as $axfrserver) {
|
foreach ($this->_axfr as $axfrserver) {
|
||||||
if (validate_ip($axfrserver, true) !== false) {
|
$ins_data['value'] = $axfrserver;
|
||||||
$ins_data['value'] = $axfrserver;
|
$ins_stmt->execute($ins_data);
|
||||||
$ins_stmt->execute($ins_data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user