Last active
October 31, 2016 14:34
-
-
Save sfan5/db040d04686ed653d9b1 to your computer and use it in GitHub Desktop.
Add randomly selected header icons to generated autoindexes in nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- nginx-1.10.2/src/http/modules/ngx_http_autoindex_module.c.orig 2016-10-18 17:03:14.000000000 +0200 | |
+++ nginx-1.10.2/src/http/modules/ngx_http_autoindex_module.c 2016-10-31 15:31:31.873696354 +0100 | |
@@ -54,6 +54,10 @@ | |
#define NGX_HTTP_AUTOINDEX_NAME_LEN 50 | |
+#define NGX_HTTP_AUTOINDEX_HDRIMG_COUNT 4 // indexing starts at zero | |
+#define NGX_HTTP_AUTOINDEX_HDRIMG_SIZE "96px" | |
+#define NGX_HTTP_AUTOINDEX_HDRIMG_UPRE "/_/h" | |
+#define NGX_HTTP_AUTOINDEX_HDRIMG_UPOST ".png" | |
static ngx_buf_t *ngx_http_autoindex_html(ngx_http_request_t *r, | |
ngx_array_t *entries); | |
@@ -444,11 +448,21 @@ | |
"<head><title>Index of " | |
; | |
- static u_char header[] = | |
+ static u_char header_a[] = | |
"</title></head>" CRLF | |
"<body bgcolor=\"white\">" CRLF | |
+ "<div style=\"display:flex;align-items:center;\">" | |
+ "<img alt=\"\" style=\"float:left;width:" NGX_HTTP_AUTOINDEX_HDRIMG_SIZE | |
+ ";\" src=\"" | |
+ ; | |
+ static u_char header_b[] = | |
+ "\">" | |
"<h1>Index of " | |
; | |
+#if NGX_HTTP_AUTOINDEX_HDRIMG_COUNT > 10 | |
+#error due to reasons NGX_HTTP_AUTOINDEX_HDRIMG_COUNT is limited to 10 | |
+#endif | |
+ const char nchr = '0' + (rand() % NGX_HTTP_AUTOINDEX_HDRIMG_COUNT); | |
static u_char tail[] = | |
"</body>" CRLF | |
@@ -472,11 +486,15 @@ | |
len = sizeof(title) - 1 | |
+ r->uri.len + escape_html | |
- + sizeof(header) - 1 | |
+ + sizeof(header_a) - 1 | |
+ + sizeof(NGX_HTTP_AUTOINDEX_HDRIMG_UPRE) - 1 | |
+ + 1 // number char | |
+ + sizeof(NGX_HTTP_AUTOINDEX_HDRIMG_UPOST) - 1 | |
+ + sizeof(header_b) - 1 | |
+ r->uri.len + escape_html | |
- + sizeof("</h1>") - 1 | |
- + sizeof("<hr><pre><a href=\"../\">../</a>" CRLF) - 1 | |
- + sizeof("</pre><hr>") - 1 | |
+ + sizeof("</h1></div>") - 1 | |
+ + sizeof("<hr style=\"border-style:ridge;\"><pre><a href=\"../\">../</a>" CRLF) - 1 | |
+ + sizeof("</pre><hr style=\"border-style:ridge;\">") - 1 | |
+ sizeof(tail) - 1; | |
entry = entries->elts; | |
@@ -517,19 +535,26 @@ | |
if (escape_html) { | |
b->last = (u_char *) ngx_escape_html(b->last, r->uri.data, r->uri.len); | |
- b->last = ngx_cpymem(b->last, header, sizeof(header) - 1); | |
- b->last = (u_char *) ngx_escape_html(b->last, r->uri.data, r->uri.len); | |
} else { | |
b->last = ngx_cpymem(b->last, r->uri.data, r->uri.len); | |
- b->last = ngx_cpymem(b->last, header, sizeof(header) - 1); | |
+ } | |
+ b->last = ngx_cpymem(b->last, header_a, sizeof(header_a) - 1); | |
+ b->last = ngx_cpymem(b->last, NGX_HTTP_AUTOINDEX_HDRIMG_UPRE, sizeof(NGX_HTTP_AUTOINDEX_HDRIMG_UPRE) - 1); | |
+ b->last = ngx_cpymem(b->last, &nchr, 1); | |
+ b->last = ngx_cpymem(b->last, NGX_HTTP_AUTOINDEX_HDRIMG_UPOST, sizeof(NGX_HTTP_AUTOINDEX_HDRIMG_UPOST) - 1); | |
+ b->last = ngx_cpymem(b->last, header_b, sizeof(header_b) - 1); | |
+ if (escape_html) { | |
+ b->last = (u_char *) ngx_escape_html(b->last, r->uri.data, r->uri.len); | |
+ | |
+ } else { | |
b->last = ngx_cpymem(b->last, r->uri.data, r->uri.len); | |
} | |
- b->last = ngx_cpymem(b->last, "</h1>", sizeof("</h1>") - 1); | |
+ b->last = ngx_cpymem(b->last, "</h1></div>", sizeof("</h1></div>") - 1); | |
- b->last = ngx_cpymem(b->last, "<hr><pre><a href=\"../\">../</a>" CRLF, | |
- sizeof("<hr><pre><a href=\"../\">../</a>" CRLF) - 1); | |
+ b->last = ngx_cpymem(b->last, "<hr style=\"border-style:ridge;\"><pre><a href=\"../\">../</a>" CRLF, | |
+ sizeof("<hr style=\"border-style:ridge;\"><pre><a href=\"../\">../</a>" CRLF) - 1); | |
alcf = ngx_http_get_module_loc_conf(r, ngx_http_autoindex_module); | |
tp = ngx_timeofday(); | |
@@ -681,7 +706,7 @@ | |
*b->last++ = LF; | |
} | |
- b->last = ngx_cpymem(b->last, "</pre><hr>", sizeof("</pre><hr>") - 1); | |
+ b->last = ngx_cpymem(b->last, "</pre><hr style=\"border-style:ridge;\">", sizeof("</pre><hr style=\"border-style:ridge;\">") - 1); | |
b->last = ngx_cpymem(b->last, tail, sizeof(tail) - 1); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment