From ce96c5baef0e511ea4f21975d2a3a35511f67ce9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 23 Feb 2023 17:52:10 +0100 Subject: [PATCH] Rename config.files.{http_info => log.webserver, ph7_error => log.ph7} and include file path in /api/logs replies Signed-off-by: DL6ER --- src/api/config.c | 9 ++---- src/api/docs/content/specs/config.yaml | 12 +++---- src/api/docs/content/specs/logs.yaml | 26 ++++++--------- src/api/logs.c | 23 ++++++++++++++ src/config/config.c | 24 +++++++------- src/config/config.h | 4 +-- src/config/dnsmasq_config.c | 10 ++++-- src/config/legacy_reader.c | 4 +-- src/log.c | 4 +-- src/setupVars.c | 44 ++++++++++++++++++++++++-- test/pihole.toml | 24 +++++++------- 11 files changed, 120 insertions(+), 64 deletions(-) diff --git a/src/api/config.c b/src/api/config.c index ae3e158b..d82052d4 100644 --- a/src/api/config.c +++ b/src/api/config.c @@ -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; diff --git a/src/api/docs/content/specs/config.yaml b/src/api/docs/content/specs/config.yaml index 35cf966e..ba5da0a5 100644 --- a/src/api/docs/content/specs/config.yaml +++ b/src/api/docs/content/specs/config.yaml @@ -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 diff --git a/src/api/docs/content/specs/logs.yaml b/src/api/docs/content/specs/logs.yaml index c55a8d51..c6c9b64f 100644 --- a/src/api/docs/content/specs/logs.yaml +++ b/src/api/docs/content/specs/logs.yaml @@ -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: diff --git a/src/api/logs.c b/src/api/logs.c index 54400148..2d3e7827 100644 --- a/src/api/logs.c +++ b/src/api/logs.c @@ -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); } diff --git a/src/config/config.c b/src/config/config.c index 13d851dd..e1b25ca8 100644 --- a/src/config/config.c +++ b/src/config/config.c @@ -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(""); - 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(""); + 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(""); - 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(""); + 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 diff --git a/src/config/config.h b/src/config/config.h index 52ed2b4d..255f8637 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -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; diff --git a/src/config/dnsmasq_config.c b/src/config/dnsmasq_config.c index 60b78af4..b21cd71b 100644 --- a/src/config/dnsmasq_config.c +++ b/src/config/dnsmasq_config.c @@ -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); diff --git a/src/config/legacy_reader.c b/src/config/legacy_reader.c index c42aa0f7..6b7a970c 100644 --- a/src/config/legacy_reader.c +++ b/src/config/legacy_reader.c @@ -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? diff --git a/src/log.c b/src/log.c index 5418eecc..ec7c7881 100644 --- a/src/log.c +++ b/src/log.c @@ -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: diff --git a/src/setupVars.c b/src/setupVars.c index 91eff878..3381f779 100644 --- a/src/setupVars.c +++ b/src/setupVars.c @@ -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); diff --git a/test/pihole.toml b/test/pihole.toml index e69a006b..c34cc4de 100644 --- a/test/pihole.toml +++ b/test/pihole.toml @@ -618,18 +618,6 @@ # setupVars = "/etc/pihole/setupVars.conf" - # The log file used by the webserver - # - # Possible values are: - # - http_info = "/var/log/pihole/HTTP_info.log" - - # The log file used by the dynamic interpreter PH7 - # - # Possible values are: - # - ph7_error = "/var/log/pihole/PH7.log" - [files.log] # The location of FTL's log file # @@ -643,6 +631,18 @@ # dnsmasq = "/var/log/pihole/pihole.log" + # The log file used by the webserver + # + # Possible values are: + # + civetweb = "/var/log/pihole/HTTP_info.log" + + # The log file used by the dynamic interpreter PH7 + # + # Possible values are: + # + 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.