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>
|
||||
<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>
|
||||
{{_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>
|
||||
<div id="tunnel-templates" class="cols">
|
||||
<div>
|
||||
|
@ -379,42 +380,45 @@ This value is used by default, but each tunnel may overide it.
|
|||
const available = {{sprintf("%J", available)}};
|
||||
function updateTunnels()
|
||||
{
|
||||
if (!htmx.closest(htmx.find("#tunnels"), "form").checkValidity()) {
|
||||
return;
|
||||
}
|
||||
const tunnels = [];
|
||||
let servercount = 0;
|
||||
const tuns = htmx.findAll("#tunnels .tunnel");
|
||||
const isvalid = htmx.closest(htmx.find("#tunnels"), "form").checkValidity();
|
||||
for (let i = 0; i < tuns.length; i++) {
|
||||
const t = tuns[i];
|
||||
const index = t.dataset.index;
|
||||
const name = htmx.find(t, "input[name=name]");
|
||||
const password = htmx.find(t, "input[name=password]");
|
||||
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 notes = htmx.find(t, "input[name=notes]");
|
||||
const enable = htmx.find(t, "input[name=enable]");
|
||||
const weight = htmx.find(t, "input[name=weight]");
|
||||
tunnels.push({
|
||||
index: index,
|
||||
type: type,
|
||||
name: name.value,
|
||||
enabled: enable.checked,
|
||||
notes: notes.value || "",
|
||||
network: network.value,
|
||||
passwd: password.value,
|
||||
key: key && key.value,
|
||||
weight: weight.value
|
||||
});
|
||||
if (isvalid) {
|
||||
const index = t.dataset.index;
|
||||
const name = htmx.find(t, "input[name=name]");
|
||||
const password = htmx.find(t, "input[name=password]");
|
||||
const key = htmx.find(t, "input[name=key]");
|
||||
const network = htmx.find(t, "input[name=network]");
|
||||
const notes = htmx.find(t, "input[name=notes]");
|
||||
const enable = htmx.find(t, "input[name=enable]");
|
||||
const weight = htmx.find(t, "input[name=weight]");
|
||||
tunnels.push({
|
||||
index: index,
|
||||
type: type,
|
||||
name: name.value,
|
||||
enabled: enable.checked,
|
||||
notes: notes.value || "",
|
||||
network: network.value,
|
||||
passwd: password.value,
|
||||
key: key && key.value,
|
||||
weight: weight.value
|
||||
});
|
||||
}
|
||||
if (type === "ls" || type === "ws") {
|
||||
servercount++;
|
||||
}
|
||||
}
|
||||
htmx.ajax("PUT", "{{request.env.REQUEST_URI}}", {
|
||||
swap: "none",
|
||||
values: { tunnels: JSON.stringify(tunnels) }
|
||||
});
|
||||
if (isvalid) {
|
||||
htmx.ajax("PUT", "{{request.env.REQUEST_URI}}", {
|
||||
swap: "none",
|
||||
values: { tunnels: JSON.stringify(tunnels) }
|
||||
});
|
||||
}
|
||||
htmx.find("input[name=tunnel_server]").required = servercount > 0 ? true : false;
|
||||
{% if (includeAdvanced) { %}
|
||||
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;
|
||||
updateTunnels();
|
||||
}
|
||||
htmx.on("#tunnel-templates button", "click", newTunnelEntry);
|
||||
htmx.on("#tunnels", "change", updateTunnels);
|
||||
|
|
Loading…
Reference in New Issue