Code Monkey home page Code Monkey logo

ngx-fancyindex's Introduction

Nginx Fancy Index module

Build Status

The Fancy Index module makes possible the generation of file listings, like the built-in autoindex module does, but adding a touch of style. This is possible because the 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 your 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.

For users of the official stable Nginx repository, extra packages repository with dynamic modules is available and fancyindex is included.

Install repository configuration, then the module package:

yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install nginx-module-fancyindex

Then load the module in /etc/nginx/nginx.conf using:

load_module "modules/ngx_http_fancyindex_module.so";

Users can install Nginx on macOS with MacPorts; fancyindex is included:

sudo port install nginx

In most other cases you will need the sources for Nginx. Any version starting from the 0.8 series should work.

In order to use the fancyindex_header_ and fancyindex_footer_ directives you will also need the ngx_http_addition_module built into Nginx.

  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, using --add-dynamic-module=… instead and load_module "modules/ngx_http_fancyindex_module.so"; in the configuration file

  4. Build and install the software:

    $ make
    

    And then, as root:

    # make install
    
  5. Configure Nginx by using the modules' configuration directives.

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.
}

The following themes demonstrate the level of customization which can be achieved using the module:

  • Theme by @TheInsomniac. Uses custom header and footer.
  • Theme by @Naereen. Uses custom header and footer. The header includes a search field to filter by file name using JavaScript.
  • Theme by @fraoustin. Responsive theme using Material Design elements.
  • Theme by @alehaa. Simple, flat theme based on Bootstrap 4 and FontAwesome.
Syntax:fancyindex [on | off]
Default:fancyindex off
Context:http, server, location
Description:Enables or disables fancy directory indexes.
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.
Syntax:fancyindex_case_sensitive [on | off]
Default:fancyindex_case_sensitive on
Context:http, server, location
Description:If enabled (default setting), sorting by name will be case-sensitive. If disabled, case will be ignored when sorting by name.
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.
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.
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.
Syntax:fancyindex_footer path [subrequest | local]
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. The optional parameter indicates whether the path is to be treated as a URI to load using a subrequest (the default), or whether it refers to a local file.

Note

Using this directive needs the ngx_http_addition_module built into Nginx.

Warning

When inserting custom a 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.

Syntax:fancyindex_header path [subrequest | local]
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. The optional parameter indicates whether the path is to be treated as a URI to load using a subrequest (the default), or whether it refers to a local file.

Note

Using this directive needs the ngx_http_addition_module built into Nginx.

Syntax:fancyindex_show_path [on | off]
Default:fancyindex_show_path on
Context:http, server, location
Description:Whether or not to output 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.

Syntax:fancyindex_show_dotfiles [on | off]
Default:fancyindex_show_dotfiles off
Context:http, server, location
Description:Whether to list files that are preceded with a dot. Normal convention is to hide these.
Syntax:fancyindex_ignore string1 [string2 [... stringN]]
Default:No default.
Context:http, server, location
Description:Specifies a list of file names which will not be shown in generated listings. If Nginx was built with PCRE support, strings are interpreted as regular expressions.
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.
Syntax:fancyindex_hide_parent_dir [on | off]
Default:fancyindex_hide_parent_dir off
Context:http, server, location
Description:When enabled, it will not show the parent directory.
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).
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 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.

ngx-fancyindex's People

Contributors

0xb8 avatar anderstrier avatar anthonyryan1 avatar aperezdc avatar darkhelmet433 avatar davidjb avatar drx avatar dvershinin avatar geoghegan avatar gyula-ny avatar jamim avatar janglapuk avatar joshuashaffer avatar joungkyun avatar kphrx avatar martchus avatar naereen avatar nicolascarpi avatar ogarcia avatar oschaaf avatar osokin avatar qjqqyy avatar quatauta avatar rustydust avatar ryandesign avatar timgates42 avatar tpxp avatar vrnagy avatar yzwduck avatar z4yx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx-fancyindex's Issues

Connection was interrupted error using fancyindex with SPDY

Here's my nginx config: https://gist.github.com/fletchowns/13680a9d101f96d5f728

My post on the nginx mailing list:

I'm using nginx 1.6.2 w/ SPDY to serve an autoindex of static files. After
I start downloading a file, I can no longer access other pages on the site.
I get a Firefox error message "The connection was interrupted" - a similar
message appears in Chrome. If I do a CTRL+F5, then I can browse the site
again while the download is going.
Is this a limitation of using SPDY to serve static files? Is there a
configuration parameter I need to adjust to avoid this issue?

The response from [email protected]

I'm able to reproduce, and from debug log it's clear that the issue is caused
by the fancyindex 3rd-party module. And a brief look through its code reveals
a number of problems with request handling.

Full thread is here: http://mailman.nginx.org/pipermail/nginx/2014-October/045334.html

Getting directory indexes with wget returns a response that wget cannot parse

The module works fine with the browsers, but there is a problem when trying to receive the directory listing with wget (GNU Wget 1.11.4).

% wget http://xxxxxxxx
--2012-10-07 02:47:55--  http://xxxxxxxx
Resolving xxxxxxxx... AA.BB.CC.DD
Connecting to xxxxxxxx|AA.BB.CC.DD|:80... connected.
HTTP request sent, awaiting response...  0
2012-10-07 02:47:55 ERROR 0: (no description).

The access.log shows no errors, and using the default directory listing of nginx the error is gone.

Allow reordering columns

It would be nice if you could set a custom order for the columns, say File Name, Date, File Size (which actually is nginx's default) instead of File Name, File Size, Date.

Allow decimal digits in rounded file sizes

When file sizes are being rounded (fancyindex_exact_size is disabled), it's not very useful to report a 4.9 GiB file as 4G: it would actually be good to include a decimal digit and show the value as 4.9G. This is specially true for magnitudes of MiB and bigger.

Go over the code of current versions of `autoindex` pick mergeable changes

As shown by issue #37, the module should be doing some things a bit differently. It would be a good thing to look at autoindex built-in module and see which changes would be worth integrating. After all, fancyindex used from the beginning the code of autoindex as a starting point, and surely it has changed along with Nginx.

It is surprising (in a good way) that fancyindex didn't need many modifications to keep working as new Nginx releases were posted. This tells many good things about Nginx as a project. But also let's not forget that I started the fancyindex module in 2007 (almost a decade ago!), and it would be indeed very good to properly check what happened to autoindex in the meanwhile.

Merge README work

There's a fork that supports showing a README. I would for love that functionality to be merged.

Unknown directive fancyindex

I followed all the steps in the README but upon running sudo nginx -t it prints this:

nginx: [emerg] unknown directive "fancyindex" in /usr/local/etc/nginx/nginx.conf:51
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed

I installed nginx with the command:

PREFIX=/usr/local
ETCDIR=${PREFIX}/etc/nginx
./configure \
    --prefix=${ETCDIR} \
    --with-cc-opt="-I ${PREFIX}/include" \
    --with-ld-opt="-L ${PREFIX}/lib" \
    --conf-path=${ETCDIR}/nginx.conf \
    --sbin-path=${PREFIX}/sbin/nginx \
    --pid-path=/var/run/nginx.pid \
    --error-log-path=/var/log/nginx-error.log \
    --user=www --group=www \
    --without-http_rewrite_module \
    --add-dynamic-module=/home/revolt/downloads/ngx-fancyindex-0.4.1

nginx.conf constains:

location /test {
    root html;
    fancyindex on;
}

$ sudo nginx -V:

nginx version: nginx/1.11.8
built by clang 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
configure arguments: --prefix=/usr/local/etc/nginx --with-cc-opt='-I /usr/local/include' --with-ld-opt='-L /usr/local/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --sbin-path=/usr/local/sbin/nginx --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx-error.log --user=www --group=www --without-http_rewrite_module --add-dynamic-module=/home/revolt/downloads/ngx-fancyindex-0.4.1

$ uname -a:

FreeBSD revolt 10.3-RELEASE FreeBSD 10.3-RELEASE #0 r297264: Fri Mar 25 02:10:02 UTC 2016 [email protected]:/usr/obj/usr/src/sys/GENERIC amd64

How to render <title> when using custom header?

When I'm using a custom header, how do I render the right <title> tag? The default template renders something like<title>Index of /test/</title>. Is there a placeholder/variable I can include in my custom header?

OOM when using `ngx_echo`'s subrequests

In light of #17 I tried to use ngx_echo to make it include README.txt, but I failed miserably.

Using 0.4.1 on nginx 1.10, any call to echo_location_async or similar from within a page generated by fancyindex rapidly eats all available memory until it crashes my machine.

Accessing the faux location directly (not through fancy index) properly includes the file I want.

Configuration:

server {
    server_name xxxxx;
    listen 443;
    ssl on;
    ssl_certificate xxxxx;
    ssl_certificate_key xxxxx;

    fancyindex on;
    fancyindex_exact_size off;
    fancyindex_header /HEADER.html;
    fancyindex_show_path off;
    root /srv/www/xxxxx/;
    index index.html index.txt;

    access_log /var/log/nginx/access_xxxxx.log main;

    location /HEADER.html {
        echo '<!DOCTYPE html>';
        echo '<html>';
        echo '<head>';
        echo '<meta name="viewport" content="width=device-width"/>';
        echo '<meta http-equiv="content-type" content="text/html; charset=utf-8"/>';
        echo '<title>Index of $request_uri</title>';
        echo '</head>';
        echo '<body>';
        echo '<h1>Index of $request_uri</h1>';
        echo_location_async '/index.txt';
    }
}

In the example above, accessing /any-dir/ crashes the server, whereas accessing /HEADER.html, which isn't handled by fancyindex, renders the page as expected.

FWIW here's directory tree for the example above:

  • /
    • srv/
      • www/
        • xxxxx/
          • any-dir/
            • file1.txt
            • file2.txt
          • index.txt
          • HEADER.html (not a physical file)

Feature request: file extension column

Increasing the fancyindex_name_length does help by exposing the ends of long filenames. However, having the ability to more robustly identify files by type, as well as provide sorting by extension would be handy.
Thanks for the module!

Option for not limiting maximum length of file names

Currently the length of file names in directory listings generated by the module are limited to 50 characters:

#define NGX_HTTP_FANCYINDEX_NAME_LEN  50

Instead of placing an ellipsis character in the output for long file names, it would be interesting to be able to set the maximum length with a directive in the configuration file. One of the options could be allowing any length (thus never trimming the names).

How to use SSI inside the footer and/or header?

Hi,

could you explain where to find information on how to have SSIs (server side includes) as footer or header using ngx-fancyindex?

I tried the obvious

ssi on;
fancyindex on;
fancyindex_header HEADER.shtml;
fancyindex_footer FOOTER.shtml;

The files exist and worked like that in Apache 2.2. However, it appears as if the header and footer are not being processed by the SSI module.

Any ideas?

Thanks in advance and thanks also for your module.

btw: I am using the version of the module which is included in Ubuntu 16.04.

Unclear CentOS7 Instructions

The installation instructions for installing on CentOS7 are very unclear.

I installed the official nginx package from the Nginx repo per these instructions

yum --showduplicates list nginx | expand
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.coreix.net
 * epel: mirrors.coreix.net
 * extras: mirrors.coreix.net
 * updates: mirrors.coreix.net
Installed Packages
nginx.x86_64            1:1.12.0-1.el7.ngx            @nginx
Available Packages
nginx.x86_64            1:1.8.0-1.el7.ngx             nginx
nginx.x86_64            1:1.8.1-1.el7.ngx             nginx
nginx.x86_64            1:1.10.0-1.el7.ngx            nginx
nginx.x86_64            1:1.10.1-1.el7.ngx            nginx
nginx.x86_64            1:1.10.2-1.el7                epel
nginx.x86_64            1:1.10.2-1.el7.ngx            nginx
nginx.x86_64            1:1.10.3-1.el7.ngx            getpagespeed-extras-x86_64
nginx.x86_64            1:1.10.3-1.el7.ngx            nginx
nginx.x86_64            1:1.12.0-1.el7.ngx            nginx

And the nginx-module-fancyindex package from the getpagespeedextras repo

yum --showduplicates list nginx-module-fancyindex | expand
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.coreix.net
 * epel: mirrors.coreix.net
 * extras: mirrors.coreix.net
 * updates: mirrors.coreix.net
Installed Packages
nginx-module-fancyindex.x86_64 1:1.12.0.0.4.1-1.el7.gps @getpagespeed-extras-x86_64
Available Packages
nginx-module-fancyindex.x86_64 1:1.12.0.0.4.1-1.el7.gps getpagespeed-extras-x86_64

The module is installed on the filesystem.

ls -lah /etc/nginx/modules/
total 344K
drwxr-xr-x. 2 root root 4.0K Jun 15 18:09 .
drwxr-xr-x. 3 root root 4.0K Apr 12 15:23 ..
-rwxr-xr-x. 1 root root  29K Apr 16 22:32 ngx_http_fancyindex_module-debug.so
-rwxr-xr-x. 1 root root  25K Apr 16 22:32 ngx_http_fancyindex_module.so
-rwxr-xr-x. 1 root root  21K Oct 31  2016 ngx_http_geoip_module.so
-rwxr-xr-x. 1 root root  24K Oct 31  2016 ngx_http_image_filter_module.so
-rwxr-xr-x. 1 root root  24K Oct 31  2016 ngx_http_perl_module.so
-rwxr-xr-x. 1 root root  24K Oct 31  2016 ngx_http_xslt_filter_module.so
-rwxr-xr-x. 1 root root  99K Oct 31  2016 ngx_mail_module.so
-rwxr-xr-x. 1 root root  79K Oct 31  2016 ngx_stream_module.so

However it is not complied into the nginx binary as one would assume given the instructions given on README.md

nginx -V
nginx version: nginx/1.12.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

So the question is, what steps am I missing here in order to get fancyindex working?

This isn't really an issue, but maybe people here will appreciate it

I was dealing with an Nginx server that was updated to use debian repos, largely for http2 support.

I didn't have access to the server in question but still needed to navigate directory pages regularly, I wrote this little jquery bookmarklet to sort flat nginx pages by date time.

javascript:void function(){function e(){var e=[].slice.call($("pre").html().split("\n"));e.shift(),e.shift(),e.pop(),e.sort(function(e,t){return new Date(e.substring(e.length-8,e.length-25)).getTime()-new Date(t.substring(t.length-8,t.length-25)).getTime()}).reverse();var t="";$.each(e,function(e,n){t=t+n+"\n"}),$("pre").html(t)}var t=document.createElement("script");t.src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js",document.getElementsByTagName("head")[0].appendChild(t),setTimeout(function(){e()},500)}();

There's a little delay as it adds jquery before executing, but if you can't install fancyindex for some reason it's better than nothing.

Foreign directory listings cause Javascript error

You cannot navigate into a directory that is not handled by fancyindex. The error is caused by history.js:

var elements = div.getElementsByClassName('box-content')[0];
target.innerHTML = elements.innerHTML;

The html of "div" is the content of the directory listing. But this listing may not be generated by fancyindex, so that "elements" is null, and accessing the property innerHTML will trigger an exception.

I fixed that by setting the location and returning false in case "elements" is null.

A somewhat better approach would be to let fancyindex send a custom header and check that header instead of relying on the presence of an element with the class name 'box-content". And the best fix would be to not fire the ajax request at all if a link points to a location that is not handled by fancyindex.

[enhancement] Allow downloading directories

It would be nice to be able to download a complete subdirectory from an index page. The tar format would should this without reading the files in memory.

Might work with a format parameter like suggested in #10.

Bug fancyindex_localtime is not working

here is my config file
fancyindex on;
fancyindex_localtime on;
fancyindex_exact_size off;
fancyindex_exact_size is working but fancyindex_localtime is not. It's showing me the mtime of the file. I tried in both Safari and Chrome, the results are the same. any idea on how this could happen? I'm using Nginx 1.12.0 and the latest version of fancyindex

Custom Header/Footer Returns 404

When using fancyindex_header "/srv/http/site2" or fancyindex_footer "/srv/http/site2" a return of 404 error is not found if the server root is /srv/http/site1

sub folders within the directory listing are returning 404.
if fancyindex_header "header.html" is used
with header.html located in the root of the directory location than header is displayed for / directory only. any subfolders return 404 error.

Using a custom header can break table header arrows

The default template.html contains a <meta> tag as follows:

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

This <meta> tag properly makes browsers interpret the entity reference codes for the sort arrows in the table headers as Unicode. Now, if a custom header is configured, and such a tag is not present (or the charset= is something else than utf-8), the sorting arrows won't show properly.

As an alternative, ngx-fancydex could generate the corresponding HTTP header instead, and the <meta> tag could be removed from the template. That could pose a problem when non custom headers or footers are not UTF-8, though this seems like a reasonable requirement for most cases.

Another option might be using the &uarr; and &darr; HTML entity references, which should render properly independently of the charset (hopefully).

Minor feature request: config option to exclude symbolic links

I have a couple of cases where there are symbolic links for Reasons(TM) but I'd like crawlers to stop seeing them.

I have a trivial prototype patch:

--- ngx_http_fancyindex_module.c.dist   2015-02-19 04:16:36.000000000 -0800
+++ ngx_http_fancyindex_module.c    2015-08-05 14:58:51.965238000 -0700
@@ -494,7 +494,7 @@

         len = ngx_de_namelen(&dir);

-        if (ngx_de_name(&dir)[0] == '.')
+        if (ngx_de_name(&dir)[0] == '.' || ngx_de_is_link(&dir))
             continue;

 #if NGX_PCRE

This will do for us, but was thinking it might be nice to have it in the upstream version with a configuration control.

I know nginx itself has an option whether or not to follow symlinks, but that is exactly the opposite of what we want. If it is blocked there, fancyindex will generate href links that result in a 404.

Provide directive to configure time format

fancyindex_localtime can only determine the timezone, but people in different timezones used to print time in different ways (as a Chinese, I would like to see time formatted like 2015-04-16 23:33), it would be very great to provide directive to configure that. The directive may looks like:

location / {
    fancyindex on;
    fancyindex_time_format "yyyy-MM-dd h:mm"
}

to represent time as 2015-04-16 23:33, use Unicode Date/Time Patterns as formatting symbol, which may already have C implementation so that it can be easier to achieve in this project :)

Error return 400 if using fancyindex module but it is fine for autoindex

Hi,

I got an Error 400 return from nginx log when I try to connect this vhost nginx from external IP. However, it works fine in localhost.

Error Log.
192.168.11.1 - - [08/Apr/2013:00:24:28 +0800] "-" 400 0 "-" "-"

I try to use autoindex modules instead, it works well on both external IP and my localhost as well.

Do you know why? Anything am i missing on the below configuration using NgxFancyindex?

server {
#General Configuration
listen 80;
server_name localhost;

#Logpath
access_log /var/log/nginx/homefileserver.log;
error_log /var/log/nginx/homefileserver.log;

root /Users/kit/fileserver/files;
location / {
  #static file
  #autoindex on;
  #autoindex_localtime on;
  #autoindex_exact_size off;
  fancyindex on;
  fancyindex_header "layout/html/header.html";
  fancyindex_footer "layout/html/footer.html";
  fancyindex_ignore "layout";
  fancyindex_exact_size off;
  fancyindex_localtime on;
}

}

Documentation gap

The fancyindex_header and fancyindex_footer functions fail (and log alerts) without the 'ngx_http_addition_module'. This needs to be stated in the requirements, otherwise somebody like me will build a version of nginx that only does errors when trying to use custom header/footer.

Randomize execution order of tests

Ideally tests (t/*.test) should be self-contained, and the order of their execution wouldn't matter. To further ensure that, it would be desirable to modify the test harness to execute them in a random order.

Create tagged release

Hi there!

Can you create/push some tags (aka releases) in the repo to ease package maintaining?

Allow sorting by columns other than file name

It would be desirable to have the module sort the file list using criteria other than file names (file size or date). Probably the easiest way of implementing this is making the table column headers clickable, and recognize an argument in the URL to decide which column is used for sorting.

[enhancement] Only return table for AJAX request

Sorry I can't provide a patch but would it be possible to allow for returning only the <h1> page title and the <table> itself when the module is called via AJAX?

ie; leave out t02_head1, t02_head2, t03_head3, the <body> part of t04_body4 and t08_foot1 when the incoming headers is x-requested-with:XMLHttpRequest

HTML5, fixing the html for accessibility, and getting the latest version into nginx-extras?

Hi; thanks for a great module and I love the look of it but I appear to be "stuck" on an old version; I'm currently using the nginx-extras mainline 1.7.0 from the standard Ubuntu 14.04 repo, and I noticed the page gives a bunch of validation errors.

But I also noticed that the headers from my nginx look like

<!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"/>

while the template file on github looks like

<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"/>

This suggests that even though this template is 5 months old, it's not making into nginx-extras builds from 2 weeks ago. Who should I prod or nudge for this?

I'd also like to make the page more accessible, eg for screenreader users, by adding some simple ARIA tags and semantics, which wouldn't affect the actual structure or markup. If I were to tweak about and make some changes which didn't affect current templates but made it valid html5 and WAI-compliant, would it be worth submitting a pull request?

Footnotes: I realise, of course, I could just "fudge" the whole thing by dropping some jquery into the footer which would modify the elements in question, but you'd be surprised how many screenreader users have javascript off, so that's a less preferable route.

And I also realise that I could modify the ngx-fancyindex source and compile into nginx, but that way lies a ridiculous amount of time and security issues when you're relying on as many extras as nginx-extras provides... being able to "apt-get update" everything is so much safer.

Fancyindex doesn't show all the files.

Hi,

I have ~30k files in a directory but fancyindex only shows ~9k.

a ls -R | wc -l gives me the output of 30059, so there's 30059 files. Browsing the directory and waiting for it to load, and then checking the source code shows that it only shows around ~9k files. Disabling Fancyindex in the conf fixes it, and all files are displayed. I recompiled fancyindex using the git version to see if that fixes it, but nope. The directory has some arabic and some unusual letters, that might have something to do with it.

My fancyindex conf:

fancyindex on;
fancyindex_localtime on;
fancyindex_exact_size off;
fancyindex_header "/f/header.html";
fancyindex_footer "/f/footer.php";
fancyindex_ignore "about.html";
fancyindex_ignore "contribute.html";
fancyindex_ignore "contact.html";
fancyindex_ignore "network.html";
fancyindex_ignore "sitemap.xml";
fancyindex_ignore "googlec70fa09c58ab028c.html";
fancyindex_ignore "about.html"
fancyindex_ignore "f"; 
fancyindex_ignore "robots.txt";
fancyindex_ignore "stats";
autoindex on;
try_files $uri $uri/ =404;

The site in question: http://bit.ly/fancyindexsite

I have another directory running on the same server, and that one has ~10k files and all of them are being displayed without any problems. I really have no idea what the problem is, has to be some kind of bug.

Using nginx 1.9.4

Nginx -V:

nginx version: nginx/1.9.4
built by gcc 4.9.2 (Debian 4.9.2-10)
built with OpenSSL 1.0.1k 8 Jan 2015
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt=-Wl,-z,relro --prefix=/home/html --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/sbin/ --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --add-module=/root/nginx-1.6.2/ngx-fancyindex --with-http_flv_module --with-http_spdy_module --with-http_geoip_module --with-http_gzip_static_module --with-http_mp4_module --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-http_addition_module --with-debug --with-pcre-jit --with-http_stub_status_module

Feature request: Smart filename sort options

I'd like to be able to sort filenames in natural order (e.g. "a1" < "a2" < "a11"). That's all I'm really interested in, though I can see locale-respectful sorting being useful for international users.

Some years ago I edited an earlier version of fancyindex to add options to disable directories first and to use Martin Pool's natsort for filenames. I would have contacted you then (it wasn't on GitHub at the time, was it?), but in order to avoid the combinatorical proliferation of sort functions, I moved the options (ascending vs. descending, name vs. time vs. size, directories first on vs. off, natural sort vs. ASCIIbetical) into an argument structure, which I passed to a single sort function via qsort_r. That's not part of the C standard, and its BSD and GNU implementations expect arguments in different orders. I've since come back and used the appropriate #if defined directives so that it works in both dialects, but I'm not sure if losing support for plain C is acceptable. Maybe you can think of a better solution?

You have directories-first optional now, and that date-formatting option I'd been meaning to write for years—but I can't update if it means giving up natural sort!

I can send you my code if you like. (It's old and I've lost the version control, so it may not be merge-suitable.)

Make CI do testing on top of building

Currently the Travis CI setup (see .travis.yml in the repository) only builds Nginx with the module enabled, and it would be great if it could also do some basic testing. Something as simple as smoke testing by running Nginx with the document root set to an empty directory and checking that fetching from the server returns something that looks like a file listing would already be a great improvement.

index files not working

The index file seems to be ignored with nginx 1.11.2 if fancyindex is enabled. If I recall correctly, the module used to work like a drop-in replacement for autoindex and respected the index files.

Segfaults when opening some directories

Bug appeared in 1e438a6. Crashed with some big and small directories, but sadly I could not save exact directory listings. It also seems to crash with empty files present. Most likely cause is OOB in ngx_sprintf(...sizes[j]).

Nginx version: nginx/1.11.6
Nginx config:

...
http {
    fancyindex_exact_size off;
    fancyindex on;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
    }
}

Folder contents:

-rw-r--r-- 1 root root    0 Nov 25 00:07 test.txt

Crash info from systemd:

           PID: 6178 (nginx)
           UID: 33 (http)
           GID: 33 (http)
        Signal: 11 (SEGV)
    Executable: /usr/bin/nginx
    ...
                Stack trace of thread 6178:
                #0  0x00000000080e5921 ngx_vslprintf (nginx)
                #1  0x00000000080e5e48 ngx_sprintf (nginx)
                #2  0x000000000805eeef n/a (nginx)
                #3  0x00000000080cb996 ngx_http_core_content_phase (nginx)
                #4  0x00000000080c9189 ngx_http_core_run_phases (nginx)
                #5  0x00000000080dd6e7 ngx_http_process_request (nginx)
                #6  0x00000000080b9964 n/a (nginx)
                #7  0x00000000080a4926 n/a (nginx)
                #8  0x00000000080d4dce ngx_process_events_and_timers (nginx)
                #9  0x00000000080f334e n/a (nginx)
                #10 0x00000000080f1be7 ngx_spawn_process (nginx)
                #11 0x00000000080f2986 ngx_master_process_cycle (nginx)
                #12 0x0000000008054b86 main (nginx)
                #13 0x00000000b7267196 __libc_start_main (libc.so.6)
                #14 0x0000000008054d54 _start (nginx)

hide Parent directory ..

Hide the parent directory (..):
fancyindex_ignore ..;

fancyindex_ignore .. will hide all accept parent dir.

Feature request: icons column are the same as in Apache

Organizations and companies in Russia are obliged to provide information about their activities on the public. Many uses for this httpd index. Column with the icon allows to distinguish between documents. When we are using Nginx we lose this opportunity. Fancyindex doesn't help in this. Moreover directory differ only in the symbol "/". See attach for examples.

02-03-2017_arpit_httpd

02-03-2017_arpit_fancyindex

Feature Request: Do not list files which are not readable by nginx

I made a log folder of the system accessible from a page which use fancyindex.
On the standard configuration fancyindex will list every files in the folder (since nginx has execution right on the folder). Now from the web some files are unreadable.
I would like to be able to ignore all unreadable files without entering manually each of them.

As a side note I discovered that when fancyindex_ignore forw with strings (nginx not compiled with PCRE), the function ignore anything that start with the string. Is it a bug? Can you add this info in the doc if it's intended? For now it help me a lot with logs who have a timestamp in their filename.

Provide tooling which allows parsing HTML in unit tests easily

Being able to parse the HTML returned by the module from shell scripts would allow greatly improving the test suite. For example, some tools like the following could be up to the task:

  • pup (written in Go, likely not readily available from distribution packages in Travis-CI, but works reall well.)
  • This answer at Stack Exchange points also to hxselect, included in W3C's html-xml-utils package. (This may be easier to get in Travis-CI.)
  • ...

This task means searching for a readily available alternative, if possible. Otherwise, probably providing a static build of pup that the unit tests can use would work — probably there's no need to build it in the CI.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.