91 lines
2.7 KiB
Bash
Executable File
91 lines
2.7 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
|
|
|
|
user_agent=$($BASHSERV_DIR/get_request_field.sh "User-Agent")
|
|
if [[ $user_agent =~ Mobile ]]; then
|
|
mobile=1
|
|
fi
|
|
|
|
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"
|
|
body+="<h3>Static leases</h3>\n"
|
|
body+="<table>\n<tr><td></td><td>Hostname</td><td>IP Address</td><td>MAC Address</td><td>Wakeup</td></tr>\n"
|
|
|
|
hosts=$(grep -i "^dhcp-host=" /etc/dnsmasq.conf | cut -d '=' -f2 | tr '[:upper:]' '[:lower:]')
|
|
for host in $hosts; do
|
|
mac=$(echo "$host" | cut -d ',' -f1)
|
|
ip=$(echo "$host" | cut -d ',' -f2)
|
|
hostname="?"
|
|
lease_hostname=$(grep -i "$mac" /var/lib/misc/dnsmasq.leases | cut -d ' ' -f4)
|
|
if [ -n "$lease_hostname" ]; then
|
|
hostname="$lease_hostname"
|
|
fi
|
|
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">⏻</button><td>\n"
|
|
body+="</tr>"
|
|
done
|
|
|
|
body+="</table>\n"
|
|
body+="<h3>Dynamic leases</h3>\n"
|
|
body+="<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 [ -z "$(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">⏻</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
|
|
|
|
exit 1
|