2022-02-15 20:07:46 -07:00
#!/usr/bin/lua
--[[
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
Copyright (C) 2021 Tim Wilkinson
Original Perl Copyright (C) 2020 - Darryl Quinn
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(TM) 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
--]]
require("nixio")
require("aredn.hardware")
require("aredn.http")
require("aredn.utils")
aredn.html = require("aredn.html")
require("uci")
aredn.info = require("aredn.info")
local html = aredn.html
local urlprefix
local target = "unknown"
2023-01-24 23:20:55 -07:00
local arch = "unknown"
2022-02-15 20:07:46 -07:00
function defaultPackageRepos(repo)
if not urlprefix then
urlprefix = "http://downloads.arednmesh.org"
local release = "unknown"
for line in io.lines("/etc/openwrt_release")
do
local m = line:match("DISTRIB_RELEASE='(.*)'")
if m then
release = m
end
m = line:match("DISTRIB_TARGET='(.*)'")
if m then
target = m
end
2023-01-24 23:20:55 -07:00
m = line:match("DISTRIB_ARCH='(.*)'")
if m then
arch = m
end
2022-02-15 20:07:46 -07:00
end
2022-12-22 13:22:49 -07:00
local a, b = release:match("^(%d+)%.(%d+)%.")
if a and b then
2022-02-15 20:07:46 -07:00
urlprefix = urlprefix .. "/releases/" .. a .. "/" .. b .. "/" .. release
else
-- nightly
2022-03-05 10:46:57 -07:00
urlprefix = urlprefix .. "/snapshots"
2022-02-15 20:07:46 -07:00
end
end
if repo:match("aredn_core") then
return urlprefix .. "/targets/" .. target .. "/packages"
else
2023-01-24 23:20:55 -07:00
return urlprefix .. "/packages/" .. arch .. "/" .. repo
2022-02-15 20:07:46 -07:00
end
end
local settings = {
{
2022-08-09 20:44:45 -06:00
category = "Link Quality Settings",
key = "aredn.@lqm[0].enable",
type = "boolean",
2022-09-09 08:41:52 -06:00
desc = "Enable <b>Link Quality Management</b><br><br><small>aredn.@lqm[0].enable</small>",
2022-08-09 20:44:45 -06:00
default = "1",
postcallback = "lqm_defaults()",
needreboot = true
2022-02-15 20:07:46 -07:00
},
{
2022-08-09 20:44:45 -06:00
category = "Link Quality Settings",
key = "aredn.@lqm[0].margin_snr",
2022-02-15 20:07:46 -07:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>SNR Margin</b> in dB above Min SNR a signal must reach to be re-activated<br><br><small>aredn.@lqm[0].margin_snr</small>",
2022-08-09 20:44:45 -06:00
default = "1",
condition = "lqm_enabled()"
2022-02-15 20:07:46 -07:00
},
2018-12-11 05:47:36 -07:00
{
2022-08-09 20:44:45 -06:00
category = "Link Quality Settings",
key = "aredn.@lqm[0].min_distance",
2022-02-15 20:07:46 -07:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Min Distance</b> in meters beyond which a neighbor RF link is allowed<br><br><small>aredn.@lqm[0].min_distance</small>",
2022-08-09 20:44:45 -06:00
default = "0",
condition = "lqm_enabled()"
2022-02-15 20:07:46 -07:00
},
{
2022-08-09 20:44:45 -06:00
category = "Link Quality Settings",
key = "aredn.@lqm[0].auto_distance",
2022-02-15 20:07:46 -07:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Default Distance</b> in meters to use when actual distance cannot be calculated<br><br><small>aredn.@lqm[0].auto_distance</small>",
2022-08-09 20:44:45 -06:00
default = "0",
condition = "lqm_enabled()"
2022-02-15 20:07:46 -07:00
},
{
2022-08-09 20:44:45 -06:00
category = "Link Quality Settings",
key = "aredn.@lqm[0].margin_quality",
2022-02-15 20:07:46 -07:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Quality Margin</b> percentage increase before neighbor can be re-activated<br><br><small>aredn.@lqm[0].margin_quality</small>",
2022-08-09 20:44:45 -06:00
default = "1",
condition = "lqm_enabled()"
2022-02-15 20:07:46 -07:00
},
{
2022-08-09 20:44:45 -06:00
category = "Link Quality Settings",
key = "aredn.@lqm[0].ping_penalty",
2022-02-15 20:07:46 -07:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Ping Penalty</b> quality percentage to add when neighbor cannot be pinged<br><br><small>aredn.@lqm[0].ping_penalty</small>",
2022-08-09 20:44:45 -06:00
default = "5",
condition = "lqm_enabled()"
2022-02-15 20:07:46 -07:00
},
2023-01-12 11:31:28 -07:00
{
category = "Link Quality Settings",
2023-02-11 12:44:10 -07:00
key = "aredn.@lqm[0].rts_threshold",
2023-01-12 11:31:28 -07:00
type = "string",
2023-02-11 12:44:10 -07:00
desc = "<b>RTS Threshold</b> in bytes before using RTS/CTS when hidden nodes are detected<br><br><small>aredn.@lqm[0].rts_threshold</small>",
2023-01-19 12:11:30 -07:00
default = "1",
2023-01-12 11:31:28 -07:00
condition = "lqm_enabled()"
},
2023-06-21 22:07:21 -06:00
{
category = "Link Quality Settings",
key = "aredn.@lqm[0].mtu",
type = "string",
desc = "<b>Maximum packet size</b> in bytes sent over WiFi (256 to 1500)<br><br><small>aredn.@lqm[0].mtu</small>",
default = "1500",
postcallback = "changeMTU()",
needreboot = true
},
2022-02-15 20:07:46 -07:00
{
2022-08-09 20:44:45 -06:00
category = "Link Quality Settings",
key = "aredn.@lqm[0].user_blocks",
2022-02-15 20:07:46 -07:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>User Blocked</b> comma-separated list of blocked MACs<br><br><small>aredn.@lqm[0].user_blocks</small>",
2022-08-09 20:44:45 -06:00
default = "",
condition = "lqm_enabled()"
2022-02-15 20:07:46 -07:00
},
{
2022-08-09 20:44:45 -06:00
category = "Link Quality Settings",
key = "aredn.@lqm[0].user_allows",
2022-02-15 20:07:46 -07:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>User Allowed</b> comma-separated list of always allowed MACs<br><br><small>aredn.@lqm[0].user_allows</small>",
2022-08-09 20:44:45 -06:00
default = "",
condition = "lqm_enabled()"
2022-02-15 20:07:46 -07:00
},
2022-08-11 01:19:33 -06:00
{
category = "WAN Settings",
key = "aredn.@wan[0].olsrd_gw",
2022-08-11 09:30:08 -06:00
type = "boolean",
2022-09-09 08:41:52 -06:00
desc = "<b>Allow other MESH nodes to use my WAN</b> - not recommended and OFF by default<br><br><small>aredn.@wan[0].olsrd_gw</small>",
2022-08-11 01:19:33 -06:00
default = "0",
postcallback = "changeWANGW()",
needreboot = true
},
{
category = "WAN Settings",
key = "aredn.@wan[0].lan_dhcp_route",
2022-08-11 09:30:08 -06:00
type = "boolean",
2022-09-09 08:41:52 -06:00
desc = "<b>Allow my LAN devices to access my WAN</b> - ON by default<br><br><small>aredn.@wan[0].lan_dhcp_route</small>",
2022-08-11 01:19:33 -06:00
default = "1",
2022-08-12 14:16:37 -06:00
postcallback = "changeWANGW()",
2022-08-11 01:19:33 -06:00
needreboot = true
},
{
category = "WAN Settings",
key = "aredn.@wan[0].lan_dhcp_defaultroute",
2022-08-11 09:30:08 -06:00
type = "boolean",
2022-09-09 08:41:52 -06:00
desc = "<b>Provide default route to LAN devices</b> even when WAN access is disabled<br><br><small>aredn.@wan[0].lan_dhcp_defaultroute</small>",
2022-08-11 01:19:33 -06:00
default = "0",
2022-08-12 14:16:37 -06:00
postcallback = "changeWANGW()",
2022-08-11 01:19:33 -06:00
needreboot = true
},
2022-02-15 20:07:46 -07:00
{
2022-08-09 20:44:45 -06:00
category = "WAN Settings",
key = "aredn.wan.vlanid",
2022-02-15 20:07:46 -07:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>WAN VLAN Number</b> - must be an integer in the range [1,4094]<br><br><small>aredn.wan.vlanid</small>",
2022-08-09 20:44:45 -06:00
default = "",
condition = "supportsVLANChange()",
current = "currentWANVLAN()",
postcallback = "changeWANVLAN()",
needreboot = true
2022-02-15 20:07:46 -07:00
},
2023-05-29 10:22:09 -06:00
{
category = "WAN Settings",
key = "aredn.@wan[0].web_access",
type = "boolean",
desc = "<b>Enable web access</b> to the node from the WAN interface<br><br><small>aredn.@wan[0].web_access</small>",
2023-07-18 23:52:41 -06:00
default = "1",
2023-05-29 10:22:09 -06:00
needreboot = true
},
{
category = "WAN Settings",
key = "aredn.@wan[0].ssh_access",
type = "boolean",
desc = "<b>Enable SSH access</b> to the node from the WAN interface<br><br><small>aredn.@wan[0].ssh_access</small>",
2023-07-18 23:52:41 -06:00
default = "1",
needreboot = true
},
{
category = "WAN Settings",
key = "aredn.@wan[0].telnet_access",
type = "boolean",
desc = "<b>Enable TELNET access</b> to the node from the WAN interface<br><br><small>aredn.@wan[0].telnet_access</small>",
default = "1",
2023-05-29 10:22:09 -06:00
needreboot = true
},
2022-02-15 20:07:46 -07:00
{
2022-05-06 20:03:03 -06:00
category = "Power Options",
2022-02-15 20:07:46 -07:00
key = "aredn.@poe[0].passthrough",
type = "boolean",
2022-09-09 08:41:52 -06:00
desc = "<b>PoE Passthrough</b> specifies whether PoE power should be enabled (Not all devices have PoE passthrough ports)<br><br><small>aredn.@poe[0].passthrough</small>",
2022-02-15 20:07:46 -07:00
default = "0",
condition = "hasPOE()",
postcallback = "setPOEOutput()"
},
{
2022-05-06 20:03:03 -06:00
category = "Power Options",
2022-02-15 20:07:46 -07:00
key = "aredn.@usb[0].passthrough",
type = "boolean",
2022-09-09 08:41:52 -06:00
desc = "<b>USB Power Passthrough</b> specifies whether USB power should be enabled (Not all devices have USB powered ports)<br><br><small>aredn.@usb[0].passthrough</small>",
2022-02-15 20:07:46 -07:00
default = "1",
postcallback = "setUSBOutput()",
condition = "hasUSB()"
},
{
2022-05-06 20:03:03 -06:00
category = "Tunnel Options",
2022-03-05 10:46:57 -07:00
key = "aredn.@tunnel[0].maxclients",
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Tunnel Maxclients</b> specifies the maximum number of tunnel clients this node can serve; must be an integer in the range [0,100].<br><br><small>aredn.@tunnel[0].maxclients</small>",
2022-03-05 10:46:57 -07:00
default = "10",
2022-02-15 20:07:46 -07:00
precallback = "restrictTunnelLimitToValidRange()",
postcallback = "adjustTunnelInterfaceCount()"
},
{
2022-05-06 20:03:03 -06:00
category = "Tunnel Options",
2022-03-05 10:46:57 -07:00
key = "aredn.@tunnel[0].maxservers",
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Tunnel Maxservers</b> specifies the maximum number of tunnel servers to which this node can connect; must be an integer in the range [0,100].<br><br><small>aredn.@tunnel[0].maxservers</small>",
2022-03-05 10:46:57 -07:00
default = "10",
2022-02-15 20:07:46 -07:00
precallback = "restrictTunnelLimitToValidRange()",
postcallback = "adjustTunnelInterfaceCount()"
},
2023-09-19 21:04:54 -06:00
{
category = "Tunnel Options",
key = "aredn.@tunnel[0].weight",
type = "string",
desc = "<b>Tunnel Weight</b> specifies the cost of using a tunnel. The higher the number, the less likely a tunnel is used.<br><br><small>aredn.@tunnel[0].weighy</small>",
default = "1",
needreboot= true
},
2022-03-20 19:55:11 -06:00
{
2022-05-06 20:03:03 -06:00
category = "Tunnel Options",
2022-03-20 19:55:11 -06:00
key = "aredn.@tunnel[0].wanonly",
type = "boolean",
2022-09-09 08:41:52 -06:00
desc = "<b>WAN-Only Tunnel</b> prevents tunnel traffic from being routed over the Mesh network itself<br><br><small>aredn.@tunnel[0].wanonly</small>",
2022-04-16 17:32:23 -06:00
default = "1",
needreboot= true
2022-03-20 19:55:11 -06:00
},
2022-02-15 20:07:46 -07:00
{
2022-08-09 20:44:45 -06:00
category = "Memory Settings",
2022-02-15 20:07:46 -07:00
key = "aredn.@meshstatus[0].lowmem",
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Low Memory Threshold</b> in KB when the Mesh Status page will be truncated<br><br><small>aredn.@meshstatus[0].lowmem</small>",
2022-02-15 20:07:46 -07:00
default = "10000"
},
{
2022-08-09 20:44:45 -06:00
category = "Memory Settings",
2022-02-15 20:07:46 -07:00
key = "aredn.@meshstatus[0].lowroutes",
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Low Memory Max Routes</b> is the maximum number of routes shown on the Mesh Status page when low memory is detected<br><br><small>aredn.@meshstatus[0].lowroutes</small>",
2022-02-15 20:07:46 -07:00
default = "1000"
},
{
2022-07-25 15:38:18 -06:00
category = "Network Tools",
2022-02-15 20:07:46 -07:00
key = "aredn.olsr.restart",
type = "none",
2022-09-09 08:41:52 -06:00
desc = "<b>OLSR Restart</b> will restart OLSR when executed; wait up to 2 or 3 minutes to receive response<br><br><small>aredn.olsr.restart</small>",
2022-02-15 20:07:46 -07:00
default = "0",
postcallback = "olsr_restart()"
},
2022-07-25 15:38:18 -06:00
{
category = "Network Tools",
key = "aredn.@iperf[0].enable",
type = "boolean",
2022-09-09 08:41:52 -06:00
desc = "<b>IPERF Enable</b> allows the included iperf3 client/server<br><br><small>aredn.@iperf[0].enable</small>",
2022-07-25 15:38:18 -06:00
default = "1"
},
2022-02-15 20:07:46 -07:00
{
2022-08-09 20:44:45 -06:00
category = "Map Paths",
key = "aredn.@map[0].maptiles",
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Map Tiles URL</b><br><br><small>aredn.@map[0].maptiles</small>",
2022-08-09 20:44:45 -06:00
default = "http://stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}.jpg"
2022-02-15 20:07:46 -07:00
},
{
2022-08-09 20:44:45 -06:00
category = "Map Paths",
key = "aredn.@map[0].leafletcss",
2022-02-15 20:07:46 -07:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Leaflet.css URL</b><br><br><small>aredn.@map[0].leafletcss</small>",
2022-08-09 20:44:45 -06:00
default = "http://unpkg.com/leaflet@0.7.7/dist/leaflet.css"
2022-02-15 20:07:46 -07:00
},
2022-03-09 13:21:37 -07:00
{
2022-08-09 20:44:45 -06:00
category = "Map Paths",
key = "aredn.@map[0].leafletjs",
2022-03-09 13:21:37 -07:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Leaflet.js URL</b><br><br><small>aredn.@map[0].leafletjs</small>",
2022-08-09 20:44:45 -06:00
default = "http://unpkg.com/leaflet@0.7.7/dist/leaflet.js"
2022-03-09 13:21:37 -07:00
},
2022-02-15 20:07:46 -07:00
{
2023-03-10 16:39:23 -07:00
category = "Firmware",
2022-08-09 20:44:45 -06:00
key = "aredn.@downloads[0].firmwarepath",
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Firmware Download URL</b><br><br><small>aredn.@downloads[0].firmwarepath</small>",
2022-08-09 20:44:45 -06:00
default = "http://downloads.arednmesh.org/firmware"
2022-04-26 20:08:46 -06:00
},
2022-05-18 11:49:00 -06:00
{
2023-03-10 16:39:23 -07:00
category = "Firmware",
2022-08-09 20:44:45 -06:00
key = "aredn.@downloads[0].pkgs_core",
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Core Packages Download URL</b><br><br><small>aredn.@downloads[0].pkgs_core</small>",
2022-08-09 20:44:45 -06:00
default = defaultPackageRepos('aredn_core'),
postcallback = "writePackageRepo('core')"
2022-05-18 11:49:00 -06:00
},
{
2023-03-10 16:39:23 -07:00
category = "Firmware",
2022-08-09 20:44:45 -06:00
key = "aredn.@downloads[0].pkgs_base",
2022-05-18 11:49:00 -06:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Base Packages URL</b><br><br><small>aredn.@downloads[0].pkgs_base</small>",
2022-08-09 20:44:45 -06:00
default = defaultPackageRepos('base'),
postcallback = "writePackageRepo('base')"
2022-05-18 11:49:00 -06:00
},
{
2023-03-10 16:39:23 -07:00
category = "Firmware",
2022-08-09 20:44:45 -06:00
key = "aredn.@downloads[0].pkgs_arednpackages",
2022-05-18 11:49:00 -06:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>AREDN Packages URL</b><br><br><small>aredn.@downloads[0].pkgs_arednpackages</small>",
2022-08-09 20:44:45 -06:00
default = defaultPackageRepos('arednpackages'),
postcallback = "writePackageRepo('arednpackages')"
2022-05-18 11:49:00 -06:00
},
2022-06-27 15:31:43 -06:00
{
2023-03-10 16:39:23 -07:00
category = "Firmware",
2022-08-09 20:44:45 -06:00
key = "aredn.@downloads[0].pkgs_luci",
2022-06-27 15:31:43 -06:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Luci Packages URL</b><br><br><small>aredn.@downloads[0].pkgs_luci</small>",
2022-08-09 20:44:45 -06:00
default = defaultPackageRepos('luci'),
postcallback = "writePackageRepo('luci')"
2022-06-27 15:31:43 -06:00
},
2022-05-18 11:49:00 -06:00
{
2023-03-10 16:39:23 -07:00
category = "Firmware",
2022-08-09 20:44:45 -06:00
key = "aredn.@downloads[0].pkgs_packages",
2022-05-18 11:49:00 -06:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Package Download URL</b> for packages not included in the other sections<br><br><small>aredn.@downloads[0].pkgs_packages</small>",
2022-08-09 20:44:45 -06:00
default = defaultPackageRepos('packages'),
postcallback = "writePackageRepo('packages')"
2022-05-18 11:49:00 -06:00
},
{
2023-03-10 16:39:23 -07:00
category = "Firmware",
2022-08-09 20:44:45 -06:00
key = "aredn.@downloads[0].pkgs_routing",
2022-05-18 11:49:00 -06:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Routing Packages URL</b><br><br><small>aredn.@downloads[0].pkgs_routing</small>",
2022-08-09 20:44:45 -06:00
default = defaultPackageRepos('routing'),
postcallback = "writePackageRepo('routing')"
2022-05-18 11:49:00 -06:00
},
{
2023-03-10 16:39:23 -07:00
category = "Firmware",
2022-08-09 20:44:45 -06:00
key = "aredn.@downloads[0].pkgs_telephony",
2022-05-18 11:49:00 -06:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Telephony Packages URL</b><br><br><small>aredn.@downloads[0].pkgs_telephony</small>",
2022-08-09 20:44:45 -06:00
default = defaultPackageRepos('telephony'),
postcallback = "writePackageRepo('telephony')"
2022-06-12 22:01:12 -06:00
},
{
2023-03-10 16:39:23 -07:00
category = "Firmware",
2022-08-09 20:44:45 -06:00
key = "aredn.@downloads[0].pkgs_freifunk",
2022-06-12 22:01:12 -06:00
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Freifunk Packages URL</b><br><br><small>aredn.@downloads[0].pkgs_freifunk</small>",
2022-08-09 20:44:45 -06:00
default = defaultPackageRepos('freifunk'),
postcallback = "writePackageRepo('freifunk')"
},
2023-03-10 16:39:23 -07:00
{
category = "Firmware",
key = "aredn.firmware.dangerous_upgrade",
type = "boolean",
desc = "<b>Dangerous Upgrade Disables</b> all safety checks usually applied when upgrading firmware<br><br><small>aredn.firmware.dangerous_upgrade</small>",
default = "0",
current = "current_force_upgrade()",
postcallback = "update_force_upgrade()"
},
2022-08-09 20:44:45 -06:00
{
category = "AREDN Alert Settings",
key = "aredn.aam.refresh",
type = "none",
2022-09-09 08:41:52 -06:00
desc = "<b>Alert Message Refresh</b> - Execute to pull any AREDN Alert messages<br><br><small>aredn.aam.refresh</small>",
2022-08-09 20:44:45 -06:00
default = "0",
postcallback = "aam_refresh()"
},
{
category = "AREDN Alert Settings",
key = "aredn.@alerts[0].localpath",
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Alert Message Local URL</b> - location from which local AREDN Alerts can be downloaded<br><br><small>aredn.@alerts[0].localpath</small>",
2022-08-09 20:44:45 -06:00
default = ""
},
2023-07-08 23:09:02 -06:00
{
category = "AREDN Alert Settings",
key = "aredn.@alerts[0].groups",
type = "string",
desc = "<b>Alert Message Groups</b> - comma seperated list of group names to check for alert messages<br><br><small>aredn.@alerts[0].groups</small>",
default = ""
},
2022-08-09 20:44:45 -06:00
{
category = "AREDN Alert Settings",
key = "aredn.@alerts[0].pollrate",
type = "string",
2022-09-09 08:41:52 -06:00
desc = "<b>Alert Message Pollrate</b> - how many hours to wait between polling for new AREDN Alerts<br><br><small>aredn.@alerts[0].pollrate</small>",
2022-08-09 20:44:45 -06:00
default = "12",
needreboot = true
},
{
category = "AREDN Alert Settings",
key = "aredn.aam.purge",
type = "none",
2022-09-09 08:41:52 -06:00
desc = "<b>Alert Message Purge</b> - execute to immediately delete all alerts from this node<br><br><small>aredn.aam.purge</small>",
2022-06-12 22:01:12 -06:00
default = "",
2022-08-09 20:44:45 -06:00
postcallback = "alert_purge()"
2022-06-12 22:01:12 -06:00
}
2018-10-25 20:06:05 -06:00
}
2022-02-15 20:07:46 -07:00
local msgs = {}
--
-- helpers
--
function msg(m)
msgs[#msgs + 1] = m
end
2022-02-28 13:38:05 -07:00
-- uci cursor
2022-03-04 19:57:16 -07:00
local cursora = uci.cursor()
local cursorb = uci.cursor("/etc/config.mesh")
2022-02-28 13:38:05 -07:00
function cursor_set(a, b, c, d)
2022-03-03 16:03:08 -07:00
if not cursora:get(a, b) and b:match("@(.+)%[0%]") then
cursora:add(a, b:match("@(.+)%[0%]"))
end
2022-02-28 13:38:05 -07:00
cursora:set(a, b, c, d)
2022-03-03 16:03:08 -07:00
if not cursorb:get(a, b) and b:match("@(.+)%[0%]") then
cursorb:add(a, b:match("@(.+)%[0%]"))
end
2022-02-28 13:38:05 -07:00
cursorb:set(a, b, c, d)
cursora:commit(a)
cursorb:commit(a)
end
function cursor_add(a, b, c)
cursora:set(a, b, c)
cursorb:set(a, b, c)
cursora:commit(a)
cursorb:commit(a)
end
function cursor_delete(a, b)
cursora:delete(a, b)
cursorb:delete(a, b)
cursora:commit(a)
cursorb:commit(a)
end
function cursor_get(a, b, c)
return cursora:get(a, b, c)
end
2022-02-15 20:07:46 -07:00
function reboot()
local node = aredn.info.get_nvram("node")
if node == "" then
node = "Node"
end
local lanip, _, lanmask = aredn.hardware.get_interface_ip4(aredn.hardware.get_iface_name("lan"))
local browser = os.getenv("REMOTE_ADDR")
local browser6 = browser:match("::ffff:([%d%.]+)")
if browser6 then
browser = browser6
end
local fromlan = false
local subnet_change = false
if lanip then
fromlan = validate_same_subnet(browser, lanip, lanmask)
if fromlan then
lanmask = ip_to_decimal(lanmask)
local cfgip = cursor_get("network", "lan", "ipaddr")
local cfgmask = ip_to_decimal(cursor_get("network", "lan", "netmask"))
2022-03-06 17:15:07 -07:00
if lanmask ~= cfgmask or nixio.bit.band(ip_to_decimal(lanip), lanmask) ~= nixio.bit.band(ip_to_decimal(cfgip), cfgmask) then
2022-02-15 20:07:46 -07:00
subnet_change = true
end
end
end
http_header()
if fromlan and subnet_change then
html.header(node .. " rebooting", true)
html.print("<body><center>")
html.print("<h1>" .. node .. " is rebooting</h1><br>")
html.print("<h3>The LAN subnet has changed. You will need to acquire a new DHCP lease<br>")
html.print("and reset any name service caches you may be using.</h3><br>")
html.print("<h3>When the node reboots you get your new DHCP lease and reconnect with<br>")
html.print("<a href='http://localnode.local.mesh:8080/'>http://localnode.local.mesh:8080/</a><br>or<br>")
html.print("<a href='http://" .. node .. ".local.mesh:8080/'>http://" .. node .. ".local.mesh:8080/</a></h3>")
else
html.header(node .. " rebooting", false)
html.print("<meta http-equiv='refresh' content='60;url=/cgi-bin/status'>")
html.print("</head><body><center>")
html.print("<h1>" .. node .. " is rebooting</h1><br>")
html.print("<h3>Your browser should return to this node in 60 seconds.</br><br>")
html.print("If something goes astray you can try to connect with<br><br>")
html.print("<a href='http://localnode.local.mesh:8080/'>http://localnode.local.mesh:8080/</a><br>")
if node ~= "Node" then
html.print("or<br><a href='http://" .. node .. ".local.mesh:8080/'>http://" .. node .. ".local.mesh:8080/</a></h3>")
end
end
html.print("</center></body></html>")
http_footer()
2022-12-22 13:22:49 -07:00
os.execute("reboot >/dev/null 2>&1")
2022-02-15 20:07:46 -07:00
os.exit()
end
-- conditionals
function hasPOE()
return aredn.hardware.has_poe()
end
function hasUSB()
return aredn.hardware.has_usb()
end
2022-04-16 22:34:57 -06:00
function supportsVLANChange()
2023-05-16 20:29:20 -06:00
-- If we support advanced networking, we dont provide this option here
local board = aredn.hardware.get_board_type()
if board == "mikrotik,hap-ac2" or board == "mikrotik,hap-ac3" then
return false
end
2022-04-16 22:34:57 -06:00
local stat = nixio.fs.stat("/etc/aredn_include/swconfig")
2022-07-25 11:02:42 -06:00
-- We always support VLAN changing on devices without switches
if not (stat and stat.size > 0) then
return true
end
2022-07-25 14:55:56 -06:00
-- We also support VLAN changing on hAP, A750 and AR150 as WAN is on it's own ethernet port
local type = aredn.hardware.get_type()
2023-01-08 15:57:45 -07:00
if type == "rb-952ui-5ac2nd" or type == "routerboard-952ui-5ac2nd" or type == "gl-ar750" then
2022-07-25 11:02:42 -06:00
return true
end
-- Otherwise
return false
2022-04-16 22:34:57 -06:00
end
2022-02-15 20:07:46 -07:00
-- callbacks
local newval
local key
function setPOEOutput()
if not newval then
newval = 0
end
os.execute("/usr/local/bin/poe_passthrough " .. newval)
end
function setUSBOutput()
if not newval then
newval = 0
end
os.execute("/usr/local/bin/usb_passthrough " .. newval)
end
function olsr_restart()
os.execute("/etc/init.d/olsrd restart")
end
function aam_refresh()
os.execute("/usr/local/bin/aredn_message.sh")
end
function alert_purge()
os.remove("/tmp/aredn_message")
os.remove("/tmp/local_message")
end
2022-05-18 11:49:00 -06:00
function lqm_enabled()
return cursor_get("aredn", "@lqm[0]", "enable") == "1"
end
function lqm_defaults()
cursor_set("aredn", "@lqm[0]", "min_snr", "15")
cursor_set("aredn", "@lqm[0]", "margin_snr", "1")
cursor_set("aredn", "@lqm[0]", "min_distance", "0")
2022-06-27 15:31:43 -06:00
cursor_set("aredn", "@lqm[0]", "auto_distance", "0")
2022-05-18 11:49:00 -06:00
cursor_set("aredn", "@lqm[0]", "max_distance", "80467")
cursor_set("aredn", "@lqm[0]", "min_quality", "50")
2022-05-20 07:10:01 -06:00
cursor_set("aredn", "@lqm[0]", "ping_penalty", "5")
2022-05-18 11:49:00 -06:00
cursor_set("aredn", "@lqm[0]", "margin_quality", "1")
end
2023-03-10 16:39:23 -07:00
function current_force_upgrade()
return nixio.fs.stat("/tmp/force-upgrade-this-is-dangerous") and 1 or 0
end
function update_force_upgrade()
if not newval or newval ~= "1" then
nixio.fs.remove("/tmp/force-upgrade-this-is-dangerous")
else
io.open("/tmp/force-upgrade-this-is-dangerous", "w+"):close()
end
end
2022-02-15 20:07:46 -07:00
function writePackageRepo(repo)
2022-03-03 16:03:08 -07:00
local uciurl = cursor_get("aredn", "@downloads[0]", "pkgs_" .. repo)
local disturl = capture("grep aredn_" .. repo .. " /etc/opkg/distfeeds.conf | cut -d' ' -f3")
if uciurl and disturl ~= "" then
os.execute("sed -i 's|" .. disturl:chomp() .. "|" .. uciurl:chomp() .. "|g' /etc/opkg/distfeeds.conf")
end
2022-02-15 20:07:46 -07:00
end
function restrictTunnelLimitToValidRange()
newval = tonumber(newval)
if not newval then
msg(key .. " must be an interger in the range [0,100]")
newval = 0
elseif newval < 0 then
msg("Lower limit of " .. key .. " is 0")
newval = 0
elseif newval > 100 then
msg("Upper limit of " .. key .. " is 100")
newval = 100
end
end
function addTunnelInterface(file, tunnum)
local section = "tun" .. tunnum
cursor_add(file, section, "interface")
cursor_set(file, section, "ifname", section)
cursor_set(file, section, "proto", "none")
end
function deleteTunnelInterface(file, tunnum)
local section = "tun" .. tunnum
cursor_delete(file, section)
end
function adjustTunnelInterfaceCount()
local tunnel_if_count = 0
cursora:foreach('network_tun', 'interface', function(s) tunnel_if_count = tunnel_if_count + 1 end)
2022-03-03 16:03:08 -07:00
local maxclients = cursor_get("aredn", "@tunnel[0]", "maxclients")
2022-02-15 20:07:46 -07:00
if not maxclients then
maxclients = 10
end
2022-03-03 16:03:08 -07:00
local maxservers = cursor_get("aredn", "@tunnel[0]", "maxservers")
2022-02-15 20:07:46 -07:00
if not maxservers then
maxservers = 10
end
local needed_if_count = maxclients + maxservers
if tunnel_if_count ~= needed_if_count then
for i = tunnel_if_count,needed_if_count-1
do
local tunnum = 50 + i
addTunnelInterface("network_tun", tunnum)
addTunnelInterface("network", tunnum)
end
for i = tunnel_if_count-1,needed_if_count,-1
do
local tunnum = 50 + i
deleteTunnelInterface("network_tun", tunnum)
deleteTunnelInterface("network", tunnum)
end
-- can't clone network because it contains macros; re-edit it instead
2022-03-05 10:46:57 -07:00
os.execute("sed -i -e '$r /etc/config.mesh/network_tun' -e '/interface.*tun',$d' /etc/config.mesh/network")
2022-02-15 20:07:46 -07:00
end
end
2022-04-17 14:41:34 -06:00
function currentWANVLAN()
for line in io.lines("/etc/config.mesh/_setup")
do
2022-12-22 13:22:49 -07:00
local vlan = line:match("^wan_intf = %w+%.(%d+)")
2022-04-17 14:41:34 -06:00
if vlan then
return vlan
end
end
2022-12-22 13:22:49 -07:00
local vlan = aredn.hardware.get_board_network_ifname("wan"):match("^%w+%.(%d+)")
2022-04-17 14:41:34 -06:00
if vlan then
return vlan
end
return ""
end
function changeWANVLAN()
2022-04-16 17:32:23 -06:00
local lines = {}
for line in io.lines("/etc/config.mesh/_setup")
do
if not line:match("^wan_intf = ") then
lines[#lines + 1] = line
end
end
if newval ~= "" then
2022-04-17 14:41:34 -06:00
local wan_intf = ""
2022-12-22 13:22:49 -07:00
for dev in aredn.hardware.get_board_network_ifname("wan"):gmatch("%S+")
2022-04-17 14:41:34 -06:00
do
wan_intf = wan_intf .. " " .. dev:match("^([^%.]+)") .. "." .. newval
end
if wan_intf ~= "" then
lines[#lines + 1] = "wan_intf =" .. wan_intf
end
2022-04-16 17:32:23 -06:00
end
local f = io.open("/etc/config.mesh/_setup", "w")
if f then
for _, line in ipairs(lines)
do
f:write(line .. "\n")
end
f:close()
end
os.execute("/usr/local/bin/node-setup -a mesh")
end
2022-08-11 01:19:33 -06:00
function changeWANGW()
os.execute("/usr/local/bin/node-setup -a mesh")
end
2023-06-21 22:07:21 -06:00
function changeMTU()
os.execute("/usr/local/bin/node-setup -a mesh")
end
2022-02-15 20:07:46 -07:00
-- read_postdata
local parms = {}
if os.getenv("REQUEST_METHOD") == "POST" then
require('luci.http')
2022-12-22 13:22:49 -07:00
local request = luci.http.Request(nixio.getenv(),
2022-02-15 20:07:46 -07:00
function()
local v = io.read(1024)
if not v then
io.close()
end
return v
end
)
parms = request:formvalue()
end
if parms.button_firstboot then
os.execute("firstboot -y")
end
if parms.button_firstboot or parms.button_reboot then
reboot()
end
local node = aredn.info.get_nvram("node")
for i, setting in ipairs(settings)
do
if parms["button_save_" .. i] then
newval = parms["newval_" .. i]
2022-03-05 16:31:44 -07:00
if not newval then
newval = ""
else
newval = newval:gsub("^%s+", ""):gsub("%s+$", "")
end
2022-02-15 20:07:46 -07:00
if setting.type == "boolean" then
if newval == "1" or newval == "true" then
newval = "1"
else
newval = "0"
end
end
key = setting.key
if setting.precallback then
loadstring(setting.precallback)()
end
local a, b, c = setting.key:match("(.+)%.(.+)%.(.*)")
cursor_set(a, b, c, newval)
msg("Changed " .. key)
if setting.postcallback then
loadstring(setting.postcallback)()
end
2022-04-16 17:32:23 -06:00
if setting.needreboot then
io.open("/tmp/reboot-required", "w"):close()
end
2022-02-15 20:07:46 -07:00
break
end
end
-- generate the page
http_header()
html.header(node .. " Advanced Configuration", false)
html.print([[
2020-08-26 17:34:30 -06:00
<style>
2022-11-01 08:49:14 -06:00
th {
padding:5px;
}
.brsm {
display:block;
margin-top:0.5em;
margin-bottom:0.5em;
}
#settings tr:hover {
background-color:gainsboro;
}
2022-02-15 20:07:46 -07:00
/* The switch - the box around the slider */
2020-08-26 17:34:30 -06:00
.switch {
2022-02-15 20:07:46 -07:00
position: relative;
display: inline-block;
2022-03-22 05:33:00 -06:00
vertical-align:middle;
width: 48px;
height: 20px;
2020-08-26 17:34:30 -06:00
}
/* Hide default HTML checkbox */
.switch input {
2022-02-15 20:07:46 -07:00
opacity: 0;
width: 0;
height: 0;
2020-08-26 17:34:30 -06:00
}
/* The slider */
.slider {
2022-02-15 20:07:46 -07:00
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
2020-08-26 17:34:30 -06:00
}
.slider:before {
2022-02-15 20:07:46 -07:00
position: absolute;
content: "";
2022-03-22 05:33:00 -06:00
height: 13px;
width: 13px;
2022-02-15 20:07:46 -07:00
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
2020-08-26 17:34:30 -06:00
}
input:checked + .slider {
2022-02-15 20:07:46 -07:00
background-color: #2196F3;
2020-08-26 17:34:30 -06:00
}
input:focus + .slider {
2022-02-15 20:07:46 -07:00
box-shadow: 0 0 1px #2196F3;
2020-08-26 17:34:30 -06:00
}
input:checked + .slider:before {
2022-02-15 20:07:46 -07:00
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
2020-08-26 17:34:30 -06:00
}
/* Rounded sliders */
.slider.round {
2022-02-15 20:07:46 -07:00
border-radius: 34px;
2020-08-26 17:34:30 -06:00
}
.slider.round:before {
2022-02-15 20:07:46 -07:00
border-radius: 50%;
2021-03-27 10:28:17 -06:00
}
2020-08-26 17:34:30 -06:00
</style>
<script>
function toggleDefault(fname, defval) {
2022-02-15 20:07:46 -07:00
if(document.getElementById(fname).checked) {
2020-08-26 17:34:30 -06:00
cval = '1'
2022-02-15 20:07:46 -07:00
} else {
2020-08-26 17:34:30 -06:00
cval = '0'
2022-02-15 20:07:46 -07:00
}
if(cval != defval) {
2020-08-26 17:34:30 -06:00
document.getElementById(fname).click();
2022-02-15 20:07:46 -07:00
}
return true;
2020-08-26 17:34:30 -06:00
}
</script>
</head>
2022-02-15 20:07:46 -07:00
]])
html.print("<body><center>")
html.alert_banner();
2022-09-09 08:41:52 -06:00
html.print("<form method=post action=advancedconfig enctype='multipart/form-data'>")
2022-02-15 20:07:46 -07:00
-- navbar
2023-04-25 21:07:19 -06:00
html.navbar_admin("advancedconfig")
2022-09-09 08:41:52 -06:00
-- help link and buttons table
2022-11-01 08:49:14 -06:00
html.print("<table width=800px><tr align=center><td>")
html.print("<a href='/help.html#advancedconfig' target='_blank'>Help</a>")
html.print(" <input type=submit name=button_reboot value=Reboot style='font-weight:bold' title='Immediately reboot this node'>")
html.print(" <input type=submit name=button_firstboot value='Reset to Firstboot' onclick=\"return confirm('All config settings and add-on packages will be lost back to first boot state. Continue?')\" title='Reset this node to the initial/firstboot status and reboot.'>")
html.print("</td></tr></table>")
2022-09-09 08:41:52 -06:00
2023-04-25 21:07:19 -06:00
html.print("<div style='margin:10px;padding:5px;background-color:#FF0000;color:#FFFFFF;width:650px;'>")
html.print("<strong>WARNING:</strong> Changing advanced settings can be harmful to the stability, security, and performance of this node and potentially the entire mesh network.<br><strong>You should only continue if you are sure of what you are doing.</strong></div>")
2022-09-09 08:41:52 -06:00
-- messages table
html.print("<table width=800px>")
2022-04-16 17:32:23 -06:00
if nixio.fs.stat("/tmp/reboot-required") then
2022-09-09 08:41:52 -06:00
html.print("<tr align=center><td width=100%><h3>Reboot is required for changes to take effect</h3></td></tr>")
2022-04-16 17:32:23 -06:00
end
2022-02-15 20:07:46 -07:00
for _, m in ipairs(msgs)
do
2022-09-09 08:41:52 -06:00
html.print("<tr align=center><td width=100%><strong>" .. m .. "</strong></td></tr>")
2022-02-15 20:07:46 -07:00
end
2022-09-09 08:41:52 -06:00
html.print("</table><br />")
2022-02-15 20:07:46 -07:00
2022-09-09 08:41:52 -06:00
-- advanced configuration settings table
2022-02-15 20:07:46 -07:00
html.print([[
2022-11-01 08:49:14 -06:00
<table id=settings border=1 style='border-collapse:collapse;' width=800px>
2022-02-15 20:07:46 -07:00
<thead>
2022-09-09 08:41:52 -06:00
<tr align=center>
<th>Setting</th>
2022-02-15 20:07:46 -07:00
<th>Value</th>
<th>Actions</th>
</tr>
</thead>
]])
-- settings
2022-09-09 08:41:52 -06:00
html.print("<tbody>")
2022-05-06 20:03:03 -06:00
local prior_category = ""
2022-02-15 20:07:46 -07:00
for i, setting in ipairs(settings)
do
if not setting.condition or loadstring("return " .. setting.condition)() then
2022-04-17 14:41:34 -06:00
local sval
if setting.current then
sval = loadstring("return " .. setting.current)()
else
local a, b, c = setting.key:match("(.+)%.(.+)%.(.*)")
sval = cursor_get(a, b, c)
end
2022-03-03 16:03:08 -07:00
sval = sval and tostring(sval) or ""
2022-05-06 20:03:03 -06:00
if setting.category ~= prior_category then
2022-09-09 08:41:52 -06:00
html.print([[<tr align=center style=background-color:lightseagreen><td colspan=3><b>]] .. setting.category .. [[</b></td></tr>]])
2022-05-06 20:03:03 -06:00
prior_category = setting.category
end
2022-09-09 08:41:52 -06:00
html.print("<tr><td width=40%>" .. setting.desc .. "</td>")
html.print("<td width=45%>")
2022-02-15 20:07:46 -07:00
if setting.type == "string" then
2022-09-09 08:41:52 -06:00
html.print("<input type='text' id='field_" .. i .. "' name='newval_" .. i .. "' style='width:100%' value='" .. sval .. "'>")
2022-03-20 19:55:11 -06:00
elseif setting.type == "boolean" then
if sval == "" then
sval = setting.default
end
if sval == "1" then
html.print("OFF<label class='switch'><input type='checkbox' id='field_" .. i .. "' name='newval_" .. i .."' value='1' checked><span class='slider round'></span></label>ON")
else
html.print("OFF<label class='switch'><input type='checkbox' id='field_" .. i .. "' name='newval_" .. i .. "' value='1'><span class='slider round'></span></label>ON")
end
2022-02-15 20:07:46 -07:00
elseif setting.type == "none" then
html.print("Click EXECUTE button to trigger this action<input type='hidden' id='field_" .. i .. "' name='newval_" .. i .."' value='" .. sval .."'>")
end
html.print("</td>")
if setting.type ~= "none" then
2022-11-01 08:49:14 -06:00
html.print("<td align='center' width=15%><span class=brsm /><input type='submit' name='button_save_" .. i .. "' value='Save Setting' /><br><span class=brsm />")
2022-02-15 20:07:46 -07:00
else
2022-11-01 08:49:14 -06:00
html.print("<td align='center' width=15%><span style='vertical-align:middle;'><input type='submit' name='button_save_" .. i .. "' value='Execute' /><span>")
2022-02-15 20:07:46 -07:00
end
if setting.type == "string" then
html.print("<input value='Set to Default' type='button' onclick=\"document.getElementById('field_" .. i .. "').value='" .. setting.default .. "';\">")
elseif setting.type == "boolean" then
html.print("<input value='Set to Default' type='button' onclick=\"return toggleDefault('field_" .. i .. "', '" .. setting.default .. "' );\">")
end
html.print("</td></tr>")
end
end
2022-09-09 08:41:52 -06:00
html.print("</tbody></table></form></center>")
2022-02-15 20:07:46 -07:00
html.footer()
html.print("</body></html>")
http_footer()