Made /wol a POST request instead of a GET
Since it does modify state. * Also fixed a bug where ping did sometimes still write to the response.
This commit is contained in:
47
handle_post.sh
Executable file
47
handle_post.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ "$REQUEST_PATH_SANE" =~ ^refresh ]]; then
|
||||
ip=$(echo "$REQUEST_PATH_SANE" | cut -d '/' -f2)
|
||||
|
||||
body="{\n\"time\": \"$(date +%T)\",\n"
|
||||
body+="\"status\": \"unknown\"\n}\n"
|
||||
|
||||
cat <<EOF
|
||||
$($BASHSERV_DIR/header.sh -t "application/json" -l $(echo -ne "$body" | wc -c))
|
||||
$(echo -ne $body)
|
||||
EOF
|
||||
|
||||
echo -ne "$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"
|
||||
|
||||
cat <<EOF
|
||||
$($BASHSERV_DIR/header.sh -t "application/json" -l $(echo -ne "$body" | wc -c))
|
||||
$(echo -ne $body)
|
||||
EOF
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit 1
|
||||
Reference in New Issue
Block a user