forked from illacceptanything/illacceptanything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server
executable file
·34 lines (34 loc) · 940 Bytes
/
server
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
#!/usr/bin/env bash
set -e
while true; do
netcat -lp 1234 -e '
read request_line
resource=$(echo $request_line | cut -f2 -d" " | cut -c 2-)
[ -n "$resource" ] || resource=.
say "Received request: $resource" 2> /dev/null
if [ -e "$resource" ]; then
echo "HTTP/1.0 200 OK"
if [ -d "$resource" ]; then
echo "Content-Type: text/html"
echo
ls "$resource" | while read file; do
if [ -d "$resource/$file" ]; then
echo "<a href=\"$resource/$file/\">$file/</a><br />"
else
echo "<a href=\"$resource/$file\">$file</a><br />"
fi
done
elif [[ "$resource" == *".php" ]]; then
echo
php -q "$resource"
else
echo
cat "$resource"
fi
else
echo "HTTP/1.0 404 Not Found"
echo "Content-Type: text/plain"
echo
echo "Resource \"$resource\" not found."
fi'
done