mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Add /config/_server offering DNS server suggestions for the settings page
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -70,6 +70,7 @@ static struct {
|
||||
{ "/api/stats/database/upstreams", "", api_stats_database_upstreams, { false, 0 }, true, HTTP_GET },
|
||||
{ "/api/auth", "", api_auth, { false, 0 }, false, HTTP_GET | HTTP_POST | HTTP_DELETE },
|
||||
{ "/api/config/_topics", "", api_config_topics, { false, 0 }, true, HTTP_GET },
|
||||
{ "/api/config/_server", "", api_config_server, { false, 0 }, true, HTTP_GET },
|
||||
{ "/api/config", "", api_config, { false, 0 }, true, HTTP_GET | HTTP_PATCH },
|
||||
{ "/api/config", "/{element}", api_config, { false, 0 }, true, HTTP_GET | HTTP_PATCH },
|
||||
{ "/api/config", "/{element}/{value}", api_config, { false, 0 }, true, HTTP_DELETE | HTTP_PUT },
|
||||
|
||||
@@ -57,6 +57,7 @@ int api_info_version(struct ftl_conn *api);
|
||||
// Config methods
|
||||
int api_config(struct ftl_conn *api);
|
||||
int api_config_topics(struct ftl_conn *api);
|
||||
int api_config_server(struct ftl_conn *api);
|
||||
|
||||
// Log methods
|
||||
int api_logs(struct ftl_conn *api);
|
||||
|
||||
@@ -41,6 +41,29 @@ static struct {
|
||||
{ "debug", "Debug settings" }
|
||||
};
|
||||
|
||||
static struct {
|
||||
const char *name;
|
||||
struct {
|
||||
const char *addr1;
|
||||
const char *addr2;
|
||||
} v4;
|
||||
struct {
|
||||
const char *addr1;
|
||||
const char *addr2;
|
||||
} v6;
|
||||
} dns_server[] =
|
||||
{
|
||||
{ "Google (ECS, DNSSEC)", { "8.8.8.8", "8.8.4.4" }, { "2001:4860:4860:0:0:0:0:8888", "2001:4860:4860:0:0:0:0:8844" } },
|
||||
{ "OpenDNS (ECS, DNSSEC)", { "208.67.222.222", "208.67.220.220" }, {"2620:119:35::35", "2620:119:53::53"} },
|
||||
{ "Level3", { "4.2.2.1", "4.2.2.2" }, { NULL, NULL } },
|
||||
{ "Comodo", { "8.26.56.26", "8.20.247.20" }, { NULL, NULL} },
|
||||
{ "DNS.WATCH (DNSSEC)", { "84.200.69.80", "84.200.70.40" }, { "2001:1608:10:25:0:0:1c04:b12f", "2001:1608:10:25:0:0:9249:d69b" } },
|
||||
{ "Quad9 (filtered, DNSSEC)", {"9.9.9.9", "149.112.112.112" }, { "2620:fe::fe", "2620:fe::9" } },
|
||||
{ "Quad9 (unfiltered, no DNSSEC)", { "9.9.9.10", "149.112.112.10" }, { "2620:fe::10", "2620:fe::fe:10" } },
|
||||
{ "Quad9 (filtered, ECS, DNSSEC)", { "9.9.9.11", "149.112.112.11" }, { "2620:fe::11", "2620:fe::fe:11" } },
|
||||
{ "Cloudflare (DNSSEC)", { "1.1.1.1", "1.0.0.1" }, { "2606:4700:4700::1111", "2606:4700:4700::1001" } }
|
||||
};
|
||||
|
||||
// The following functions are used to create the JSON output
|
||||
// of the /api/config endpoint.
|
||||
|
||||
@@ -787,3 +810,34 @@ int api_config_topics(struct ftl_conn *api)
|
||||
JSON_ADD_ITEM_TO_OBJECT(json, "topics", topics);
|
||||
JSON_SEND_OBJECT(json);
|
||||
}
|
||||
|
||||
int api_config_server(struct ftl_conn *api)
|
||||
{
|
||||
cJSON *servers = JSON_NEW_ARRAY();
|
||||
for(unsigned int i = 0; i < sizeof(dns_server)/sizeof(*dns_server); i++)
|
||||
{
|
||||
cJSON *server = JSON_NEW_OBJECT();
|
||||
JSON_REF_STR_IN_OBJECT(server, "name", dns_server[i].name);
|
||||
|
||||
cJSON *v4 = JSON_NEW_ARRAY();
|
||||
if(dns_server[i].v4.addr1 != NULL)
|
||||
JSON_REF_STR_IN_ARRAY(v4, dns_server[i].v4.addr1);
|
||||
if(dns_server[i].v4.addr2 != NULL)
|
||||
JSON_REF_STR_IN_ARRAY(v4, dns_server[i].v4.addr2);
|
||||
JSON_ADD_ITEM_TO_OBJECT(server, "v4", v4);
|
||||
|
||||
cJSON *v6 = JSON_NEW_ARRAY();
|
||||
if(dns_server[i].v6.addr1 != NULL)
|
||||
JSON_REF_STR_IN_ARRAY(v6, dns_server[i].v6.addr1);
|
||||
if(dns_server[i].v6.addr2 != NULL)
|
||||
JSON_REF_STR_IN_ARRAY(v6, dns_server[i].v6.addr2);
|
||||
JSON_ADD_ITEM_TO_OBJECT(server, "v6", v6);
|
||||
|
||||
JSON_ADD_ITEM_TO_ARRAY(servers, server);
|
||||
}
|
||||
|
||||
// Build and return JSON response
|
||||
cJSON *json = JSON_NEW_OBJECT();
|
||||
JSON_ADD_ITEM_TO_OBJECT(json, "server", servers);
|
||||
JSON_SEND_OBJECT(json);
|
||||
}
|
||||
|
||||
@@ -169,6 +169,30 @@ components:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: 'common.yaml#/components/errors/unauthorized'
|
||||
server:
|
||||
get:
|
||||
summary: Get DNS server suggestions
|
||||
tags:
|
||||
- "Pi-hole Configuration"
|
||||
operationId: "get_config_server_suggestions"
|
||||
description: |
|
||||
This API hook returns a list of DNS servers known to be compatible with Pi-hole.
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: 'config.yaml#/components/schemas/server'
|
||||
examples:
|
||||
server:
|
||||
$ref: 'config.yaml#/components/examples/server'
|
||||
'401':
|
||||
description: Unauthorized
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: 'common.yaml#/components/errors/unauthorized'
|
||||
schemas:
|
||||
config:
|
||||
type: object
|
||||
@@ -503,6 +527,27 @@ components:
|
||||
description:
|
||||
type: string
|
||||
description: A human-readable description of the topic
|
||||
server:
|
||||
type: object
|
||||
properties:
|
||||
server:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
description: Human-readable name of this server
|
||||
v4:
|
||||
type: array
|
||||
description: Array of IPv4 addresses (if any)
|
||||
items:
|
||||
type: string
|
||||
v6:
|
||||
type: array
|
||||
description: Array of IPv6 addresses (if any)
|
||||
items:
|
||||
type: string
|
||||
|
||||
examples:
|
||||
config:
|
||||
@@ -690,6 +735,16 @@ components:
|
||||
description: Miscellaneous settings
|
||||
- name: Debug
|
||||
description: Debug settings
|
||||
server:
|
||||
summary: Several servers being suggested
|
||||
value:
|
||||
server:
|
||||
- name: Google (ECS, DNSSEC)
|
||||
v4: ["8.8.8.8", "8.8.4.4"]
|
||||
v6: ["2001:4860:4860:0:0:0:0:8888","2001:4860:4860:0:0:0:0:8844"]
|
||||
- name: OpenDNS (ECS, DNSSEC)
|
||||
v4: ["208.67.222.222", "208.67.220.220"]
|
||||
v6: ["2620:119:35::35","2620:119:53::53"]
|
||||
errors:
|
||||
bad_request:
|
||||
invalid_path_depth:
|
||||
|
||||
@@ -176,6 +176,9 @@ paths:
|
||||
/config/_topics:
|
||||
$ref: 'config.yaml#/components/paths/topics'
|
||||
|
||||
/config/_server:
|
||||
$ref: 'config.yaml#/components/paths/server'
|
||||
|
||||
/config/{element}:
|
||||
$ref: 'config.yaml#/components/paths/config_elem'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user