Custom Automatic Directory Index with Thumbnails
From OpenFSG
|
When the Apache web server displays a directory that does not contain an index.html or --if PHP is enabled-- index.php file, it uses the built-in module mod_autoindex to generate a directory index. Freecom has modified that module, hence it displays a only limited information on the files and applies some Freecom branding to the generated web page. Unfortunately, you cannot change the mod_autoindex module if you are not satisfied with this. Running a full fledged HTML-based file manager is one option, but often overkill. The option that is described here, is to place an index.php file into all relevant web folders and use it to display a custom directory index. By installing further packages via IPKG, even on-the-fly generation of thumbnails for JPEG pictures is possible.
A selection of available PHP index solutions
Several open source PHP scripts are available that provide a replacement for mod_autoindex and are known to work on the Freecom devices, e.g.
- http://autoindex.sourceforge.net Versions 1.x runs with PHP4. However, there exists a Security Advisory concerning a Cross Site Scripting (XSS) vulnerability. Hence, install it on our own risk and take in particular care that the search feature is disabled.
- http://filenice.com No security vulnerabilities are known.
Installation
The installation of the PHP index solutions is always the same:
- Let the PHP-enabled Web server host the directory you want to make publicly available as described in the Setting up Web Front Pages Section of Host a Web Site. In particular, make sure that the box 'enable PHP' is checked.
- To test that this was successful: Try to access your directory via your web browser: you should see the usual Freecom directory index.
- Place your PHP index solution into your directory (usually by unpacking a zip file).
- Sometimes you can configure the PHP index solutions, either via editing a text file or at the first access via your web browser.
- Now, your PHP index solution will display the directory index when accessing your directory via a web browser.
On-the-fly generation of thumbnails
Some PHP index solutions (as well as photo gallery PHP scripts) allow to display on-the-fly generated thumbnail previews of files containing pictures. However, the hardware of your Freecom device is not powerful enough to support this feature (In particular when treating JPEG images, the following restrictions are relevant: no hardware support for floating point arithmetic and sometimes even not enough memory for keeping the decompressed image in main memory): Most of the time, the GD library of image functions is used for creating the thumbnail preview; for any reasonable sized JPEG picture, the GD library will fail to scale the picture on your Freecom device.
However, there is a solution: The libjpeg package that is based on sources of the Independent JPEG Group comes with the command line tool djpeg to decompress JPEG files. By using the -scale option, it is possible to create quite fast a smaller version of the original image. The resulting downscaled image can then usually be post-processed by other non-optimised tools like the GD library or ImageMagick. As an example, the following command line scales the original image down using the djpeg command by a factor of 8 and then applies the slower (but more flexible) ImageMagick convert command to process the downscaled image in order to create the final thumbnail with a height of 80 pixels (for a 6 mega pixel JPEG image, my FSG takes 1 second to create the thumbnail):
/opt/bin/djpeg -fast -scale 1/8 myimage.jpg | /opt/bin/convert - -scale x80 myimage_thumb.jpg
Note: djpeg and convert are not available on your Freecom device by default, but need to be installed via IPKG by installing the packages libjpeg and imagemagick.
A PHP index script for on-the-fly generation of thumbnails
If your expectations are not to high, the speed of the above approach is sufficient to create thumbnails on-the-fly. The following download offers a PHP script that generates a directory index with thumbnails.
Features
- Dynamic creation of directory index (just like Apache mod_autoindex).
- On-the-fly generation of thumbnails for JPEG images.
- Already generated thumbnails are cached in a directory.
- Files that have been modified within the last n days, are highlighted.
- Configurable via editing some variables.
Requirements
- PHP4 (or PHP5) with GD (for determining height of JPEG image), i.e. at least Freecom Firmware 3.2.3.
- libjpeg package (installable via IPKG).
- imagemagick package (installable via IPKG).
Setup and configuration
- As generically described in the above Section Installation.
- The PHP script comes with a reasonable default configuration. Hence, it is usually not necessary to change the configuration. If you nevertheless want to change it, open index.php in a text editor and edit the variables defined at top of the file between // Global settings. Please adjust: and // End of global settings. comments.
Download
- Latest version: index_php.zip
Changelog
Older versions of the file are available on its history page: Image:Index php.zip.
Version 1.0
- Initial release
Feature requests
I do not intend to implement any requested features. However, feel free to modify the source and to create e.g. a picture gallery (if your solution is based on the sources offered here: the source is distributed under the GPL license, hence make the PHP source of your modification available as well)!
