Skip to content

Commit f247f93

Browse files
author
Jared Hendrickson
committed
Fixed caption on API UI page that mentioned old authentication methods, added endpoint to read current DHCP leases, added unit test for DHCP leases endpoint, updated documentation
1 parent f2eb71a commit f247f93

8 files changed

Lines changed: 362 additions & 36 deletions

File tree

README.md

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,10 @@ There is no limit to API calls at this time but is important to note that pfSens
510510

511511
* [FIREWALL/NAT/ONE_TO_ONE](#firewallnatone_to_one)
512512

513-
* [Create NAT 1:1 Mappings](#1-create-nat-1:1-mappings)
514-
* [Delete NAT 1:1 Mappings](#2-delete-nat-1:1-mappings)
515-
* [Read NAT 1:1 Mappings](#3-read-nat-1:1-mappings)
516-
* [Update NAT 1:1 Mappings](#4-update-nat-1:1-mappings)
513+
* [Create NAT 1-to-1 Mappings](#1-create-nat-1-to-1-mappings)
514+
* [Delete NAT 1-to-1 Mappings](#2-delete-nat-1-to-1-mappings)
515+
* [Read NAT 1-to-1 Mappings](#3-read-nat-1-to-1-mappings)
516+
* [Update NAT 1-to-1 Mappings](#4-update-nat-1-to-1-mappings)
517517

518518
* [FIREWALL/NAT/OUTBOUND](#firewallnatoutbound)
519519

@@ -612,6 +612,10 @@ There is no limit to API calls at this time but is important to note that pfSens
612612
* [Stop DHCPd Service](#4-stop-dhcpd-service)
613613
* [Update DHCPd Service Configuration](#5-update-dhcpd-service-configuration)
614614

615+
* [SERVICES/DHCPD/LEASE](#servicesdhcpdlease)
616+
617+
* [Read DHCPd Leases](#1-read-dhcpd-leases)
618+
615619
* [SERVICES/DHCPD/STATIC_MAPPING](#servicesdhcpdstatic_mapping)
616620

617621
* [Create DHCPd Static Mappings](#1-create-dhcpd-static-mappings)
@@ -1062,7 +1066,7 @@ URL: https://{{$hostname}}/api/v1/firewall/apply
10621066

10631067

10641068

1065-
### 1. Create NAT 1:1 Mappings
1069+
### 1. Create NAT 1-to-1 Mappings
10661070

10671071

10681072
Add a new NAT 1:1 Mapping.<br><br>
@@ -1075,7 +1079,7 @@ _Requires at least one of the following privileges:_ [`page-all`, `page-firewall
10751079
```bash
10761080
Method: POST
10771081
Type: RAW
1078-
URL: https://{{$hostname}}/api/v1/firewall/nat/port_forward
1082+
URL: https://{{$hostname}}/api/v1/firewall/nat/one_to_one
10791083
```
10801084

10811085

@@ -1115,7 +1119,7 @@ URL: https://{{$hostname}}/api/v1/firewall/nat/port_forward
11151119

11161120

11171121

1118-
### 2. Delete NAT 1:1 Mappings
1122+
### 2. Delete NAT 1-to-1 Mappings
11191123

11201124

11211125
Delete an existing NAT 1:1 mapping by ID.<br>
@@ -1128,7 +1132,7 @@ _Requires at least one of the following privileges:_ [`page-all`, `page-firewall
11281132
```bash
11291133
Method: DELETE
11301134
Type: RAW
1131-
URL: https://{{$hostname}}/api/v1/firewall/nat/port_forward
1135+
URL: https://{{$hostname}}/api/v1/firewall/nat/one_to_one
11321136
```
11331137

11341138

@@ -1153,7 +1157,7 @@ URL: https://{{$hostname}}/api/v1/firewall/nat/port_forward
11531157

11541158

11551159

1156-
### 3. Read NAT 1:1 Mappings
1160+
### 3. Read NAT 1-to-1 Mappings
11571161

11581162

11591163
Read 1:1 NAT mappings.<br><br>
@@ -1181,7 +1185,7 @@ URL: https://{{$hostname}}/api/v1/firewall/nat/one_to_one
11811185

11821186

11831187

1184-
### 4. Update NAT 1:1 Mappings
1188+
### 4. Update NAT 1-to-1 Mappings
11851189

11861190

11871191
Update an existing NAT 1:1 Mapping.<br><br>
@@ -1194,7 +1198,7 @@ _Requires at least one of the following privileges:_ [`page-all`, `page-firewall
11941198
```bash
11951199
Method: PUT
11961200
Type: RAW
1197-
URL: https://{{$hostname}}/api/v1/firewall/nat/port_forward
1201+
URL: https://{{$hostname}}/api/v1/firewall/nat/one_to_one
11981202
```
11991203

12001204

@@ -3269,6 +3273,39 @@ URL: https://{{$hostname}}/api/v1/services/dhcpd
32693273

32703274

32713275

3276+
## SERVICES/DHCPD/LEASE
3277+
3278+
3279+
3280+
### 1. Read DHCPd Leases
3281+
3282+
3283+
Read the current DHCPd leases.<br>
3284+
3285+
3286+
_Requires at least one of the following privileges:_ [`page-all`, `page-status-dhcpleases`]
3287+
3288+
3289+
***Endpoint:***
3290+
3291+
```bash
3292+
Method: GET
3293+
Type: RAW
3294+
URL: https://{{$hostname}}/api/v1/services/dhcpd/leases
3295+
```
3296+
3297+
3298+
3299+
***Body:***
3300+
3301+
```js
3302+
{
3303+
3304+
}
3305+
```
3306+
3307+
3308+
32723309
## SERVICES/DHCPD/STATIC_MAPPING
32733310

32743311

docs/documentation.json

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2982,7 +2982,7 @@
29822982
"name": "ONE_TO_ONE",
29832983
"item": [
29842984
{
2985-
"name": "Read NAT 1:1 Mappings",
2985+
"name": "Read NAT 1-to-1 Mappings",
29862986
"protocolProfileBehavior": {
29872987
"disableBodyPruning": true
29882988
},
@@ -3017,7 +3017,7 @@
30173017
"response": []
30183018
},
30193019
{
3020-
"name": "Create NAT 1:1 Mappings",
3020+
"name": "Create NAT 1-to-1 Mappings",
30213021
"request": {
30223022
"method": "POST",
30233023
"header": [],
@@ -3031,7 +3031,7 @@
30313031
}
30323032
},
30333033
"url": {
3034-
"raw": "https://{{$hostname}}/api/v1/firewall/nat/port_forward?interface=string&src=string&dst=string&external=string&natreflection=string&descr=string&disabled=boolean&nobinat=boolean&top=boolean&apply=boolean",
3034+
"raw": "https://{{$hostname}}/api/v1/firewall/nat/one_to_one?interface=string&src=string&dst=string&external=string&natreflection=string&descr=string&disabled=boolean&nobinat=boolean&top=boolean&apply=boolean",
30353035
"protocol": "https",
30363036
"host": [
30373037
"{{$hostname}}"
@@ -3041,7 +3041,7 @@
30413041
"v1",
30423042
"firewall",
30433043
"nat",
3044-
"port_forward"
3044+
"one_to_one"
30453045
],
30463046
"query": [
30473047
{
@@ -3101,7 +3101,7 @@
31013101
"response": []
31023102
},
31033103
{
3104-
"name": "Update NAT 1:1 Mappings",
3104+
"name": "Update NAT 1-to-1 Mappings",
31053105
"request": {
31063106
"method": "PUT",
31073107
"header": [],
@@ -3115,7 +3115,7 @@
31153115
}
31163116
},
31173117
"url": {
3118-
"raw": "https://{{$hostname}}/api/v1/firewall/nat/port_forward?id=integer&interface=string&src=string&dst=string&external=string&natreflection=string&descr=string&disabled=boolean&nobinat=boolean&top=boolean&apply=boolean",
3118+
"raw": "https://{{$hostname}}/api/v1/firewall/nat/one_to_one?id=integer&interface=string&src=string&dst=string&external=string&natreflection=string&descr=string&disabled=boolean&nobinat=boolean&top=boolean&apply=boolean",
31193119
"protocol": "https",
31203120
"host": [
31213121
"{{$hostname}}"
@@ -3125,7 +3125,7 @@
31253125
"v1",
31263126
"firewall",
31273127
"nat",
3128-
"port_forward"
3128+
"one_to_one"
31293129
],
31303130
"query": [
31313131
{
@@ -3190,7 +3190,7 @@
31903190
"response": []
31913191
},
31923192
{
3193-
"name": "Delete NAT 1:1 Mappings",
3193+
"name": "Delete NAT 1-to-1 Mappings",
31943194
"request": {
31953195
"method": "DELETE",
31963196
"header": [],
@@ -3204,7 +3204,7 @@
32043204
}
32053205
},
32063206
"url": {
3207-
"raw": "https://{{$hostname}}/api/v1/firewall/nat/port_forward?id=string or integer&apply=boolean",
3207+
"raw": "https://{{$hostname}}/api/v1/firewall/nat/one_to_one?id=string or integer&apply=boolean",
32083208
"protocol": "https",
32093209
"host": [
32103210
"{{$hostname}}"
@@ -3214,7 +3214,7 @@
32143214
"v1",
32153215
"firewall",
32163216
"nat",
3217-
"port_forward"
3217+
"one_to_one"
32183218
],
32193219
"query": [
32203220
{
@@ -7013,6 +7013,49 @@
70137013
"protocolProfileBehavior": {},
70147014
"_postman_isSubFolder": true
70157015
},
7016+
{
7017+
"name": "LEASE",
7018+
"item": [
7019+
{
7020+
"name": "Read DHCPd Leases",
7021+
"protocolProfileBehavior": {
7022+
"disableBodyPruning": true
7023+
},
7024+
"request": {
7025+
"method": "GET",
7026+
"header": [],
7027+
"body": {
7028+
"mode": "raw",
7029+
"raw": "{\n \n}",
7030+
"options": {
7031+
"raw": {
7032+
"language": "json"
7033+
}
7034+
}
7035+
},
7036+
"url": {
7037+
"raw": "https://{{$hostname}}/api/v1/services/dhcpd/leases",
7038+
"protocol": "https",
7039+
"host": [
7040+
"{{$hostname}}"
7041+
],
7042+
"path": [
7043+
"api",
7044+
"v1",
7045+
"services",
7046+
"dhcpd",
7047+
"leases"
7048+
]
7049+
},
7050+
"description": "Read the current DHCPd leases.<br>\n\n\n_Requires at least one of the following privileges:_ [`page-all`, `page-status-dhcpleases`]"
7051+
},
7052+
"response": []
7053+
}
7054+
],
7055+
"description": "API endpoints that create, read, update and delete DHCPd leases.",
7056+
"protocolProfileBehavior": {},
7057+
"_postman_isSubFolder": true
7058+
},
70167059
{
70177060
"name": "Start DHCPd Service",
70187061
"request": {
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 APIServicesDHCPdLease extends APIEndpoint {
19+
public function __construct() {
20+
$this->url = "/api/v1/services/dhcpd/lease";
21+
}
22+
23+
protected function get() {
24+
return (new APIServicesDHCPdLeaseRead())->call();
25+
}
26+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class APIEndpoint {
7070
header("Referer: no-referrer");
7171
http_response_code($resp["code"]);
7272
echo json_encode($resp) . PHP_EOL;
73+
session_destroy();
7374
exit();
7475
}
7576
}

0 commit comments

Comments
 (0)