Skip to content

Commit ad8e118

Browse files
author
Jared Hendrickson
committed
Fixed minor bugs in routing endpoints, created firewall and routing apply endpoints to apply pending changes, updated documentation
1 parent 77bd033 commit ad8e118

26 files changed

Lines changed: 709 additions & 289 deletions

README.md

Lines changed: 79 additions & 28 deletions
Large diffs are not rendered by default.

docs/documentation.json

Lines changed: 162 additions & 61 deletions
Large diffs are not rendered by default.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
// Copyright 2020 Jared Hendrickson
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
require_once("api/framework/APIEndpoint.inc");
17+
18+
class APIFirewallApply extends APIEndpoint {
19+
public function __construct() {
20+
$this->url = "/api/v1/firewall/apply";
21+
}
22+
23+
protected function post() {
24+
return (new APIFirewallApplyCreate())->call();
25+
}
26+
}

pfSense-pkg-API/files/etc/inc/api/endpoints/APIFirewallNAT.inc renamed to pfSense-pkg-API/files/etc/inc/api/endpoints/APIRoutingApply.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515

1616
require_once("api/framework/APIEndpoint.inc");
1717

18-
class APIFirewallNAT extends APIEndpoint {
18+
class APIRoutingApply extends APIEndpoint {
1919
public function __construct() {
20-
$this->url = "/api/v1/firewall/nat";
20+
$this->url = "/api/v1/routing/apply";
2121
}
2222

23-
protected function get() {
24-
return (new APIFirewallNATRead())->call();
23+
protected function post() {
24+
return (new APIRoutingApplyCreate())->call();
2525
}
2626
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
// Copyright 2020 Jared Hendrickson
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
require_once("api/framework/APIModel.inc");
17+
require_once("api/framework/APIResponse.inc");
18+
19+
20+
class APIFirewallApplyCreate extends APIModel {
21+
# Create our method constructor
22+
public function __construct() {
23+
parent::__construct();
24+
$this->privileges = [
25+
"page-all",
26+
"page-firewall-rules",
27+
"page-firewall-rules-edit",
28+
"page-firewall-aliases",
29+
"page-firewall-aliases-edit",
30+
"page-firewall-nat-1-1",
31+
"page-firewall-nat-1-1-edit",
32+
"page-firewall-nat-outbound",
33+
"page-firewall-nat-outbound-edit",
34+
"page-firewall-nat-portforward",
35+
"page-firewall-nat-portforward-edit"
36+
];
37+
}
38+
39+
public function action() {
40+
filter_configure();
41+
clear_subsystem_dirty('natconf');
42+
clear_subsystem_dirty('filter');
43+
return APIResponse\get(0);
44+
}
45+
}

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,7 @@ class APIFirewallNATOneToOneCreate extends APIModel {
3939
$this->config["nat"]["onetoone"][$this->id] = $this->validated_data;
4040
APITools\sort_nat_rules($this->initial_data["top"], $this->id, "onetoone");
4141
$this->write_config();
42-
mark_subsystem_dirty('natconf');
43-
44-
# Allow clients to apply this rule immediately if they passed in an apply value
45-
if ($this->initial_data["apply"] === true) {
46-
filter_configure();
47-
clear_subsystem_dirty('natconf');
48-
clear_subsystem_dirty('filter');
49-
}
42+
$this->apply();
5043
return APIResponse\get(0, $this->validated_data);
5144
}
5245

@@ -151,4 +144,16 @@ class APIFirewallNATOneToOneCreate extends APIModel {
151144
$this->__validate_descr();
152145
$this->__validate_natreflection();
153146
}
147+
148+
public function apply() {
149+
# Mark the NAT subsystem as changed, clear if applied
150+
mark_subsystem_dirty('natconf');
151+
152+
# Allow clients to apply this rule immediately if they passed in an apply value
153+
if ($this->initial_data["apply"] === true) {
154+
filter_configure();
155+
clear_subsystem_dirty('natconf');
156+
clear_subsystem_dirty('filter');
157+
}
158+
}
154159
}

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,12 @@ class APIFirewallNATOneToOneDelete extends APIModel {
3030
unset($this->config["nat"]["onetoone"][$this->id]);
3131
APITools\sort_nat_rules(null, null, "onetoone");
3232
$this->write_config();
33-
mark_subsystem_dirty('natconf');
34-
35-
# Allow clients to delete this rule immediately if they passed in an apply value
36-
if ($this->initial_data["apply"] === true) {
37-
filter_configure();
38-
clear_subsystem_dirty('natconf');
39-
clear_subsystem_dirty('filter');
40-
}
33+
$this->apply();
4134
return APIResponse\get(0, $del_rule);
4235
}
4336

4437
public function validate_payload() {
45-
38+
# Require clients to pass in 1:1 rule ID to locate the rule to delete
4639
if (isset($this->initial_data['id'])) {
4740
// Check that our rule ID exists
4841
if (array_key_exists($this->initial_data['id'], $this->config["nat"]["onetoone"])) {
@@ -54,4 +47,17 @@ class APIFirewallNATOneToOneDelete extends APIModel {
5447
$this->errors[] = APIResponse\get(4083);
5548
}
5649
}
50+
51+
public function apply() {
52+
# Mark the NAT subsystem as changed, clear if applied
53+
mark_subsystem_dirty('natconf');
54+
55+
# Allow clients to apply this rule immediately if they passed in an apply value
56+
if ($this->initial_data["apply"] === true) {
57+
filter_configure();
58+
clear_subsystem_dirty('natconf');
59+
clear_subsystem_dirty('filter');
60+
}
61+
}
62+
5763
}

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,7 @@ class APIFirewallNATOneToOneUpdate extends APIModel {
3232
$this->config["nat"]["onetoone"][$this->id] = $this->validated_data;
3333
APITools\sort_nat_rules($this->initial_data["top"], $this->id, "onetoone");
3434
$this->write_config();
35-
mark_subsystem_dirty('natconf');
36-
37-
# Allow clients to apply this rule immediately if they passed in an apply value
38-
if ($this->initial_data["apply"] === true) {
39-
filter_configure();
40-
clear_subsystem_dirty('natconf');
41-
clear_subsystem_dirty('filter');
42-
}
35+
$this->apply();
4336
return APIResponse\get(0, $this->validated_data);
4437
}
4538

@@ -160,4 +153,17 @@ class APIFirewallNATOneToOneUpdate extends APIModel {
160153
$this->__validate_descr();
161154
$this->__validate_natreflection();
162155
}
156+
157+
public function apply() {
158+
# Mark the NAT subsystem as changed, clear if applied
159+
mark_subsystem_dirty('natconf');
160+
161+
# Allow clients to apply this rule immediately if they passed in an apply value
162+
if ($this->initial_data["apply"] === true) {
163+
filter_configure();
164+
clear_subsystem_dirty('natconf');
165+
clear_subsystem_dirty('filter');
166+
}
167+
}
168+
163169
}

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,7 @@ class APIFirewallNATOutboundMappingCreate extends APIModel {
4040
$this->config["nat"]["outbound"]["rule"][$this->id] = $this->validated_data;
4141
APITools\sort_nat_rules($this->initial_data["top"], $this->id, "outbound");
4242
$this->write_config();
43-
mark_subsystem_dirty('natconf');
44-
45-
# Allow clients to apply this rule immediately if they passed in an apply value
46-
if ($this->initial_data["apply"] === true) {
47-
filter_configure();
48-
clear_subsystem_dirty('natconf');
49-
clear_subsystem_dirty('filter');
50-
}
43+
$this->apply();
5144
return APIResponse\get(0, $this->validated_data);
5245
}
5346

@@ -292,5 +285,16 @@ class APIFirewallNATOutboundMappingCreate extends APIModel {
292285
$this->validated_data["updated"] = $this->validated_data["created"];
293286
}
294287

288+
public function apply() {
289+
# Mark the NAT subsystem as changed, clear if applied
290+
mark_subsystem_dirty('natconf');
291+
292+
# Allow clients to apply this rule immediately if they passed in an apply value
293+
if ($this->initial_data["apply"] === true) {
294+
filter_configure();
295+
clear_subsystem_dirty('natconf');
296+
clear_subsystem_dirty('filter');
297+
}
298+
}
295299

296300
}

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,12 @@ class APIFirewallNATOutboundMappingDelete extends APIModel {
3030
unset($this->config["nat"]["outbound"]["rule"][$this->id]);
3131
APITools\sort_nat_rules(null, null, "outbound");
3232
$this->write_config();
33-
mark_subsystem_dirty('natconf');
34-
35-
# Allow clients to delete this rule immediately if they passed in an apply value
36-
if ($this->initial_data["apply"] === true) {
37-
filter_configure();
38-
clear_subsystem_dirty('natconf');
39-
clear_subsystem_dirty('filter');
40-
}
33+
$this->apply();
4134
return APIResponse\get(0, $del_rule);
4235
}
4336

4437
public function validate_payload() {
45-
38+
# Require clients to pass in a outbound rule ID to locate the rule to delete
4639
if (isset($this->initial_data['id'])) {
4740
// Check that our rule ID exists
4841
if (array_key_exists($this->initial_data['id'], $this->config["nat"]["outbound"]["rule"])) {
@@ -54,4 +47,16 @@ class APIFirewallNATOutboundMappingDelete extends APIModel {
5447
$this->errors[] = APIResponse\get(4104);
5548
}
5649
}
50+
51+
public function apply() {
52+
# Mark the NAT subsystem as changed, clear if applied
53+
mark_subsystem_dirty('natconf');
54+
55+
# Allow clients to apply this rule immediately if they passed in an apply value
56+
if ($this->initial_data["apply"] === true) {
57+
filter_configure();
58+
clear_subsystem_dirty('natconf');
59+
clear_subsystem_dirty('filter');
60+
}
61+
}
5762
}

0 commit comments

Comments
 (0)