From a4180db79a80882f81bc8c880ec1e2db5ee9bf6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Tue, 14 Jun 2011 15:56:38 +0300 Subject: filter: rename modes to something that makes more sense Also, make sure the categorize mode is not touching authdb datastructures as they are invalid in that mode. --- src/squark-filter.c | 54 ++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'src/squark-filter.c') diff --git a/src/squark-filter.c b/src/squark-filter.c index db8fb38..5615e9e 100644 --- a/src/squark-filter.c +++ b/src/squark-filter.c @@ -26,8 +26,8 @@ #define FILTER_OVERRIDE_TIMEOUT (15*60) -#define MODE_NOAUTH 0 -#define MODE_TRACK 1 +#define MODE_CATEGORIZE 0 +#define MODE_FILTER 1 #define MODE_CAPTIVE 2 static struct sqdb db; @@ -407,22 +407,23 @@ static void read_input(struct sqdb *db) else category = 0; - if (mode == MODE_NOAUTH) { + if (mode == MODE_CATEGORIZE) { + send_ok(id, get_category_name(db, category), 0); + continue; + } + + token = authdb_get(&adb, &addr, &entry, 1); + if (authdb_check_login(token, &entry, username, now, &adbc)) { + auth_ok = 1; + username = BLOB_STRLEN(entry.p.login_name); + } else if (mode == MODE_FILTER) { auth_ok = 1; + authdb_clear_entry(&entry); + memcpy(entry.p.login_name, username.ptr, username.len); + authdb_commit_login(token, &entry, now, &adbc); } else { - token = authdb_get(&adb, &addr, &entry, 1); - if (authdb_check_login(token, &entry, username, now, &adbc)) { - auth_ok = 1; - username = BLOB_STRLEN(entry.p.login_name); - } else if (mode == MODE_TRACK) { - auth_ok = 1; - authdb_clear_entry(&entry); - memcpy(entry.p.login_name, username.ptr, username.len); - authdb_commit_login(token, &entry, now, &adbc); - } else { - /* mode == MODE_CAPTIVE, and not authenticated */ - auth_ok = 0; - } + /* mode == MODE_CAPTIVE, and not authenticated */ + auth_ok = 0; } if (!auth_ok) { @@ -432,9 +433,10 @@ static void read_input(struct sqdb *db) now > entry.override_time + FILTER_OVERRIDE_TIMEOUT || ((1ULL << category) & entry.p.hard_block_categories))) { send_redirect(BLOB_STR("warning.cgi"), id, url, get_category_name(db, category), username); - } else + } else { send_ok(id, get_category_name(db, category), !!((1ULL << category) & entry.p.block_categories)); + } } if (b.len) { @@ -448,13 +450,15 @@ static void read_input(struct sqdb *db) static int usage(const char *progname) { fprintf(stderr, - "Usage: %s [-m {captive|track|nauth}]\n" + "Usage: %s [-m {categorize|filter|captive}]\n" "\n" "Program arguments:\n" " -m Select authentication mode:\n" - " captive captive portal authentication enforced\n" - " track squid authentication is tracked if available\n" - " noauth authentication infromation is ignored (filter only)\n", + " categorize just analyze URLs and report it to squid\n" + " filter categorization and additionally blocking with\n" + " per-user override possiblity\n" + " captive as filter and require authentication with\n" + " captive portal type login\n" progname); return 1; } @@ -468,10 +472,10 @@ int main(int argc, char **argv) case 'm': if (!strcmp(optarg, "captive")) mode = MODE_CAPTIVE; - else if (!strcmp(optarg, "track")) - mode = MODE_TRACK; - else if (!strcmp(optarg, "noauth")) - mode = MODE_NOAUTH; + else if (!strcmp(optarg, "filter")) + mode = MODE_FILTER; + else if (!strcmp(optarg, "categorize")) + mode = MODE_CATEGORIZE; else return usage(argv[0]); break; -- cgit v1.2.3