4

Listing a directory content with ls -l shows this output:

total 12
drwxr-xr-x 3 root root 4096 Dec 11 16:38 2.3
drwxr-xr-x 5 root root 4096 Dec 11 16:38 2.4
drwxr-xr-x 2 root root 4096 Dec 11 16:38 archive
lrwxrwxrwx 1 root root   10 Dec 11 16:38 current -> 2.4/2.4.1/
lrwxrwxrwx 1 root root   10 Dec 11 16:38 next -> 2.4/2.4.2/
lrwxrwxrwx 1 root root   10 Dec 11 16:38 previous -> 2.4/2.4.0/

Notice how it shows the symbolic links and their respective targets.

I need to know if there is a way of getting the same behaviour in apache directory browsing.

If apache is not capable of it as I suspect, is there an application (FLOSS) providing that kind of behaviour ?

3 Answers 3

1

I looked for a solution to this problem in the context of a continuous delivery pipeline. In the binary repository management, versions evolve this way between stages : beta -> rc -> stable.

I use Apache 2.2 to access binary from any server. I decided to use the apache Index description field.

Here is my setup :

1 ) Add fancy indexing in the virtual host config file (ie. /etc/apache2/site-available/my- vhost )

<VirtualHost *: 80 >
...
  DocumentRoot /path/to/root
  IndexOptions FancyIndexing
...
</ VirtualHost>

2) create a .htaccess file in the root directory (path/to/root) containing symbolic links.

#              $version   $lifecycle
AddDescription "2.10.0.5" beta
AddDescription "2.10.0.4" rc
AddDescription "2.9.0.9" stable

3) Then use SSH + sed to replace " infile " the version number : here is an example for the beta,

ssh user@server "cd /path/to/root; sed -i 's/AddDescription.*$lifecycle$/AddDescription \"$version\" $lifecycle/g' .htaccess" && {
  echo "Success."
} || {
  echo "Failed.";
}

Of course this requires some scripting but this solution is sufficiently dynamic to me. .htaccess is taken into account dynamically by Apache.

The target of the symlink is printed under the description column.

Hope this help.

0

You can indicate what the link points to in the "Description" field in the table.

screenshot of a partial Apache mod_autoindex file listing where the symlink target indicated in the Description column

I wrote a shell script (GPL v3) that helps you generate .htaccess files with the appropriate AddDescription lines:

#!/bin/bash
# vi: et sts=4 sw=4 ts=4

# Usage: make-descriptions [DIR]...
# By default, adds a .htaccess file to '.'

set -e
shopt -s nullglob

if [[ $# -gt 0 ]]; then
    DIRS=("$@")
else
    DIRS=(.)
fi

escape() {
    printf '%s\n' \
        "${1//'&'/'&amp;'}"
}

quote() {
    printf '"%s"\n' \
        "${1//'"'/'\"'}"
}

for DIR in "${DIRS[@]}"; do
    HTACCESS=$DIR/.htaccess
    printf 'IndexOptions -SuppressDescription\n' \
        > "$HTACCESS"

    for FN in "$DIR"/*; do
        if [[ -L $FN ]]; then
            TGT=$(readlink -- "$FN")
            DESC=$(
                printf '&rarr; <a href=%s><tt>%s</tt></a>' \
                    "$(quote "$(escape "$TGT")")" \
                    "$(escape "$TGT")"
            )
            printf 'AddDescription %s %s\n' \
                "$(quote "$DESC")" \
                "$(quote "$(basename -- "$FN")")" \
                >> "$HTACCESS"
        fi

    done
done
-1

This should be possible with the mod_autoindex options.

Take a look at the options IndexOptions and IndexStyleSheet here.

2
  • Seems there is no such option/no simple way of doing this. Dec 12, 2012 at 10:10
  • I think that exactly the same behavior as your ls -l output is not possible with mod_autoindex, but you can take a look at github.com/eigan/Apache-Autoindex-Style for a easy way to improve the original directory listing design. Hope this helps you anyways.
    – teissler
    Dec 12, 2012 at 13:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .