-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwifipanel.html
80 lines (74 loc) · 2.2 KB
/
wifipanel.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Control Room</title>
<script>
function httpGetAsync(theUrl, callback)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
if (callback) callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true);
xmlHttp.send(null);
}
window.onload = function(){
// window.setInterval(main, 1000);
httpGetAsync("/api", setup);
}
function reload(){
location.reload();
}
function setup(data){
data = JSON.parse(data);
var options = document.getElementById("wifis");
for (var i=0; i<data["wifi"].length; i++){
var newOption = document.createElement("option");
newOption.text = data["wifi"][i]["ssid"]+" ("+data["wifi"][i]["pass"].length+")";
newOption.value = data["wifi"][i]["id"];
options.options.add(newOption, newOption.value);
}
}
function remove(){
var selection = document.getElementById("wifis");
console.log(selection.options[selection.options.selectedIndex].value);
httpGetAsync("/api?remove=wifi&id="+selection.options[selection.options.selectedIndex].value);
selection.options.remove(selection.options.selectedIndex);
return false;
}
function add(){
console.log("/api?add=wifi&ssid="+document.getElementById("ssid").value+"&pass="+document.getElementById("pass").value);
httpGetAsync("/api?add=wifi&ssid="+document.getElementById("ssid").value+"&pass="+document.getElementById("pass").value, reload);
return false;
}
</script>
<style>
button, select , input{
display: block;
margin: 1px;
}
button, input {
min-width: 200px;
}
body {
background-color: #EEEEEE;
}
</style>
</head>
<body>
<form action="/api" method="get" onsubmit="return remove()">
<select id="wifis">
</select>
<input type="submit" value="Delete">
</form>
<form action="/api" method="get" onsubmit="return add()">
<span>SSID: </span><input id="ssid" type="text">
<span>PASS: </span><input id="pass" type="password">
<input type="submit" value="Add">
</form>
<button id="wifi" onclick="javascript:location.href='/'" >Home</button>
<button id="rfid" onclick="javascript:location.href='/rfid'" >RFID Setup</button>
</body>
</html>