slitaz-base-files 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 178de496f806
children 8e1a647b61e7
files rootfs/var/www/cgi-bin/index.cgi
line diff
     1.1 --- a/rootfs/var/www/cgi-bin/index.cgi	Sun Apr 13 01:36:58 2014 +0200
     1.2 +++ b/rootfs/var/www/cgi-bin/index.cgi	Tue Apr 15 06:38:36 2014 +0200
     1.3 @@ -1,46 +1,54 @@
     1.4  #!/bin/sh
     1.5 -. /lib/libtaz.sh
     1.6 +#
     1.7 +# Directory lister for BusyBox HTTPd
     1.8 +# Copyright (C) 2014 SliTaz GNU/Linux - BSD License
     1.9 +#
    1.10 +. /usr/lib/slitaz/httphelper.sh
    1.11 +header
    1.12  
    1.13 -# Internationalization.
    1.14 -TEXTDOMAIN='slitaz-base'
    1.15 -. /etc/locale.conf
    1.16 -export TEXTDOMAIN LANG
    1.17 +# Security check
    1.18 +case "$QUERY_STRING" in
    1.19 +	..*) echo "Security exit" && exit 1 ;;
    1.20 +esac
    1.21  
    1.22 -if [ ! -d ..$QUERY_STRING ]; then
    1.23 -	echo "HTTP/1.1 404 Not Found";
    1.24 -else
    1.25 -	title=$(_ 'Index of $QUERY_STRING')
    1.26 -	cat << EOT
    1.27 -Content-type: text/html
    1.28 +# Html5 head
    1.29 +cat << EOT
    1.30 +<!DOCTYPE html>
    1.31 +<html lang="en">
    1.32 +<head>
    1.33 +	<meta charset="utf-8" />
    1.34 +	<title>Index of /$QUERY_STRING</title>
    1.35 +	<link rel="stylesheet" type="text/css" href="/style.css" />
    1.36 +	<style type="text/css">
    1.37 +		#header h1 { width: auto; }
    1.38 +		ul { line-height: 1.5em; } li { color: #666; }
    1.39 +	</style>
    1.40 +</head>
    1.41 +<body>
    1.42 +<div id="header">
    1.43 +	<h1>Index of /$QUERY_STRING</h1>
    1.44 +</div>
    1.45 +<section id="content">
    1.46 +<div>Files: $(ls ../$QUERY_STRING | wc -l)</div>
    1.47 +<ul>
    1.48 +EOT
    1.49  
    1.50 -<!DOCTYPE html>
    1.51 -<html xmlns="http://www.w3.org/1999/xhtml">
    1.52 -<head>
    1.53 -	<title>$title</title>
    1.54 -	<meta charset="utf-8" />
    1.55 -	<link rel="stylesheet" type="text/css" href="/style.css" />
    1.56 -</head>
    1.57 +[ "$QUERY_STRING" ] && echo '<li><a href="../">../</a></li>'
    1.58  
    1.59 -<!-- Header -->
    1.60 -<div id="header">
    1.61 -	<h1>$title</h1>
    1.62 -</div>
    1.63 +# We need ?/path
    1.64 +for i in $(ls -p ../$QUERY_STRING)
    1.65 +do
    1.66 +	if [ -f "../$QUERY_STRING/$i" ]; then
    1.67 +		echo "<li><a href='/${QUERY_STRING}${i}'>$i</a></li>"
    1.68 +	else
    1.69 +		echo "<li><a href='/${QUERY_STRING}${i}?${QUERY_STRING}${i}'>$i</a></li>"
    1.70 +	fi
    1.71 +done
    1.72  
    1.73 -<!-- Content -->
    1.74 -<div id="content">
    1.75 -<body>
    1.76 -	<ul>
    1.77 -$({ [ "$QUERY_STRING" != "/" ] && echo "../"; ls -p ..$QUERY_STRING; } | \
    1.78 -  sed 's|.*|		<li><a href="&">&</a></li>|')
    1.79 -	</ul>
    1.80 -</div>
    1.81 -
    1.82 -<!-- Footer -->
    1.83 -<div id="footer">
    1.84 -	Copyright &copy; $(date +%Y) <a href="http://www.slitaz.org/">SliTaz GNU/Linux</a>
    1.85 -</div>
    1.86 -
    1.87 +cat << EOT
    1.88 +</ul>
    1.89 +</section>
    1.90 +<footer id="footer"></footer>
    1.91  </body>
    1.92  </html>
    1.93  EOT
    1.94 -fi