logo

etc_portage

Unnamed repository; edit this file 'description' to name the repository. git clone https://hacktivis.me/git/etc_portage.git

02 custom autoindex.patch (7646B)


  1. diff --git a/src/http/modules/ngx_http_autoindex_module.c.old b/src/http/modules/ngx_http_autoindex_module.c
  2. index 2af88a0..18c7570 100644
  3. --- a/src/http/modules/ngx_http_autoindex_module.c.old
  4. +++ b/src/http/modules/ngx_http_autoindex_module.c
  5. @@ -52,9 +52,6 @@ typedef struct {
  6. #define NGX_HTTP_AUTOINDEX_PREALLOCATE 50
  7. -#define NGX_HTTP_AUTOINDEX_NAME_LEN 50
  8. -
  9. -
  10. static ngx_buf_t *ngx_http_autoindex_html(ngx_http_request_t *r,
  11. ngx_array_t *entries);
  12. static ngx_buf_t *ngx_http_autoindex_json(ngx_http_request_t *r,
  13. @@ -476,7 +475,8 @@ ngx_http_autoindex_html(ngx_http_request_t *r, ngx_array_t *entries)
  14. + sizeof(header) - 1
  15. + r->uri.len + escape_html
  16. + sizeof("</h1>") - 1
  17. - + sizeof("<hr><pre><a href=\"../\">../</a>" CRLF) - 1
  18. + + sizeof("<table><tr><th>Name</th><th>Date</th><th>Size</th></tr>" CRLF) - 1
  19. + + sizeof("<tr><td><a href=\"../\">../</a></td></tr>" CRLF) - 1
  20. + sizeof("</pre><hr>") - 1
  21. + sizeof(tail) - 1;
  22. @@ -498,12 +498,11 @@ ngx_http_autoindex_html(ngx_http_request_t *r, ngx_array_t *entries)
  23. + entry[i].name.len + entry[i].escape
  24. + 1 /* 1 is for "/" */
  25. + sizeof("\">") - 1
  26. - + entry[i].name.len - entry[i].utf_len
  27. + + entry[i].utf_len
  28. + entry[i].escape_html
  29. - + NGX_HTTP_AUTOINDEX_NAME_LEN + sizeof("&gt;") - 2
  30. + sizeof("</a>") - 1
  31. + sizeof(" 28-Sep-1970 12:00 ") - 1
  32. - + 20 /* the file size */
  33. + + 256 /* the file size */
  34. + 2;
  35. if (len > NGX_MAX_SIZE_T_VALUE - entry_len) {
  36. @@ -531,14 +527,14 @@ ngx_http_autoindex_html(ngx_http_request_t *r, ngx_array_t *entries)
  37. b->last = ngx_cpymem(b->last, "</h1>", sizeof("</h1>") - 1);
  38. - b->last = ngx_cpymem(b->last, "<hr><pre><a href=\"../\">../</a>" CRLF,
  39. - sizeof("<hr><pre><a href=\"../\">../</a>" CRLF) - 1);
  40. + b->last = ngx_cpymem(b->last, "<hr><table><tr><th>Name</th><th>Date</th><th>Size</th></tr>" CRLF "<tr><td><a href=\"../\">../</a></td></tr>" CRLF,
  41. + sizeof("<hr><table><tr><th>Name</th><th>Date</th><th>Size</th></tr>" CRLF "<tr><td><a href=\"../\">../</a></td></tr>" CRLF) - 1);
  42. alcf = ngx_http_get_module_loc_conf(r, ngx_http_autoindex_module);
  43. tp = ngx_timeofday();
  44. for (i = 0; i < entries->nelts; i++) {
  45. - b->last = ngx_cpymem(b->last, "<a href=\"", sizeof("<a href=\"") - 1);
  46. + b->last = ngx_cpymem(b->last, "<tr><td><a href=\"", sizeof("<tr><td><a href=\"") - 1);
  47. if (entry[i].escape) {
  48. ngx_escape_uri(b->last, entry[i].name.data, entry[i].name.len,
  49. @@ -558,69 +556,27 @@ ngx_http_autoindex_html(ngx_http_request_t *r, ngx_array_t *entries)
  50. *b->last++ = '"';
  51. *b->last++ = '>';
  52. len = entry[i].utf_len;
  53. - if (entry[i].name.len != len) {
  54. - if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
  55. - char_len = NGX_HTTP_AUTOINDEX_NAME_LEN - 3 + 1;
  56. -
  57. - } else {
  58. - char_len = NGX_HTTP_AUTOINDEX_NAME_LEN + 1;
  59. - }
  60. -
  61. - last = b->last;
  62. - b->last = ngx_utf8_cpystrn(b->last, entry[i].name.data,
  63. - char_len, entry[i].name.len + 1);
  64. + last = b->last;
  65. + b->last = ngx_cpymem(b->last, entry[i].name.data,
  66. + entry[i].name.len);
  67. - if (entry[i].escape_html) {
  68. - b->last = (u_char *) ngx_escape_html(last, entry[i].name.data,
  69. - b->last - last);
  70. - }
  71. + if (entry[i].escape_html) {
  72. + b->last = (u_char *) ngx_escape_html(last, entry[i].name.data,
  73. + b->last - last);
  74. + }
  75. - last = b->last;
  76. -
  77. - } else {
  78. - if (entry[i].escape_html) {
  79. - if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
  80. - char_len = NGX_HTTP_AUTOINDEX_NAME_LEN - 3;
  81. -
  82. - } else {
  83. - char_len = len;
  84. - }
  85. -
  86. - b->last = (u_char *) ngx_escape_html(b->last,
  87. - entry[i].name.data, char_len);
  88. - last = b->last;
  89. -
  90. - } else {
  91. - b->last = ngx_cpystrn(b->last, entry[i].name.data,
  92. - NGX_HTTP_AUTOINDEX_NAME_LEN + 1);
  93. - last = b->last - 3;
  94. - }
  95. - }
  96. -
  97. - if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
  98. - b->last = ngx_cpymem(last, "..&gt;</a>", sizeof("..&gt;</a>") - 1);
  99. -
  100. - } else {
  101. - if (entry[i].dir && NGX_HTTP_AUTOINDEX_NAME_LEN - len > 0) {
  102. - *b->last++ = '/';
  103. - len++;
  104. - }
  105. -
  106. - b->last = ngx_cpymem(b->last, "</a>", sizeof("</a>") - 1);
  107. -
  108. - if (NGX_HTTP_AUTOINDEX_NAME_LEN - len > 0) {
  109. - ngx_memset(b->last, ' ', NGX_HTTP_AUTOINDEX_NAME_LEN - len);
  110. - b->last += NGX_HTTP_AUTOINDEX_NAME_LEN - len;
  111. - }
  112. + if (entry[i].dir) {
  113. + *b->last++ = '/';
  114. + len++;
  115. }
  116. - *b->last++ = ' ';
  117. + b->last = ngx_cpymem(b->last, "</a></td>", sizeof("</a></td>") - 1);
  118. ngx_gmtime(entry[i].mtime + tp->gmtoff * 60 * alcf->localtime, &tm);
  119. - b->last = ngx_sprintf(b->last, "%02d-%02d-%02d %02d:%02d ",
  120. + b->last = ngx_sprintf(b->last, "<td>%02d-%02d-%02d %02d:%02d</td>",
  121. tm.ngx_tm_year,
  122. tm.ngx_tm_mon,
  123. tm.ngx_tm_mday,
  124. @@ -628,19 +574,12 @@ ngx_http_autoindex_html(ngx_http_request_t *r, ngx_array_t *entries)
  125. tm.ngx_tm_min);
  126. if (alcf->exact_size) {
  127. - if (entry[i].dir) {
  128. - b->last = ngx_cpymem(b->last, " -",
  129. - sizeof(" -") - 1);
  130. - } else {
  131. - b->last = ngx_sprintf(b->last, "%19O", entry[i].size);
  132. + if (!entry[i].dir) {
  133. + b->last = ngx_sprintf(b->last, "<td>%O</td>", entry[i].size);
  134. }
  135. } else {
  136. - if (entry[i].dir) {
  137. - b->last = ngx_cpymem(b->last, " -",
  138. - sizeof(" -") - 1);
  139. -
  140. - } else {
  141. + if (!entry[i].dir) {
  142. length = entry[i].size;
  143. if (length > 1024 * 1024 * 1024 - 1) {
  144. @@ -672,19 +611,18 @@ ngx_http_autoindex_html(ngx_http_request_t *r, ngx_array_t *entries)
  145. }
  146. if (scale) {
  147. - b->last = ngx_sprintf(b->last, "%6i%c", size, scale);
  148. + b->last = ngx_sprintf(b->last, "<td>%i%c</td>", size, scale);
  149. } else {
  150. - b->last = ngx_sprintf(b->last, " %6i", size);
  151. + b->last = ngx_sprintf(b->last, "<td>%i</td>", size);
  152. }
  153. }
  154. }
  155. - *b->last++ = CR;
  156. - *b->last++ = LF;
  157. + b->last = ngx_sprintf(b->last, "</tr>" CRLF);
  158. }
  159. - b->last = ngx_cpymem(b->last, "</pre><hr>", sizeof("</pre><hr>") - 1);
  160. + b->last = ngx_cpymem(b->last, "</table>", sizeof("</table>") - 1);
  161. b->last = ngx_cpymem(b->last, tail, sizeof(tail) - 1);