From efbdff9ee6ab880f7dce50fa2362a8ffcec24bfe Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 16 Jul 2019 22:52:40 +0200 Subject: [PATCH 1/2] Add new config flag REGEX_IGNORECASE that can be enabled to make FTL's regex case insensitive. It defaults to false (legacy behavior). Signed-off-by: DL6ER --- src/config.c | 13 +++++++++++++ src/config.h | 1 + src/regex.c | 5 ++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 3c5339f8e..68ead9513 100644 --- a/src/config.c +++ b/src/config.c @@ -332,6 +332,19 @@ void read_FTLconf(void) else logg(" PARSE_ARP_CACHE: Inactive"); + // REGEX_IGNORECASE + // defaults to: No + config.regex_ignorecase = false; + buffer = parse_FTLconf(fp, "REGEX_IGNORECASE"); + + if(buffer != NULL && strcasecmp(buffer, "true") == 0) + config.regex_ignorecase = true; + + if(config.regex_ignorecase) + logg(" REGEX_IGNORECASE: Enabled. Regex is case insensitive"); + else + logg(" REGEX_IGNORECASE: Disabled. Regex is case sensitive"); + // Read DEBUG_... setting from pihole-FTL.conf read_debuging_settings(fp); diff --git a/src/config.h b/src/config.h index 64ebc9597..b36b1be07 100644 --- a/src/config.h +++ b/src/config.h @@ -32,6 +32,7 @@ typedef struct { bool analyze_only_A_AAAA; bool DBimport; bool parse_arp_cache; + bool regex_ignorecase; } ConfigStruct; typedef struct { diff --git a/src/regex.c b/src/regex.c index e6a5c85ba..63d7c21e0 100644 --- a/src/regex.c +++ b/src/regex.c @@ -39,7 +39,10 @@ static bool init_regex(const char *regexin, const int index) { // compile regular expressions into data structures that // can be used with regexec to match against a string - const int errcode = regcomp(®ex[index], regexin, REG_EXTENDED); + int regflags = REG_EXTENDED; + if(config.regex_ignorecase) + regflags |= REG_ICASE; + const int errcode = regcomp(®ex[index], regexin, regflags); if(errcode != 0) { log_regex_error("compiling", errcode, index); From 55803ddb746a8b1de9274c1ec3463d363dcb9e94 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 17 Jul 2019 11:41:50 +0200 Subject: [PATCH 2/2] Update code comments: Boolean settings default to false instead of No (even though this has no effect because everything that is not "true" (case insensitive) is considered false by FTL). Signed-off-by: DL6ER --- src/config.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index 68ead9513..a1935482a 100644 --- a/src/config.c +++ b/src/config.c @@ -243,7 +243,7 @@ void read_FTLconf(void) logg(" PRIVACYLEVEL: Set to %i", config.privacylevel); // IGNORE_LOCALHOST - // defaults to: No + // defaults to: false config.ignore_localhost = false; buffer = parse_FTLconf(fp, "IGNORE_LOCALHOST"); @@ -278,7 +278,7 @@ void read_FTLconf(void) } // ANALYZE_ONLY_A_AND_AAAA - // defaults to: No + // defaults to: false config.analyze_only_A_AAAA = false; buffer = parse_FTLconf(fp, "ANALYZE_ONLY_A_AND_AAAA"); @@ -333,7 +333,7 @@ void read_FTLconf(void) logg(" PARSE_ARP_CACHE: Inactive"); // REGEX_IGNORECASE - // defaults to: No + // defaults to: false config.regex_ignorecase = false; buffer = parse_FTLconf(fp, "REGEX_IGNORECASE");