mirror of https://github.com/aredn/aredn.git
186 lines
7.7 KiB
Plaintext
Executable File
186 lines
7.7 KiB
Plaintext
Executable File
{%
|
|
/*
|
|
* Part of AREDN® -- Used for creating Amateur Radio Emergency Data Networks
|
|
* Copyright (C) 2024 Tim Wilkinson
|
|
* See Contributors file for additional contributors
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation version 3 of the License.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* Additional Terms:
|
|
*
|
|
* Additional use restrictions exist on the AREDN® trademark and logo.
|
|
* See AREDNLicense.txt for more info.
|
|
*
|
|
* Attributions to the AREDN® Project must be retained in the source code.
|
|
* If importing this code into a new or existing project attribution
|
|
* to the AREDN® project must be added to the source code.
|
|
*
|
|
* You must not misrepresent the origin of the material contained within.
|
|
*
|
|
* Modified versions must be modified to attribute to the original source
|
|
* and be marked in reasonable ways as differentiate it from the original
|
|
* version
|
|
*/
|
|
%}
|
|
{%
|
|
const nodes = mesh.getNodeList();
|
|
const mynode = configuration.getName();
|
|
%}
|
|
<div class="dialog wide">
|
|
{{_R("tool-header", "iPerf3")}}
|
|
<div class="simple-tool compact client-server">
|
|
<div class="cols">
|
|
<div>
|
|
<div class="o">Server A‌ddress</div>
|
|
<div class="m">Node name or a‌ddress</div>
|
|
</div>
|
|
<div>
|
|
<input id="tool-target" type="text" size="40" required list="mesh-nodes">
|
|
<button id="target-swap"><div class="icon updownarrow"></div></button>
|
|
</div>
|
|
</div>
|
|
<div class="cols">
|
|
<div>
|
|
<div class="o">Client A‌ddress</div>
|
|
<div class="m">Node name or a‌ddress</div>
|
|
</div>
|
|
<div>
|
|
<input id="tool-client" type="text" size="40" required value="{{mynode}}" list="mesh-nodes">
|
|
<div id="target-swap-dummy" style="width:42px"></div>
|
|
</div>
|
|
</div>
|
|
<datalist id="mesh-nodes">
|
|
<option value="{{mynode}}">{{mynode}}</option>
|
|
{%
|
|
for (let i = 0; i < length(nodes); i++) {
|
|
if (nodes[i] !== mynode) {
|
|
print(`<option value="${nodes[i]}">${nodes[i]}</option>`);
|
|
}
|
|
}
|
|
%}
|
|
</datalist>
|
|
{{_H("Use iperf3 to measure the bandwidth between a client and a server. The client and server must be nodes on the mesh. By default the client is the current node.")}}
|
|
<div class="cols">
|
|
<div class="tool-console">
|
|
<pre></pre>
|
|
</div>
|
|
<div>
|
|
<button id="tool-start">Go</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{{_R("tool-footer")}}
|
|
<script>
|
|
(function(){
|
|
{{_R("open")}}
|
|
{% if (!request.mobile) { %}
|
|
htmx.find("#tool-target").focus();
|
|
{% } %}
|
|
const mynode = "{{mynode}}";
|
|
htmx.on("#target-swap", "click", _ => {
|
|
const v = htmx.find("#tool-target").value;
|
|
htmx.find("#tool-target").value = htmx.find("#tool-client").value;
|
|
htmx.find("#tool-client").value = v;
|
|
});
|
|
htmx.on("#tool-start", "click", async _ => {
|
|
const server = htmx.find("#tool-target").value;
|
|
const client = htmx.find("#tool-client").value;
|
|
if (server && client) {
|
|
const con = htmx.find(".tool-console pre");
|
|
con.innerText = "";
|
|
function out(line) {
|
|
con.innerText += `${line}\n`;
|
|
}
|
|
out("iperf3 test started");
|
|
out("");
|
|
try {
|
|
const r = await fetch(`http://${client}.local.mesh/cgi-bin/iperf?server=${server}.local.mesh&kill=1&protocol=tcp`);
|
|
const reader = r.body.getReader();
|
|
let state = "BEGIN";
|
|
for (;;) {
|
|
const { done, value } = await reader.read();
|
|
if (done) {
|
|
if (state !== "DONE") {
|
|
out("iperf3 Terminated.");
|
|
}
|
|
break;
|
|
}
|
|
const lines = String.fromCharCode.apply(null, value).split("\n");
|
|
lines.forEach(line => {
|
|
line = line.trim();
|
|
switch (state) {
|
|
case "BEGIN":
|
|
{
|
|
const m = line.match(/<title>(.*)<\/title>/);
|
|
if (m) {
|
|
if (m[1] === "SUCCESS") {
|
|
state = "CONNECTING";
|
|
out(`Client: ${client}`);
|
|
out(`Server: ${server}`);
|
|
out("");
|
|
}
|
|
else {
|
|
state = "ERROR";
|
|
const m = line.match(/<pre>(.*)<\/pre>/);
|
|
if (m) {
|
|
out(`ERROR: ${m[1]}`);
|
|
state = "DONE";
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case "CONNECTING":
|
|
if (line.match(/^Connecting/)) {
|
|
state = "PRINT";
|
|
}
|
|
break;
|
|
case "PRINT":
|
|
if (line) {
|
|
if (line.match(/iperf Done/)) {
|
|
state = "DONE";
|
|
out("");
|
|
out(line);
|
|
out("");
|
|
out(Date().toString());
|
|
}
|
|
else {
|
|
out(line);
|
|
}
|
|
}
|
|
break;
|
|
case "ERROR":
|
|
{
|
|
const m = line.match(/<pre>(.*)<\/pre>/);
|
|
if (m) {
|
|
out(`ERROR: ${m[1]}`);
|
|
state = "DONE";
|
|
}
|
|
break;
|
|
}
|
|
case "DONE":
|
|
default:
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
catch (_) {
|
|
out("iperf3 Failed.");
|
|
}
|
|
}
|
|
});
|
|
})();
|
|
</script>
|
|
</div>
|