Skip to content

Commit f2eb71a

Browse files
author
Jared Hendrickson
committed
Fixed bug in NAT endpoints that attempt to write configuration before the config array was initialized
1 parent 643dfd3 commit f2eb71a

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class APIFirewallNATOutboundMappingCreate extends APIModel {
3737

3838
public function action() {
3939
# Add our new configuration
40+
$this->__init_config();
4041
$this->config["nat"]["outbound"]["rule"][$this->id] = $this->validated_data;
4142
APITools\sort_nat_rules($this->initial_data["top"], $this->id, "outbound");
4243
$this->write_config();
@@ -285,6 +286,12 @@ class APIFirewallNATOutboundMappingCreate extends APIModel {
285286
$this->validated_data["updated"] = $this->validated_data["created"];
286287
}
287288

289+
private function __init_config() {
290+
$this->config["nat"] = (is_array($this->config["nat"])) ? $this->config["nat"] : [];
291+
$this->config["nat"]["outbound"] = (is_array($this->config["nat"]["outbound"])) ? $this->config["nat"]["outbound"] : [];
292+
$this->config["nat"]["outbound"]["rule"] = (is_array($this->config["nat"]["outbound"]["rule"])) ? $this->config["nat"]["outbound"]["rule"] : [];
293+
}
294+
288295
public function apply() {
289296
# Mark the NAT subsystem as changed, clear if applied
290297
mark_subsystem_dirty('natconf');

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ class APIFirewallNATOutboundUpdate extends APIModel {
2525
parent::__construct();
2626
$this->privileges = ["page-all", "page-firewall-nat-outbound"];
2727
$this->modes = ["automatic", "hybrid", "advanced", "disabled"];
28-
var_dump($this->initial_data);
29-
3028
}
3129

3230
public function action() {
@@ -107,7 +105,15 @@ class APIFirewallNATOutboundUpdate extends APIModel {
107105
return false;
108106
}
109107

108+
# Ensures we have our configuration array formatted for outbound NAT configurations
109+
private function __init_config() {
110+
$this->config["nat"] = (is_array($this->config["nat"])) ? $this->config["nat"] : [];
111+
$this->config["nat"]["outbound"] = (is_array($this->config["nat"]["outbound"])) ? $this->config["nat"]["outbound"] : [];
112+
$this->config["nat"]["outbound"]["rule"] = (is_array($this->config["nat"]["outbound"]["rule"])) ? $this->config["nat"]["outbound"]["rule"] : [];
113+
}
114+
110115
public function validate_payload() {
116+
$this->__init_config();
111117
$this->__get_default();
112118
$this->__validate_mode();
113119
}

0 commit comments

Comments
 (0)