Skip to content

Commit

Permalink
Merge pull request #559 from jaredhendrickson13/next_patch
Browse files Browse the repository at this point in the history
v2.1.1 Fixes
  • Loading branch information
jaredhendrickson13 authored Sep 7, 2024
2 parents b62e4ba + 3239af6 commit 9ebf524
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 22 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@ provide you with the information you need to configure and use the package effec

## Quickstart

For new users, it is recommended to refer to the links in the [Getting Started section](#getting-started) to begin. Otherwise, the install
command is included below for quick reference:
For new users, it is recommended to refer to the links in the [Getting Started section](#getting-started) to begin. Otherwise, the installation
commands are included below for quick reference.

Install on pfSense CE:

```bash
pkg-static add https://github.com/jaredhendrickson13/pfsense-api/releases/latest/download/pfSense-2.7.2-pkg-RESTAPI.pkg
```

Install on pfSense Plus:

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

> [!NOTE]
> [!IMPORTANT]
> You may need to customize the installation command to reference the package built for your pfSense version. Check
> the [releases page](https://github.com/jaredhendrickson13/pfsense-api/releases) to find the package built for
> your version of pfSense.
Expand Down
22 changes: 14 additions & 8 deletions docs/INSTALL_AND_CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,26 @@ run pfSense. It's recommended to follow Netgate's [minimum hardware requirements
## Installing the package

The pfSense REST API package is built just like any other pfSense package and can therefor be installed easily using
`pkg` from the pfSense command line:
`pkg` from the pfSense command line. Below are the installation commands for the latest version of the package.

**Install on pfSense CE**

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

!!! Note
You may need to customize the installation command to reference the package built for your pfSense version. Check
the [releases page](https://github.com/jaredhendrickson13/pfsense-api/releases) to find the package built for
your version of pfSense.
**Install on pfSense Plus**

```bash
pkg-static -C /dev/null add https://github.com/jaredhendrickson13/pfsense-api/releases/latest/download/pfSense-24.03-pkg-RESTAPI.pkg
```

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

## Configuring the package

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,11 @@ class ModelSet {
$field = $query_options['field'];
$filter_name = $query_options['filter'];

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

# Ensure this object has the requested field
if (!property_exists($model_object, $field)) {
$is_match = false;
break;
}

# Obtain the value for this field. If it is the ID, handle accordingly.
$field_value = $field === 'id' ? $model_object->id : $model_object->$field->value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DefaultGateway extends Model {

# Set model fields
$this->defaultgw4 = new ForeignModelField(
model_name: 'RoutingGateway',
model_name: ['RoutingGateway', 'RoutingGatewayGroup'],
model_field: 'name',
model_query: ['ipprotocol' => 'inet'],
allowed_keywords: ['', '-'],
Expand All @@ -32,7 +32,7 @@ class DefaultGateway extends Model {
'automatically determine the default gateway, or set to `-` to assign no gateway.',
);
$this->defaultgw6 = new ForeignModelField(
model_name: 'RoutingGateway',
model_name: ['RoutingGateway', 'RoutingGatewayGroup'],
model_field: 'name',
model_query: ['ipprotocol' => 'inet6'],
allowed_keywords: ['', '-'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class RESTAPIVersion extends Model {
);
$this->update_available = new BooleanField(
read_only: true,
indicates_true: true,
help_text: 'Indicates if an API update is available for this system.',
);
$this->install_version = new StringField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class WireGuardPeer extends Model {
$this->publickey = new StringField(required: true, unique: true, help_text: 'The public key for this peer.');
$this->presharedkey = new StringField(
default: '',
allow_empty: true,
allow_null: true,
write_only: true,
help_text: 'The pre-shared key for this tunnel.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,52 @@ namespace RESTAPI\Tests;

use RESTAPI\Core\TestCase;
use RESTAPI\Models\DefaultGateway;
use RESTAPI\Models\RoutingGateway;
use RESTAPI\Models\RoutingGatewayGroup;

class APIModelsDefaultGatewayTestCase extends TestCase {
/**
* @var RoutingGateway $gateway The RoutingGateway object we will use for testing.
*/
private RoutingGateway $gateway;

/**
* @var RoutingGatewayGroup $gateway_group The RoutingGatewayGroup object we will use for testing.
*/
private RoutingGatewayGroup $gateway_group;

/**
* Setup the test case by creating a new RoutingGateway and GatewayGroup we can use for testing.
*/
public function setup(): void {
# Create a gateway object we can use for testing
$this->gateway = new RoutingGateway(
name: 'testgw',
interface: 'wan',
gateway: '1.2.3.4',
nonlocalgateway: true,
ipprotocol: 'inet',
);
$this->gateway->create();

# Create a gateway group object we can use for testing
$this->gateway_group = new RoutingGatewayGroup(
name: 'testgwgroup',
trigger: 'down',
descr: 'Test Gateway Group',
priorities: [['gateway' => $this->gateway->name->value, 'tier' => 1, 'virtual_ip' => 'address']],
);
$this->gateway_group->create();
}

/**
* Tear down the test case by deleting the RoutingGateway and GatewayGroup objects we created.
*/
public function teardown(): void {
$this->gateway_group->delete();
$this->gateway->delete();
}

/**
* Ensure we can update the DefaultGateway for both IPv4 and IPv6
*/
Expand All @@ -17,4 +61,19 @@ class APIModelsDefaultGatewayTestCase extends TestCase {
},
);
}

/**
* Ensure we can assign an existing RoutingGateway or RoutingGatewayGroup as the DefaultGateway
*/
public function test_assign_gateway_or_gateway_group(): void {
$this->assert_does_not_throw(
callable: function () {
$default_gw = new DefaultGateway(defaultgw4: $this->gateway->name->value);
$default_gw->validate();

$default_gw = new DefaultGateway(defaultgw4: $this->gateway_group->name->value);
$default_gw->validate();
},
);
}
}

0 comments on commit 9ebf524

Please sign in to comment.