Koray Yanik
3f6c392969
Since it does modify state. * Also fixed a bug where ping did sometimes still write to the response.
80 lines
1.8 KiB
Bash
Executable File
80 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
echo "[$(date +%T)] GET $REQUEST_PATH_SANE ($REQUEST_PATH)" >> Get.log
|
|
|
|
./handle_requests.sh "$@"
|
|
if [ $? -eq 0 ]; then
|
|
exit 0
|
|
fi
|
|
|
|
set $REQUEST_FIELDS
|
|
while [[ $# -gt 0 ]]; do
|
|
length="$1"
|
|
key="$2"
|
|
shift
|
|
shift
|
|
|
|
value=""
|
|
for i in $(seq 1 $length); do
|
|
value+="$1 "
|
|
shift
|
|
done
|
|
|
|
case $key in
|
|
User-Agent)
|
|
if [[ $value =~ Mobile ]]; then
|
|
mobile=1
|
|
fi
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "$REQUEST_PATH_SANE" -o "$REQUEST_PATH_SANE" == "index.html" ]; then
|
|
body="<html>\n<head>\n<title>$WAKEBOARD_TITLE</title>\n"
|
|
body+="<script type='text/javascript' src='main.js'></script>\n"
|
|
|
|
if [ $mobile ]; then
|
|
body+="<link rel='stylesheet' href='mobile.css'></link>\n</head>\n"
|
|
else
|
|
body+="<link rel='stylesheet' href='main.css'></link>\n</head>\n"
|
|
fi
|
|
|
|
body+="<body>\n<table>\n<tr><td></td><td>Hostname</td><td>IP Address</td><td>MAC Address</td><td>Wakeup</td></tr>\n"
|
|
|
|
IFS=$'\n'
|
|
leases=$(cat /var/lib/misc/dnsmasq.leases | cut -d ' ' -f2-4)
|
|
for lease in $leases; do
|
|
mac=$(echo $lease | cut -d ' ' -f1)
|
|
ip=$(echo $lease | cut -d ' ' -f2)
|
|
hostname=$(echo $lease | cut -d ' ' -f3)
|
|
|
|
if [ -n "$(grep -i "$mac" /etc/dnsmasq.conf)" ]; then
|
|
body+="<tr class='host' data-ip='$ip' data-mac='$mac'>\n"
|
|
|
|
body+="<td class='status'>"
|
|
body+="<div 'class='fail'>X</div>"
|
|
body+="<div class='success' style='display: none;'>✓</div>"
|
|
body+="<div class='undef' style='display: none;'>?</div>"
|
|
body+="</td>\n"
|
|
|
|
body+="<td>$hostname</td>"
|
|
body+="<td>$ip</td>"
|
|
body+="<td>$mac</td>"
|
|
body+="<td><button class='wol' value="$mac">Wake up!</button><td>\n"
|
|
body+="</tr>"
|
|
fi
|
|
done
|
|
|
|
body+="</table>\n</body>\n</html>\n"
|
|
|
|
cat <<EOF
|
|
$($BASHSERV_DIR/header.sh -t "text/html" -l $(echo -ne "$body" | wc -c))
|
|
$(echo -ne $body)
|
|
EOF
|
|
|
|
exit 0
|
|
fi
|
|
|
|
./handle_404.sh $@
|
|
exit $?
|