slitaz-base-files view rootfs/var/www/cgi-bin/index.cgi @ rev 235
Rewrite CGI directory lister
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue Apr 15 06:38:36 2014 +0200 (2014-04-15) |
parents | b2311939ad7e |
children | 8253327a882a |
line source
1 #!/bin/sh
2 #
3 # Directory lister for BusyBox HTTPd
4 # Copyright (C) 2014 SliTaz GNU/Linux - BSD License
5 #
6 . /usr/lib/slitaz/httphelper.sh
7 header
9 # Security check
10 case "$QUERY_STRING" in
11 ..*) echo "Security exit" && exit 1 ;;
12 esac
14 # Html5 head
15 cat << EOT
16 <!DOCTYPE html>
17 <html lang="en">
18 <head>
19 <meta charset="utf-8" />
20 <title>Index of /$QUERY_STRING</title>
21 <link rel="stylesheet" type="text/css" href="/style.css" />
22 <style type="text/css">
23 #header h1 { width: auto; }
24 ul { line-height: 1.5em; } li { color: #666; }
25 </style>
26 </head>
27 <body>
28 <div id="header">
29 <h1>Index of /$QUERY_STRING</h1>
30 </div>
31 <section id="content">
32 <div>Files: $(ls ../$QUERY_STRING | wc -l)</div>
33 <ul>
34 EOT
36 [ "$QUERY_STRING" ] && echo '<li><a href="../">../</a></li>'
38 # We need ?/path
39 for i in $(ls -p ../$QUERY_STRING)
40 do
41 if [ -f "../$QUERY_STRING/$i" ]; then
42 echo "<li><a href='/${QUERY_STRING}${i}'>$i</a></li>"
43 else
44 echo "<li><a href='/${QUERY_STRING}${i}?${QUERY_STRING}${i}'>$i</a></li>"
45 fi
46 done
48 cat << EOT
49 </ul>
50 </section>
51 <footer id="footer"></footer>
52 </body>
53 </html>
54 EOT