-
Notifications
You must be signed in to change notification settings - Fork 1
/
nw_config_v2.html
185 lines (162 loc) · 5.73 KB
/
nw_config_v2.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<html>
<head>
<title>WiFi-Einstellungen</title>
</head>
<script>
async function load_config() {
const response = await fetch('http://' + window.location.host + '/rest/nw/');
const json = await response.json();
document.getElementById("dhcp_hostname").value = json["wifi_config"]["dhcp_hostname"]
document.getElementById("ap_ssid").value = json["wifi_config"]["ap_ssid"]
document.getElementById("ap_pass").value = json["wifi_config"]["ap_pass"]
var table = document.getElementById("wifi-nets");
for (var key in json["wifi_nets"]) {
var row = table.insertRow();
var f1 = document.createElement("input")
f1.value = json["wifi_nets"][key]["ssid"]
row.insertCell(0).appendChild(f1);
var f2 = document.createElement("input")
f2.value = json["wifi_nets"][key]["pass"]
f2.type = "password"
row.insertCell(1).appendChild(f2);
var f3 = document.createElement("input")
if (json["wifi_nets"][key]["bssid"]) {
f3.value = json["wifi_nets"][key]["bssid"];
} else {
f3.value = ""
}
row.insertCell(2).appendChild(f3);
var b4 = document.createElement("input");
b4.type = "button";
b4.value = "Löschen"
b4.onclick = del_row
row.insertCell(3).appendChild(b4);
}
}
async function load_nets() {
const response = await fetch('http://' + window.location.host + '/sensor/wifinets');
const json = await response.json();
var authmodes = {
0: "open",
1: "WEP",
2: "WPA-PSK",
3: "WPA2-PSK",
4: "WPA/WPA2-PSK"
}
var table = document.getElementById("avail-wifi-nets");
for (var key in json) {
var row = table.insertRow();
row.insertCell(0).innerHTML = json[key]["ssid"];
row.insertCell(1).innerHTML = json[key]["bssid"];
row.insertCell(2).innerHTML = json[key]["channel"];
row.insertCell(3).innerHTML = json[key]["rssi"];
row.insertCell(4).innerHTML = authmodes[json[key]["authmode"]];
row.insertCell(5).innerHTML = json[key]["hidden"];
}
}
function add_row() {
var table = document.getElementById("wifi-nets");
var row = table.insertRow();
var f1 = document.createElement("input")
row.insertCell(0).appendChild(f1);
var f2 = document.createElement("input")
row.insertCell(1).appendChild(f2);
var f3 = document.createElement("input")
row.insertCell(2).appendChild(f3);
var b4 = document.createElement("input");
b4.type = "button";
b4.value = "Löschen"
b4.onclick = del_row
row.insertCell(3).appendChild(b4);
}
function del_row(e) {
e.srcElement.closest('tr').remove()
}
async function put() {
var config = {
"wifi_config": {
"dhcp_hostname": document.getElementById("dhcp_hostname").value,
"ap_ssid": document.getElementById("ap_ssid").value,
"ap_pass": document.getElementById("ap_pass").value,
},
"wifi_nets": [],
}
var table = document.getElementById("wifi-nets");
for (var i = 1, row; row = table.rows[i]; i++) {
var net = {
"ssid": row.cells[0].getElementsByTagName("input")[0].value,
"pass": row.cells[1].getElementsByTagName("input")[0].value,
}
var bssid = row.cells[2].getElementsByTagName("input")[0].value
if (bssid != "") {
net["bssid"] = bssid
}
config["wifi_nets"].push(net)
}
var s = JSON.stringify(config)
const response = await fetch('http://' + window.location.host + '/rest/nw/', {
method: 'PUT',
body: s,
headers: {
'Content-Type': 'application/json; charset=UTF-8'
}
});
var res = await response
document.getElementById("status").innerHTML = res.statusText
}
</script>
<body>
<div class="container">
<h1>WiFi-Einstellungen</h1>
<table class="table">
<tr>
<td>DHCP Hostname:</td>
<td><input type="text" id="dhcp_hostname"></td>
</tr>
<tr>
<td>AP-Mode SSID:</td>
<td><input type="text" id="ap_ssid"></td>
</tr>
<tr>
<td>AP-Mode Passwort:</td>
<td><input type="text" id="ap_pass"></td>
</tr>
</table>
</div>
<div class="container">
<h3>WiFi-Netze</h3>
<table id="wifi-nets" class="table">
<thead>
<tr>
<td>SSID</td>
<td>Passwort</td>
<td>BSSID</td>
<td>Bearbeiten</td>
</tr>
</thead>
</table>
<input type="button" value="neue Zeile" onclick="add_row()">
</div>
<div class="container">
<h3>Verfügbare WiFi-Netze</h3>
<table id="avail-wifi-nets" class="table">
<thead>
<tr>
<td>SSID</td>
<td>BSSID</td>
<td>Channel</td>
<td>RSSI</td>
<td>Authmode</td>
<td>Versteckt</td>
</tr>
</thead>
</table>
</div>
<input type="button" value="Speichern" onclick="put()">
<div id="status"></div>
</body>
<script>
load_config()
load_nets()
</script>
</html>