diff options
Diffstat (limited to 'squark-filter.c')
-rw-r--r-- | squark-filter.c | 59 |
1 files changed, 8 insertions, 51 deletions
diff --git a/squark-filter.c b/squark-filter.c index 1fa1ec9..995da40 100644 --- a/squark-filter.c +++ b/squark-filter.c @@ -25,13 +25,15 @@ #define FILTER_OVERRIDE_TIMEOUT (15*60) +static struct sqdb db; +static struct authdb adb; +static struct authdb_config adbc; + static int running = 1; -static uint64_t banned_categories = 0; static const blob_t dash = BLOB_STR_INIT("-"); static const blob_t space = BLOB_STR_INIT(" "); static const blob_t slash = BLOB_STR_INIT("/"); static const blob_t lf = BLOB_STR_INIT("\n"); -static blob_t redirect_banned_page, redirect_login_page; static struct authdb adb; static time_t now; @@ -303,23 +305,6 @@ static blob_t get_category_name(struct sqdb *db, int id) return sqdb_get_string_literal(db, c[id]); } -static int find_category_id(struct sqdb *db, blob_t cat) -{ - uint32_t size, *ptr; - int i; - - ptr = sqdb_section_get(db, SQDB_SECTION_CATEGORIES, &size); - if (ptr == NULL) - return -1; - - size /= sizeof(uint32_t); - for (i = 0; i < size; i++) - if (blob_cmp(cat, sqdb_get_string_literal(db, ptr[i])) == 0) - return i; - - return -1; -} - static void send_ok(blob_t tag) { static char buffer[64]; @@ -339,6 +324,7 @@ static void send_redirect(blob_t redirect_page, blob_t tag, blob_t url, blob_t c blob_push(&b, tag); blob_push(&b, BLOB_STR(" 302:")); + blob_push(&b, adbc.redirect_url_base); blob_push(&b, redirect_page); blob_push(&b, BLOB_STR("?REASON=")); blob_push_urlencode(&b, categ); @@ -414,12 +400,12 @@ static void read_input(struct sqdb *db) } if (!auth_ok) { - send_redirect(redirect_login_page, id, url, BLOB_STR("auth"), username); + send_redirect(BLOB_STR("login.cgi"), id, url, BLOB_STR("auth"), username); } else if (((1ULL << category) & entry.p.block_categories) && (now < entry.override_time || now > entry.override_time + FILTER_OVERRIDE_TIMEOUT || ((1ULL << category) & entry.p.hard_block_categories))) { - send_redirect(redirect_banned_page, id, url, get_category_name(db, category), username); + send_redirect(BLOB_STR("warning.cgi"), id, url, get_category_name(db, category), username); } else send_ok(id); } @@ -432,39 +418,10 @@ static void read_input(struct sqdb *db) } while (b.len); } -static void ban_category(struct sqdb *db, blob_t c) -{ - int category; - - category = find_category_id(db, c); - if (category >= 0) - banned_categories |= 1ULL << category; - else - fprintf(stderr, "WARNING: unknown category '%.*s'\n", - c.len, c.ptr); -} - int main(int argc, char **argv) { - struct sqdb db; - int opt; - - authdb_open(&adb); sqdb_open(&db, "/var/lib/squark/squark.db"); - - while ((opt = getopt(argc, argv, "r:b:c:")) != -1) { - switch (opt) { - case 'r': - redirect_banned_page = BLOB_STRLEN(optarg); - break; - case 'c': - redirect_login_page = BLOB_STRLEN(optarg); - break; - case 'b': - ban_category(&db, BLOB_STRLEN(optarg)); - break; - } - } + authdb_open(&adb, &adbc, &db); while (running) read_input(&db); |