commit d239995b2d466d59485b01ddcb086da27784e3fa
parent e6f332943648d46e5d01ea93c7209c613b754394
Author: Joris Vink <joris@coders.se>
Date: Thu, 19 Apr 2018 05:30:40 +0000
add referer log
Diffstat:
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/conf/blog.conf b/conf/blog.conf
@@ -6,9 +6,16 @@ workers 4
runas nobody
chroot /var/chroot/kore-blog
+validator v_referer function referer
+
+authentication referer_log {
+ authentication_type request
+ authentication_validator v_referer
+}
+
domain * {
- static / post_list
- dynamic ^/posts/[a-z1-9\-]+$ post_render
+ static / post_list referer_log
+ dynamic ^/posts/[a-z1-9\-]+$ post_render referer_log
static /drafts/ draft_list
dynamic ^/drafts/[a-z1-9\-]+$ draft_render
diff --git a/src/blog.c b/src/blog.c
@@ -62,6 +62,7 @@ int post_list(struct http_request *);
int post_render(struct http_request *);
int draft_list(struct http_request *);
int draft_render(struct http_request *);
+int referer(struct http_request *, const void *);
int list_posts(struct http_request *, const char *, int);
static TAILQ_HEAD(, post) posts;
@@ -264,6 +265,28 @@ post_remove(struct post *post)
}
int
+referer(struct http_request *req, const void *unused)
+{
+ const char *ref, *p;
+
+ if (!http_request_header(req, "referer", &ref))
+ return (KORE_RESULT_OK);
+
+ p = ref;
+
+ while (*p != '\0') {
+ if (!isprint(*(const unsigned char *)p++)) {
+ ref = "[not printable]";
+ break;
+ }
+ }
+
+ kore_log(LOG_NOTICE, "blog (%s) visit from %s", req->path, ref);
+
+ return (KORE_RESULT_OK);
+}
+
+int
redirect(struct http_request *req)
{
http_response_header(req, "location", "/");