Skip to content

Commit 9ebf524

Browse files
Merge pull request #559 from jaredhendrickson13/next_patch
v2.1.1 Fixes
2 parents b62e4ba + 3239af6 commit 9ebf524

7 files changed

Lines changed: 91 additions & 22 deletions

File tree

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,22 @@ provide you with the information you need to configure and use the package effec
2626

2727
## Quickstart
2828

29-
For new users, it is recommended to refer to the links in the [Getting Started section](#getting-started) to begin. Otherwise, the install
30-
command is included below for quick reference:
29+
For new users, it is recommended to refer to the links in the [Getting Started section](#getting-started) to begin. Otherwise, the installation
30+
commands are included below for quick reference.
31+
32+
Install on pfSense CE:
33+
34+
```bash
35+
pkg-static add https://github.com/jaredhendrickson13/pfsense-api/releases/latest/download/pfSense-2.7.2-pkg-RESTAPI.pkg
36+
```
37+
38+
Install on pfSense Plus:
3139

3240
```bash
33-
pkg-static -C /dev/null add https://github.com/jaredhendrickson13/pfsense-api/releases/latest/download/pfSense-2.7.2-pkg-RESTAPI.pkg
41+
pkg-static -C /dev/null add https://github.com/jaredhendrickson13/pfsense-api/releases/latest/download/pfSense-24.03-pkg-RESTAPI.pkg
3442
```
3543

36-
> [!NOTE]
44+
> [!IMPORTANT]
3745
> You may need to customize the installation command to reference the package built for your pfSense version. Check
3846
> the [releases page](https://github.com/jaredhendrickson13/pfsense-api/releases) to find the package built for
3947
> your version of pfSense.

docs/INSTALL_AND_CONFIG.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,26 @@ run pfSense. It's recommended to follow Netgate's [minimum hardware requirements
2424
## Installing the package
2525

2626
The pfSense REST API package is built just like any other pfSense package and can therefor be installed easily using
27-
`pkg` from the pfSense command line:
27+
`pkg` from the pfSense command line. Below are the installation commands for the latest version of the package.
28+
29+
**Install on pfSense CE**
2830

2931
```bash
30-
pkg-static -C /dev/null add https://github.com/jaredhendrickson13/pfsense-api/releases/latest/download/pfSense-2.7.2-pkg-RESTAPI.pkg
32+
pkg-static add https://github.com/jaredhendrickson13/pfsense-api/releases/latest/download/pfSense-2.7.2-pkg-RESTAPI.pkg
3133
```
3234

33-
!!! Note
34-
You may need to customize the installation command to reference the package built for your pfSense version. Check
35-
the [releases page](https://github.com/jaredhendrickson13/pfsense-api/releases) to find the package built for
36-
your version of pfSense.
35+
**Install on pfSense Plus**
36+
37+
```bash
38+
pkg-static -C /dev/null add https://github.com/jaredhendrickson13/pfsense-api/releases/latest/download/pfSense-24.03-pkg-RESTAPI.pkg
39+
```
3740

3841
!!! Important
39-
When updating pfSense, **you must reinstall this package afterward** as pfSense removes unofficial packages during
40-
system updates and has no way to automatically reinstall them.
42+
- You may need to customize the installation command to reference the package built for your pfSense version. Check
43+
the [releases page](https://github.com/jaredhendrickson13/pfsense-api/releases) to find the package built for
44+
your version of pfSense.
45+
- When updating pfSense, **you must reinstall this package afterward** as pfSense removes unofficial packages during
46+
system updates and has no way to automatically reinstall them.
4147

4248
## Configuring the package
4349

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/ModelSet.inc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,11 @@ class ModelSet {
157157
$field = $query_options['field'];
158158
$filter_name = $query_options['filter'];
159159

160-
# Skip this field if it's excluded
161-
if (in_array($field, $excluded)) {
160+
# Skip this field if it's excluded or not present in the model object
161+
if (in_array($field, $excluded) or !property_exists($model_object, $field)) {
162162
continue;
163163
}
164164

165-
# Ensure this object has the requested field
166-
if (!property_exists($model_object, $field)) {
167-
$is_match = false;
168-
break;
169-
}
170-
171165
# Obtain the value for this field. If it is the ID, handle accordingly.
172166
$field_value = $field === 'id' ? $model_object->id : $model_object->$field->value;
173167

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DefaultGateway.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DefaultGateway extends Model {
2222

2323
# Set model fields
2424
$this->defaultgw4 = new ForeignModelField(
25-
model_name: 'RoutingGateway',
25+
model_name: ['RoutingGateway', 'RoutingGatewayGroup'],
2626
model_field: 'name',
2727
model_query: ['ipprotocol' => 'inet'],
2828
allowed_keywords: ['', '-'],
@@ -32,7 +32,7 @@ class DefaultGateway extends Model {
3232
'automatically determine the default gateway, or set to `-` to assign no gateway.',
3333
);
3434
$this->defaultgw6 = new ForeignModelField(
35-
model_name: 'RoutingGateway',
35+
model_name: ['RoutingGateway', 'RoutingGatewayGroup'],
3636
model_field: 'name',
3737
model_query: ['ipprotocol' => 'inet6'],
3838
allowed_keywords: ['', '-'],

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/RESTAPIVersion.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class RESTAPIVersion extends Model {
4343
);
4444
$this->update_available = new BooleanField(
4545
read_only: true,
46+
indicates_true: true,
4647
help_text: 'Indicates if an API update is available for this system.',
4748
);
4849
$this->install_version = new StringField(

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/WireGuardPeer.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class WireGuardPeer extends Model {
7171
$this->publickey = new StringField(required: true, unique: true, help_text: 'The public key for this peer.');
7272
$this->presharedkey = new StringField(
7373
default: '',
74+
allow_empty: true,
7475
allow_null: true,
7576
write_only: true,
7677
help_text: 'The pre-shared key for this tunnel.',

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDefaultGatewayTestCase.inc

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,52 @@ namespace RESTAPI\Tests;
44

55
use RESTAPI\Core\TestCase;
66
use RESTAPI\Models\DefaultGateway;
7+
use RESTAPI\Models\RoutingGateway;
8+
use RESTAPI\Models\RoutingGatewayGroup;
79

810
class APIModelsDefaultGatewayTestCase extends TestCase {
11+
/**
12+
* @var RoutingGateway $gateway The RoutingGateway object we will use for testing.
13+
*/
14+
private RoutingGateway $gateway;
15+
16+
/**
17+
* @var RoutingGatewayGroup $gateway_group The RoutingGatewayGroup object we will use for testing.
18+
*/
19+
private RoutingGatewayGroup $gateway_group;
20+
21+
/**
22+
* Setup the test case by creating a new RoutingGateway and GatewayGroup we can use for testing.
23+
*/
24+
public function setup(): void {
25+
# Create a gateway object we can use for testing
26+
$this->gateway = new RoutingGateway(
27+
name: 'testgw',
28+
interface: 'wan',
29+
gateway: '1.2.3.4',
30+
nonlocalgateway: true,
31+
ipprotocol: 'inet',
32+
);
33+
$this->gateway->create();
34+
35+
# Create a gateway group object we can use for testing
36+
$this->gateway_group = new RoutingGatewayGroup(
37+
name: 'testgwgroup',
38+
trigger: 'down',
39+
descr: 'Test Gateway Group',
40+
priorities: [['gateway' => $this->gateway->name->value, 'tier' => 1, 'virtual_ip' => 'address']],
41+
);
42+
$this->gateway_group->create();
43+
}
44+
45+
/**
46+
* Tear down the test case by deleting the RoutingGateway and GatewayGroup objects we created.
47+
*/
48+
public function teardown(): void {
49+
$this->gateway_group->delete();
50+
$this->gateway->delete();
51+
}
52+
953
/**
1054
* Ensure we can update the DefaultGateway for both IPv4 and IPv6
1155
*/
@@ -17,4 +61,19 @@ class APIModelsDefaultGatewayTestCase extends TestCase {
1761
},
1862
);
1963
}
64+
65+
/**
66+
* Ensure we can assign an existing RoutingGateway or RoutingGatewayGroup as the DefaultGateway
67+
*/
68+
public function test_assign_gateway_or_gateway_group(): void {
69+
$this->assert_does_not_throw(
70+
callable: function () {
71+
$default_gw = new DefaultGateway(defaultgw4: $this->gateway->name->value);
72+
$default_gw->validate();
73+
74+
$default_gw = new DefaultGateway(defaultgw4: $this->gateway_group->name->value);
75+
$default_gw->validate();
76+
},
77+
);
78+
}
2079
}

0 commit comments

Comments
 (0)