Skip to content

Commit 474d594

Browse files
author
Jared Hendrickson
committed
Fixed typos, removed unnecessary operators, updated documentation for new release
1 parent 11b72fb commit 474d594

9 files changed

Lines changed: 146 additions & 112 deletions

File tree

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,29 @@ webConfigurator are required to make calls to the API endpoints
2121
# Installation
2222
To install pfSense API, simply run the following command from the pfSense shell:<br>
2323
```
24-
pkg add https://github.com/jaredhendrickson13/pfsense-api/releases/download/v1.0.0/pfSense-2-4-pkg-API-1.0_0.txz && /etc/rc.restart_webgui
24+
pkg add https://github.com/jaredhendrickson13/pfsense-api/releases/latest/download/pfSense-2.4-pkg-API.txz && /etc/rc.restart_webgui
2525
```
2626

27-
To uninstall, run the following command:<br>
27+
To uninstall pfSense API, run the following command:<br>
2828
```
2929
pkg delete pfSense-pkg-API
3030
```
3131

32+
To update pfSense API to latest version, run the following command:
33+
```
34+
pkg delete pfSense-pkg-API && pkg add https://github.com/jaredhendrickson13/pfsense-api/releases/latest/download/pfSense-2.4-pkg-API.txz && /etc/rc.restart_webgui
35+
```
36+
3237
### Notes:
38+
- pfSense API is supported on the pfSense 2.5 developer snapshots. To install the 2.5 package, simply change the `2.4` in the install URL to `2.5`.
3339
- In order for pfSense to apply some required web server changes, it is required to restart the webConfigurator after installing the package
3440
- If you do not have shell access to pfSense, you can still install via the webConfigurator by navigating to
3541
'Diagnostics > Command Prompt' and enter the commands there
42+
- When updating pfSense, **_you must reinstall pfSense API afterwards_**. Unfortunately, pfSense removes all existing packages and only reinstalls packages found within pfSense's package repositories. Since pfSense API is not an official package in pfSense's repositories, it does not get reinstalled automatically.
3643

3744

3845
# UI Settings & Documentation
39-
After installation, you will be able to access the API user interface pages within the pfSense webConfigurator. These will be found under System > API. The settings tab will allow you change various API settings such as enabled API interfaces, authentication modes, and more. Additionally, the documentation tab will give you access to an embedded documentation tool that makes it easy to view the full API documentation with context to your pfSense instance.
46+
After installation, you will be able to access the API user interface pages within the pfSense webConfigurator. These will be found under System > API. The settings tab will allow you change various API settings such as enabled API interfaces, authentication modes, and more. Additionally, the documentation tab will give you access to an embedded documentation tool that makes it easy to view the full API documentation in context to your pfSense instance.
4047

4148
### Notes:
4249
- Users must hold the `page-all` or `page-system-api` privileges to access the API page within the webConfigurator

docs/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ writing a model that tests user's local database credentials and do not want the
100100
auth mode you would specify `$this->set_auth_mode = "local";` to always force local authentication. Defaults to the
101101
API's configured auth mode in the /api/ webConfigurator page.
102102

103-
- `$this->set_read_mode` : Allows the read only API setting to be bypassed for this model. If you set this value to
104-
`true` the model will be allowed to use POST, PUT or DELETE methods even when the API is in read only mode. There is
103+
- `$this->set_read_mode` : Allows the read-only API setting to be bypassed for this model. If you set this value to
104+
`true` the model will be allowed to use POST, PUT or DELETE methods even when the API is in read-only mode. There is
105105
rarely a use case for this. Do not override this property unless absolutely needed.
106106

107107
- `$this->change_note` : Sets the description of the action that occurred via API. This value will be shown in the

docs/documentation.json

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class APIAuth {
123123
# If no require privileges were given, assume call is always authorized
124124
if (!empty($this->req_privs)) {
125125
# If API is in readonly mode, only allow GET requests
126-
if ($this->read_mode === false or ($this->read_mode === true and $_SERVER['REQUEST_METHOD'] === "GET")) {
126+
if (!$this->read_mode or ($this->read_mode and $_SERVER['REQUEST_METHOD'] === "GET")) {
127127
# Loop through each of our req privs and ensure the client has them, also check if access is read only
128128
foreach ($this->req_privs as &$priv) {
129129
if (in_array($priv, $this->privs)) {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ class APIModel {
3737
error_reporting(E_ERROR);
3838
$this->config =& $config;
3939
$this->privileges = ["page-all"];
40-
$this->client = null;
4140
$this->requires_auth = true;
42-
$this->set_auth_mode = null;
43-
$this->bypass_read_mode = null;
4441
$this->change_note = "Made unknown change via API";
45-
$this->id = null;
4642
$this->validate_id = true;
4743
$this->initial_data = APITools\get_request_data();
4844
$this->validated_data = [];

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,12 @@ class APIFirewallRuleUpdate extends APIModel {
8888
if (isset($this->initial_data['protocol'])) {
8989
$missing_port = (!in_array($this->validated_data["protocol"], ["tcp", "udp", "tcp/udp"])) ? true : false;
9090
$requires_port = (in_array($this->initial_data["protocol"], ["tcp", "udp", "tcp/udp"])) ? true : false;
91+
$this->unset_ports();
9192
$protocol_options = [
9293
"any", "tcp", "udp", "tcp/udp", "icmp", "esp", "ah",
9394
"gre", "ipv6", "igmp", "pim", "ospf", "carp", "pfsync"
9495
];
9596

96-
# If a new protocol was chosen that doesn't require a port, remove existing ports from the rule
97-
if ((!in_array($this->initial_data["protocol"], ["tcp", "udp", "tcp/udp"]))) {
98-
unset($this->validated_data["source"]["port"]);
99-
unset($this->validated_data["destination"]["port"]);
100-
}
101-
10297
# Check that our protocol value is a support option
10398
if (in_array($this->initial_data["protocol"], $protocol_options)) {
10499
# Don't add a specific protocol if any
@@ -196,7 +191,6 @@ class APIFirewallRuleUpdate extends APIModel {
196191
}
197192
}
198193

199-
200194
# Check for our optional 'disabled' payload value
201195
if ($this->initial_data['disabled'] === true) {
202196
$this->validated_data["disabled"] = "";
@@ -225,4 +219,13 @@ class APIFirewallRuleUpdate extends APIModel {
225219
"username" => $this->client->username."@".$this->client->ip_address." (API)"
226220
];
227221
}
222+
223+
# Removes port specifications when updating to a protocol that is not port based
224+
private function unset_ports() {
225+
# If a new protocol was chosen that doesn't require a port, remove existing ports from the rule
226+
if ((!in_array($this->initial_data["protocol"], ["tcp", "udp", "tcp/udp"]))) {
227+
unset($this->validated_data["source"]["port"]);
228+
unset($this->validated_data["destination"]["port"]);
229+
}
230+
}
228231
}

0 commit comments

Comments
 (0)