1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!/bin/sh
# Simple little web server.
PORT=80
DOCROOT=/var/log
log () {
logger -t httpd "$@"
}
run_nc () {
nc -p $PORT -l -e $1 </dev/null >/dev/null 2>/dev/null &
}
header () {
echo "HTTP/1.0 $1 $2"
echo "Content-Type: $3"
echo
}
if [ -z "$HTTPD_STARTED" ]; then
[ -f /var/lib/httpd_stop ] && exit
HTTPD_STARTED=1
export HTTPD_STARTED
# daemonize
run_nc $0
exit
else
# start up the next listener process
[ -f /var/lib/httpd_stop ] || run_nc $0
fi
read GET page x y z
page="$(echo "$page" | sed 's/[^-.A-Za-z0-9_]//g')" # security; note no subdirs
# Reading the rest of the client's request is important; clients tend to get
# confused otherwise. Junk it all..
while read xx ; do
test "${xx}" || break
test "${xx}" = "
" && break
done
if [ -d "$DOCROOT/$page" ]; then
header 200 OK "text/html"
echo "<html><head><title>Debian-installer logs and screenshots</title></head><body>"
echo "<b>Debian-installer logs and screenshots</b><br><br><ul>"
for file in $(cd "$DOCROOT/$page"; find -type f 2>/dev/null | sed 's/^\.\///' | sort); do
echo "<li><a href=\"$file\">$file</a>"
done
echo "</ul></body></html>"
elif [ -e "$DOCROOT/$page" ]; then
if [ "${page%.ppm}" != "$page" ]; then
header 200 "OK" "image/x-portable-pixmap"
elif [ "${page%.png}" != "$page" ]; then
header 200 "OK" "image/x-png"
else
header 200 "OK" "text/plain"
fi
if ! cat "$DOCROOT/$page" 2>/dev/null; then
echo "error!"
fi
else
header 404 "Not Found" "text/plain"
echo "File not found."
fi
|