mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Add /api/info/login and remove some parts from /api/auth
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -44,6 +44,7 @@ static struct {
|
||||
{ "/api/groups", "/{name}", api_list, { false, true, 0 }, true, HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_DELETE },
|
||||
{ "/api/lists", "/{list}", api_list, { false, true, 0 }, true, HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_DELETE },
|
||||
{ "/api/info/client", "", api_info_client, { false, true, 0 }, false, HTTP_GET },
|
||||
{ "/api/info/login", "", api_info_login, { false, true, 0 }, false, HTTP_GET },
|
||||
{ "/api/info/system", "", api_info_system, { false, true, 0 }, true, HTTP_GET },
|
||||
{ "/api/info/database", "", api_info_database, { false, true, 0 }, true, HTTP_GET },
|
||||
{ "/api/info/sensors", "", api_info_sensors, { false, true, 0 }, true, HTTP_GET },
|
||||
|
||||
@@ -60,6 +60,7 @@ int api_info_version(struct ftl_conn *api);
|
||||
int api_info_messages_count(struct ftl_conn *api);
|
||||
int api_info_messages(struct ftl_conn *api);
|
||||
int api_info_metrics(struct ftl_conn *api);
|
||||
int api_info_login(struct ftl_conn *api);
|
||||
|
||||
// Config methods
|
||||
int api_config(struct ftl_conn *api);
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#include "daemon.h"
|
||||
// sha256_raw_to_hex()
|
||||
#include "config/password.h"
|
||||
// get_https_port()
|
||||
#include "webserver/webserver.h"
|
||||
|
||||
// crypto library
|
||||
#include <nettle/sha2.h>
|
||||
@@ -304,7 +302,6 @@ static int get_all_sessions(struct ftl_conn *api, cJSON *json)
|
||||
static int get_session_object(struct ftl_conn *api, cJSON *json, const int user_id, const time_t now)
|
||||
{
|
||||
cJSON *session = JSON_NEW_OBJECT();
|
||||
const bool dns = get_blockingstatus() != DNS_FAILED;
|
||||
|
||||
// Authentication not needed
|
||||
if(user_id == API_AUTH_LOCALHOST || user_id == API_AUTH_EMPTYPASS)
|
||||
@@ -314,8 +311,6 @@ static int get_session_object(struct ftl_conn *api, cJSON *json, const int user_
|
||||
JSON_ADD_NULL_TO_OBJECT(session, "sid");
|
||||
JSON_ADD_NUMBER_TO_OBJECT(session, "validity", -1);
|
||||
JSON_ADD_ITEM_TO_OBJECT(json, "session", session);
|
||||
JSON_ADD_NUMBER_TO_OBJECT(json, "https_port", get_https_port());
|
||||
JSON_ADD_BOOL_TO_OBJECT(json, "dns", dns);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -328,8 +323,6 @@ static int get_session_object(struct ftl_conn *api, cJSON *json, const int user_
|
||||
JSON_REF_STR_IN_OBJECT(session, "csrf", auth_data[user_id].csrf);
|
||||
JSON_ADD_NUMBER_TO_OBJECT(session, "validity", auth_data[user_id].valid_until - now);
|
||||
JSON_ADD_ITEM_TO_OBJECT(json, "session", session);
|
||||
JSON_ADD_NUMBER_TO_OBJECT(json, "https_port", get_https_port());
|
||||
JSON_ADD_BOOL_TO_OBJECT(json, "dns", dns);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -339,8 +332,6 @@ static int get_session_object(struct ftl_conn *api, cJSON *json, const int user_
|
||||
JSON_ADD_NULL_TO_OBJECT(session, "sid");
|
||||
JSON_ADD_NUMBER_TO_OBJECT(session, "validity", -1);
|
||||
JSON_ADD_ITEM_TO_OBJECT(json, "session", session);
|
||||
JSON_ADD_NUMBER_TO_OBJECT(json, "https_port", get_https_port());
|
||||
JSON_ADD_BOOL_TO_OBJECT(json, "dns", dns);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ components:
|
||||
$ref: 'auth.yaml#/components/examples/no_login_required'
|
||||
login_required:
|
||||
$ref: 'auth.yaml#/components/examples/login_required'
|
||||
dns_failure:
|
||||
$ref: 'auth.yaml#/components/examples/dns_failure'
|
||||
post:
|
||||
summary: Submit password for login
|
||||
tags:
|
||||
@@ -245,12 +243,6 @@ components:
|
||||
validity:
|
||||
type: integer
|
||||
description: Remaining lifetime of this session unless refreshed (seconds)
|
||||
https_port:
|
||||
type: integer
|
||||
description: HTTPS port of the Pi-hole webserver (0 if disabled)
|
||||
dns:
|
||||
type: boolean
|
||||
description: Whether the DNS server is up and running. False only in failed state
|
||||
|
||||
password:
|
||||
type: object
|
||||
@@ -374,8 +366,6 @@ components:
|
||||
sid: null
|
||||
csrf: null
|
||||
validity: 300
|
||||
https_port: 443
|
||||
dns: true
|
||||
no_login_required:
|
||||
summary: No login required for this client
|
||||
value:
|
||||
@@ -385,8 +375,6 @@ components:
|
||||
sid: null
|
||||
csrf: null
|
||||
validity: -1
|
||||
https_port: 443
|
||||
dns: true
|
||||
login_required:
|
||||
summary: Login required
|
||||
value:
|
||||
@@ -396,8 +384,6 @@ components:
|
||||
sid: null
|
||||
csrf: null
|
||||
validity: -1
|
||||
https_port: 443
|
||||
dns: true
|
||||
login_failed:
|
||||
summary: Login failed
|
||||
value:
|
||||
@@ -407,19 +393,6 @@ components:
|
||||
sid: null
|
||||
csrf: null
|
||||
validity: -1
|
||||
https_port: 443
|
||||
dns: true
|
||||
dns_failure:
|
||||
summary: DNS server failure
|
||||
value:
|
||||
session:
|
||||
valid: false
|
||||
totp: false
|
||||
sid: null
|
||||
csrf: null
|
||||
validity: -1
|
||||
https_port: 443
|
||||
dns: false
|
||||
errors:
|
||||
no_payload:
|
||||
summary: Bad request (no valid JSON payload)
|
||||
|
||||
@@ -278,6 +278,23 @@ components:
|
||||
allOf:
|
||||
- $ref: 'common.yaml#/components/errors/unauthorized'
|
||||
- $ref: 'common.yaml#/components/schemas/took'
|
||||
login:
|
||||
get:
|
||||
summary: Login page related information
|
||||
tags:
|
||||
- "FTL information"
|
||||
operationId: "get_logininfo"
|
||||
description: |
|
||||
This API hook returns information used on the login page to possibly display messages/warnings.
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: 'info.yaml#/components/schemas/login'
|
||||
- $ref: 'common.yaml#/components/schemas/took'
|
||||
|
||||
schemas:
|
||||
client:
|
||||
@@ -1068,6 +1085,15 @@ components:
|
||||
type: integer
|
||||
description: Number of items
|
||||
example: 42
|
||||
login:
|
||||
type: object
|
||||
properties:
|
||||
https_port:
|
||||
type: integer
|
||||
description: HTTPS port of the Pi-hole webserver (0 if disabled)
|
||||
dns:
|
||||
type: boolean
|
||||
description: Whether the DNS server is up and running. False only in failed state
|
||||
examples:
|
||||
errors:
|
||||
messages:
|
||||
|
||||
@@ -190,6 +190,9 @@ paths:
|
||||
/info/metrics:
|
||||
$ref: 'info.yaml#/components/paths/metrics'
|
||||
|
||||
/info/login:
|
||||
$ref: 'info.yaml#/components/paths/login'
|
||||
|
||||
/logs/dnsmasq:
|
||||
$ref: 'logs.yaml#/components/paths/logs/dnsmasq'
|
||||
|
||||
|
||||
@@ -49,6 +49,9 @@
|
||||
#include <limits.h>
|
||||
#include "metrics.h"
|
||||
|
||||
// get_https_port()
|
||||
#include "webserver/webserver.h"
|
||||
|
||||
// DIR
|
||||
#include <dirent.h>
|
||||
|
||||
@@ -1032,3 +1035,15 @@ int api_info_metrics(struct ftl_conn *api)
|
||||
JSON_ADD_ITEM_TO_OBJECT(json2, "metrics", json);
|
||||
JSON_SEND_OBJECT(json2);
|
||||
}
|
||||
|
||||
int api_info_login(struct ftl_conn *api)
|
||||
{
|
||||
cJSON *json = JSON_NEW_OBJECT();
|
||||
|
||||
const bool dns = get_blockingstatus() != DNS_FAILED;
|
||||
JSON_ADD_BOOL_TO_OBJECT(json, "dns", dns);
|
||||
|
||||
JSON_ADD_NUMBER_TO_OBJECT(json, "https_port", get_https_port());
|
||||
|
||||
JSON_SEND_OBJECT(json);
|
||||
}
|
||||
|
||||
@@ -1266,7 +1266,7 @@
|
||||
@test "API authorization (without password): No login required" {
|
||||
run bash -c 'curl -s 127.0.0.1/api/auth'
|
||||
printf "%s\n" "${lines[@]}"
|
||||
[[ ${lines[0]} == '{"session":{"valid":true,"totp":false,"sid":null,"validity":-1},"https_port":443,"dns":true,"took":'*'}' ]]
|
||||
[[ ${lines[0]} == '{"session":{"valid":true,"totp":false,"sid":null,"validity":-1},"took":'*'}' ]]
|
||||
}
|
||||
|
||||
@test "API authorization: Setting password" {
|
||||
|
||||
Reference in New Issue
Block a user