wakeboard/handle_post.sh

44 lines
931 B
Bash
Executable File

#!/bin/bash
if [[ "$REQUEST_PATH_SANE" =~ ^refresh ]]; then
ip=$(echo "$POST_DATA" | cut -d '=' -f2)
body="{\n\"time\": \"$(date +%T)\",\n"
body+="\"status\": \"ok\"\n}\n"
$BASHSERV_DIR/header.sh -t "application/json" -l $(echo -ne "$body" | wc -c)
printf "%b" "$body"
printf "%b" "$body" > status/$ip
ret=1
for i in {0..30}; do
ping -c 1 -w 5 -t 1 -q "$ip" > /dev/null 2>&1
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 [[ "$REQUEST_PATH_SANE" =~ ^wol ]]; then
mac=$(echo "$POST_DATA" | cut -d '=' -f2)
wol "$mac" > /dev/null
body="{\"response\": \"ok\"}\n"
$BASHSERV_DIR/header.sh -t "application/json" -l $(echo -ne "$body" | wc -c)
printf "%b" "$body"
exit 0
fi
exit 1