use basic auth again
This commit is contained in:
parent
bda65724aa
commit
a4870fd6fd
2 changed files with 22 additions and 0 deletions
|
@ -41,6 +41,19 @@ namespace fw
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth_t API::check_auth()
|
||||||
|
{
|
||||||
|
if (server->authenticate(this->credentials.username, this->credentials.password))
|
||||||
|
{
|
||||||
|
return AUTHENTICATED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->json_message_response("unauthorized", 403);
|
||||||
|
return DENIED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void API::setup_routing()
|
void API::setup_routing()
|
||||||
{
|
{
|
||||||
this->server->on(UriRegex("/api/v1/firewall/([0-9]+)"), HTTP_GET, std::bind(&API::get_firewall_rule_handler, this));
|
this->server->on(UriRegex("/api/v1/firewall/([0-9]+)"), HTTP_GET, std::bind(&API::get_firewall_rule_handler, this));
|
||||||
|
@ -57,6 +70,8 @@ namespace fw
|
||||||
|
|
||||||
void API::get_firewall_rule_handler()
|
void API::get_firewall_rule_handler()
|
||||||
{
|
{
|
||||||
|
if (this->check_auth() == DENIED)
|
||||||
|
return;
|
||||||
String param = this->server->pathArg(0);
|
String param = this->server->pathArg(0);
|
||||||
int rule_number = atoi(param.c_str());
|
int rule_number = atoi(param.c_str());
|
||||||
firewall_rule_t *rule_ptr = get_rule_from_firewall(rule_number);
|
firewall_rule_t *rule_ptr = get_rule_from_firewall(rule_number);
|
||||||
|
@ -72,11 +87,15 @@ namespace fw
|
||||||
|
|
||||||
void API::get_firewall_rules_handler()
|
void API::get_firewall_rules_handler()
|
||||||
{
|
{
|
||||||
|
if (this->check_auth() == DENIED)
|
||||||
|
return;
|
||||||
this->json_generic_response(this->construct_json_firewall(), 200);
|
this->json_generic_response(this->construct_json_firewall(), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void API::post_firewall_handler()
|
void API::post_firewall_handler()
|
||||||
{
|
{
|
||||||
|
if (this->check_auth() == DENIED)
|
||||||
|
return;
|
||||||
if (request_has_firewall_parameter())
|
if (request_has_firewall_parameter())
|
||||||
{
|
{
|
||||||
firewall_rule_t *rule_ptr = (firewall_rule_t *)malloc(sizeof(firewall_rule_t));
|
firewall_rule_t *rule_ptr = (firewall_rule_t *)malloc(sizeof(firewall_rule_t));
|
||||||
|
@ -103,6 +122,8 @@ namespace fw
|
||||||
|
|
||||||
void API::delete_firewall_handler()
|
void API::delete_firewall_handler()
|
||||||
{
|
{
|
||||||
|
if (this->check_auth() == DENIED)
|
||||||
|
return;
|
||||||
String param = this->server->pathArg(0);
|
String param = this->server->pathArg(0);
|
||||||
int rule_number = atoi(param.c_str());
|
int rule_number = atoi(param.c_str());
|
||||||
if (delete_rule_from_firewall(rule_number) == SUCCESS)
|
if (delete_rule_from_firewall(rule_number) == SUCCESS)
|
||||||
|
|
|
@ -24,6 +24,7 @@ namespace fw
|
||||||
credential_t credentials;
|
credential_t credentials;
|
||||||
|
|
||||||
ok_t setup_auth(const char *, const char *);
|
ok_t setup_auth(const char *, const char *);
|
||||||
|
auth_t check_auth();
|
||||||
|
|
||||||
void setup_routing();
|
void setup_routing();
|
||||||
void get_firewall_rule_handler();
|
void get_firewall_rule_handler();
|
||||||
|
|
Reference in a new issue