diff --git a/src/api/stats.c b/src/api/stats.c index 226a0c18..c9a1b4d4 100644 --- a/src/api/stats.c +++ b/src/api/stats.c @@ -20,8 +20,6 @@ #include "../log.h" // config struct #include "../config/config.h" -// in_auditlist() -#include "../database/gravity-db.h" // overTime data #include "../overTime.h" // enum REGEX @@ -140,7 +138,6 @@ int api_stats_summary(struct ftl_conn *api) int api_stats_top_domains(struct ftl_conn *api) { int count = 10; - bool audit = false; const int domains = counters->domains; int *temparray = calloc(2*domains, sizeof(int*)); if(temparray == NULL) @@ -174,9 +171,6 @@ int api_stats_top_domains(struct ftl_conn *api) // Does the user request a non-default number of replies? // Note: We do not accept zero query requests here get_int_var(api->request->query_string, "count", &count); - - // Apply Audit Log filtering? - get_bool_var(api->request->query_string, "audit", &audit); } // Lock shared memory @@ -231,30 +225,19 @@ int api_stats_top_domains(struct ftl_conn *api) if(domain == NULL) continue; - // Skip this domain if there is a filter on it (but only if not in audit mode) - if(!audit) + // Skip this domain if there is a filter on it + bool skip_domain = false; + for(unsigned int j = 0; j < excludeDomains; j++) { - // Check if this domain should be skipped - bool skip_domain = false; - for(unsigned int j = 0; j < excludeDomains; j++) + cJSON *item = cJSON_GetArrayItem(config.webserver.api.excludeDomains.v.json, j); + if(strcmp(getstr(domain->domainpos), item->valuestring) == 0) { - cJSON *item = cJSON_GetArrayItem(config.webserver.api.excludeDomains.v.json, j); - if(strcmp(getstr(domain->domainpos), item->valuestring) == 0) - { - skip_domain = true; - break; - } + skip_domain = true; + break; } - if(skip_domain) - continue; } - - // Skip this domain if already audited - if(audit && in_auditlist(getstr(domain->domainpos)) > 0) - { - log_debug(DEBUG_API, "API: %s has been audited.", getstr(domain->domainpos)); + if(skip_domain) continue; - } // Hidden domain, probably due to privacy level. Skip this in the top lists if(strcmp(getstr(domain->domainpos), HIDDEN_DOMAIN) == 0) @@ -288,9 +271,9 @@ int api_stats_top_domains(struct ftl_conn *api) cJSON *json = JSON_NEW_OBJECT(); JSON_ADD_ITEM_TO_OBJECT(json, "domains", top_domains); - const int blocked_queries = get_blocked_count(); + const int blocked_count = get_blocked_count(); JSON_ADD_NUMBER_TO_OBJECT(json, "total_queries", counters->queries); - JSON_ADD_NUMBER_TO_OBJECT(json, "blocked_queries", blocked_queries); + JSON_ADD_NUMBER_TO_OBJECT(json, "blocked_queries", blocked_count); JSON_SEND_OBJECT_UNLOCK(json); } @@ -411,8 +394,8 @@ int api_stats_top_clients(struct ftl_conn *api) cJSON *json = JSON_NEW_OBJECT(); JSON_ADD_ITEM_TO_OBJECT(json, "clients", top_clients); - const int blocked_queries = get_blocked_count(); - JSON_ADD_NUMBER_TO_OBJECT(json, "blocked_queries", blocked_queries); + const int blocked_count = get_blocked_count(); + JSON_ADD_NUMBER_TO_OBJECT(json, "blocked_queries", blocked_count); JSON_ADD_NUMBER_TO_OBJECT(json, "total_queries", counters->queries); JSON_SEND_OBJECT_UNLOCK(json); } @@ -526,8 +509,8 @@ int api_stats_upstreams(struct ftl_conn *api) cJSON *json = JSON_NEW_OBJECT(); JSON_ADD_ITEM_TO_OBJECT(json, "upstreams", top_upstreams); - const int forwarded_queries = get_forwarded_count(); - JSON_ADD_NUMBER_TO_OBJECT(json, "forwarded_queries", forwarded_queries); + const int forwarded_count = get_forwarded_count(); + JSON_ADD_NUMBER_TO_OBJECT(json, "forwarded_queries", forwarded_count); JSON_ADD_NUMBER_TO_OBJECT(json, "total_queries", counters->queries); JSON_SEND_OBJECT_UNLOCK(json); } diff --git a/src/database/gravity-db.c b/src/database/gravity-db.c index fbb3a1c6..70d25aa8 100644 --- a/src/database/gravity-db.c +++ b/src/database/gravity-db.c @@ -46,7 +46,6 @@ sqlite3_stmt_vec *blacklist_stmt = NULL; // Private variables static sqlite3 *gravity_db = NULL; static sqlite3_stmt* table_stmt = NULL; -static sqlite3_stmt* auditlist_stmt = NULL; bool gravityDB_opened = false; static bool gravity_abp_format = false; @@ -174,35 +173,6 @@ bool gravityDB_open(void) return false; } - // Prepare audit statement - log_debug(DEBUG_DATABASE, "gravityDB_open(): Preparing audit query"); - - // We support adding audit domains with a wildcard character (*) - // Example 1: google.de - // matches only google.de - // Example 2: *.google.de - // matches all subdomains of google.de - // BUT NOT google.de itself - // Example 3: *google.de - // matches 'google.de' and all of its subdomains but - // also other domains ending in google.de, like - // abcgoogle.de - rc = sqlite3_prepare_v3(gravity_db, - "SELECT domain, " - "CASE WHEN substr(domain, 1, 1) = '*' " // Does the database string start in '*' ? - "THEN '*' || substr(:input, - length(domain) + 1) " // If so: Crop the input domain and prepend '*' - "ELSE :input " // If not: Use input domain directly for comparison - "END matcher " - "FROM domain_audit WHERE matcher = domain" // Match where (modified) domain equals the database domain - ";", -1, SQLITE_PREPARE_PERSISTENT, &auditlist_stmt, NULL); - - if( rc != SQLITE_OK ) - { - log_err("gravityDB_open(\"SELECT EXISTS(... domain_audit ...)\") - SQL error prepare: %s", sqlite3_errstr(rc)); - gravityDB_close(); - return false; - } - // Set SQLite3 busy timeout to a user-defined value (defaults to 1 second) // to avoid immediate failures when the gravity database is still busy // writing the changes to disk @@ -983,10 +953,6 @@ void gravityDB_close(void) free_sqlite3_stmt_vec(&gravity_stmt); free_sqlite3_stmt_vec(&antigravity_stmt); - // Finalize audit list statement - sqlite3_finalize(auditlist_stmt); - auditlist_stmt = NULL; - // Close table sqlite3_close(gravity_db); gravity_db = NULL; @@ -1187,7 +1153,7 @@ static enum db_result domain_in_list(const char *domain, sqlite3_stmt *stmt, con // Bind domain to prepared statement // SQLITE_STATIC: Use the string without first duplicating it internally. // We can do this as domain has dynamic scope that exceeds that of the binding. - // We need to bind the domain only once even to the prepared audit statement as: + // We need to bind the domain only once: // When the same named SQL parameter is used more than once, second and // subsequent occurrences have the same index as the first occurrence. // (https://www.sqlite.org/c3ref/bind_blob.html) @@ -1503,17 +1469,6 @@ enum db_result in_denylist(const char *domain, DNSCacheData *dns_cache, clientsD return domain_in_list(domain, stmt, "blacklist", &dns_cache->domainlist_id); } -bool in_auditlist(const char *domain) -{ - // If audit list statement is not ready and cannot be initialized (e.g. no access - // to the database), we return false (not in audit list) to prevent an FTL crash - if(auditlist_stmt == NULL) - return false; - - // We check the domain_audit table for the given domain - return domain_in_list(domain, auditlist_stmt, "auditlist", NULL) == FOUND; -} - bool gravityDB_get_regex_client_groups(clientsData* client, const unsigned int numregex, const regexData *regex, const unsigned char type, const char* table) { diff --git a/src/database/gravity-db.h b/src/database/gravity-db.h index 8b77fdec..512ac80a 100644 --- a/src/database/gravity-db.h +++ b/src/database/gravity-db.h @@ -59,7 +59,6 @@ cJSON *gen_abp_patterns(const char *domain, const bool antigravity); enum db_result in_gravity(const char *domain, clientsData *client, const bool antigravity, int* domain_id); enum db_result in_denylist(const char *domain, DNSCacheData *dns_cache, clientsData *client); enum db_result in_allowlist(const char *domain, DNSCacheData *dns_cache, clientsData *client); -bool in_auditlist(const char *domain); bool gravityDB_get_regex_client_groups(clientsData* client, const unsigned int numregex, const regexData *regex, const unsigned char type, const char* table); diff --git a/src/zip/teleporter.c b/src/zip/teleporter.c index d541a8e4..ee0cf0b7 100644 --- a/src/zip/teleporter.c +++ b/src/zip/teleporter.c @@ -48,8 +48,7 @@ static const char *gravity_tables[] = { "domainlist", "domainlist_by_group", "client", - "client_by_group", - "domain_audit" + "client_by_group" }; // Tables to copy from the FTL database to the Teleporter database diff --git a/test/gravity.db.sql b/test/gravity.db.sql index a8c1438f..21e970b3 100644 --- a/test/gravity.db.sql +++ b/test/gravity.db.sql @@ -66,13 +66,6 @@ CREATE TABLE info INSERT INTO "info" VALUES('version','12'); -CREATE TABLE domain_audit -( - id INTEGER PRIMARY KEY AUTOINCREMENT, - domain TEXT UNIQUE NOT NULL, - date_added INTEGER NOT NULL DEFAULT (cast(strftime('%s', 'now') as int)) -); - CREATE TABLE domainlist_by_group ( domainlist_id INTEGER NOT NULL REFERENCES domainlist (id), @@ -251,8 +244,6 @@ INSERT INTO info VALUES('updated',0); INSERT INTO "group" VALUES(1,0,'Test group',1559928803,1559928803,'A disabled test group'); INSERT INTO domainlist_by_group VALUES(15,1); -INSERT INTO domain_audit VALUES(1,'google.com',1559928803); - INSERT INTO client (id,ip) VALUES(1,'127.0.0.1'); INSERT INTO client (id,ip) VALUES(2,'127.0.0.2');