Move refresh to a POST request

Technically it changes state...
This commit is contained in:
Koray Yanik 2022-03-11 15:14:15 +00:00
parent 3f6c392969
commit 1ec8fdc54e
3 changed files with 5 additions and 34 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash
if [[ "$REQUEST_PATH_SANE" =~ ^refresh ]]; then
ip=$(echo "$REQUEST_PATH_SANE" | cut -d '/' -f2)
ip=$(echo "$POST_DATA" | cut -d '=' -f2)
body="{\n\"time\": \"$(date +%T)\",\n"
body+="\"status\": \"unknown\"\n}\n"

View File

@ -1,35 +1,5 @@
#!/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" =~ ^status ]]; then
ip=$(echo "$REQUEST_PATH_SANE" | cut -d '/' -f2)

View File

@ -41,8 +41,10 @@ var request_refresh = function (host) {
}
});
request.open("GET", "refresh/" + host.ip);
request.send();
var params = "ip=" + host.ip;
request.open("POST", "refresh", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send(params);
setTimeout(function () {
request_status(host);
@ -70,7 +72,6 @@ var request_wol = function (host) {
});
var params = "mac=" + host.mac;
request.open("POST", "wol", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send(params);