ESP32/ESP8266 Firewall 1.0.0
a software firewall for ESP23 or ESP8266
|
The API to create, edit or remove Firewall rules. More...
#include <API.hpp>
Public Member Functions | |
API (Firewall *, const char *cert, const char *key, const char *username, const char *password, const String ip, const uint16_t port=8080) | |
Construct a new API object, assign ip and port to generate endpoint list, setup authentication, create WebServer, setup routing. More... | |
~API () | |
Destroy the API object. | |
Private Member Functions | |
String | get_url_base () |
Get the url base string e.g. http://0.0.0.0:8080/api. More... | |
ok_t | setup_auth (const char *username, const char *password) |
Set up authentication. More... | |
auth_t | check_auth () |
check if request to API can proceed or needs to stop More... | |
void | setup_routing (const char *cert, const char *key) |
Set up the routing/endpoints and encryption. More... | |
void | add_endpoint_to_list (const String uri, const char *method, const char *description) |
add endpoint information to linked list that is used for the /api endpoint More... | |
void | not_found_handler () |
handling not found | |
void | get_endpoint_list_handler () |
GET handler to retrieve endpoint list. | |
void | get_firewall_rule_handler () |
GET handler to retrieve single firewall rule. | |
void | get_firewall_rules_handler () |
GET handler to retrieve firewall rules. | |
void | post_firewall_handler () |
POST handler to create firewall rule. | |
void | put_firewall_handler () |
PUT handler to update firewall rule. | |
void | delete_firewall_handler () |
DELETE handler to delete firewall rule. | |
bool | request_has_all_firewall_parameter () |
check if request to create/update firewall rule has all required parameter More... | |
String | json_new_attribute (String key, String value, bool last=false) |
add another attribute to the json object More... | |
String | json_new_attribute (String key, uint32_t value, bool last=false) |
add another attribute to the json object More... | |
void | json_generic_response (String serialized_string, const uint16_t response_code) |
json response to send any string and response code More... | |
void | json_array_response (String serialized_string, const uint16_t response_code) |
json response that wraps the message in array brackets More... | |
void | json_message_response (String message, const uint16_t response_code) |
json response to send message as json object More... | |
String | construct_json_firewall_rule (firewall_rule_t *rule_ptr) |
construct a firewall rule as json object More... | |
String | construct_json_firewall () |
construct array of all firewall rules as json object More... | |
String | construct_json_api_endpoint (api_endpoint_t *api_ptr) |
construct an API endpoint as json object More... | |
String | construct_json_api () |
construct array of all endpoints as json object More... | |
Private Attributes | |
WebServer * | server |
Firewall * | firewall |
credential_t | credentials |
api_endpoint_t * | endpoint_head = NULL |
String | api_ip = "0.0.0.0" |
uint16_t | api_port |
String | json_response_type = "application/json; charset=utf-8" |
const char * | TAG = "[API]" |
fw::API::API | ( | fw::Firewall * | firewall, |
const char * | cert, | ||
const char * | key, | ||
const char * | username, | ||
const char * | password, | ||
const String | ip, | ||
const uint16_t | port = 8080 |
||
) |
Construct a new API object, assign ip and port to generate endpoint list, setup authentication, create WebServer, setup routing.
cert | |
key | |
username | |
password | |
ip | |
port |
|
private |
add endpoint information to linked list that is used for the /api endpoint
uri | |
method | |
description |
|
private |
check if request to API can proceed or needs to stop
|
private |
construct array of all endpoints as json object
api_ptr |
|
private |
|
private |
construct array of all firewall rules as json object
|
private |
construct a firewall rule as json object
rule_ptr |
|
private |
Get the url base string e.g. http://0.0.0.0:8080/api.
|
private |
json response that wraps the message in array brackets
serialized_string | |
response_code |
|
private |
json response to send any string and response code
serialized_string | |
response_code |
|
private |
json response to send message as json object
message | |
response_code |
|
private |
add another attribute to the json object
key | |
value | |
last |
|
private |
add another attribute to the json object
key | |
value | |
last |
|
private |
check if request to create/update firewall rule has all required parameter
|
private |
Set up authentication.
username | |
password |
|
private |
Set up the routing/endpoints and encryption.
cert | |
key |