From fbc00d7932a717a227389040a96443e61b597d7c Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 13 Sep 2020 20:50:54 +0200 Subject: Implement API --- static/js/api_client.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 static/js/api_client.js (limited to 'static') diff --git a/static/js/api_client.js b/static/js/api_client.js new file mode 100644 index 0000000..4c80651 --- /dev/null +++ b/static/js/api_client.js @@ -0,0 +1,40 @@ + + +/* + picontrol - A small Web Application to shutdown or reboot your Raspberry Pi. + + Copyright (C) 2020 xengineering + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + + +function poweroff() { + var xhr = new XMLHttpRequest(); + xhr.open("POST", "/api", true); + xhr.setRequestHeader("Content-type", "application/json"); + var data = {"cmd":"poweroff"} + var json = JSON.stringify(data); + xhr.send(json); +} + + +function reboot() { + var xhr = new XMLHttpRequest(); + xhr.open("POST", "/api", true); + xhr.setRequestHeader("Content-type", "application/json"); + var data = {"cmd":"reboot"} + var json = JSON.stringify(data); + xhr.send(json); +} -- cgit v1.2.3-70-g09d2