Add magic upstream destinations "blocklist" and "cache"
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
4f7e347893
commit
87a1e4a2de
|
@ -263,7 +263,16 @@ int api_queries(struct ftl_conn *api)
|
|||
|
||||
// Upstream filtering?
|
||||
if(GET_STR("upstream", upstreamname, api->request->query_string) > 0)
|
||||
add_querystr_string(api, querystr, "f.forward=", ":upstream", &where);
|
||||
{
|
||||
if(strcmp(upstreamname, "blocklist") == 0)
|
||||
// Pseudo-upstream for blocked queries
|
||||
add_querystr_string(api, querystr, "q.status IN ", get_blocked_statuslist(), &where);
|
||||
else if(strcmp(upstreamname, "cache") == 0)
|
||||
// Pseudo-upstream for cached queries
|
||||
add_querystr_string(api, querystr, "q.status IN ", get_cached_statuslist(), &where);
|
||||
else
|
||||
add_querystr_string(api, querystr, "f.forward=", ":upstream", &where);
|
||||
}
|
||||
|
||||
// Client IP filtering?
|
||||
if(GET_STR("client_ip", clientip, api->request->query_string) > 0)
|
||||
|
|
|
@ -780,6 +780,52 @@ bool __attribute__ ((const)) is_blocked(const enum query_status status)
|
|||
}
|
||||
}
|
||||
|
||||
static char blocked_list[32] = { 0 };
|
||||
const char * __attribute__ ((const)) get_blocked_statuslist(void)
|
||||
{
|
||||
if(blocked_list[0] != '\0')
|
||||
return blocked_list;
|
||||
|
||||
// Build a list of blocked query statuses
|
||||
unsigned int first = 0;
|
||||
// Open parenthesis
|
||||
blocked_list[0] = '(';
|
||||
for(enum query_status status = 0; status < QUERY_STATUS_MAX; status++)
|
||||
if(is_blocked(status))
|
||||
snprintf(blocked_list + strlen(blocked_list),
|
||||
sizeof(blocked_list) - strlen(blocked_list),
|
||||
"%s%d", first++ < 1 ? "" : ",", status);
|
||||
|
||||
// Close parenthesis
|
||||
const size_t len = strlen(blocked_list);
|
||||
blocked_list[len] = ')';
|
||||
blocked_list[len + 1] = '\0';
|
||||
return blocked_list;
|
||||
}
|
||||
|
||||
static char cached_list[32] = { 0 };
|
||||
const char * __attribute__ ((const)) get_cached_statuslist(void)
|
||||
{
|
||||
if(cached_list[0] != '\0')
|
||||
return cached_list;
|
||||
|
||||
// Build a list of cached query statuses
|
||||
unsigned int first = 0;
|
||||
// Open parenthesis
|
||||
cached_list[0] = '(';
|
||||
for(enum query_status status = 0; status < QUERY_STATUS_MAX; status++)
|
||||
if(is_cached(status))
|
||||
snprintf(cached_list + strlen(cached_list),
|
||||
sizeof(cached_list) - strlen(cached_list),
|
||||
"%s%d", first++ < 1 ? "" : ",", status);
|
||||
|
||||
// Close parenthesis
|
||||
const size_t len = strlen(cached_list);
|
||||
cached_list[len] = ')';
|
||||
cached_list[len + 1] = '\0';
|
||||
return cached_list;
|
||||
}
|
||||
|
||||
int __attribute__ ((pure)) get_blocked_count(void)
|
||||
{
|
||||
int blocked = 0;
|
||||
|
|
|
@ -130,6 +130,8 @@ bool isValidIPv6(const char *addr);
|
|||
|
||||
bool is_blocked(const enum query_status status) __attribute__ ((const));
|
||||
bool is_cached(const enum query_status status) __attribute__ ((const));
|
||||
const char *get_blocked_statuslist(void) __attribute__ ((const));
|
||||
const char *get_cached_statuslist(void) __attribute__ ((const));
|
||||
int get_blocked_count(void) __attribute__ ((pure));
|
||||
int get_forwarded_count(void) __attribute__ ((pure));
|
||||
int get_cached_count(void) __attribute__ ((pure));
|
||||
|
|
|
@ -28,10 +28,10 @@ void allocate_lua(void)
|
|||
// Build login URI string (webhome + login)
|
||||
// Append "login" to webhome string
|
||||
const size_t login_uri_len = strlen(config.webserver.paths.webhome.v.s);
|
||||
login_uri = calloc(login_uri_len + 7, sizeof(char));
|
||||
login_uri = calloc(login_uri_len + 6, sizeof(char));
|
||||
memcpy(login_uri, config.webserver.paths.webhome.v.s, login_uri_len);
|
||||
strcpy(login_uri + login_uri_len, "login");
|
||||
login_uri[login_uri_len + 7u] = '\0';
|
||||
login_uri[login_uri_len + 5u] = '\0';
|
||||
|
||||
// Build "wrong" API URI string (webhome + api)
|
||||
// Append "api" to webhome string
|
||||
|
@ -39,7 +39,7 @@ void allocate_lua(void)
|
|||
admin_api_uri = calloc(admin_api_uri_len + 4, sizeof(char));
|
||||
memcpy(admin_api_uri, config.webserver.paths.webhome.v.s, admin_api_uri_len);
|
||||
strcpy(admin_api_uri + admin_api_uri_len, "api");
|
||||
admin_api_uri[admin_api_uri_len + 4u] = '\0';
|
||||
admin_api_uri[admin_api_uri_len + 3u] = '\0';
|
||||
}
|
||||
|
||||
void free_lua(void)
|
||||
|
|
Loading…
Reference in New Issue