Improve and simplify WAN config (#1539)

* Simplify WAN enable/disable

* Improve
This commit is contained in:
Tim Wilkinson 2024-09-18 19:31:05 -07:00 committed by GitHub
parent 83e852044e
commit 752dfc514b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 51 deletions

View File

@ -108,16 +108,11 @@ if (request.env.REQUEST_METHOD === "PUT") {
configuration.setSetting("dhcp_end", request.args.lan_dhcp_end); configuration.setSetting("dhcp_end", request.args.lan_dhcp_end);
} }
} }
if ("wan_enable" in request.args) {
if (request.args.wan_enable === "off") {
configuration.setSetting("wan_proto", "disabled");
}
else {
configuration.setSetting("wan_proto", "dhcp");
}
}
if ("wan_mode" in request.args) { if ("wan_mode" in request.args) {
if (request.args.wan_mode === "0") { if (request.args.wan_mode === "0") {
configuration.setSetting("wan_proto", "disabled");
}
else if (request.args.wan_mode === "1") {
configuration.setSetting("wan_proto", "dhcp"); configuration.setSetting("wan_proto", "dhcp");
} }
else { else {
@ -299,32 +294,22 @@ const gateway_altnet = dmz_mode === 1 ? dhcp.gateway : "";
</div> </div>
</div> </div>
<hr> <hr>
<div class="hideable" data-hideable='{{wan_proto === "disabled" ? "off" : "on"}}'> <div class="compact hideable" data-hideable='{{wan_proto === "static" ? 2 : wan_proto === "dhcp" ? 1 : 0}}'>
<div class="cols"> <div class="cols">
<div> <div>
<div class="o">WAN Enable</div> <div class="o">WAN Mode</div>
<div class="m">Allow node to directly access the Internet</div> <div class="m">Disabled, static or DHCP mode</div>
</div>
<div style="flex:0">
{{_R("hideable-switch", { name: "wan_enable", value: wan_proto === "disabled" ? false : true })}}
</div>
</div>
{{_H("Enable the WAN interface on this node, to allow it to access the Internet directly.")}}
<div class="compact hideable hideable0" data-hideable='{{wan_proto === "static" ? 1 : 0}}'>
<div class="cols">
<div>
<div class="o">Mode</div>
<div class="m">Static or DHCP mode</div>
</div> </div>
<div style="flex:0"> <div style="flex:0">
<select hx-put="{{request.env.REQUEST_URI}}" hx-swap="none" name="wan_mode" {{_R("hideable-onselect")}}> <select hx-put="{{request.env.REQUEST_URI}}" hx-swap="none" name="wan_mode" {{_R("hideable-onselect")}}>
<option value="0" {{wan_proto !== "static" ? "selected" : ""}}>DHCP</option> <option value="0" {{wan_proto === "disabled" ? "selected" : ""}}>Disabled</option>
<option value="1" {{wan_proto === "static" ? "selected" : ""}}>Static</option> <option value="1" {{wan_proto === "dhcp" ? "selected" : ""}}>DHCP</option>
<option value="2" {{wan_proto === "static" ? "selected" : ""}}>Static</option>
</select> </select>
</div> </div>
</div> </div>
{{_H("The WAN interface can either use DHCP to retrieve an IP address, or it can be set statically.")}} {{_H("The WAN interface can either use DHCP to retrieve an IP address, or it can be set statically.")}}
<div class="hideable1"> <div class="hideable2">
<div class="cols"> <div class="cols">
<div> <div>
<div class="o">A&zwnj;ddress</div> <div class="o">A&zwnj;ddress</div>
@ -357,7 +342,6 @@ const gateway_altnet = dmz_mode === 1 ? dhcp.gateway : "";
{{_H("The default gateway his node should use to access the Internet.")}} {{_H("The default gateway his node should use to access the Internet.")}}
</div> </div>
</div> </div>
</div>
<hr> <hr>
<div class="cols"> <div class="cols">
<div> <div>

View File

@ -237,7 +237,7 @@ end
-- delete some config lines if necessary -- delete some config lines if necessary
if cfg.wan_proto == "dhcp" then if cfg.wan_proto ~= "static" then
deleteme.wan_ip = true deleteme.wan_ip = true
deleteme.wan_gw = true deleteme.wan_gw = true
deleteme.wan_mask = true deleteme.wan_mask = true