Codebase list nginx / bc3cf7a
http-fancyindex: Upgrade to 0.4.3 Christos Trochalakis 5 years ago
11 changed file(s) with 229 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
5454
5555 Module: http-fancyindex
5656 Homepage: https://github.com/aperezdc/ngx-fancyindex
57 Version: 0.4.2
57 Version: 0.4.3
5858 Files-Excluded: .gitignore .travis.yml
5959
6060 Module: http-subs-filter
11 All notable changes to this project will be documented in this file.
22
33 ## [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>>.)
416
517 ## [0.4.2] - 2017-08-19
618 ### Changed
117129 - `NEWS.rst` file, to act as change log.
118130
119131
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
121134 [0.4.2]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.4.1...v0.4.2
122135 [0.4.1]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.4.0...v0.4.1
123136 [0.4.0]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.3.6...v0.4.0
3838
3939 yum install nginx-module-fancyindex
4040
41 Then load the module in `/etc/nginx/nginx.conf` using
41 Then load the module in `/etc/nginx/nginx.conf` using::
4242
4343 load_module "modules/ngx_http_fancyindex_module.so";
4444
5050 versions in the 0.6 series by applying ``nginx-0.6-support.patch``, but this
5151 is unsupported (YMMV).
5252
53 In order to use the fancyindex_header_ and fancyindex_footer_ directives
53 In order to use the ``fancyindex_header_`` and ``fancyindex_footer_`` directives
5454 you will also need the `ngx_http_addition_module <http://nginx.org/en/docs/http/ngx_http_addition_module.html>`_
5555 built into Nginx.
5656
7777
7878 Since version 0.4.0, the module can also be built as a
7979 `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";``
8182 in the configuration file
8283
8384 4. Build and install the software::
113114 `@TheInsomniac <https://github.com/TheInsomniac>`__. Uses custom header and
114115 footer.
115116 * `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
117118 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.
118125
119126
120127 Directives
771771 * <td>size</td><td>date</td>
772772 * </tr>
773773 */
774 len += ngx_sizeof_ssz("<tr><td><a href=\"")
774 len += ngx_sizeof_ssz("<tr><td class=\"link\"><a href=\"")
775775 + entry[i].name.len + entry[i].escape /* Escaped URL */
776776 + ngx_sizeof_ssz("?C=x&amp;O=y") /* URL sorting arguments */
777777 + ngx_sizeof_ssz("\" title=\"")
779779 + ngx_sizeof_ssz("\">")
780780 + entry[i].name.len + entry[i].utf_len
781781 + alcf->name_length + ngx_sizeof_ssz("&gt;")
782 + ngx_sizeof_ssz("</a></td><td>")
782 + ngx_sizeof_ssz("</a></td><td class=\"size\">")
783783 + 20 /* File size */
784 + ngx_sizeof_ssz("</td><td>") /* Date prefix */
784 + ngx_sizeof_ssz("</td><td class=\"date\">") /* Date prefix */
785785 + ngx_sizeof_ssz("</td></tr>\n") /* Date suffix */
786786 + 2 /* CR LF */
787787 ;
903903 if (r->uri.len > 1) {
904904 b->last = ngx_cpymem_ssz(b->last,
905905 "<tr>"
906 "<td><a href=\"../");
906 "<td class=\"link\"><a href=\"../");
907907 if (*sort_url_args) {
908908 b->last = ngx_cpymem(b->last,
909909 sort_url_args,
911911 }
912912 b->last = ngx_cpymem_ssz(b->last,
913913 "\">Parent directory/</a></td>"
914 "<td>-</td>"
915 "<td>-</td>"
914 "<td class=\"size\">-</td>"
915 "<td class=\"date\">-</td>"
916916 "</tr>");
917917 }
918918
919919 /* Entries for directories and files */
920920 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=\"");
922922
923923 if (entry[i].escape) {
924924 ngx_fancyindex_escape_uri(b->last,
966966 }
967967
968968 if (len > alcf->name_length) {
969 b->last = ngx_cpymem_ssz(last, "..&gt;</a></td><td>");
969 b->last = ngx_cpymem_ssz(last, "..&gt;</a></td><td class=\"size\">");
970970
971971 } else {
972972 if (entry[i].dir && alcf->name_length - len > 0) {
974974 len++;
975975 }
976976
977 b->last = ngx_cpymem_ssz(b->last, "</a></td><td>");
977 b->last = ngx_cpymem_ssz(b->last, "</a></td><td class=\"size\">");
978978 }
979979
980980 if (alcf->exact_size) {
10041004 }
10051005
10061006 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\">");
10081008 b->last = ngx_fancyindex_timefmt(b->last, &alcf->time_format, &tm);
10091009 b->last = ngx_cpymem_ssz(b->last, "</td></tr>");
10101010
12281228 ngx_http_fancyindex_entry_t *first = (ngx_http_fancyindex_entry_t *) one;
12291229 ngx_http_fancyindex_entry_t *second = (ngx_http_fancyindex_entry_t *) two;
12301230
1231 return (first->size > second->size) - (first->size < second->size);
1231 return (first->size < second->size) - (first->size > second->size);
12321232 }
12331233
12341234
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}"
3838 rm -f "${NGINX_CONF}" "${NGINX_PID}"
3939 mkdir -p "${PREFIX}/logs"
4040
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
4157 function nginx () {
4258 env - PATH="${PATH}" "${PREFIX}/sbin/nginx" "$@"
4359 }
7187 wget "${opts[@]}" -O- "http://localhost:8888${1:-/}" 2>&1
7288 }
7389
90 function skip () {
91 printf '(--) '
92 printf "$@"
93 exit 111
94 } 1>&2
95
7496 function fail () {
75 printf "(FF) "
97 printf '(FF) '
7698 printf "$@"
7799 exit 1
78100 } 1>&2
79101
80102 function warn () {
81 printf "(WW)"
103 printf '(WW) '
82104 printf "$@"
83105 } 1>&2
2424
2525 declare -a t_pass=( )
2626 declare -a t_fail=( )
27 declare -a t_skip=( )
2728
2829 for t in `ls "$T"/*.test | sort -R` ; do
2930 name="t/${t##*/}"
4243 if bash -e "${shfile}" > "${outfile}" 2> "${errfile}" ; then
4344 t_pass+=( "${name}" )
4445 printf 'passed\n'
46 elif [[ $? -eq 111 ]] ; then
47 t_skip+=( "${name}" )
48 printf 'skipped\n'
4549 else
4650 t_fail+=( "${name}" )
4751 printf 'failed\n'
5862 echo
5963 done
6064
61 printf '=== passed/failed/total: %d/%d/%d\n' \
62 ${#t_pass[@]} ${#t_fail[@]} $(( ${#t_pass[@]} + ${#t_fail[@]} ))
65 if [[ ${#t_skip[@]} -gt 0 ]] ; then
66 echo
67 printf 'Skipped tests:\n'
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 '=== passed/skipped/failed/total: %d/%d/%d/%d\n' \
81 ${#t_pass[@]} ${#t_skip[@]} ${#t_fail[@]} $(( ${#t_pass[@]} + ${#t_fail[@]} ))
6382
6483 if [[ ${#t_fail[@]} -gt 0 ]] ; then
6584 exit 1
6666 ;
6767 static const u_char t_parentdir_entry[] = ""
6868 "<tr>"
69 "<td><a href=\"../?C=N&amp;O=A\">Parent directory/</a></td>"
70 "<td>-</td>"
71 "<td>-</td>"
69 "<td class=\"link\"><a href=\"../?C=N&amp;O=A\">Parent directory/</a></td>"
70 "<td class=\"size\">-</td>"
71 "<td class=\"date\">-</td>"
7272 "</tr>"
7373 "\n"
7474 ;
6363 <tbody>
6464 <!-- var t_parentdir_entry -->
6565 <tr>
66 <td><a href="../?C=N&amp;O=A">Parent directory/</a></td>
67 <td>-</td>
68 <td>-</td>
66 <td class="link"><a href="../?C=N&amp;O=A">Parent directory/</a></td>
67 <td class="size">-</td>
68 <td class="date">-</td>
6969 </tr>
7070
7171 <!-- var NONE -->