This commit is contained in:
root
2017-02-26 00:07:07 +01:00
parent 0df597b47d
commit 74c3c310e6
21 changed files with 2494 additions and 0 deletions

4
ngx-fancyindex/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*.sw[op]
/t/*.sh
/t/*.out
/t/*.err

View File

@@ -0,0 +1,34 @@
language: c
compiler:
- clang
- gcc
env:
# Mainline
- NGINX=1.11.3
- NGINX=1.11.3 DYNAMIC=1
# Stable
- NGINX=1.10.1
- NGINX=1.10.1 DYNAMIC=1
# Other configurations
- NGINX=1.9.15
- NGINX=1.9.15 DYNAMIC=1
- NGINX=1.8.1
# Also, the oldest supported version
# TODO: Fails building because it won't find IOV_MAX from header.
#- NGINX=0.7.69
sudo: false
addons:
apt:
packages:
- libpcre3-dev
- libssl-dev
cache: ccache
script:
- echo "NGINX=${NGINX} ${DYNAMIC:+DYNAMIC=${DYNAMIC}}"
- t/build-and-run ${NGINX} ${DYNAMIC}

111
ngx-fancyindex/CHANGELOG.md Normal file
View File

@@ -0,0 +1,111 @@
# Change Log
All notable changes to this project will be documented in this file.
## [Unreleased]
## [0.4.1] - 2016-08-18
### Added
- New `fancyindex_directories_first` configuration directive (enabled by
default), which allows setting whether directories are sorted before other
files. (Patch by Luke Zapart <<luke@zapart.org>>.)
### Fixed
- Fix index files not working when the fancyindex module is in use (#46).
## [0.4.0] - 2016-06-08
### Added
- The module can now be built as a [dynamic
module](https://www.nginx.com/resources/wiki/extending/converting/).
(Patch by Róbert Nagy <<vrnagy@gmail.com>>.)
- New configuration directive `fancyindex_show_path`, which allows hiding the
`<h1>` header which contains the current path.
(Patch by Thomas P. <<tpxp@live.fr>>.)
### Changed
- Directory and file links in listings now have a title="..." attribute.
(Patch by `@janglapuk` <<trusdi.agus@gmail.com>>.)
### Fixed
- Fix for hung requests when the module is used along with `ngx_pagespeed`.
(Patch by Otto van der Schaaf <<oschaaf@we-amp.com>>.)
## [0.3.6] - 2016-01-26
### Added
- New feature: Allow filtering out symbolic links using the
`fancyindex_hide_symlinks` configuration directive. (Idea and prototype
patch by Thomas Wemm.)
- New feature: Allow specifying the format of timestamps using the
`fancyindex_time_format` configuration directive. (Idea suggested by Xiao
Meng <<novoreorx@gmail.com>>).
### Changed
- Listings in top-level directories will not generate a "Parent Directory"
link as first element of the listing. (Patch by Thomas P.)
### Fixed
- Fix propagation and overriding of the `fancyindex_css_href` setting inside
nested locations.
- Minor changes in the code to allow building cleanly under Windows with
Visual Studio 2013. (Patch by Y. Yuan <<yzwduck@gmail.com>>).
## [0.3.5] - 2015-02-19
### Added
- New feature: Allow setting the default sort criterion using the
`fancyindex_default_sort` configuration directive. (Patch by
Алексей Урбанский).
- New feature: Allow changing the maximum length of file names, using
the `fancyindex_name_length` configuration directive. (Patch by
Martin Herkt).
### Changed
- Renames `NEWS.rst` to `CHANGELOG.md`, which follows the recommendations
from [Keep a Change Log](http://keepachangelog.com/).
- Configuring Nginx without the `http_addition_module` will generate a
warning during configuration, as it is needed for the `fancyindex_footer`
and `fancyindex_header` directives.
## [0.3.4] - 2014-09-03
### Added
- Viewport is now defined in the generated HTML, which works better
for mobile devices.
### Changed
- Even-odd row styling moved to the CSS using :nth-child(). This
makes the HTML served to clients smaller.
## [0.3.3] - 2013-10-25
### Added
- New feature: table headers in the default template are now clickable
to set the sorting criteria and direction of the index entries.
(https://github.com/aperezdc/ngx-fancyindex/issues/7)
## [0.3.2] - 2013-06-05
### Fixed
- Solved a bug that would leave certain clients stalled forever.
- Improved handling of subrequests for non-builtin headers/footers.
## [0.3.1] - 2011-04-04
### Added
- `NEWS.rst` file, to act as change log.
[Unreleased]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.4.1...HEAD
[0.4.1]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.4.0...v0.4.1
[0.4.0]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.3.6...v0.4.0
[0.3.6]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.3.5...v0.3.6
[0.3.5]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.3.4...v0.3.5
[0.3.4]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.3.3...v0.3.4
[0.3.3]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.3.2...v0.3.3
[0.3.2]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.3.1...v0.3.2
[0.3.1]: https://github.com/aperezdc/ngx-fancyindex/compare/v0.3...v0.3.1

24
ngx-fancyindex/HACKING.md Normal file
View File

@@ -0,0 +1,24 @@
# Fancy Index module Hacking HOW-TO
## How to modify the template
The template is in the `template.html` file. Note that comment markers are
used to control how the `template.awk` Awk script generates the C header
which gets ultimately included in the compiled object code. Comment markers
have the `<!-- var identifier -->` format. Here `identifier` must be
a valid C identifier. All the text following the marker until the next
marker will be flattened into a C string.
If the identifier is `NONE` (capitalized) the text from that marker up to
the next marker will be discarded.
## Regenerating the C header
You will need Awk. I hope any decent implementation will do, but the GNU one
is known to work flawlessly. Just do:
$ awk -f template.awk template.html > template.h
If your copy of `awk` is not the GNU implementation, you will need to
install it and use `gawk` instead in the command line above.

20
ngx-fancyindex/LICENSE Normal file
View File

@@ -0,0 +1,20 @@
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

273
ngx-fancyindex/README.rst Normal file
View File

@@ -0,0 +1,273 @@
========================
Nginx Fancy Index module
========================
.. image:: https://travis-ci.org/aperezdc/ngx-fancyindex.svg?branch=master
:target: https://travis-ci.org/aperezdc/ngx-fancyindex
:alt: Build Status
.. contents::
The Fancy Index module makes possible the generation of file listings, like
the built-in `autoindex <http://wiki.nginx.org/NginxHttpAutoindexModule>`__
module does, but adding a touch of style. This is possible because the module
module allows a certain degree of customization of the generated content:
* Custom headers. Either local or stored remotely.
* Custom footers. Either local or stored remotely.
* Add you own CSS style rules.
* Allow choosing to sort elements by name (default), modification time, or
size; both ascending (default), or descending.
This module is designed to work with Nginx_, a high performance open source web
server written by `Igor Sysoev <http://sysoev.ru>`__.
Requirements
============
You will need the sources for Nginx_. Any version starting from the 0.7
series onwards will work. Note that the modules *might* compile with
versions in the 0.6 series by applying ``nginx-0.6-support.patch``, but this
is unsupported (YMMV).
In order to use the fancyindex_header_ and fancyindex_footer_ directives
you will also need the `ngx_http_addition_module <http://nginx.org/en/docs/http/ngx_http_addition_module.html>`_
built into Nginx.
Building
========
1. Unpack the Nginx_ sources::
$ gunzip -c nginx-?.?.?.tar.gz | tar -xvf -
2. Unpack the sources for the fancy indexing module::
$ gunzip -c nginx-fancyindex-?.?.?.tar.gz | tar -xvf -
3. Change to the directory which contains the Nginx_ sources, run the
configuration script with the desired options and be sure to put an
``--add-module`` flag pointing to the directory which contains the source
of the fancy indexing module::
$ cd nginx-?.?.?
$ ./configure --add-module=../nginx-fancyindex-?.?.? \
[--with-http_addition_module] [extra desired options]
Since version 0.4.0, the module can also be built as a
`dynamic module <https://www.nginx.com/resources/wiki/extending/converting/>`_,
using ``--add-dynamic-module=…`` instead.
4. Build and install the software::
$ make
And then, as ``root``::
# make install
5. Configure Nginx_ by using the modules' configuration directives_.
Example
=======
You can test the default built-in style by adding the following lines into
a ``server`` section in your Nginx_ configuration file::
location / {
fancyindex on; # Enable fancy indexes.
fancyindex_exact_size off; # Output human-readable file sizes.
}
Themes
~~~~~~
The following themes demonstrate the level of customization which can be
achieved using the module:
* `Theme <https://github.com/TheInsomniac/Nginx-Fancyindex-Theme>`__ by
`@TheInsomniac <https://github.com/TheInsomniac>`__. Uses custom header and
footer.
* `Theme <https://github.com/nwrd/Nginx-Fancyindex-Theme>`__ by
nwrd <https://github.com/nwrd>`__. Uses custom header and footer, the
header includes search field to filter by filename using JavaScript
(`demo <http://nwrd.sly.io/>`__).
Directives
==========
fancyindex
~~~~~~~~~~
:Syntax: *fancyindex* [*on* | *off*]
:Default: fancyindex off
:Context: http, server, location
:Description:
Enables or disables fancy directory indexes.
fancyindex_default_sort
~~~~~~~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_default_sort* [*name* | *size* | *date* | *name_desc* | *size_desc* | *date_desc*]
:Default: fancyindex_default_sort name
:Context: http, server, location
:Description:
Defines sorting criterion by default.
fancyindex_directories_first
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_directories_first* [*on* | *off*]
:Default: fancyindex_directories_first on
:Context: http, server, location
:Description:
If enabled (default setting), groups directories together and sorts them
before all regular files. If disabled, directories are sorted together with files.
fancyindex_css_href
~~~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_css_href uri*
:Default: fancyindex_css_href ""
:Context: http, server, location
:Description:
Allows inserting a link to a CSS style sheet in generated listings. The
provided *uri* parameter will be inserted as-is in a ``<link>`` HTML tag.
The link is inserted after the built-in CSS rules, so you can override the
default styles.
fancyindex_exact_size
~~~~~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_exact_size* [*on* | *off*]
:Default: fancyindex_exact_size on
:Context: http, server, location
:Description:
Defines how to represent file sizes in the directory listing; either
accurately, or rounding off to the kilobyte, the megabyte and the
gigabyte.
fancyindex_name_length
~~~~~~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_name_length length*
:Default: fancyindex_name_length 50
:Context: http, server, location
:Description:
Defines the maximum file name length limit in bytes.
fancyindex_footer
~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_footer path*
:Default: fancyindex_footer ""
:Context: http, server, location
:Description:
Specifies which file should be inserted at the foot of directory listings.
If set to an empty string, the default footer supplied by the module will
be sent.
.. note:: Using this directive needs the ngx_http_addition_module_ built
into Nginx.
.. warning:: When inserting custom header/footer a subrequest will be
issued so potentially any URL can be used as source for them. Although it
will work with external URLs, only using internal ones is supported.
External URLs are totally untested and using them will make Nginx_ block
while waiting for the subrequest to complete. If you feel like external
header/footer is a must-have for you, please
`let me know <mailto:aperez@igalia.com>`__.
fancyindex_header
~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_header path*
:Default: fancyindex_header ""
:Context: http, server, location
:Description:
Specifies which file should be inserted at the head of directory listings.
If set to an empty string, the default header supplied by the module will
be sent.
.. note:: Using this directive needs the ngx_http_addition_module_ built
into Nginx.
fancyindex_show_path
~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_show_path* [*on* | *off*]
:Default: fancyindex_show_path on
:Context: http, server, location
:Description:
Whether to output or not the path and the closing </h1> tag after the header.
This is useful when you want to handle the path displaying with a PHP script
for example.
.. warning:: This directive can be turned off only if a custom header is provided
using fancyindex_header.
fancyindex_ignore
~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_ignore string1 [string2 [... stringN]]*
:Default: No default.
:Context: http, server, location
:Description:
Specifies a list of file names which will be not be shown in generated
listings. If Nginx was built with PCRE support strings are interpreted as
regular expressions.
fancyindex_hide_symlinks
~~~~~~~~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_hide_symlinks* [*on* | *off*]
:Default: fancyindex_hide_symlinks off
:Context: http, server, location
:Description:
When enabled, generated listings will not contain symbolic links.
fancyindex_localtime
~~~~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_localtime* [*on* | *off*]
:Default: fancyindex_localtime off
:Context: http, server, location
:Description:
Enables showing file times as local time. Default is “off” (GMT time).
fancyindex_time_format
~~~~~~~~~~~~~~~~~~~~~~
:Syntax: *fancyindex_time_format* string
:Default: fancyindex_time_format "%Y-%b-%d %H:%M"
:Context: http, server, location
:Description:
Format string used for timestamps. The format specifiers are a subset of
those supported by the `strftime <http://linux.die.net/man/3/strftime>`_
function, and the behavior is locale-independent (for example, day and month
names are always in English). The supported formats are:
* ``%a``: Abbreviated name of the day of the week.
* ``%A``: Full name of the day of the week.
* ``%b``: Abbreviated month name.
* ``%B``: Full month name.
* ``%d``: Day of the month as a decimal number (range 01 to 31).
* ``%e``: Like ``%d``, the day of the month as a decimal number, but a
leading zero is replaced by a space.
* ``%F``: Equivalent to ``%Y-%m-%d`` (the ISO 8601 date format).
* ``%H``: Hour as a decimal number using a 24-hour clock (range 00
to 23).
* ``%I``: Hour as a decimal number using a 12-hour clock (range 01 to 12).
* ``%k``: Hour (24-hour clock) as a decimal number (range 0 to 23);
single digits are preceded by a blank.
* ``%l``: Hour (12-hour clock) as a decimal number (range 1 to 12); single
digits are preceded by a blank.
* ``%m``: Month as a decimal number (range 01 to 12).
* ``%M``: Minute as a decimal number (range 00 to 59).
* ``%p``: Either "AM" or "PM" according to the given time value.
* ``%P``: Like ``%p`` but in lowercase: "am" or "pm".
* ``%r``: Time in a.m. or p.m. notation. Equivalent to ``%I:%M:%S %p``.
* ``%R``: Time in 24-hour notation (``%H:%M``).
* ``%S``: Second as a decimal number (range 00 to 60).
* ``%T``: Time in 24-hour notation (``%H:%M:%S``).
* ``%u``: Day of the week as a decimal, range 1 to 7, Monday being 1.
* ``%w``: Day of the week as a decimal, range 0 to 6, Monday being 0.
* ``%y``: Year as a decimal number without a century (range 00 to 99).
* ``%Y``: Year as a decimal number including the century.
.. _nginx: http://nginx.net
.. vim:ft=rst:spell:spelllang=en:

20
ngx-fancyindex/config Normal file
View File

@@ -0,0 +1,20 @@
# vim:ft=sh:
ngx_addon_name=ngx_http_fancyindex_module
if [ "$ngx_module_link" = DYNAMIC ] ; then
ngx_module_type=HTTP
ngx_module_name=ngx_http_fancyindex_module
ngx_module_srcs="$ngx_addon_dir/ngx_http_fancyindex_module.c"
ngx_module_deps="$ngx_addon_dir/template.h"
ngx_module_order="$ngx_module_name ngx_http_autoindex_module"
. auto/module
else
# XXX: Insert fancyindex module *after* index module!
#
HTTP_MODULES=`echo "${HTTP_MODULES}" | sed -e \
's/ngx_http_index_module/ngx_http_fancyindex_module ngx_http_index_module/'`
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fancyindex_module.c"
if [ $HTTP_ADDITION != YES ] ; then
echo " - The 'addition' filter is needed for fancyindex_{header,footer}, but it was disabled"
fi
fi

View File

@@ -0,0 +1,23 @@
=== modified file 'ngx_http_fancyindex_module.c'
--- ngx_http_fancyindex_module.c 2008-09-11 17:55:52 +0000
+++ ngx_http_fancyindex_module.c 2008-12-10 01:33:43 +0000
@@ -383,7 +383,7 @@
entry->mtime = ngx_de_mtime(&dir);
entry->size = ngx_de_size(&dir);
entry->utf_len = (r->utf8)
- ? ngx_utf8_length(entry->name.data, entry->name.len)
+ ? ngx_utf_length(entry->name.data, entry->name.len)
: len;
}
@@ -478,8 +478,7 @@
copy = NGX_HTTP_FANCYINDEX_NAME_LEN + 1;
}
- b->last = ngx_utf8_cpystrn(b->last, entry[i].name.data,
- copy, entry[i].name.len);
+ b->last = ngx_utf_cpystrn(b->last, entry[i].name.data, copy);
last = b->last;
} else {

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
#! /bin/bash
cat <<---
This test checks that the built Nginx either has the dynamic fancyindex
module available, or that it's not there (for static builds).
--
readonly nginx_path="${PREFIX}/sbin/nginx"
readonly so_path="${PREFIX}/modules/ngx_http_fancyindex_module.so"
if [[ ! -x ${nginx_path} ]] ; then
fail "executable binary not found at '%s'\n" "${nginx_path}"
fi
if ${DYNAMIC} ; then
if [[ ! -r ${so_path} ]] ; then
fail "module not found at '%s'\n" "${so_path}"
fi
else
if [[ -r ${so_path} ]] ; then
fail "module should not exist at '%s'\n" "${so_path}"
fi
fi

View File

@@ -0,0 +1,7 @@
#! /bin/bash
cat <<---
This test fetches the root directory served by Nginx, which has no index file,
and checks that the output contains something that resembles a directory index.
--
nginx_start
grep 'Index of' <( fetch )

View File

@@ -0,0 +1,11 @@
#! /bin/bash
cat <<---
This test fetches the root directory served by Nginx, which has no index file,
and checks that the output contains something that resembles the output from
the fancyindex module.
--
nginx_start
content=$(fetch --with-headers)
grep 'Index of /' <<< "${content}" # It is an index
grep '\<table\>' <<< "${content}" # It contains a table
grep '^ Content-Type:[[:space:]]*text/html' <<< "${content}"

25
ngx-fancyindex/t/build-and-run Executable file
View File

@@ -0,0 +1,25 @@
#! /bin/bash
set -e
if [[ $# -lt 1 || $# -gt 2 ]] ; then
echo "Usage: $0 <nginx-version> [1]" 1>&2
exit 1
fi
readonly NGINX=$1
if [[ $2 -eq 1 ]] ; then
readonly DYNAMIC=$2
fi
cd "$(dirname "$0")/.."
wget -O - http://nginx.org/download/nginx-${NGINX}.tar.gz | tar -xzf -
rm -rf prefix/
cd nginx-${NGINX}
./configure \
--add-${DYNAMIC:+dynamic-}module=.. \
--with-http_addition_module \
--prefix="$(pwd)/../prefix"
make install
cd ..
exec ./t/run prefix ${DYNAMIC}

View File

@@ -0,0 +1,7 @@
#! /bin/bash
cat <<---
This test ensures that the "index.html" is returned instead of a directory
listing when fetching a directory which contains an index file.
--
nginx_start
diff -u "${TESTDIR}/has-index/index.html" <( fetch /has-index/ ) 1>&2

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Index file test</title>
</head>
<body>
This is <code>index.html</code>.
</body>
</html>

View File

@@ -0,0 +1,25 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

84
ngx-fancyindex/t/preamble Normal file
View File

@@ -0,0 +1,84 @@
#! /bin/bash
#
# preamble
# Copyright (C) 2016 Adrian Perez <aperez@igalia.com>
#
# Distributed under terms of the MIT license.
#
function nginx_conf_generate () {
if ${DYNAMIC} ; then
echo 'load_module modules/ngx_http_fancyindex_module.so;'
fi
cat <<-EOF
worker_processes 1;
events { worker_connections 1024; }
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
server_name localhost;
listen 127.0.0.1:8888;
root ${TESTDIR};
error_page 500 502 503 504 /50x.html;
location = /50x.html { root html; }
location / {
index index.html;
fancyindex on;
$*
}
}
}
EOF
}
readonly NGINX_CONF="${PREFIX}/conf/nginx.conf"
readonly NGINX_PID="${PREFIX}/logs/nginx.pid"
rm -f "${NGINX_CONF}" "${NGINX_PID}"
mkdir -p "${PREFIX}/logs"
function nginx () {
env - PATH="${PATH}" "${PREFIX}/sbin/nginx" "$@"
}
function nginx_conf () {
nginx_conf_generate "$@" > "${NGINX_CONF}"
}
function nginx_is_running () {
[[ -r ${NGINX_PID} ]] && kill -0 $(< "${NGINX_PID}")
}
function nginx_stop () {
if nginx_is_running ; then nginx -s stop ; fi
rm -f "${NGINX_PID}"
}
trap nginx_stop EXIT
function nginx_start () {
if [[ $# -gt 0 || ! -r ${NGINX_CONF} ]] ; then nginx_conf "$@" ; fi
nginx_stop # Ensure that it is not running.
nginx
}
function fetch () {
local -a opts=( -q )
if [[ $1 = --with-headers ]] ; then
opts+=( -S )
shift
fi
wget "${opts[@]}" -O- "http://localhost:8888${1:-/}" 2>&1
}
function fail () {
printf "(FF) "
printf "$@"
exit 1
} 1>&2
function warn () {
printf "(WW)"
printf "$@"
} 1>&2

67
ngx-fancyindex/t/run Executable file
View File

@@ -0,0 +1,67 @@
#! /bin/bash
set -e
if [[ $# -lt 1 || $# -gt 2 ]] ; then
echo "Usage: $0 <prefix-path> [1]" 1>&2
exit 1
fi
# Obtain the absolute path to the tests directory
pushd "$(dirname "$0")" &> /dev/null
readonly T=$(pwd)
popd &> /dev/null
export T
# Same for the nginx prefix directory
pushd "$1" &> /dev/null
readonly prefix=$(pwd)
popd &> /dev/null
dynamic=false
if [[ $# -gt 1 && $2 -eq 1 ]] ; then
dynamic=true
fi
readonly dynamic
declare -a t_pass=( )
declare -a t_fail=( )
for t in "$T"/*.test ; do
name="t/${t##*/}"
name=${name%.test}
printf "${name} ... "
errfile="${name}.err"
outfile="${name}.out"
shfile="${name}.sh"
cat > "${shfile}" <<-EOF
readonly DYNAMIC=${dynamic}
readonly TESTDIR='$T'
readonly PREFIX='${prefix}'
$(< "$T/preamble")
$(< "$t")
EOF
if bash -e "${shfile}" > "${outfile}" 2> "${errfile}" ; then
t_pass+=( "${name}" )
printf 'passed\n'
else
t_fail+=( "${name}" )
printf 'failed\n'
fi
done
for name in "${t_fail[@]}" ; do
echo
printf '=== %s.out\n' "${name}"
cat "${name}.out"
echo
printf '=== %s.err\n' "${name}"
cat "${name}.err"
echo
done
printf '=== passed/failed/total: %d/%d/%d\n' \
${#t_pass[@]} ${#t_fail[@]} $(( ${#t_pass[@]} + ${#t_fail[@]} ))
if [[ ${#t_fail[@]} -gt 0 ]] ; then
exit 1
fi

52
ngx-fancyindex/template.awk Executable file
View File

@@ -0,0 +1,52 @@
#! /usr/bin/awk -f
#
# Copyright © Adrian Perez <aperez@igalia.com>
#
# Converts an HTML template into a C header suitable for inclusion.
# Take a look at the HACKING.rst file to know how to use it :-)
#
# This code is placed in the public domain.
BEGIN {
varname = 0;
print "/* Automagically generated, do not edit! */"
vars_count = 0;
}
/^<!--[[:space:]]*var[[:space:]]+[^[:space:]]+[[:space:]]*-->$/ {
if (varname) print ";";
if ($3 == "NONE") {
varname = 0;
next;
}
varname = $3;
vars[vars_count++] = varname;
print "static const u_char " varname "[] = \"\"";
next;
}
/^$/ {
if (!varname) next;
print "\"\\n\"";
next;
}
{
if (!varname) next;
# Order matters
gsub(/[\t\v\n\r\f]+/, "");
gsub(/\\/, "\\\\");
gsub(/"/, "\\\"");
print "\"" $0 "\""
}
END {
if (varname) print ";";
print "#define NFI_TEMPLATE_SIZE (0 \\";
for (var in vars) {
print "\t+ nfi_sizeof_ssz(" vars[var] ") \\";
}
print "\t)"
}

103
ngx-fancyindex/template.h Normal file
View File

@@ -0,0 +1,103 @@
/* Automagically generated, do not edit! */
static const u_char t01_head1[] = ""
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
"\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\">"
"\n"
"<head>"
"<meta name=\"viewport\" content=\"width=device-width\"/>"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>"
"<style type=\"text/css\">"
"body,html {"
"background:#fff;"
"font-family:\"Bitstream Vera Sans\",\"Lucida Grande\","
"\"Lucida Sans Unicode\",Lucidux,Verdana,Lucida,sans-serif;"
"}"
"tr:nth-child(even) {"
"background:#f4f4f4;"
"}"
"th,td {"
"padding:0.1em 0.5em;"
"}"
"th {"
"text-align:left;"
"font-weight:bold;"
"background:#eee;"
"border-bottom:1px solid #aaa;"
"}"
"#list {"
"border:1px solid #aaa;"
"width:100%;"
"}"
"a {"
"color:#a33;"
"}"
"a:hover {"
"color:#e33;"
"}"
"</style>"
"\n"
;
static const u_char t02_head2[] = ""
"\n"
"<title>Index of "
;
static const u_char t03_head3[] = ""
"</title>"
"\n"
"</head>"
;
static const u_char t04_body1[] = ""
"<body>"
"<h1>Index of "
;
static const u_char t05_body2[] = ""
"</h1>"
"\n"
;
static const u_char t06_list1[] = ""
"<table id=\"list\" cellpadding=\"0.1em\" cellspacing=\"0\">"
"\n"
"<colgroup>"
"<col width=\"55%\"/>"
"<col width=\"20%\"/>"
"<col width=\"25%\"/>"
"</colgroup>"
"\n"
"<thead>"
"<tr>"
"<th><a href=\"?C=N&O=A\">File Name</a>&nbsp;<a href=\"?C=N&O=D\">&nbsp;&#8595;&nbsp;</a></th>"
"<th><a href=\"?C=S&O=A\">File Size</a>&nbsp;<a href=\"?C=S&O=D\">&nbsp;&#8595;&nbsp;</a></th>"
"<th><a href=\"?C=M&O=A\">Date</a>&nbsp;<a href=\"?C=M&O=D\">&nbsp;&#8595;&nbsp;</a></th>"
"</tr>"
"</thead>"
"\n"
"<tbody>"
;
static const u_char t_parentdir_entry[] = ""
"<tr>"
"<td><a href=\"../?C=N&amp;O=A\">Parent directory/</a></td>"
"<td>-</td>"
"<td>-</td>"
"</tr>"
"\n"
;
static const u_char t07_list2[] = ""
"</tbody>"
"</table>"
;
static const u_char t08_foot1[] = ""
"</body>"
"</html>"
;
#define NFI_TEMPLATE_SIZE (0 \
+ nfi_sizeof_ssz(t01_head1) \
+ nfi_sizeof_ssz(t02_head2) \
+ nfi_sizeof_ssz(t03_head3) \
+ nfi_sizeof_ssz(t04_body1) \
+ nfi_sizeof_ssz(t05_body2) \
+ nfi_sizeof_ssz(t06_list1) \
+ nfi_sizeof_ssz(t_parentdir_entry) \
+ nfi_sizeof_ssz(t07_list2) \
+ nfi_sizeof_ssz(t08_foot1) \
)

View File

@@ -0,0 +1,102 @@
<!-- var t01_head1 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width"/>
<style type="text/css">
body,html {
background:#fff;
font-family:"Bitstream Vera Sans","Lucida Grande",
"Lucida Sans Unicode",Lucidux,Verdana,Lucida,sans-serif;
}
tr:nth-child(even) {
background:#f4f4f4;
}
th,td {
padding:0.1em 0.5em;
}
th {
text-align:left;
font-weight:bold;
background:#eee;
border-bottom:1px solid #aaa;
}
#list {
border:1px solid #aaa;
width:100%;
}
a {
color:#a33;
}
a:hover {
color:#e33;
}
</style>
<!-- var t02_head2 -->
<title>Index of
<!-- var NONE -->
/path/to/somewhere
<!-- var t03_head3 -->
</title>
</head>
<!-- var t04_body1 -->
<body>
<h1>Index of
<!-- var NONE -->
/path/to/somewhere
<!-- var t05_body2 -->
</h1>
<!-- var t06_list1 -->
<table id="list" cellpadding="0.1em" cellspacing="0">
<colgroup>
<col width="55%"/>
<col width="20%"/>
<col width="25%"/>
</colgroup>
<thead>
<tr>
<th><a href="?C=N&O=A">File Name</a>&nbsp;<a href="?C=N&O=D">&nbsp;&#8595;&nbsp;</a></th>
<th><a href="?C=S&O=A">File Size</a>&nbsp;<a href="?C=S&O=D">&nbsp;&#8595;&nbsp;</a></th>
<th><a href="?C=M&O=A">Date</a>&nbsp;<a href="?C=M&O=D">&nbsp;&#8595;&nbsp;</a></th>
</tr>
</thead>
<tbody>
<!-- var t_parentdir_entry -->
<tr>
<td><a href="../?C=N&amp;O=A">Parent directory/</a></td>
<td>-</td>
<td>-</td>
</tr>
<!-- var NONE -->
<tr>
<td>test file 1</td>
<td>123kB</td>
<td>date</td>
</tr>
<tr>
<td>test file 2</td>
<td>321MB</td>
<td>date</td>
</tr>
<tr>
<td>test file 3</td>
<td>666</td>
<td>date</td>
</tr>
<!-- var t07_list2 -->
</tbody>
</table>
<!-- var t08_foot1 -->
</body>
</html>