« Previous | Next»

Configure lighttp to simulate .htaccess rules (Deny From All)

Posted by coldtobi | 19 Jun, 2010, 13:14

Unfortunatly, lighhtpd does not support ".htaccess" rules directly. So if you want to use a script targeted for Apache, you have to implement your own rules.

Luckily, the most needed rule is to forbid the serving of a whole directory, the "Deny From All" rule.

This one can be emulated within the lighttpd.con -- but you have to list every affected directory.  A tedious task to find out every .htaccess contianing the rule and then adding the path to the configuration.

But this can be automated:

_ASIP_

 

#!/bin/bash

# run this script in the base directory of the web content

# give a parameter the mapping to the webroot, eg.
# if it is running under localhost/xyz/, say "/xyz/"

found=$(find -name ".htaccess" )
echo $found >&2

for files in $found
do
        f=$(echo $files |  sed -e "s/^\.\///"  -e "s/\.htaccess$//g" )
        cat $files | grep -i "Deny" | grep -i "from" | grep -i -L "All" 
        if [[ $? -eq 0 ]]
        then
                echo '# Detected deny from all in ' $files
                echo '$HTTP["url"] =~ "^'$1/$f'" {'
                echo -e "\\turl.access-deny = (\"\") \\n}"
        fi
done


Invoke this script in the root directory of your apache-flavoured webscript, giving it a parameter what the "webprefix" of the directory is.

For example, if your script is located in /usr/share/squirellmail, the url is "http://<host>/squirrel execute it in  /usr/share/squirellmail with the parameter "squirrel"

The output of the script can be directly appended to the lighttpd.conf (e.g piping it with >>)

(Note: Always check the result before applying it! The script might not find all files to block, or failing to parse more complicated rules!)

Linux / Debian, Tips and Tricks, Thecus N2100 | Comments (0) | Trackbacks (0)

Related Articles:

0 Comments | "Configure lighttp to simulate .htaccess rules (Deny From All)" »