Skip to content

Commit e27c740

Browse files
committed
New API: network_address_aliases_get / filter_rules_get
network_address_aliases_get --- - Returns address aliaes used by rules. - HTTP: **GET** - Params: none *Example Request* ```bash curl \ -X GET \ --silent \ --insecure \ --header "fauxapi-auth: <auth-value>" \ "https://<host-address>/fauxapi/v1/?action=network_address_aliases_get" ``` *Example Response* ```javascript { "callid": "5e205fc052956", "action": "network_address_aliases_get", "message": "ok", "data": { "aliases": { "alias": [ { "name": "EasyRuleBlockHostsWAN", "type": "network", "address": "1.2.3.4/32 5.6.7.8/32", "descr": "Hosts blocked from Firewall Log view", "detail": "Entry added Fri, 27 Dec 2019 00:53:01 -0800||\u5df2\u6dfb\u52a0\u6761\u76ee Thu, 16 Jan 2020 03:42:37 -0800" } ] } } } ``` filter_rules_get --- - Returns address aliaes used by rules. - HTTP: **GET** - Params: none *Example Request* ```bash curl \ -X GET \ --silent \ --insecure \ --header "fauxapi-auth: <auth-value>" \ "https://<host-address>/fauxapi/v1/?action=filter_rules_get" ``` *Example Response* ```javascript { "callid": "5e2060797a602", "action": "filter_rules_get", "message": "ok", "data": { "filter": { "rules": [ { "id": "", "tracker": "1579178400", "type": "pass", "interface": "wan", "ipprotocol": "inet", "tag": "", "tagged": "", "max": "", "max-src-nodes": "", "max-src-conn": "", "max-src-states": "", "statetimeout": "", "statetype": "keep state", "os": "", "protocol": "tcp", "source": { "address": "1.2.1.1" }, "destination": { "any": "", "port": "1-65535" }, "descr": "", "updated": { "time": "1579178400", "username": "admin@192.168.88.1 (Local Database)" }, "created": { "time": "1579178400", "username": "admin@192.168.88.1 (Local Database)" } }, { "type": "block", "interface": "wan", "ipprotocol": "inet", "source": { "address": "EasyRuleBlockHostsWAN" }, "destination": { "any": "" }, "descr": "Easy Rule: Blocked from Firewall Log View", "created": { "time": "1577436781", "username": "Easy Rule" }, "tracker": "1577436781" }, { "type": "drop", "ipprotocol": "inet", "descr": "Default allow LAN to any rule", "interface": "lan", "source": { "network": "lan" }, "destination": { "ip": "192.10.1.1" } } ] } } } ``` Signed-off-by: lilinzhe <slayercat.subscription@gmail.com>
1 parent 74964de commit e27c740

3 files changed

Lines changed: 201 additions & 0 deletions

File tree

README.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ tasks feasible.
2323
- [send_event](#user-content-send_event) - Performs a pfSense "send_event" command to cause various pfSense system actions.
2424
- [system_reboot](#user-content-system_reboot) - Reboots the pfSense system.
2525
- [system_stats](#user-content-system_stats) - Returns various useful system stats.
26+
- [network_address_aliases_get](#user-content-network_address_aliases_get) - Returns address aliaes used by rules.
27+
- [filter_rules_get](#user-content-filter_rules_get) - Returns firewall filters.
2628

2729

2830
## Approach
@@ -869,6 +871,135 @@ curl \
869871
}
870872
```
871873
---
874+
### network_address_aliases_get
875+
- Returns address aliaes used by rules.
876+
- HTTP: **GET**
877+
- Params: none
878+
879+
*Example Request*
880+
```bash
881+
curl \
882+
-X GET \
883+
--silent \
884+
--insecure \
885+
--header "fauxapi-auth: <auth-value>" \
886+
"https://<host-address>/fauxapi/v1/?action=network_address_aliases_get"
887+
```
888+
889+
*Example Response*
890+
```javascript
891+
{
892+
"callid": "5e205fc052956",
893+
"action": "network_address_aliases_get",
894+
"message": "ok",
895+
"data": {
896+
"aliases": {
897+
"alias": [
898+
{
899+
"name": "EasyRuleBlockHostsWAN",
900+
"type": "network",
901+
"address": "1.2.3.4/32 5.6.7.8/32",
902+
"descr": "Hosts blocked from Firewall Log view",
903+
"detail": "Entry added Fri, 27 Dec 2019 00:53:01 -0800||\u5df2\u6dfb\u52a0\u6761\u76ee Thu, 16 Jan 2020 03:42:37 -0800"
904+
}
905+
]
906+
}
907+
}
908+
}
909+
```
910+
---
911+
### filter_rules_get
912+
- Returns firewall filters.
913+
- HTTP: **GET**
914+
- Params: none
915+
916+
*Example Request*
917+
```bash
918+
curl \
919+
-X GET \
920+
--silent \
921+
--insecure \
922+
--header "fauxapi-auth: <auth-value>" \
923+
"https://<host-address>/fauxapi/v1/?action=filter_rules_get"
924+
```
925+
926+
*Example Response*
927+
```javascript
928+
{
929+
"callid": "5e2060797a602",
930+
"action": "filter_rules_get",
931+
"message": "ok",
932+
"data": {
933+
"filter": {
934+
"rules": [
935+
{
936+
"id": "",
937+
"tracker": "1579178400",
938+
"type": "pass",
939+
"interface": "wan",
940+
"ipprotocol": "inet",
941+
"tag": "",
942+
"tagged": "",
943+
"max": "",
944+
"max-src-nodes": "",
945+
"max-src-conn": "",
946+
"max-src-states": "",
947+
"statetimeout": "",
948+
"statetype": "keep state",
949+
"os": "",
950+
"protocol": "tcp",
951+
"source": {
952+
"address": "1.2.1.1"
953+
},
954+
"destination": {
955+
"any": "",
956+
"port": "1-65535"
957+
},
958+
"descr": "",
959+
"updated": {
960+
"time": "1579178400",
961+
"username": "admin@192.168.88.1 (Local Database)"
962+
},
963+
"created": {
964+
"time": "1579178400",
965+
"username": "admin@192.168.88.1 (Local Database)"
966+
}
967+
},
968+
{
969+
"type": "block",
970+
"interface": "wan",
971+
"ipprotocol": "inet",
972+
"source": {
973+
"address": "EasyRuleBlockHostsWAN"
974+
},
975+
"destination": {
976+
"any": ""
977+
},
978+
"descr": "Easy Rule: Blocked from Firewall Log View",
979+
"created": {
980+
"time": "1577436781",
981+
"username": "Easy Rule"
982+
},
983+
"tracker": "1577436781"
984+
},
985+
{
986+
"type": "drop",
987+
"ipprotocol": "inet",
988+
"descr": "Default allow LAN to any rule",
989+
"interface": "lan",
990+
"source": {
991+
"network": "lan"
992+
},
993+
"destination": {
994+
"ip": "192.10.1.1"
995+
}
996+
}
997+
]
998+
}
999+
}
1000+
}
1001+
```
1002+
---
8721003
8731004
## Versions and Testing
8741005
The FauxAPI has been developed against pfSense 2.3.2, 2.3.3, 2.3.4, 2.3.5, 2.4.3, 2.4.4 it has

pfSense-pkg-FauxAPI/files/etc/inc/fauxapi/fauxapi_actions.inc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,54 @@ class fauxApiActions {
401401
);
402402
return TRUE;
403403
}
404+
405+
/**
406+
* filter_rules_get()
407+
*
408+
* @return boolean
409+
*/
410+
public function filter_rules_get() {
411+
fauxApiLogger::debug(__METHOD__);
412+
413+
$rules = $this->PfsenseInterface->filter_rules_get();
414+
415+
if (empty($rules)) {
416+
$this->response->http_code = 500;
417+
$this->response->message = 'unable to get filter rule(s)';
418+
return FALSE;
419+
}
420+
$this->response->http_code = 200;
421+
$this->response->message = 'ok';
422+
$this->response->data = array(
423+
'filter' => array(
424+
'rules' => $rules
425+
),
426+
);
427+
return TRUE;
428+
}
429+
430+
/**
431+
* address_aliases_get()
432+
*
433+
* @return boolean
434+
*/
435+
public function network_address_aliases_get() {
436+
fauxApiLogger::debug(__METHOD__);
437+
438+
$alias = $this->PfsenseInterface->network_address_aliases_get();
439+
440+
if (empty($alias)) {
441+
$this->response->http_code = 500;
442+
$this->response->message = 'unable to get address aliases';
443+
return FALSE;
444+
}
445+
$this->response->http_code = 200;
446+
$this->response->message = 'ok';
447+
$this->response->data = array(
448+
'aliases' => $alias,
449+
);
450+
return TRUE;
451+
}
404452

405453
/**
406454
* alias_update_urltables()

pfSense-pkg-FauxAPI/files/etc/inc/fauxapi/fauxapi_pfsense_interface.inc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,28 @@ class fauxApiPfsenseInterface {
719719
return \pfSense_get_interface_stats($interface);
720720
}
721721

722+
/**
723+
* filter_rules_get()
724+
*
725+
* @return array
726+
*/
727+
public function filter_rules_get(){
728+
global $config;
729+
fauxApiLogger::debug(__METHOD__);
730+
return $config["filter"]["rule"];
731+
}
732+
733+
/**
734+
* network_address_aliases_get()
735+
*
736+
* @return array
737+
*/
738+
public function network_address_aliases_get(){
739+
global $config;
740+
fauxApiLogger::debug(__METHOD__);
741+
return $config["aliases"];
742+
}
743+
722744
/**
723745
* function_call()
724746
*

0 commit comments

Comments
 (0)