forked from mirrors/kore
Add a "return" configuration option.
This hooks into the existing redirection framework but allows you to quickly deny certain paths with a 403 or other status code. The snippet below would for example declare a filemap served from 'www' directory but denying all access to the files under the 'data' directory: filemap / www deny /data 403
This commit is contained in:
parent
9e5e698e4b
commit
db31f37ab0
33
src/config.c
33
src/config.c
|
@ -110,6 +110,7 @@ static int configure_client_verify_depth(char *);
|
|||
#if !defined(KORE_NO_HTTP)
|
||||
static int configure_route(char *);
|
||||
static int configure_filemap(char *);
|
||||
static int configure_return(char *);
|
||||
static int configure_redirect(char *);
|
||||
static int configure_static_handler(char *);
|
||||
static int configure_dynamic_handler(char *);
|
||||
|
@ -192,6 +193,7 @@ static struct {
|
|||
{ "route", configure_route},
|
||||
{ "filemap", configure_filemap },
|
||||
{ "redirect", configure_redirect },
|
||||
{ "return", configure_return },
|
||||
{ "static", configure_static_handler },
|
||||
{ "dynamic", configure_dynamic_handler },
|
||||
{ "accesslog", configure_accesslog },
|
||||
|
@ -1030,6 +1032,37 @@ configure_route(char *options)
|
|||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
configure_return(char *options)
|
||||
{
|
||||
char *argv[3];
|
||||
int elm, status, err;
|
||||
|
||||
if (current_domain == NULL) {
|
||||
printf("return outside of domain context\n");
|
||||
return (KORE_RESULT_ERROR);
|
||||
}
|
||||
|
||||
elm = kore_split_string(options, " ", argv, 3);
|
||||
if (elm != 2) {
|
||||
printf("missing parameters for return\n");
|
||||
return (KORE_RESULT_ERROR);
|
||||
}
|
||||
|
||||
status = kore_strtonum(argv[1], 10, 400, 600, &err);
|
||||
if (err != KORE_RESULT_OK) {
|
||||
printf("invalid status code on return (%s)\n", argv[1]);
|
||||
return (KORE_RESULT_ERROR);
|
||||
}
|
||||
|
||||
if (!http_redirect_add(current_domain, argv[0], status, NULL)) {
|
||||
printf("invalid regex on return path\n");
|
||||
return (KORE_RESULT_ERROR);
|
||||
}
|
||||
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
configure_redirect(char *options)
|
||||
{
|
||||
|
|
14
src/http.c
14
src/http.c
|
@ -1500,7 +1500,11 @@ http_redirect_add(struct kore_domain *dom, const char *path, int status,
|
|||
}
|
||||
|
||||
rdr->status = status;
|
||||
|
||||
if (target != NULL)
|
||||
rdr->target = kore_strdup(target);
|
||||
else
|
||||
rdr->target = NULL;
|
||||
|
||||
TAILQ_INSERT_TAIL(&dom->redirects, rdr, list);
|
||||
|
||||
|
@ -1525,7 +1529,10 @@ http_check_redirect(struct http_request *req, struct kore_domain *dom)
|
|||
if (rdr == NULL)
|
||||
return (KORE_RESULT_ERROR);
|
||||
|
||||
uri = NULL;
|
||||
kore_buf_init(&location, 128);
|
||||
|
||||
if (rdr->target) {
|
||||
kore_buf_appendf(&location, "%s", rdr->target);
|
||||
|
||||
if (req->query_string != NULL) {
|
||||
|
@ -1547,12 +1554,17 @@ http_check_redirect(struct http_request *req, struct kore_domain *dom)
|
|||
}
|
||||
|
||||
uri = kore_buf_stringify(&location, NULL);
|
||||
}
|
||||
|
||||
if (uri)
|
||||
http_response_header(req, "location", uri);
|
||||
http_response(req, rdr->status, NULL, 0);
|
||||
|
||||
http_response(req, rdr->status, NULL, 0);
|
||||
kore_buf_cleanup(&location);
|
||||
|
||||
if (dom->accesslog)
|
||||
kore_accesslog(req);
|
||||
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue