commit 0a65725361255f05f12c8e556771c8932a0db3cd Author: Koray Yanik Date: Wed Feb 23 12:38:39 2022 +0000 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..00de9ae --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.log +status diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d0b83ac --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "bashserv"] + path = bashserv + url = https://github.com/fumyuun/bashserv.git diff --git a/README.md b/README.md new file mode 100644 index 0000000..0aa18b5 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Wakeboard +A simple status page to remotely wake up hosts, to use on a DHCP server using `dnsmasq`. It will read the leases as given out, and display all hosts that are statically configured, uses ping to figure out if they are awake or not, and can send a wake-on-lan packet to awake them. + +It is likely full of security holes, so please ensure it is not accessable from an untrusted network :) + diff --git a/bashserv b/bashserv new file mode 160000 index 0000000..797abde --- /dev/null +++ b/bashserv @@ -0,0 +1 @@ +Subproject commit 797abde65eeecc327bdb577c75b05942716ef8ea diff --git a/handle_404.sh b/handle_404.sh new file mode 100755 index 0000000..c8ed11e --- /dev/null +++ b/handle_404.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +body="\n" +body+="Not found\n" +body+="The requested resource $2 was not found\n" +body+="\n" + +cat <> get.log + +./handle_requests.sh $@ +if [ $? -eq 0 ]; then + exit 0 +fi + +if [ -z "$1" -o "$1" == "index.html" ]; then + body="\n\n$WAKEBOARD_TITLE\n\n\n\n" + body+="\n\n\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+="\n" + + body+="\n" + + body+="" + body+="" + body+="" + body+="" + fi + done + + body+="
HostnameIP AddressMAC AddressWakeup
" + body+="
X
" + body+="" + body+="" + body+="
$hostname$ip$mac\n" + body+="
\n\n\n" + +cat < status/$ip + + ret=1 + for i in {0..30}; do + ping -c 1 -w 5 -t 1 -q "$ip" + ret=$? + [ $ret -eq 0 ] && break + done + + echo -e "{\n\"time\": \"$(date +%T)\"," > status/$ip + + if [ $ret -eq 0 ]; then + echo -e "\"status\": \"up\"\n}\n" >> status/$ip + else + echo -e "\"status\": \"down\"\n}\n" >> status/$ip + fi + exit 0 +fi + +if [[ "$1" =~ ^status ]]; then + ip=$(echo "$1" | cut -d '/' -f2) + + if [ ! -r "status/$ip" ]; then + body="{\n\"status\": \"unknown\"\n}\n" + else + body=$(cat status/$ip) + fi + +cat < ping.log + ret=$? + [ $ret -eq 0 ] && break + done + + if [ $ret -eq 0 ]; then + body="{\"response\": \"ok\"}\n" + else + body="{\"response: \"fail\"}\n" + fi + +cat < /dev/null + body="{\"response\": \"ok\"}\n" + +cat <] [-p|--port ]" + echo " -h | --help: Show this help" + echo " -t | --title: Title to give to the served page (defaults to Wakeboard)" + echo " -p | --port : Port number to use (default 8000)" + exit 0 +fi + +if [ ! -d "status" ]; then + mkdir "status" +fi + +# Ensure variable can be read by the get handler +export WAKEBOARD_TITLE + +./bashserv/bashserv.sh -s "./static" -g "./handle_get.sh" -p "$PORT" +