5#include "ESP8266WebServerSecure.h"
9#include "uri/UriBraces.h"
10#include "Firewall.hpp"
37 API(
Firewall *,
const char *cert,
const char *key,
const char *username,
const char *password,
const String ip,
const uint16_t port = 8080);
50 BearSSL::ESP8266WebServerSecure *server;
51 BearSSL::ServerSessions *serverCache;
58 String api_ip =
"0.0.0.0";
60 String json_response_type =
"application/json; charset=utf-8";
61 const char *TAG =
"[API]";
78 ok_t
setup_auth(
const char *username,
const char *password);
The API to create, edit or remove Firewall rules.
Definition: API.hpp:21
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,...
Definition: API.cpp:5
String json_new_attribute(String key, String value, bool last=false)
add another attribute to the json object
Definition: API.cpp:225
String construct_json_api_endpoint(api_endpoint_t *api_ptr)
construct an API endpoint as json object
Definition: API.cpp:284
void json_array_response(String serialized_string, const uint16_t response_code)
json response that wraps the message in array brackets
Definition: API.cpp:244
void post_firewall_handler()
POST handler to create firewall rule.
Definition: API.cpp:156
ok_t setup_auth(const char *username, const char *password)
Set up authentication.
Definition: API.cpp:52
void delete_firewall_handler()
DELETE handler to delete firewall rule.
Definition: API.cpp:201
~API()
Destroy the API object.
Definition: API.cpp:31
String construct_json_firewall()
construct array of all firewall rules as json object
Definition: API.cpp:270
void json_message_response(String message, const uint16_t response_code)
json response to send message as json object
Definition: API.cpp:249
void put_firewall_handler()
PUT handler to update firewall rule.
Definition: API.cpp:176
void get_endpoint_list_handler()
GET handler to retrieve endpoint list.
Definition: API.cpp:131
void setup_routing(const char *cert, const char *key)
Set up the routing/endpoints and encryption.
Definition: API.cpp:79
String construct_json_api()
construct array of all endpoints as json object
Definition: API.cpp:294
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
Definition: API.cpp:100
void get_firewall_rules_handler()
GET handler to retrieve firewall rules.
Definition: API.cpp:149
bool request_has_all_firewall_parameter()
check if request to create/update firewall rule has all required parameter
Definition: API.cpp:213
String construct_json_firewall_rule(firewall_rule_t *rule_ptr)
construct a firewall rule as json object
Definition: API.cpp:257
void get_firewall_rule_handler()
GET handler to retrieve single firewall rule.
Definition: API.cpp:136
void json_generic_response(String serialized_string, const uint16_t response_code)
json response to send any string and response code
Definition: API.cpp:239
auth_t check_auth()
check if request to API can proceed or needs to stop
Definition: API.cpp:69
void not_found_handler()
handling not found
Definition: API.cpp:126
String get_url_base()
Get the url base string e.g. http://0.0.0.0:8080/api.
Definition: API.cpp:43
The Firewall will handle Firewall rules as linked list.
Definition: Firewall.hpp:20