114 lines
3.0 KiB
HTML
114 lines
3.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Routing config</title>
|
|
<script src="jquery-3.7.1.min.js" type="text/javascript"></script>
|
|
</head>
|
|
<body>
|
|
<span id="loading">Loading...</span>
|
|
<div style="display: none" id="panel">
|
|
|
|
<div id="update-panel">Checking for updates...</div>
|
|
|
|
Selected networks:
|
|
<table id="net-table">
|
|
<tr>
|
|
<td><input type="checkbox"></td>
|
|
<td><span>Network name</span></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<div>
|
|
<button id="save">Save</button>
|
|
<button id="restart-quagga">Restart quagga</button>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script type="module">
|
|
import {JSONRPC} from "./jrpc.js";
|
|
|
|
let config = {};
|
|
let networks = {};
|
|
|
|
async function auth() {
|
|
let authorized = await JSONRPC.__invoke("auth");
|
|
if (!authorized) {
|
|
do {
|
|
let pass = prompt("Password");
|
|
authorized = await JSONRPC.__invoke("auth", {
|
|
"password": pass
|
|
});
|
|
|
|
if (!authorized) {
|
|
alert("Wrong password");
|
|
}
|
|
} while (!authorized);
|
|
}
|
|
|
|
config = await JSONRPC.__invoke("getConfig");
|
|
networks = await JSONRPC.__invoke("getNetworks");
|
|
|
|
$("#loading").hide();
|
|
|
|
fillNetworks();
|
|
|
|
$("#panel").show();
|
|
}
|
|
|
|
|
|
function fillNetworks() {
|
|
let proto = $("#net-table tr");
|
|
proto.detach();
|
|
|
|
for (const net in networks) {
|
|
let item = proto.clone();
|
|
item.find("input").prop('checked', config.networks.indexOf(net) !== -1).change(function () {
|
|
if ($(this).prop('checked')) {
|
|
config.networks.push(net);
|
|
} else {
|
|
config.networks = config.networks.filter(e => e !== net);
|
|
}
|
|
});
|
|
item.find("span").text(net);
|
|
$("#net-table").append(item);
|
|
}
|
|
}
|
|
|
|
$(document).ready(function () {
|
|
auth();
|
|
$("#save").click(function () {
|
|
const self = $(this);
|
|
self.prop("disabled", true);
|
|
(async function () {
|
|
await JSONRPC.__invoke("setConfig", config);
|
|
alert("Config saved!");
|
|
self.prop("disabled", false);
|
|
})();
|
|
});
|
|
$("#restart-quagga").click(function () {
|
|
if (confirm("Are you sure?")) {
|
|
const self = $(this);
|
|
self.prop("disabled", true);
|
|
(async function () {
|
|
try {
|
|
alert( await JSONRPC.__invoke("restart_quagga"));
|
|
} finally {
|
|
setTimeout(() => {
|
|
self.prop("disabled", false);
|
|
}, 5000);
|
|
}
|
|
|
|
})();
|
|
}
|
|
});
|
|
(async function(){
|
|
alert(await JSONRPC.__invoke("checkUpdates"));
|
|
})();
|
|
});
|
|
</script>
|
|
|
|
|
|
</body>
|
|
</html> |