variousscripts/controlserverwebpage/index.html

91 lines
3.0 KiB
HTML

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Control page</title>
</head>
<body>
Status: <b id="status"></b>
<br><br>
<input type="button" onclick="checkStatus();" value="Check status"/>
<input id="pwdButton" type="button" onclick="password();" value="Enter password"/>
<input type="button" onclick="rebootS();" value="Reboot"/>
<input type="button" onclick="haltS();" value="Shutdown"/>
<script type="text/javascript">
var waitState = "false";
function checkStatus() {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'status.php');
xhr.send(null);
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
xhr.responseText.split('\n').forEach(function(line) {
if (waitState == "true") { document.getElementById("status").innerHTML = "<font color=red>wait ... </font>" + line }
else { document.getElementById("status").innerHTML = line; }
})
}
}
}
function password() {
var answer = prompt('Enter password', '');
if (!((answer == null) || (answer == ''))) {
document.getElementById("pwdButton").disabled = true;
document.getElementById("status").innerHTML = "<font color=red>wait</font>";
waitState = "true";
var xhr = new XMLHttpRequest();
xhr.open('GET', 'password.php?pass=' + answer);
xhr.send(null);
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
xhr.responseText.split('\n').forEach(function(line) {
document.getElementById("status").innerHTML = line;
document.getElementById("pwdButton").disabled = false;
waitState = "false";
})
}
document.getElementById("status").innerHTML = "";
document.getElementById("pwdButton").disabled = false;
waitState = "false";
checkStatus();
}
}
}
function rebootS() {
var answerpw = prompt('Enter password for reboot', '');
if (!((answerpw == null) || (answerpw == ''))) {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'reboot.php?pass=' + answerpw);
xhr.send(null);
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
xhr.responseText.split('\n').forEach(function(line) {
document.getElementById("status").innerHTML = line;
})
}
}
}
}
function haltS() {
var answerpw = prompt('Enter password for sutdown', '');
if (!((answerpw == null) || (answerpw == ''))) {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'halt.php?pass=' + answerpw);
xhr.send(null);
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
xhr.responseText.split('\n').forEach(function(line) {
document.getElementById("status").innerHTML = line;
})
}
}
}
}
</script>
</body>
</html>