http-fancyindex: Upgrade to 0.4.3
Christos Trochalakis
5 years ago
54 | 54 | |
55 | 55 | Module: http-fancyindex |
56 | 56 | Homepage: https://github.com/aperezdc/ngx-fancyindex |
57 | Version: 0.4.2 | |
57 | Version: 0.4.3 | |
58 | 58 | Files-Excluded: .gitignore .travis.yml |
59 | 59 | |
60 | 60 | Module: http-subs-filter |
1 | 1 | All notable changes to this project will be documented in this file. |
2 | 2 | |
3 | 3 | ## [Unreleased] |
4 | ||
5 | ## [0.4.3] - 2018-07-03 | |
6 | ### Added | |
7 | - Table cells now have class names, which allows for better CSS styling. | |
8 | (Patch by qjqqyy <<gyula@nyirfalvi.hu>>.) | |
9 | - The test suite now can parse and check elements from the HTML returned | |
10 | by the module, thanks to the [pup](https://github.com/EricChiang/pup) | |
11 | tool. | |
12 | ||
13 | ### Fixed | |
14 | - Sorting by file size now works correctly. | |
15 | (Patch by qjqqyy <<gyula@nyirfalvi.hu>>.) | |
4 | 16 | |
5 | 17 | ## [0.4.2] - 2017-08-19 |
6 | 18 | ### Changed |
117 | 129 | - `NEWS.rst` file, to act as change log. |
118 | 130 | |
119 | 131 | |
120 | [Unreleased]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.4.2...HEAD | |
132 | [Unreleased]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.4.3...HEAD | |
133 | [0.4.3]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.4.2...v0.4.3 | |
121 | 134 | [0.4.2]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.4.1...v0.4.2 |
122 | 135 | [0.4.1]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.4.0...v0.4.1 |
123 | 136 | [0.4.0]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.3.6...v0.4.0 |
38 | 38 | |
39 | 39 | yum install nginx-module-fancyindex |
40 | 40 | |
41 | Then load the module in `/etc/nginx/nginx.conf` using | |
41 | Then load the module in `/etc/nginx/nginx.conf` using:: | |
42 | 42 | |
43 | 43 | load_module "modules/ngx_http_fancyindex_module.so"; |
44 | 44 | |
50 | 50 | versions in the 0.6 series by applying ``nginx-0.6-support.patch``, but this |
51 | 51 | is unsupported (YMMV). |
52 | 52 | |
53 | In order to use the fancyindex_header_ and fancyindex_footer_ directives | |
53 | In order to use the ``fancyindex_header_`` and ``fancyindex_footer_`` directives | |
54 | 54 | you will also need the `ngx_http_addition_module <http://nginx.org/en/docs/http/ngx_http_addition_module.html>`_ |
55 | 55 | built into Nginx. |
56 | 56 | |
77 | 77 | |
78 | 78 | Since version 0.4.0, the module can also be built as a |
79 | 79 | `dynamic module <https://www.nginx.com/resources/wiki/extending/converting/>`_, |
80 | using ``--add-dynamic-module=…`` instead and ``load_module "modules/ngx_http_fancyindex_module.so";` | |
80 | using ``--add-dynamic-module=…`` instead and | |
81 | ``load_module "modules/ngx_http_fancyindex_module.so";`` | |
81 | 82 | in the configuration file |
82 | 83 | |
83 | 84 | 4. Build and install the software:: |
113 | 114 | `@TheInsomniac <https://github.com/TheInsomniac>`__. Uses custom header and |
114 | 115 | footer. |
115 | 116 | * `Theme <https://github.com/Naereen/Nginx-Fancyindex-Theme>`__ by |
116 | `Naereen <https://github.com/Naereen/>`__. Uses custom header and footer, the | |
117 | `@Naereen <https://github.com/Naereen/>`__. Uses custom header and footer, the | |
117 | 118 | header includes search field to filter by filename using JavaScript. |
119 | * `Theme <https://github.com/fraoustin/Nginx-Fancyindex-Theme>`__ by | |
120 | `@fraoustin <https://github.com/fraoustin>`__. Responsive theme using | |
121 | Material Design elements. | |
122 | * `Theme <https://github.com/alehaa/nginx-fancyindex-flat-theme>`__ by | |
123 | `@alehaa <https://github.com/alehaa>`__. Simple, flat theme based on | |
124 | Bootstrap 4 and FontAwesome. | |
118 | 125 | |
119 | 126 | |
120 | 127 | Directives |
771 | 771 | * <td>size</td><td>date</td> |
772 | 772 | * </tr> |
773 | 773 | */ |
774 | len += ngx_sizeof_ssz("<tr><td><a href=\"") | |
774 | len += ngx_sizeof_ssz("<tr><td class=\"link\"><a href=\"") | |
775 | 775 | + entry[i].name.len + entry[i].escape /* Escaped URL */ |
776 | 776 | + ngx_sizeof_ssz("?C=x&O=y") /* URL sorting arguments */ |
777 | 777 | + ngx_sizeof_ssz("\" title=\"") |
779 | 779 | + ngx_sizeof_ssz("\">") |
780 | 780 | + entry[i].name.len + entry[i].utf_len |
781 | 781 | + alcf->name_length + ngx_sizeof_ssz(">") |
782 | + ngx_sizeof_ssz("</a></td><td>") | |
782 | + ngx_sizeof_ssz("</a></td><td class=\"size\">") | |
783 | 783 | + 20 /* File size */ |
784 | + ngx_sizeof_ssz("</td><td>") /* Date prefix */ | |
784 | + ngx_sizeof_ssz("</td><td class=\"date\">") /* Date prefix */ | |
785 | 785 | + ngx_sizeof_ssz("</td></tr>\n") /* Date suffix */ |
786 | 786 | + 2 /* CR LF */ |
787 | 787 | ; |
903 | 903 | if (r->uri.len > 1) { |
904 | 904 | b->last = ngx_cpymem_ssz(b->last, |
905 | 905 | "<tr>" |
906 | "<td><a href=\"../"); | |
906 | "<td class=\"link\"><a href=\"../"); | |
907 | 907 | if (*sort_url_args) { |
908 | 908 | b->last = ngx_cpymem(b->last, |
909 | 909 | sort_url_args, |
911 | 911 | } |
912 | 912 | b->last = ngx_cpymem_ssz(b->last, |
913 | 913 | "\">Parent directory/</a></td>" |
914 | "<td>-</td>" | |
915 | "<td>-</td>" | |
914 | "<td class=\"size\">-</td>" | |
915 | "<td class=\"date\">-</td>" | |
916 | 916 | "</tr>"); |
917 | 917 | } |
918 | 918 | |
919 | 919 | /* Entries for directories and files */ |
920 | 920 | for (i = 0; i < entries.nelts; i++) { |
921 | b->last = ngx_cpymem_ssz(b->last, "<tr><td><a href=\""); | |
921 | b->last = ngx_cpymem_ssz(b->last, "<tr><td class=\"link\"><a href=\""); | |
922 | 922 | |
923 | 923 | if (entry[i].escape) { |
924 | 924 | ngx_fancyindex_escape_uri(b->last, |
966 | 966 | } |
967 | 967 | |
968 | 968 | if (len > alcf->name_length) { |
969 | b->last = ngx_cpymem_ssz(last, "..></a></td><td>"); | |
969 | b->last = ngx_cpymem_ssz(last, "..></a></td><td class=\"size\">"); | |
970 | 970 | |
971 | 971 | } else { |
972 | 972 | if (entry[i].dir && alcf->name_length - len > 0) { |
974 | 974 | len++; |
975 | 975 | } |
976 | 976 | |
977 | b->last = ngx_cpymem_ssz(b->last, "</a></td><td>"); | |
977 | b->last = ngx_cpymem_ssz(b->last, "</a></td><td class=\"size\">"); | |
978 | 978 | } |
979 | 979 | |
980 | 980 | if (alcf->exact_size) { |
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | ngx_gmtime(entry[i].mtime + tp->gmtoff * 60 * alcf->localtime, &tm); |
1007 | b->last = ngx_cpymem_ssz(b->last, "</td><td>"); | |
1007 | b->last = ngx_cpymem_ssz(b->last, "</td><td class=\"date\">"); | |
1008 | 1008 | b->last = ngx_fancyindex_timefmt(b->last, &alcf->time_format, &tm); |
1009 | 1009 | b->last = ngx_cpymem_ssz(b->last, "</td></tr>"); |
1010 | 1010 | |
1228 | 1228 | ngx_http_fancyindex_entry_t *first = (ngx_http_fancyindex_entry_t *) one; |
1229 | 1229 | ngx_http_fancyindex_entry_t *second = (ngx_http_fancyindex_entry_t *) two; |
1230 | 1230 | |
1231 | return (first->size > second->size) - (first->size < second->size); | |
1231 | return (first->size < second->size) - (first->size > second->size); | |
1232 | 1232 | } |
1233 | 1233 | |
1234 | 1234 |
0 | #! /bin/bash | |
1 | cat <<--- | |
2 | This test fetches the root directory served by Nginx, which has no index | |
3 | file, and checks the output contains a few HTML elements know to exist in | |
4 | a directory index. | |
5 | -- | |
6 | use pup | |
7 | nginx_start | |
8 | ||
9 | content=$( fetch ) | |
10 | ||
11 | # Check page title | |
12 | [[ $(pup -p title text{} <<< "${content}") = 'Index of /' ]] | |
13 | ||
14 | # Check table headers | |
15 | [[ $(pup -n body table thead th a:first-child <<< "${content}") -eq 3 ]] | |
16 | { | |
17 | read -r name_label | |
18 | read -r size_label | |
19 | read -r date_label | |
20 | } < <( pup -p body table thead th a:first-child text{} <<< "${content}" ) | |
21 | [[ ${name_label} = File\ Name ]] | |
22 | [[ ${size_label} = File\ Size ]] | |
23 | [[ ${date_label} = Date ]] |
0 | #! /bin/bash | |
1 | cat <<--- | |
2 | This test validates that the sorting by file size works. | |
3 | -- | |
4 | use pup | |
5 | nginx_start | |
6 | ||
7 | # Ascending sort. | |
8 | previous='' | |
9 | while read -r size ; do | |
10 | if [[ ${size} = - ]] ; then | |
11 | continue | |
12 | fi | |
13 | if [[ -z ${previous} ]] ; then | |
14 | previous=${size} | |
15 | continue | |
16 | fi | |
17 | [[ ${previous} -le ${size} ]] || fail \ | |
18 | 'Size %d should be smaller than %d\n' "${previous}" "${size}" | |
19 | done < <( fetch '/?C=S&O=A' \ | |
20 | | pup -p body table tbody 'td:nth-child(2)' text{} ) | |
21 | ||
22 | # Descending sort. | |
23 | previous='' | |
24 | while read -r size ; do | |
25 | if [[ ${size} = - ]] ; then | |
26 | continue | |
27 | fi | |
28 | if [[ -z ${previous} ]] ; then | |
29 | previous=${size} | |
30 | continue | |
31 | fi | |
32 | [[ ${previous} -ge ${size} ]] || fail \ | |
33 | 'Size %d should be greater than %d\n' "${previous}" "${size}" | |
34 | done < <( fetch '/?C=S&O=D' \ | |
35 | | pup -p body table tbody 'td:nth-child(2)' text{} ) |
0 | #! /bin/bash | |
1 | set -e | |
2 | ||
3 | declare -r VERSION='0.4.0' | |
4 | declare -r SHASUMS='\ | |
5 | 75c27caa0008a9cc639beb7506077ad9f32facbffcc4e815e999eaf9588a527e pup_v0.4.0_darwin_386.zip | |
6 | c539a697efee2f8e56614a54cb3b215338e00de1f6a7c2fa93144ab6e1db8ebe pup_v0.4.0_darwin_amd64.zip | |
7 | 259eee82c7d7d766f1b8f93a382be21dcfefebc855a9ce8124fd78717f9df439 pup_v0.4.0_dragonfly_amd64.zip | |
8 | ba0fe5e87a24cab818e5d2efdd7540714ddfb1b7246600135915c666fdf1a601 pup_v0.4.0_freebsd_386.zip | |
9 | 1838ef84ec1f961e8009d19a4d1e6a23b926ee315da3d60c08878f3d69af5692 pup_v0.4.0_freebsd_amd64.zip | |
10 | 6886a9c60a912a810d012610bc3f784f0417999ff7d7df833a0695b9af60395b pup_v0.4.0_freebsd_arm.zip | |
11 | e486b32ca07552cd3aa713cbf2f9d1b6e210ddb51d34b3090c7643f465828057 pup_v0.4.0_linux_386.zip | |
12 | ec3d29e9fb375b87ac492c8b546ad6be84b0c0b49dab7ff4c6b582eac71ba01c pup_v0.4.0_linux_amd64.zip | |
13 | c09b669fa8240f4f869dee7d34ee3c7ea620a0280cee1ea7d559593bcdd062c9 pup_v0.4.0_linux_arm64.zip | |
14 | ebf70b3c76c02e0202c94af7ef06dcb3ecc866d1b9b84453d43fe01fa5dd5870 pup_v0.4.0_linux_arm.zip | |
15 | a98a4d1f3c3a103e8ebe1a7aba9cb9d3cb045003208ca6f5f3d54889a225f267 pup_v0.4.0_linux_mips64le.zip | |
16 | 8e471cf6cfa118b2497bb3f42a7a48c52d0096107f748f37216855c8ab94f8e5 pup_v0.4.0_linux_mips64.zip | |
17 | cfda9375eba65f710e052b1b59893c228c3fc92b0510756bb3f02c25938eee30 pup_v0.4.0_linux_ppc64le.zip | |
18 | 91a1e07ffb2c373d6053252e4de732f5db78c8eace49c6e1a0ef52402ecdf56c pup_v0.4.0_linux_ppc64.zip | |
19 | fdc9b28a3daac5ad096023e1647292a7eccea6d9b1686f871307dae9f3bd064f pup_v0.4.0_nacl_386.zip | |
20 | c8d3c9b56783bd5a55446f4580e1835606b2b945da2d1417ed509c5927a5f8bc pup_v0.4.0_nacl_amd64p32.zip | |
21 | 48c068c4353672528c8c3447a536208b0719f1e6d0f8fab8416b38b63ad0c1d9 pup_v0.4.0_nacl_arm.zip | |
22 | 7a27497b2f0be95c51bb2cbc25da12efba682c4f766bc5abc5742e9fc8d1eeb0 pup_v0.4.0_netbsd_386.zip | |
23 | 71a1808eb1b6442aa45d1de9e1c4fca543b2754c1aff5ba3d62b3456f9519691 pup_v0.4.0_netbsd_amd64.zip | |
24 | 928e6691b11c68ae3f28826848a13dc5c1c9673848fe7cf7f80dd76c9fb6e8a6 pup_v0.4.0_netbsd_arm.zip | |
25 | 5aca20a9b3264d2fde5a8d32f213c434edf9570ee6fae18953b8fff09d2976e2 pup_v0.4.0_openbsd_386.zip | |
26 | e965c6f04b897240d84c60e2c18226deb231a657c5583680f58a61051ff5a100 pup_v0.4.0_openbsd_amd64.zip | |
27 | 30bc88a1e06606f4f3449af9fbf586f97c2e958677460a72bb1a168f67c4911c pup_v0.4.0_openbsd_arm.zip | |
28 | 9d50decf4572292f187cfec84660648d648336bc6109e1f032b1699ba1d28549 pup_v0.4.0_plan9_386.zip | |
29 | 1b2a6bd2388ddd691ca429497d88b2b047ec8dfb7bce9436925cb2f30632bf8e pup_v0.4.0_plan9_amd64.zip | |
30 | 0835de9c10a9e2b3b958b82d148da49eaafc695fe4a018cbaf7bb861b455583f pup_v0.4.0_solaris_amd64.zip | |
31 | 01acae220b69fb1ba8477d0e7f4d7669ef5de147966dc819cf75a845af74c5f3 pup_v0.4.0_windows_386.zip | |
32 | 6755cbd43e94eaf173689e93e914c7056a2249c2977e5b90024fb397f9b45ba4 pup_v0.4.0_windows_amd64.zip | |
33 | ' | |
34 | ||
35 | declare -r BASEURL="https://github.com/ericchiang/pup/releases/download/v${VERSION}" | |
36 | declare -r TDIR=$(dirname "$0") | |
37 | ARCH='' | |
38 | OS='' | |
39 | ||
40 | case $(uname -m) in | |
41 | x86_64 | amd64 ) ARCH=amd64 ;; | |
42 | i[3456]86 ) ARCH=386 ;; | |
43 | esac | |
44 | ||
45 | OS=$(uname -s | tr 'A-Z' 'a-z') | |
46 | case ${OS} in | |
47 | linux | freebsd | openbsd | netbsd | darwin ) ;; | |
48 | * ) OS='' | |
49 | esac | |
50 | ||
51 | if [[ -z ${ARCH} || -z ${OS} ]] ; then | |
52 | echo "pup ${VERSION} is not available for $(uname -s) on $(uname -m)" 1>&2 | |
53 | exit 1 | |
54 | fi | |
55 | ||
56 | declare -r ZIPFILE="pup_v${VERSION}_${OS}_${ARCH}.zip" | |
57 | EXPECT_SHA='' | |
58 | ||
59 | while read sum fname ; do | |
60 | if [[ ${fname} = ${ZIPFILE} ]] ; then | |
61 | EXPECT_SHA=${sum} | |
62 | break | |
63 | fi | |
64 | done <<< "${SHASUMS}" | |
65 | ||
66 | wget -cO "${TDIR}/${ZIPFILE}" "${BASEURL}/${ZIPFILE}" | |
67 | ||
68 | read -r GOT_SHA _ < <( sha256sum "${TDIR}/${ZIPFILE}" ) | |
69 | if [[ ${EXPECT_SHA} = ${GOT_SHA} ]] ; then | |
70 | echo "Checksum for ${ZIPFILE} verified :-)" | |
71 | else | |
72 | rm -f "${TDIR}/${ZIPFILE}" "${TDIR}/pup" | |
73 | echo "Checksum for ${ZIPFILE} does not match :-(" | |
74 | echo " Expected: ${EXPECT_SHA}" | |
75 | echo " Got: ${GOT_SHA}" | |
76 | exit 2 | |
77 | fi 1>&2 | |
78 | ||
79 | rm -f "${TDIR}/pup" | |
80 | unzip "${TDIR}/${ZIPFILE}" pup -d "${TDIR}" |
38 | 38 | rm -f "${NGINX_CONF}" "${NGINX_PID}" |
39 | 39 | mkdir -p "${PREFIX}/logs" |
40 | 40 | |
41 | function pup () { | |
42 | if [[ -x ${TESTDIR}/pup ]] ; then | |
43 | "${TESTDIR}/pup" "$@" | |
44 | else | |
45 | skip 'Test uses "pup", which is not available' | |
46 | fi | |
47 | } | |
48 | ||
49 | function use () { | |
50 | case $1 in | |
51 | pup ) [[ -x ${TESTDIR}/pup ]] \ | |
52 | || skip 'Test uses "pup", which is unavailable\n' ;; | |
53 | * ) warn "Invalid 'use' flag: '%s'\n'" "$1" ;; | |
54 | esac | |
55 | } | |
56 | ||
41 | 57 | function nginx () { |
42 | 58 | env - PATH="${PATH}" "${PREFIX}/sbin/nginx" "$@" |
43 | 59 | } |
71 | 87 | wget "${opts[@]}" -O- "http://localhost:8888${1:-/}" 2>&1 |
72 | 88 | } |
73 | 89 | |
90 | function skip () { | |
91 | printf '(--) ' | |
92 | printf "$@" | |
93 | exit 111 | |
94 | } 1>&2 | |
95 | ||
74 | 96 | function fail () { |
75 | printf "(FF) " | |
97 | printf '(FF) ' | |
76 | 98 | printf "$@" |
77 | 99 | exit 1 |
78 | 100 | } 1>&2 |
79 | 101 | |
80 | 102 | function warn () { |
81 | printf "(WW)" | |
103 | printf '(WW) ' | |
82 | 104 | printf "$@" |
83 | 105 | } 1>&2 |
24 | 24 | |
25 | 25 | declare -a t_pass=( ) |
26 | 26 | declare -a t_fail=( ) |
27 | declare -a t_skip=( ) | |
27 | 28 | |
28 | 29 | for t in `ls "$T"/*.test | sort -R` ; do |
29 | 30 | name="t/${t##*/}" |
42 | 43 | if bash -e "${shfile}" > "${outfile}" 2> "${errfile}" ; then |
43 | 44 | t_pass+=( "${name}" ) |
44 | 45 | printf '[1;32mpassed[0;0m\n' |
46 | elif [[ $? -eq 111 ]] ; then | |
47 | t_skip+=( "${name}" ) | |
48 | printf '[1;33mskipped[0;0m\n' | |
45 | 49 | else |
46 | 50 | t_fail+=( "${name}" ) |
47 | 51 | printf '[1;31mfailed[0;0m\n' |
58 | 62 | echo |
59 | 63 | done |
60 | 64 | |
61 | printf '[1m===[0m passed/failed/total: [1;32m%d[0;0m/[1;31m%d[0;0m/[1m%d[0m\n' \ | |
62 | ${#t_pass[@]} ${#t_fail[@]} $(( ${#t_pass[@]} + ${#t_fail[@]} )) | |
65 | if [[ ${#t_skip[@]} -gt 0 ]] ; then | |
66 | echo | |
67 | printf '[1;33mSkipped tests:\n[0;0m' | |
68 | for name in "${t_skip[@]}" ; do | |
69 | reason=$(grep '^(\-\-) ' "${name}.err" | head -1) | |
70 | if [[ -z ${reason} ]] ; then | |
71 | reason='No reason given' | |
72 | else | |
73 | reason=${reason:5} | |
74 | fi | |
75 | printf ' - %s: %s\n' "${name}" "${reason:-No reason given}" | |
76 | done | |
77 | echo | |
78 | fi | |
79 | ||
80 | printf '[1m===[0m passed/skipped/failed/total: [1;32m%d[0;0m/[1;33m%d[0;0m/[1;31m%d[0;0m/[1m%d[0m\n' \ | |
81 | ${#t_pass[@]} ${#t_skip[@]} ${#t_fail[@]} $(( ${#t_pass[@]} + ${#t_fail[@]} )) | |
63 | 82 | |
64 | 83 | if [[ ${#t_fail[@]} -gt 0 ]] ; then |
65 | 84 | exit 1 |
66 | 66 | ; |
67 | 67 | static const u_char t_parentdir_entry[] = "" |
68 | 68 | "<tr>" |
69 | "<td><a href=\"../?C=N&O=A\">Parent directory/</a></td>" | |
70 | "<td>-</td>" | |
71 | "<td>-</td>" | |
69 | "<td class=\"link\"><a href=\"../?C=N&O=A\">Parent directory/</a></td>" | |
70 | "<td class=\"size\">-</td>" | |
71 | "<td class=\"date\">-</td>" | |
72 | 72 | "</tr>" |
73 | 73 | "\n" |
74 | 74 | ; |
63 | 63 | <tbody> |
64 | 64 | <!-- var t_parentdir_entry --> |
65 | 65 | <tr> |
66 | <td><a href="../?C=N&O=A">Parent directory/</a></td> | |
67 | <td>-</td> | |
68 | <td>-</td> | |
66 | <td class="link"><a href="../?C=N&O=A">Parent directory/</a></td> | |
67 | <td class="size">-</td> | |
68 | <td class="date">-</td> | |
69 | 69 | </tr> |
70 | 70 | |
71 | 71 | <!-- var NONE --> |