Rename config.files.{http_info => log.webserver, ph7_error => log.ph7} and include file path in /api/logs replies

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2023-02-23 17:52:10 +01:00
parent 6a199427b4
commit ce96c5baef
11 changed files with 120 additions and 64 deletions
+2 -7
View File
@@ -749,9 +749,9 @@ static int api_config_put_delete(struct ftl_conn *api)
const char *hint = NULL, *message = NULL;
if(api->method == HTTP_PUT)
hint = "Use, e.g., PUT /config/dnsmasq/upstreams/127.0.0.1 to add \"127.0.0.1\" to config.dns.upstreams";
hint = "Use, e.g., PUT /api/config/dnsmasq/upstreams/127.0.0.1 to add \"127.0.0.1\" to config.dns.upstreams";
else
hint = "Use, e.g., DELETE /config/dnsmasq/upstreams/127.0.0.1 to remove \"127.0.0.1\" from config.dns.upstreams";
hint = "Use, e.g., DELETE /api/config/dnsmasq/upstreams/127.0.0.1 to remove \"127.0.0.1\" from config.dns.upstreams";
if(min_level < 2)
{
@@ -767,11 +767,6 @@ static int api_config_put_delete(struct ftl_conn *api)
char *new_item_str = requested_path[min_level - 1];
// Convert path to items, e.g.,
// dnsmasq/dhcp/active -> dhcp.active
//char *item = strdup(api->item);
//replace_char(item, '/', '.');
// Read all known config items
bool dnsmasq_changed = false;
bool rewrite_custom_list = false;
+6 -6
View File
@@ -390,10 +390,6 @@ components:
type: string
setupVars:
type: string
http_info:
type: string
ph7_error:
type: string
log:
type: object
properties:
@@ -401,6 +397,10 @@ components:
type: string
dnsmasq:
type: string
civetweb:
type: string
ph7:
type: string
misc:
type: object
properties:
@@ -627,11 +627,11 @@ components:
gravity: "/etc/pihole/gravity.db"
macvendor: "/etc/pihole/macvendor.db"
setupVars: "/etc/pihole/setupVars.conf"
http_info: "/var/log/pihole/HTTP_info.log"
ph7_error: "/var/log/pihole/PH7.log"
log:
ftl: "/var/log/pihole/FTL.log"
dnsmasq: "/var/log/pihole/pihole.log"
civetweb: "/var/log/pihole/HTTP_info.log"
ph7: "/var/log/pihole/PH7.log"
misc:
nice: -10
delay_startup: 10
+10 -16
View File
@@ -24,9 +24,7 @@ components:
content:
application/json:
schema:
allOf:
- $ref: 'logs.yaml#/components/schemas/logs/dnsmasq/log'
- $ref: 'logs.yaml#/components/schemas/logs/dnsmasq/nextID'
$ref: 'logs.yaml#/components/schemas/logs/dnsmasq/log'
'401':
description: Unauthorized
content:
@@ -55,9 +53,7 @@ components:
content:
application/json:
schema:
allOf:
- $ref: 'logs.yaml#/components/schemas/logs/dnsmasq/log'
- $ref: 'logs.yaml#/components/schemas/logs/dnsmasq/nextID'
$ref: 'logs.yaml#/components/schemas/logs/dnsmasq/log'
'401':
description: Unauthorized
content:
@@ -86,9 +82,7 @@ components:
content:
application/json:
schema:
allOf:
- $ref: 'logs.yaml#/components/schemas/logs/dnsmasq/log'
- $ref: 'logs.yaml#/components/schemas/logs/dnsmasq/nextID'
$ref: 'logs.yaml#/components/schemas/logs/dnsmasq/log'
'401':
description: Unauthorized
content:
@@ -117,9 +111,7 @@ components:
content:
application/json:
schema:
allOf:
- $ref: 'logs.yaml#/components/schemas/logs/dnsmasq/log'
- $ref: 'logs.yaml#/components/schemas/logs/dnsmasq/nextID'
$ref: 'logs.yaml#/components/schemas/logs/dnsmasq/log'
'401':
description: Unauthorized
content:
@@ -153,13 +145,15 @@ components:
message: "read /etc/hosts - 7 addresses"
- timestamp: 1611729969.0
message: "query[A] connectivity-check.ubuntu.com from 127.0.0.1"
nextID:
type: object
properties:
nextID:
type: integer
description: next ID to query if checking for new log lines
description: Next ID to query if checking for new log lines
example: 229
file:
type: string
description: Path to respective log file on disk
example: /var/log/pihole/pihole.log
parameters:
logs:
dnsmasq:
+23
View File
@@ -14,6 +14,7 @@
#include "api/api.h"
// struct fifologData
#include "log.h"
#include "config/config.h"
// fifologData is allocated in shared memory for cross-fork compatibility
fifologData *fifo_log = NULL;
@@ -71,6 +72,28 @@ int api_logs(struct ftl_conn *api)
JSON_ADD_ITEM_TO_OBJECT(json, "log", log);
JSON_ADD_NUMBER_TO_OBJECT(json, "nextID", fifo_log->logs[api->opts.which].next_id);
// Add file name
const char *logfile = NULL;
switch(api->opts.which)
{
case FIFO_FTL:
logfile = config.files.log.ftl.v.s;
break;
case FIFO_DNSMASQ:
logfile = config.files.log.dnsmasq.v.s;
break;
case FIFO_CIVETWEB:
logfile = config.files.log.civetweb.v.s;
break;
case FIFO_PH7:
logfile = config.files.log.ph7.v.s;
break;
case FIFO_MAX:
// This should never happen
break;
}
JSON_REF_STR_IN_OBJECT(json, "file", logfile);
// Send data
JSON_SEND_OBJECT(json);
}
+12 -12
View File
@@ -963,19 +963,19 @@ void initConfig(struct config *conf)
conf->files.setupVars.f = FLAG_ADVANCED_SETTING;
conf->files.setupVars.d.s = (char*)"/etc/pihole/setupVars.conf";
conf->files.http_info.k = "files.http_info";
conf->files.http_info.h = "The log file used by the webserver";
conf->files.http_info.a = cJSON_CreateStringReference("<any writable file>");
conf->files.http_info.t = CONF_STRING;
conf->files.http_info.f = FLAG_ADVANCED_SETTING;
conf->files.http_info.d.s = (char*)"/var/log/pihole/HTTP_info.log";
conf->files.log.civetweb.k = "files.log.civetweb";
conf->files.log.civetweb.h = "The log file used by the webserver";
conf->files.log.civetweb.a = cJSON_CreateStringReference("<any writable file>");
conf->files.log.civetweb.t = CONF_STRING;
conf->files.log.civetweb.f = FLAG_ADVANCED_SETTING;
conf->files.log.civetweb.d.s = (char*)"/var/log/pihole/HTTP_info.log";
conf->files.ph7_error.k = "files.ph7_error";
conf->files.ph7_error.h = "The log file used by the dynamic interpreter PH7";
conf->files.ph7_error.a = cJSON_CreateStringReference("<any writable file>");
conf->files.ph7_error.t = CONF_STRING;
conf->files.ph7_error.f = FLAG_ADVANCED_SETTING;
conf->files.ph7_error.d.s = (char*)"/var/log/pihole/PH7.log";
conf->files.log.ph7.k = "files.log.ph7";
conf->files.log.ph7.h = "The log file used by the dynamic interpreter PH7";
conf->files.log.ph7.a = cJSON_CreateStringReference("<any writable file>");
conf->files.log.ph7.t = CONF_STRING;
conf->files.log.ph7.f = FLAG_ADVANCED_SETTING;
conf->files.log.ph7.d.s = (char*)"/var/log/pihole/PH7.log";
// sub-struct files.log
// conf->files.log.ftl is set in a separate function
+2 -2
View File
@@ -230,11 +230,11 @@ struct config {
struct conf_item gravity;
struct conf_item macvendor;
struct conf_item setupVars;
struct conf_item http_info;
struct conf_item ph7_error;
struct {
struct conf_item ftl;
struct conf_item dnsmasq;
struct conf_item civetweb;
struct conf_item ph7;
} log;
} files;
+7 -3
View File
@@ -428,16 +428,20 @@ bool __attribute__((const)) write_dnsmasq_config(struct config *conf, bool test_
// on which the DHCP request was received for IPv6,
// whilst [fd00::] is replaced with the ULA, if it
// exists, and [fe80::] with the link-local address.
fputs("# Advertive the DNS server multiple times to work around\n", pihole_conf);
fputs("# Advertise the DNS server multiple times to work around\n", pihole_conf);
fputs("# issues with some clients adding their own servers if only\n", pihole_conf);
fputs("# one DNS server is advertised by the DHCP server.\n", pihole_conf);
fputs("dhcp-option=option:dns-server,0.0.0.0,0.0.0.0,0.0.0.0\n", pihole_conf);
fputs("dhcp-option=option6:dns-server,[::],[::],[fd00::],[fd00::],[fe80::],[fe80::]\n", pihole_conf);
}
if(conf->dhcp.ipv6.v.b)
{
fputs("dhcp-option=option6:dns-server,[::]\n", pihole_conf);
// Add dns-server option only if not already done above (dhcp.multiDNS)
if(conf->dhcp.multiDNS.v.b)
fputs("dhcp-option=option6:dns-server,[::],[::],[fd00::],[fd00::],[fe80::],[fe80::]\n", pihole_conf);
else
fputs("dhcp-option=option6:dns-server,[::]\n", pihole_conf);
fputs("# Enable IPv6 DHCP variant\n", pihole_conf);
fprintf(pihole_conf, "dhcp-range=::,constructor:%s,ra-names,ra-stateless,64\n", interface);
}
fputs("\n", pihole_conf);
+2 -2
View File
@@ -322,10 +322,10 @@ const char *readFTLlegacy(struct config *conf)
parseBool(buffer, &conf->webserver.api.prettyJSON.v.b);
// API_ERROR_LOG
conf->files.ph7_error.v.s = getPath(fp, "API_ERROR_LOG", conf->files.ph7_error.v.s);
conf->files.log.ph7.v.s = getPath(fp, "API_ERROR_LOG", conf->files.log.ph7.v.s);
// API_INFO_LOG
conf->files.http_info.v.s = getPath(fp, "API_INFO_LOG", conf->files.http_info.v.s);
conf->files.log.civetweb.v.s = getPath(fp, "API_INFO_LOG", conf->files.log.civetweb.v.s);
// NICE
// Shall we change the nice of the current process?
+2 -2
View File
@@ -347,10 +347,10 @@ static FILE * __attribute__((malloc, warn_unused_result)) open_web_log(const enu
switch (which)
{
case FIFO_CIVETWEB:
file = config.files.http_info.v.s;
file = config.files.log.civetweb.v.s;
break;
case FIFO_PH7:
file = config.files.ph7_error.v.s;
file = config.files.log.ph7.v.s;
break;
case FIFO_FTL:
case FIFO_DNSMASQ:
+42 -2
View File
@@ -190,6 +190,46 @@ static void get_conf_weblayout_from_setupVars(void)
config.webserver.interface.boxed.k,config.webserver.interface.boxed.v.b ? "true" : "false");
}
static void get_conf_webtheme_from_setupVars(void)
{
// Try to obtain listening mode
const char *listeningMode = read_setupVarsconf("WEBTHEME");
if(listeningMode == NULL)
{
// Do not change default value, this value is not set in setupVars.conf
log_debug(DEBUG_CONFIG, "setupVars.conf:WEBTHEME -> Not set");
// Free memory, harmless to call if read_setupVarsconf() didn't return a result
clearSetupVarsArray();
return;
}
bool set = false;
int web_theme_enum = get_web_theme_val(listeningMode);
if(web_theme_enum != -1)
{
set = true;
config.webserver.interface.theme.v.web_theme = web_theme_enum;
}
// Free memory, harmless to call if read_setupVarsconf() didn't return a result
clearSetupVarsArray();
if(set)
{
// Parameter present in setupVars.conf
log_debug(DEBUG_CONFIG, "setupVars.conf:WEBTHEME -> Setting %s to %s",
config.webserver.interface.theme.k,
get_web_theme_str(config.webserver.interface.theme.v.web_theme));
}
else
{
// Parameter not present in setupVars.conf
log_debug(DEBUG_CONFIG, "setupVars.conf:WEBTHEME -> Not set (found invalid value)");
}
}
static void get_conf_listeningMode_from_setupVars(void)
{
// Try to obtain listening mode
@@ -252,8 +292,8 @@ void importsetupVarsConf(void)
// Try to obtain web layout
get_conf_weblayout_from_setupVars();
// Try to obtain theme string
get_conf_string_from_setupVars("WEBTHEME", &config.webserver.interface.theme);
// Try to obtain web theme
get_conf_webtheme_from_setupVars();
// Try to obtain list of upstream servers
get_conf_upstream_servers_from_setupVars(&config.dns.upstreams);
+12 -12
View File
@@ -618,18 +618,6 @@
# <any Pi-hole setupVars file>
setupVars = "/etc/pihole/setupVars.conf"
# The log file used by the webserver
#
# Possible values are:
# <any writable file>
http_info = "/var/log/pihole/HTTP_info.log"
# The log file used by the dynamic interpreter PH7
#
# Possible values are:
# <any writable file>
ph7_error = "/var/log/pihole/PH7.log"
[files.log]
# The location of FTL's log file
#
@@ -643,6 +631,18 @@
# <any writable file>
dnsmasq = "/var/log/pihole/pihole.log"
# The log file used by the webserver
#
# Possible values are:
# <any writable file>
civetweb = "/var/log/pihole/HTTP_info.log"
# The log file used by the dynamic interpreter PH7
#
# Possible values are:
# <any writable file>
ph7 = "/var/log/pihole/PH7.log"
[misc]
# Using privacy levels you can specify which level of detail you want to see in your
# Pi-hole statistics.