mirror of https://github.com/aredn/aredn.git
Make tunnel server name optional if you have no server tunnels (#1688)
* Make tunnel server name optional if yuo have no server tunnels * Do less if we're already invalid
This commit is contained in:
parent
0eeca43e44
commit
bdff952f9b
|
@ -272,11 +272,12 @@ function t2t(type)
|
||||||
<div class="m">DNS name of this tunnel server</div>
|
<div class="m">DNS name of this tunnel server</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="flex:0">
|
<div style="flex:0">
|
||||||
<input hx-put="{{request.env.REQUEST_URI}}" name="tunnel_server" type="text" size="25" required placeholder="DNS name or IP address" value="{{uciMesh.get("vtun", "@network[0]", "dns")}}">
|
<input hx-put="{{request.env.REQUEST_URI}}" name="tunnel_server" type="text" size="25" {{servercount > 0 ? "required": ""}} placeholder="DNS name or IP address" value="{{uciMesh.get("vtun", "@network[0]", "dns")}}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{_H("Set either the hostname or the Internet IP Address for this tunnel server. This is the target for any tunnels
|
{{_H("Set either the hostname or the Internet IP Address for this tunnel server. This is the target for any tunnels
|
||||||
created which will connect to this node (legacy or wireguard).")}}
|
created which will connect to this node (legacy or wireguard). This only needs to be set if you are creating server tunnels.
|
||||||
|
It is not required for client tunnels.")}}
|
||||||
<hr>
|
<hr>
|
||||||
<div id="tunnel-templates" class="cols">
|
<div id="tunnel-templates" class="cols">
|
||||||
<div>
|
<div>
|
||||||
|
@ -379,19 +380,18 @@ This value is used by default, but each tunnel may overide it.
|
||||||
const available = {{sprintf("%J", available)}};
|
const available = {{sprintf("%J", available)}};
|
||||||
function updateTunnels()
|
function updateTunnels()
|
||||||
{
|
{
|
||||||
if (!htmx.closest(htmx.find("#tunnels"), "form").checkValidity()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const tunnels = [];
|
const tunnels = [];
|
||||||
let servercount = 0;
|
let servercount = 0;
|
||||||
const tuns = htmx.findAll("#tunnels .tunnel");
|
const tuns = htmx.findAll("#tunnels .tunnel");
|
||||||
|
const isvalid = htmx.closest(htmx.find("#tunnels"), "form").checkValidity();
|
||||||
for (let i = 0; i < tuns.length; i++) {
|
for (let i = 0; i < tuns.length; i++) {
|
||||||
const t = tuns[i];
|
const t = tuns[i];
|
||||||
|
const type = htmx.find(t, "div[data-type]").dataset.type;
|
||||||
|
if (isvalid) {
|
||||||
const index = t.dataset.index;
|
const index = t.dataset.index;
|
||||||
const name = htmx.find(t, "input[name=name]");
|
const name = htmx.find(t, "input[name=name]");
|
||||||
const password = htmx.find(t, "input[name=password]");
|
const password = htmx.find(t, "input[name=password]");
|
||||||
const key = htmx.find(t, "input[name=key]");
|
const key = htmx.find(t, "input[name=key]");
|
||||||
const type = htmx.find(t, "div[data-type]").dataset.type;
|
|
||||||
const network = htmx.find(t, "input[name=network]");
|
const network = htmx.find(t, "input[name=network]");
|
||||||
const notes = htmx.find(t, "input[name=notes]");
|
const notes = htmx.find(t, "input[name=notes]");
|
||||||
const enable = htmx.find(t, "input[name=enable]");
|
const enable = htmx.find(t, "input[name=enable]");
|
||||||
|
@ -407,14 +407,18 @@ This value is used by default, but each tunnel may overide it.
|
||||||
key: key && key.value,
|
key: key && key.value,
|
||||||
weight: weight.value
|
weight: weight.value
|
||||||
});
|
});
|
||||||
|
}
|
||||||
if (type === "ls" || type === "ws") {
|
if (type === "ls" || type === "ws") {
|
||||||
servercount++;
|
servercount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isvalid) {
|
||||||
htmx.ajax("PUT", "{{request.env.REQUEST_URI}}", {
|
htmx.ajax("PUT", "{{request.env.REQUEST_URI}}", {
|
||||||
swap: "none",
|
swap: "none",
|
||||||
values: { tunnels: JSON.stringify(tunnels) }
|
values: { tunnels: JSON.stringify(tunnels) }
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
htmx.find("input[name=tunnel_server]").required = servercount > 0 ? true : false;
|
||||||
{% if (includeAdvanced) { %}
|
{% if (includeAdvanced) { %}
|
||||||
htmx.find("input[name=tunnel_range_start]").disabled = servercount > 0 ? true : false;
|
htmx.find("input[name=tunnel_range_start]").disabled = servercount > 0 ? true : false;
|
||||||
{% } %}
|
{% } %}
|
||||||
|
@ -551,6 +555,7 @@ This value is used by default, but each tunnel may overide it.
|
||||||
}
|
}
|
||||||
{% } %}
|
{% } %}
|
||||||
htmx.find("#dialog-done").disabled = true;
|
htmx.find("#dialog-done").disabled = true;
|
||||||
|
updateTunnels();
|
||||||
}
|
}
|
||||||
htmx.on("#tunnel-templates button", "click", newTunnelEntry);
|
htmx.on("#tunnel-templates button", "click", newTunnelEntry);
|
||||||
htmx.on("#tunnels", "change", updateTunnels);
|
htmx.on("#tunnels", "change", updateTunnels);
|
||||||
|
|
Loading…
Reference in New Issue