Skip to content

Commit 5afa9e9

Browse files
Merge branch 'v120' of github.com:jaredhendrickson13/pfsense-api into v120
2 parents 6996f90 + 7d29ce8 commit 5afa9e9

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

pfSense-pkg-API/files/etc/inc/api/framework/APIModel.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,17 @@ class APIModel {
141141
$allow_ifs = $pkg_conf["allowed_interfaces"];
142142
$whitelist = explode(",", $allow_ifs);
143143

144-
// Check if our server IP is in our whitelist
144+
# Check if our server IP is in our whitelist
145145
foreach ($whitelist as $wif) {
146146
$if_info = get_interface_info($wif);
147-
// Check if our server IP is a valid if address, localhost, or any
148-
if ($_SERVER["SERVER_ADDR"] === $if_info["ipaddr"]) {
147+
# Check if our server IP is a valid if address, VIP, localhost, or any
148+
if ($_SERVER["SERVER_ADDR"] === $if_info["ipaddr"] or APITools\is_ip_vip($_SERVER["SERVER_ADDR"], $wif)) {
149149
return;
150150
} elseif ($_SERVER["SERVER_ADDR"] === $if_info["ipaddrv6"]) {
151151
return;
152152
} elseif (in_array($_SERVER["SERVER_ADDR"], ["::1", "127.0.0.1", "localhost"]) and $wif === "localhost") {
153153
return;
154-
}elseif ($wif === "any") {
154+
} elseif ($wif === "any") {
155155
return;
156156
}
157157
}

pfSense-pkg-API/files/etc/inc/api/framework/APITools.inc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,35 @@ function is_ip_subnet_or_alias($value) {
10501050
}
10511051
}
10521052

1053+
# Checks if a given IP is within a given CIDR
1054+
function is_ip_in_cidr($ip, $cidr) {
1055+
# Use IP2Long to determine if a specified IP is within a specified cidr
1056+
$subnet = explode('/', $cidr)[0];
1057+
$subnet = ip2long($subnet);
1058+
$bits = (!is_null(explode('/', $cidr)[1])) ? explode('/', $cidr)[1] : 32;
1059+
$ip = ip2long($ip);
1060+
$mask = -1 << (32 - $bits);
1061+
$subnet &= $mask;
1062+
return ($ip & $mask) == $subnet;
1063+
}
1064+
1065+
# Check if a specified IP is a configured virtual IP
1066+
function is_ip_vip($ip, $if=null) {
1067+
global $config;
1068+
1069+
# Loop through each configured virtual IP
1070+
foreach ($config["virtualip"]["vip"] as $vip) {
1071+
# Check if this VIPs interface matches the requested interface, or any if none was specified
1072+
if ($vip["interface"] === $if or $if === null) {
1073+
# Check if the specified IP is contained in this VIP
1074+
if (is_ip_in_cidr($ip, $vip["subnet"]."/".$vip["subnet_bits"])) {
1075+
return true;
1076+
}
1077+
}
1078+
}
1079+
return false;
1080+
}
1081+
10531082
# Checks if an array is a associative array. Returns true if assoc, false if numeric, or null if not array
10541083
function is_assoc_array($array, $strict_seq=false) {
10551084
# Local variables

0 commit comments

Comments
 (0)