This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
forked from owntracks/web-configurator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
283 lines (268 loc) · 11 KB
/
index.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="x-ua-compatible" content="ie=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>OwnTracks Android Client Web Configurator</title>
<style>
form#form > fieldset {
column-count: 4;
column-rule-style: solid;
column-rule-width: thin;
column-rule-color: #999;
margin-bottom: 1rem;
}
form#form > fieldset > p {
text-align: right;
break-inside: avoid-column;
}
form#form > fieldset > p > input, form#form > fieldset > p > select {
margin-left: 1rem;
}
div#config > pre#outputConfig {
float: left;
width: 45%;
}
div#config > div#links {
margin-left: 1rem;
float: left;
}
</style>
</head>
<body>
<script type="application/javascript">
let config = {
"_type": "configuration",
"auth": true,
"autostartOnBoot": true,
"cleanSession": false,
"clientId": "",
"cmd": false,
"debugLog": false,
"deviceId": "",
"experimentalFeatures": [],
"fusedRegionDetection": true,
"host": "",
"ignoreInaccurateLocations": 150,
"ignoreStaleLocations": 0.0,
"keepalive": 900,
"locatorDisplacement": 5,
"locatorInterval": 60,
"locatorPriority": 2,
"mode": 0,
"monitoring": 1,
"moveModeLocatorInterval": 2,
"mqttProtocolLevel": 3,
"notificationHigherPriority": false,
"notificationLocation": true,
"opencageApiKey": "",
"password": "",
"ping": 30,
"port": 1883,
"pubExtendedData": true,
"pubQos": 1,
"pubRetain": true,
"pubTopicBase": "owntracks/%u/%d",
"remoteConfiguration": true,
"reverseGeocodeProvider": "Device",
"sub": true,
"subQos": 2,
"subTopic": "owntracks/+/+",
"tls": false,
"usePassword": true,
"username": "",
"ws": false
}
function generateConfig() {
document.getElementById("outputConfig").innerText = JSON.stringify(config, null, '\t');
let base64Config = btoa(JSON.stringify(config));
let owntracksConfigURI = "owntracks:///config?inline=" + base64Config;
document.getElementById("outputURL").value = owntracksConfigURI;
document.location.hash = base64Config;
document.getElementById("outputLink").setAttribute("href", owntracksConfigURI);
}
function initializeElements() {
for (const [key, value] of Object.entries(config)) {
let element = document.getElementById(key);
if (element) {
if (element.getAttribute("type") === "checkbox") {
document.getElementById(key).checked = value;
} else {
document.getElementById(key).value = value;
}
}
}
document.getElementById("outputURL").onclick = function () {
this.select();
}
}
document.addEventListener("DOMContentLoaded", function () {
initializeElements();
if (document.location.hash !== "") {
console.log("Loading Config from URL");
let inputBase64Config = document.location.hash.substring(1);
try {
let inputConfigJSON = atob(inputBase64Config);
let inputConfig = JSON.parse(inputConfigJSON);
for (const [key, value] of Object.entries(config)) {
if (key !== "_configuration" &&
key in inputConfig &&
typeof (inputConfig[key]) === typeof (value) && document.getElementById(key)) {
console.log(`loading ${key} with value ${inputConfig[key]}`);
config[key] = inputConfig[key]
let element = document.getElementById(key);
if (element.localName === "select") {
document.getElementById(key).value = inputConfig[key];
}
if (element.getAttribute("type") === "checkbox") {
document.getElementById(key).checked = inputConfig[key];
} else {
document.getElementById(key).value = inputConfig[key];
}
}
}
} catch (e) {
console.error(`Failed to decode config in URL: ${e}`);
}
}
generateConfig();
let inputs = Array.prototype.slice.call(document.getElementById("form").getElementsByTagName("input"));
let selects = Array.prototype.slice.call(document.getElementById("form").getElementsByTagName("select"));
inputs.concat(selects).forEach(input => {
input.onchange = function (a) {
if (this.getAttribute("type") === "checkbox") {
config[this.id] = this.checked;
} else if (this.getAttribute("type") === "text") {
// get configu value type
let type = typeof (config[this.id]);
if (type === "number") {
config[this.id] = parseInt(this.value, 10);
} else {
config[this.id] = this.value;
}
} else if (this.localName === "select") {
let maybeNumeric = parseInt(this.value, 10);
if (isNaN(maybeNumeric)) {
config[this.id] = this.value;
} else {
config[this.id] = parseInt(this.value, 10);
}
}
generateConfig()
}
})
});
</script>
<h1>OwnTracks Web Configurator</h1>
<form id="form">
<p>
<label for="mode">Mode</label><select id="mode">
<option value="0">MQTT</option>
<option value="3">HTTP</option>
</select>
</p>
<fieldset>
<legend>MQTT connection options</legend>
<p><label for="mqttProtocolLevel">MQTT Protocol Level</label>
<select id="mqttProtocolLevel">
<option value="3">MQTT 3.1</option>
<option value="4">MQTT 3.1.1</option>
</select>
</p>
<p><label for="auth">Auth</label><input type="checkbox" id="auth"/></p>
<p><label for="host">Host</label><input type="text" id="host"/></p>
<p><label for="port">Port</label><input type="text" id="port"/></p>
<p><label for="username">Username</label><input type="text" id="username"/></p>
<p><label for="password">Password</label><input type="text" id="password"/></p>
<p><label for="ws">Use websockets</label><input type="checkbox" id="ws"/></p>
<p><label for="tls">TLS</label><input type="checkbox" id="tls"/></p>
<p><label for="keepalive">Keepalive</label><input type="text" id="keepalive"/></p>
<p><label for="clientId">MQTT Client ID</label><input type="text" id="clientId"/></p>
<p><label for="deviceId">Device ID</label><input type="text" id="deviceId"/></p>
<p><label for="cleanSession">Clean Session</label><input type="checkbox" id="cleanSession"/></p>
<p>
<label for="pubQos">Publish QoS</label>
<select id="pubQos">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</p>
<p><label for="pubRetain">Publish Retain</label><input type="checkbox" id="pubRetain"/></p>
<p><label for="pubTopicBase">Publish Topic</label><input type="checkbox" id="pubTopicBase"/></p>
<p><label for="subQos">Subscription QoS</label><select id="subQos">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select></p>
<p><label for="subTopic">Subscription Topic</label><input type="checkbox" id="subTopic"/></p>
</fieldset>
<fieldset>
<legend>Reverse Geocoding</legend>
<p>
<label for="reverseGeocodeProvider">Reverse Geocode Provider</label>
<select id="reverseGeocodeProvider">
<option value="None">None</option>
<option value="Device">Device (Google)</option>
<option value="OpenCage">OpenCage</option>
</select>
</p>
<p><label for="opencageApiKey">OpenCage API Key</label><input type="text" id="opencageApiKey"/></p>
</fieldset>
<fieldset>
<legend>Locator Settings</legend>
<p>
<label for="ignoreInaccurateLocations">Ignore inaccurate locations (m)</label>
<input type="text" id="ignoreInaccurateLocations"/>
</p>
<p>
<label for="ignoreStaleLocations">Ignore stale locations (s)</label>
<input type="text" id="ignoreStaleLocations"/>
</p>
<p>
<label for="moveModeLocatorInterval">Locator Interval (Move Mode) (s)</label>
<input type="text" id="moveModeLocatorInterval"/>
</p>
<p><label for="locatorInterval">Locator Interval</label><input type="text" id="locatorInterval"/></p>
<p><label for="locatorPriority">Locator Priority</label><input type="text" id="locatorPriority"/></p>
<p>
<label for="locatorDisplacement">Locator Displacement</label>
<input type="checkbox" id="locatorDisplacement"/>
</p>
</fieldset>
<fieldset>
<legend>Misc</legend>
<p><label for="autostartOnBoot">Autostart on Boot</label><input type="checkbox" id="autostartOnBoot"/></p>
<p><label for="debugLog">Debug Log</label><input type="checkbox" id="debugLog"/></p>
<p>
<label for="notificationHigherPriority">Notification has higher priority?</label>
<input type="checkbox" id="notificationHigherPriority"/>
</p>
<p>
<label for="notificationLocation">Notification shows current location</label>
<input type="checkbox" id="notificationLocation"/>
</p>
<p><label for="pubExtendedData">Publish Extended Data</label><input type="checkbox" id="pubExtendedData"/></p>
<p>
<label for="remoteConfiguration">Enable Remote Configuration</label>
<input type="checkbox" id="remoteConfiguration"/>
</p>
</fieldset>
</form>
<div id="config">
<p><label for="outputConfig">Output Configuration</label>
<pre id="outputConfig"></pre>
<div id="links">
<p>
<label for="outputURL">Output Configuration URL</label>
<br/>
<textarea id="outputURL" readonly="readonly" cols="100" rows="10"></textarea>
</p>
<p>
<label for="outputLink">Output Configuration Link</label>
<a href="" id="outputLink">Clickable</a></p>
</div>
</div>
</body>
</html>