Skip to content

Commit 066ec98

Browse files
Merge pull request #77 from jaredhendrickson13/v114_bugfixes
v1.1.4 Bug Fixes
2 parents 70ac5ab + b1c4608 commit 066ec98

8 files changed

Lines changed: 50 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ class APIQuery {
117117
return $this->gt($entry[$q], $value);
118118
case "gte":
119119
return $this->gte($entry[$q], $value);
120+
case null:
121+
return ($entry[$q] === $value);
120122
default:
121123
return false;
122124
}

pfSense-pkg-API/files/etc/inc/api/models/APIFirewallNATPortForwardCreate.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,10 @@ class APIFirewallNATPortForwardCreate extends APIModel {
243243

244244
private function __init_config() {
245245
# Ensure our config is formatted for NAT rules
246-
if (!is_array($this->config["nat"]["rule"])) {
246+
if (!is_array($this->config["nat"])) {
247247
$this->config["nat"] = [];
248+
}
249+
if (!is_array($this->config["nat"]["rule"])) {
248250
$this->config["nat"]["rule"] = [];
249251
}
250252
}

pfSense-pkg-API/files/etc/inc/api/models/APIFirewallNATPortForwardUpdate.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,15 @@ class APIFirewallNATPortForwardUpdate extends APIModel {
123123
if (isset($this->initial_data['src'])) {
124124
$rule_check = APITools\is_valid_rule_addr($this->initial_data['src'], "source");
125125
if ($rule_check["valid"]) {
126+
# Retain the source port and update the source array
127+
$origin_port = $this->validated_data["source"]["port"];
126128
$this->validated_data["source"] = $rule_check["data"]["source"];
129+
130+
# If we had a source port, rewrite it
131+
if (isset($origin_port)) {
132+
$this->validated_data["source"]["port"] = $origin_port;
133+
}
134+
127135
} else {
128136
$this->errors[] = APIResponse\get(4011);
129137
}
@@ -135,7 +143,14 @@ class APIFirewallNATPortForwardUpdate extends APIModel {
135143
if (isset($this->initial_data['dst'])) {
136144
$rule_check = APITools\is_valid_rule_addr($this->initial_data['dst'], "destination");
137145
if ($rule_check["valid"]) {
146+
# Retain the destination port and update the destination array
147+
$origin_port = $this->validated_data["destination"]["port"];
138148
$this->validated_data["destination"] = $rule_check["data"]["destination"];
149+
150+
# If we had a destination port, rewrite it
151+
if (isset($origin_port)) {
152+
$this->validated_data["destination"]["port"] = $origin_port;
153+
}
139154
} else {
140155
$this->errors[] = APIResponse\get(4012);
141156
}

pfSense-pkg-API/files/etc/inc/api/models/APIFirewallRuleCreate.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ class APIFirewallRuleCreate extends APIModel {
249249
$this->__validate_log();
250250
$this->__validate_top();
251251

252+
# Delay generating the tracker. Reduces the likelihood of two rules getting the same tracker in looped calls
253+
# todo: this is a quick fix and still does not guarantee uniqueness, a better solution is needed
254+
sleep(1);
255+
252256
# Add our static 'tracker', 'created' and 'updated' values
253257
$this->validated_data["tracker"] = (int)microtime(true);
254258
$this->validated_data["created"] = [

pfSense-pkg-API/files/etc/inc/api/models/APIFirewallVirtualIPCreate.inc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class APIFirewallVirtualIPCreate extends APIModel {
3535
APITools\apply_virtual_ip($this->validated_data);
3636
return APIResponse\get(0, $this->validated_data);
3737
}
38-
38+
3939
public function validate_payload() {
4040

4141
# Validate our required 'mode' payload value
@@ -105,7 +105,7 @@ class APIFirewallVirtualIPCreate extends APIModel {
105105
if ($this->validated_data["mode"] === "carp") {
106106
# Check for our optional 'vhid' payload value. Assume default if none was specified.
107107
if (isset($this->initial_data['vhid'])) {
108-
if (vhid_exists($this->initial_data['vhid'])) {
108+
if ($this->__vhid_exists($this->initial_data['vhid'])) {
109109
$this->errors[] = APIResponse\get(4027);
110110
} elseif (1 > $this->initial_data['vhid'] or $this->initial_data['vhid'] > 255) {
111111
$this->errors[] = APIResponse\get(4028);
@@ -152,4 +152,15 @@ class APIFirewallVirtualIPCreate extends APIModel {
152152
# Set virtual IP type to network. This is easier to handle than allow single IPs too.
153153
$this->validated_data["type"] = "network";
154154
}
155+
156+
private function __vhid_exists($vhid) {
157+
# Loop through each virtual IP and ensure it is not using the requested vhid
158+
foreach ($this->config["virtualip"]["vip"] as $vip) {
159+
if (intval($vhid) === intval($vip["vhid"])) {
160+
return true;
161+
}
162+
}
163+
return false;
164+
}
165+
155166
}

pfSense-pkg-API/files/etc/inc/api/models/APIFirewallVirtualIPUpdate.inc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class APIFirewallVirtualIPUpdate extends APIModel {
105105
if ($this->validated_data["mode"] === "carp") {
106106
# Check for our optional 'vhid' payload value. Assume default if none was specified.
107107
if (isset($this->initial_data['vhid'])) {
108-
if (vhid_exists($this->initial_data['vhid'])) {
108+
if ($this->__vhid_exists($this->initial_data['vhid'])) {
109109
$this->errors[] = APIResponse\get(4027);
110110
} elseif (1 > $this->initial_data['vhid'] or $this->initial_data['vhid'] > 255) {
111111
$this->errors[] = APIResponse\get(4028);
@@ -152,4 +152,14 @@ class APIFirewallVirtualIPUpdate extends APIModel {
152152
# Set virtual IP type to network. This is easier to handle than allow single IPs too.
153153
$this->validated_data["type"] = "network";
154154
}
155+
156+
private function __vhid_exists($vhid) {
157+
# Loop through each virtual IP and ensure it is not using the requested vhid
158+
foreach ($this->config["virtualip"]["vip"] as $vip) {
159+
if (intval($vhid) === intval($vip["vhid"]) and intval($vhid) !== intval($this->validated_data["vhid"])) {
160+
return true;
161+
}
162+
}
163+
return false;
164+
}
155165
}

tests/test_api_v1_firewall_virtual_ip.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class APIUnitTestFirewallVirtualIP(unit_test_framework.APIUnitTest):
3939
"interface": "wan",
4040
"subnet": "172.16.77.229/32",
4141
"password": "newtestpass",
42+
"vhid": 25,
4243
"descr": "Updated unit Test"
4344
},
4445
{

tools/templates/Makefile.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
PORTNAME=pfSense-pkg-API
44
PORTVERSION=1.1
5-
PORTREVISION=3
5+
PORTREVISION=4
66
CATEGORIES=sysutils
77
MASTER_SITES=# empty
88
DISTFILES=# empty

0 commit comments

Comments
 (0)