Skip to content

Commit 1658a8e

Browse files
Merge pull request #161 from jaredhendrickson13/v131
v1.3.1 Fixes & Features
2 parents d7c41c1 + 1361035 commit 1658a8e

32 files changed

+1628
-281
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,9 @@ URL: https://{{$hostname}}/api/v1/firewall/alias
10301030
| descr | string | Description of new alias (optional) |
10311031
| address | string or array | Array of values to add to alias. A single value may be specified as string. |
10321032
| detail | string or array | Array of descriptions for alias values. Descriptions must match the order the that they are specified in the `address` array. Single descriptions may be specified as string |
1033+
| apply | boolean | Specify whether or not you would like this alias to be applied immediately, or simply written to the configuration to be applied later. Typically, if you are creating multiple aliases at once it is best to set this to false and apply the changes afterwards using the `/api/v1/firewall/apply` endpoint. Otherwise, If you are only creating a single alias, you may set this true to apply it immediately. Defaults to true. (optional)
1034+
1035+
_Note: currently this defaults to always reload the firewall filter after in order to remain backwards compatible with previous releases, this will be changed to not reload the filter by default in a future release._ |
10331036

10341037

10351038

@@ -1069,6 +1072,9 @@ URL: https://{{$hostname}}/api/v1/firewall/alias
10691072
| Key | Type | Description |
10701073
| --- | ------|-------------|
10711074
| id | string | Name or ID of alias to delete. This alias cannot be in use elsewhere in configuration |
1075+
| apply | boolean | Specify whether or not you would like this alias to be applied immediately, or simply written to the configuration to be applied later. Typically, if you are creating multiple aliases at once it is best to set this to false and apply the changes afterwards using the `/api/v1/firewall/apply` endpoint. Otherwise, If you are only creating a single alias, you may set this true to apply it immediately. Defaults to true. (optional)
1076+
1077+
_Note: currently this defaults to always reload the firewall filter after in order to remain backwards compatible with previous releases, this will be changed to not reload the filter by default in a future release._ |
10721078

10731079

10741080

@@ -1126,6 +1132,9 @@ URL: https://{{$hostname}}/api/v1/firewall/alias
11261132
| descr | string | Change alias description (optional) |
11271133
| address | string or array | Overwrite existing alias addresses with new addresses. Multiple values may be passed in as array, singular values may be passed in as string (optional) |
11281134
| detail | string or array | Overwrite existing alias address details with new details. Multiple values may be passed in as array, singular values may be passed in as string. Detail values must match index of alias addresses (optional) |
1135+
| apply | boolean | Specify whether or not you would like this alias to be applied immediately, or simply written to the configuration to be applied later. Typically, if you are creating multiple aliases at once it is best to set this to false and apply the changes afterwards using the `/api/v1/firewall/apply` endpoint. Otherwise, If you are only creating a single alias, you may set this true to apply it immediately. Defaults to true. (optional)
1136+
1137+
_Note: currently this defaults to always reload the firewall filter after in order to remain backwards compatible with previous releases, this will be changed to not reload the filter by default in a future release._ |
11291138

11301139

11311140

@@ -1172,6 +1181,10 @@ URL: https://{{$hostname}}/api/v1/firewall/alias/entry
11721181
| name | string | Name of alias to add new address values |
11731182
| address | string or array | Array of values to add to alias. A single value may be specified as string. |
11741183
| detail | string or array | Array of descriptions for alias values. Descriptions must match the order the that they are specified in the `address` array. Single descriptions may be specified as string. If you pass In less `detail` values than `address` values, a default auto-created detail will be applied to the remaining values. (optional) |
1184+
| detail | string or array | Array of descriptions for alias values. Descriptions must match the order the that they are specified in the `address` array. Single descriptions may be specified as string. If you pass In less `detail` values than `address` values, a default auto-created detail will be applied to the remaining values. (optional) |
1185+
| apply | boolean | Specify whether or not you would like this alias to be applied immediately, or simply written to the configuration to be applied later. Typically, if you are creating multiple aliases at once it is best to set this to false and apply the changes afterwards using the `/api/v1/firewall/apply` endpoint. Otherwise, If you are only creating a single alias, you may set this true to apply it immediately. Defaults to true. (optional)
1186+
1187+
_Note: currently this defaults to always reload the firewall filter after in order to remain backwards compatible with previous releases, this will be changed to not reload the filter by default in a future release._ |
11751188

11761189

11771190

@@ -1210,6 +1223,9 @@ URL: https://{{$hostname}}/api/v1/firewall/alias/entry
12101223
| --- | ------|-------------|
12111224
| name | string | Name of alias to delete address values from |
12121225
| address | string | Array of values to delete from alias. A single value may be specified as string. |
1226+
| apply | boolean | Specify whether or not you would like this alias to be applied immediately, or simply written to the configuration to be applied later. Typically, if you are creating multiple aliases at once it is best to set this to false and apply the changes afterwards using the `/api/v1/firewall/apply` endpoint. Otherwise, If you are only creating a single alias, you may set this true to apply it immediately. Defaults to true. (optional)
1227+
1228+
_Note: currently this defaults to always reload the firewall filter after in order to remain backwards compatible with previous releases, this will be changed to not reload the filter by default in a future release._ |
12131229

12141230

12151231

@@ -1481,6 +1497,9 @@ URL: https://{{$hostname}}/api/v1/firewall/nat/outbound
14811497
| Key | Type | Description |
14821498
| --- | ------|-------------|
14831499
| mode | string | Update the outbound NAT mode. Options are `automatic` to automatically generate outbound NAT rules, `hybrid` to support both automatic and manual outbound NAT rules , `advanced` to require all rules to be entered manually, or `disabled` to disable outbound NAT altogether. If updating to `advanced` from `automatic` or `hybrid`, the API will automatically create manual entries for each automatically generated outbound NAT entry. |
1500+
| apply | boolean | Specify whether or not you would like this setting to be applied immediately, or simply written to the configuration to be applied later. Typically, if you are creating multiple firewall related objects at once it is best to set this to false and apply the changes afterwards using the `/api/v1/firewall/apply` endpoint. Otherwise, If you are only updating the outbound NAT settings, you may set this true to apply it immediately. Defaults to true. (optional)
1501+
1502+
_Note: currently this defaults to always reload the firewall filter after in order to remain backwards compatible with previous releases, this will be changed to not reload the filter by default in a future release._ |
14841503

14851504

14861505

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3271,6 +3271,12 @@ function get($id, $data=[], $all=false) {
32713271
"return" => $id,
32723272
"message" => "Gateway ID does not exist"
32733273
],
3274+
6029 => [
3275+
"status" => "bad request",
3276+
"code" => 400,
3277+
"return" => $id,
3278+
"message" => "Only 1 dynamic gateway per eligible interface is allowed"
3279+
],
32743280

32753281
// 7000-7999 reserved for /diagnostics API calls
32763282
7000 => [

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

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -900,55 +900,6 @@ function get_ipv6_if_list() {
900900
return($dyn_v6_ifs);
901901
}
902902

903-
// Apply a new interface configuration
904-
function apply_interface_config($if_id, $if_conf) {
905-
// Local variables
906-
global $config;
907-
$vlan_redo = false;
908-
// Check that our if configuration is an array
909-
if (is_array($if_conf)) {
910-
if (isset($config['interfaces'][$if_id]['enable'])) {
911-
interface_bring_down($if_id, false, $if_conf);
912-
interface_configure($if_id, true);
913-
if ($config['interfaces'][$if_id]['ipaddrv6'] == "track6") {
914-
// Configure IPv6 track6 type if present
915-
$wan_cfg = $config['interfaces'][$if_id];
916-
interface_track6_configure($if_id, $wan_cfg, true);
917-
}
918-
} else {
919-
interface_bring_down($if_id, true, $if_conf);
920-
// Restart DHCPD if enabled
921-
if (isset($config['dhcpd'][$if_id]['enable']) ||
922-
isset($config['dhcpdv6'][$if_id]['enable'])) {
923-
services_dhcpd_configure();
924-
}
925-
}
926-
// Check if VLANs are configured for this interface, if so, reapply them
927-
if (interface_has_clones(get_real_interface($if_id))) {
928-
$vlan_redo = true;
929-
}
930-
}
931-
// Check if DHCP needs to be reloaded
932-
if ($if_conf['ipaddr'] == "dhcp") {
933-
kill_dhclient_process($if_conf['if']);
934-
}
935-
if ($if_conf['ipaddrv6'] == "dhcp6") {
936-
kill_dhcp6client_process($if_conf['if'],true);
937-
}
938-
// Reapply VLANs if necessary
939-
if ($vlan_redo) {
940-
interfaces_vlan_configure();
941-
}
942-
// Restart services that may reference IP
943-
services_snmpd_configure();
944-
setup_gateways_monitor();
945-
filter_configure();
946-
enable_rrd_graphing();
947-
system_routing_configure();
948-
// Return true or false if configuration was successful
949-
return true;
950-
}
951-
952903
function delete_static_route($id) {
953904
global $config;
954905
$a_routes = &$config['staticroutes']['route'];

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,18 @@ class APIFirewallAliasCreate extends APIModel {
2525
}
2626

2727
public function action() {
28-
// Add our alias
28+
# Add our new alias and reload configuration as requested
2929
$this->config["aliases"] = !is_array($this->config["aliases"]) ? array("alias" => []) : $this->config["aliases"];
30-
$this->config["aliases"]["alias"][] = $this->validated_data; // Write our configuration change
31-
$this->write_config(); // Apply our configuration change
32-
send_event("filter reload"); // Ensure our firewall filter is reloaded
30+
$this->config["aliases"]["alias"][] = $this->validated_data;
31+
$this->write_config();
32+
mark_subsystem_dirty("aliases");
33+
34+
# Only reload the firewall filter if a false value was not passed in
35+
# TODO: This condition applies the changes by default to stay backwards compatible with v1.3.0
36+
# TODO: this should be refactored in a future release to not apply by default
37+
if ($this->initial_data["apply"] !== false) {
38+
APIFirewallApplyCreate::apply();
39+
}
3340
return APIResponse\get(0, $this->validated_data);
3441
}
3542

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,19 @@ class APIFirewallAliasDelete extends APIModel {
2525
}
2626

2727
public function action() {
28-
$del_conf = $this->config["aliases"]["alias"][$this->id];
28+
# Remove this alias from configuration and apply changes as requested
2929
unset($this->config["aliases"]["alias"][$this->id]);
3030
$this->config["aliases"]["alias"] = array_values($this->config["aliases"]["alias"]);
3131
$this->write_config();
32-
send_event("filter reload");
33-
return APIResponse\get(0, $del_conf);
32+
mark_subsystem_dirty("aliases");
33+
34+
# Only reload the firewall filter if a false value was not passed in
35+
# TODO: This condition applies the changes by default to stay backwards compatible with v1.3.0
36+
# TODO: this should be refactored in a future release to not apply by default
37+
if ($this->initial_data["apply"] !== false) {
38+
APIFirewallApplyCreate::apply();
39+
}
40+
return APIResponse\get(0, $this->validated_data);
3441
}
3542

3643
private function __validate_id() {
@@ -62,4 +69,4 @@ class APIFirewallAliasDelete extends APIModel {
6269
public function validate_payload() {
6370
$this->__validate_id();
6471
}
65-
}
72+
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ class APIFirewallAliasEntryCreate extends APIModel {
2828
# Update our alias with the new entries
2929
$this->config["aliases"]["alias"][$this->id] = $this->validated_data;
3030
$this->write_config();
31-
send_event("filter reload");
31+
mark_subsystem_dirty("aliases");
32+
33+
# Only reload the firewall filter if a false value was not passed in
34+
# TODO: This condition applies the changes by default to stay backwards compatible with v1.3.0
35+
# TODO: this should be refactored in a future release to not apply by default
36+
if ($this->initial_data["apply"] !== false) {
37+
APIFirewallApplyCreate::apply();
38+
}
3239

3340
return APIResponse\get(0, $this->config["aliases"]["alias"][$this->id]);
3441
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ class APIFirewallAliasEntryDelete extends APIModel {
2525
}
2626

2727
public function action() {
28+
# Write our new alias entry
2829
$this->config["aliases"]["alias"][$this->id] = $this->validated_data;
2930
$this->write_config();
30-
send_event("filter reload");
31+
mark_subsystem_dirty("aliases");
32+
33+
# Only reload the firewall filter if a false value was not passed in
34+
# TODO: This condition applies the changes by default to stay backwards compatible with v1.3.0
35+
# TODO: this should be refactored in a future release to not apply by default
36+
if ($this->initial_data["apply"] !== false) {
37+
APIFirewallApplyCreate::apply();
38+
}
3139
return APIResponse\get(0, $this->validated_data);
3240
}
3341

@@ -90,4 +98,4 @@ class APIFirewallAliasEntryDelete extends APIModel {
9098
return $value;
9199
}
92100
}
93-
}
101+
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ class APIFirewallAliasUpdate extends APIModel {
3232
$this->config["aliases"]["alias"][$this->id] = $this->validated_data;
3333
$this->__rename_alias_references__();
3434
$this->write_config();
35-
send_event("filter reload");
35+
mark_subsystem_dirty("aliases");
36+
37+
# Only reload the firewall filter if a false value was not passed in
38+
# TODO: This condition applies the changes by default to stay backwards compatible with v1.3.0
39+
# TODO: this should be refactored in a future release to not apply by default
40+
if ($this->initial_data["apply"] !== false) {
41+
APIFirewallApplyCreate::apply();
42+
}
3643
return APIResponse\get(0, $this->config["aliases"]["alias"][$this->id]);
3744
}
3845

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ class APIFirewallApplyCreate extends APIModel {
3737
}
3838

3939
public function action() {
40+
$this->apply();
41+
return APIResponse\get(0);
42+
}
43+
44+
public static function apply() {
4045
filter_configure();
46+
clear_subsystem_dirty('aliases');
4147
clear_subsystem_dirty('natconf');
4248
clear_subsystem_dirty('filter');
43-
return APIResponse\get(0);
4449
}
45-
}
50+
}

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ class APIFirewallNATOutboundMappingCreate extends APIModel {
4141
$this->config["nat"]["outbound"]["rule"][$this->id] = $this->validated_data;
4242
APITools\sort_nat_rules($this->initial_data["top"], $this->id, "outbound");
4343
$this->write_config();
44-
$this->apply();
44+
mark_subsystem_dirty('natconf');
45+
46+
# Only reload the firewall filter if it was requested by the client
47+
if ($this->initial_data["apply"] === true) {
48+
APIFirewallApplyCreate::apply();
49+
}
4550
return APIResponse\get(0, $this->validated_data);
4651
}
4752

@@ -294,17 +299,4 @@ class APIFirewallNATOutboundMappingCreate extends APIModel {
294299
$this->config["nat"]["outbound"] = (is_array($this->config["nat"]["outbound"])) ? $this->config["nat"]["outbound"] : [];
295300
$this->config["nat"]["outbound"]["rule"] = (is_array($this->config["nat"]["outbound"]["rule"])) ? $this->config["nat"]["outbound"]["rule"] : [];
296301
}
297-
298-
public function apply() {
299-
# Mark the NAT subsystem as changed, clear if applied
300-
mark_subsystem_dirty('natconf');
301-
302-
# Allow clients to apply this rule immediately if they passed in an apply value
303-
if ($this->initial_data["apply"] === true) {
304-
filter_configure();
305-
clear_subsystem_dirty('natconf');
306-
clear_subsystem_dirty('filter');
307-
}
308-
}
309-
310-
}
302+
}

0 commit comments

Comments
 (0)