2022-02-22 18:25:01 -07:00
#!/usr/bin/lua
--[[
2024-05-29 01:45:25 -06:00
Part of AREDN® -- Used for creating Amateur Radio Emergency Data Networks
2022-02-22 18:25:01 -07:00
Copyright (C) 2021 Tim Wilkinson
Original Perl Copyright (C) 2019 Joe Ayers AE6XE
Original Perl Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
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:
2024-05-29 01:45:25 -06:00
Additional use restrictions exist on the AREDN® trademark and logo.
2022-02-22 18:25:01 -07:00
See AREDNLicense.txt for more info.
2024-05-29 01:45:25 -06:00
Attributions to the AREDN® Project must be retained in the source code.
2022-02-22 18:25:01 -07:00
If importing this code into a new or existing project attribution
2024-05-29 01:45:25 -06:00
to the AREDN® project must be added to the source code.
2022-02-22 18:25:01 -07:00
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.http")
require("aredn.utils")
require("aredn.hardware")
require("uci")
2023-12-17 17:20:41 -07:00
require('luci.http')
2022-02-22 18:25:01 -07:00
local html = require("aredn.html")
2024-04-01 23:15:45 -06:00
require("aredn.info")
2022-02-22 18:25:01 -07:00
local errors = {}
local output = {}
local hidden = {}
2022-03-03 17:06:26 -07:00
-- uci cursor
local cursor = uci.cursor()
2022-02-22 18:25:01 -07:00
-- helpers start
function capture_and_match(cmd, pattern)
local f = io.popen(cmd)
if f then
for line in f:lines()
do
local r = line:match(pattern)
if r then
f:close()
return r
end
end
f:close()
end
end
function err(str)
errors[#errors + 1] = str
end
function out(str)
output[#output + 1] = str
end
2022-07-22 17:49:58 -06:00
function validate_hostname(raw_name, name_type)
local trimmed_name = raw_name:match("^%s*(.-)%s*$")
if trimmed_name == "" then
if name_type == "node" then
err("you must set the node name")
end
-- A missing tactical name is not an error
else
local hostname = trimmed_name:match("^%f[%w]([-%w]+)%f[%W]$") -- RFC 1123 + RFC 952
if not hostname then
err(string.format('"%s" is not a valid %s name; only alphanumerics and internal hyphens are allowed', trimmed_name, name_type))
elseif string.len(hostname) > 63 then
err(string.format('%s name "%s" exceeds 63 characters', name_type, hostname)) -- RFC 2181
else
return hostname
end
end
return ""
end
2022-02-22 18:25:01 -07:00
-- helper end
-- timezones
local tz_db_names = {}
for line in io.lines("/etc/zoneinfo")
do
2022-03-01 22:40:11 -07:00
local name, tz = line:match("^(.*)\t(.*)")
tz_db_names[#tz_db_names + 1] = { name = name, tz = tz }
2022-02-22 18:25:01 -07:00
end
-- online ping
local pingOK = false
if capture_and_match("ping -W1 -c1 8.8.8.8", "1 packets received") then
pingOK = true
end
2022-03-01 07:19:19 -07:00
-- must be global not local
dmz_lan_ip = ""
dmz_lan_mask = ""
lan_gw = ""
wan_ip = ""
wan_mask = ""
wan_gw = ""
passwd1 = ""
passwd2 = ""
2023-05-25 22:27:59 -06:00
wifi_intf = ""
2022-02-22 18:25:01 -07:00
2023-12-06 11:12:11 -07:00
local phycount = aredn.hardware.get_radio_count()
2023-04-22 07:24:20 -06:00
local radio_name = (aredn.hardware.get_radio() or {}).name or ""
2023-02-19 00:09:23 -07:00
local M9model = radio_name:match("M9")
local M3model = radio_name:match("M3")
local M39model = M9model or M3model
2022-02-22 18:25:01 -07:00
-- post_data
local parms = {}
local has_parms = false
if os.getenv("REQUEST_METHOD") == "POST" then
2022-12-22 13:22:49 -07:00
local request = luci.http.Request(nixio.getenv(),
2022-02-22 18:25:01 -07:00
function()
local v = io.read(1024)
if not v then
io.close()
end
return v
end
)
parms = request:formvalue()
for _,_ in pairs(parms)
do
has_parms = true
break
end
end
if parms.button_uploaddata then
local si = capture("curl 'http://localnode:8080/cgi-bin/sysinfo.json?hosts=1' 2>/dev/null"):chomp()
-- strip closing }
2022-03-18 18:42:20 -06:00
si = si:sub(1, #si - 1)
2022-02-22 18:25:01 -07:00
-- get olsrd topo information
2022-03-18 18:42:20 -06:00
local topo = capture("curl 'http://localnode:9090/links' 2>/dev/null"):chomp()
2022-02-22 18:25:01 -07:00
-- add topo subdoc and close root doc
local newsi = string.format("%s,\"olsr\": %s}", si, topo)
-- PUT it to the server
2022-06-22 12:57:16 -06:00
local upcurl = os.execute("curl -f -H 'Accept: application/json' -X PUT -d '" .. newsi .. "' http://data.arednmesh.org/sysinfo >/dev/null 2>&1")
2022-02-22 18:25:01 -07:00
if upcurl == 0 then
out("AREDN online map updated")
else
2022-06-22 12:57:16 -06:00
err("ERROR: Cannot update online map.");
2022-02-22 18:25:01 -07:00
end
end
if parms.button_default then
2024-04-01 23:15:45 -06:00
local node = aredn.info.get_nvram("node")
local mac2 = aredn.info.get_nvram("mac2")
local dtdmac = aredn.info.get_nvram("dtdmac")
2022-02-22 18:25:01 -07:00
for line in io.lines("/etc/config.mesh/_setup.default")
do
if not (line:match("^%s*#") or line:match("^%s*$")) then
line = line:gsub("<NODE>", node):gsub("<MAC2>", mac2):gsub("<DTDMAC>", dtdmac)
local k, v = line:match("^([^%s]*)%s*=%s*(.*)%s*$")
_G[k] = v
end
end
2013-11-14 23:11:16 -07:00
else
2022-02-22 18:25:01 -07:00
for k, v in pairs(parms)
do
if k:match("^%w+") then
v = v:gsub("^%s+", ""):gsub("%s+$", "")
_G[k] = v
end
end
if parms.button_reset or not has_parms then
2024-04-01 23:15:45 -06:00
local node = aredn.info.get_nvram("node")
local mac2 = aredn.info.get_nvram("mac2")
local dtdmac = aredn.info.get_nvram("dtdmac")
2022-02-22 18:25:01 -07:00
for line in io.lines("/etc/config.mesh/_setup")
do
if not (line:match("^%s*#") or line:match("^%s*$")) then
2022-03-01 07:19:19 -07:00
line = line:gsub("<NODE>", node):gsub("<MAC2>", mac2):gsub("<DTDMAC>", dtdmac)
2022-02-22 18:25:01 -07:00
local k, v = line:match("^([^%s]*)%s*=%s*(.*)%s*$")
_G[k] = v
end
end
local function h2s(hex)
local s = ""
if hex then
for i = 1,#hex,2
do
2022-03-01 07:19:19 -07:00
local p = hex:sub(i, i+1)
if p:match("[0-9a-f][0-9a-f]") then
s = s .. string.char(tonumber(p, 16))
else
s = s .. p
end
2022-02-22 18:25:01 -07:00
end
end
return s
end
wifi2_key = h2s(wifi2_key)
wifi2_ssid = h2s(wifi2_ssid)
wifi3_key = h2s(wifi3_key)
wifi3_ssid = h2s(wifi3_ssid)
end
end
2023-05-25 22:27:59 -06:00
if not wifi_intf or wifi_intf == "" then
wifi_intf = aredn.hardware.get_iface_name("wifi")
end
local phy = iwinfo.nl80211.phyname(wifi_intf)
2022-02-22 18:25:01 -07:00
-- make sure everything we need is initialized
2022-08-11 01:19:33 -06:00
local d0 = { "lan_dhcp", "olsrd_bridge", "wifi2_enable", "wifi_enable", "wifi3_enable", "dhcp_start", "dhcp_end" }
2022-02-22 18:25:01 -07:00
for _, k in ipairs(d0)
do
if not parms[k] then
parms[k] = "0"
end
if not _G[k] then
_G[k] = "0"
end
end
for _, k in ipairs({ "wifi_channel", "wifi2_channel", "wifi_txpower", "dhcp_start", "dhcp_end" })
do
if _G[k] then
_G[k] = tonumber(_G[k])
end
end
local nodetac
if parms.button_reset or parms.button_default or (not nodetac and not has_parms) then
2024-04-01 23:15:45 -06:00
nodetac = aredn.info.get_nvram("node")
tactical = aredn.info.get_nvram("tactical")
2022-02-22 18:25:01 -07:00
if tactical ~= "" then
nodetac = nodetac .. " / " .. tactical
end
2013-11-14 23:11:16 -07:00
else
2022-02-22 18:25:01 -07:00
nodetac = parms.nodetac
end
-- lan is always static
local lan_proto = "static"
-- enforce direct mode settings
-- (formerly known as dmz mode)
if not dmz_mode then
dmz_mode = cursor:get("aredn", "@dmz[0]", "mode")
end
dmz_mode = tonumber(dmz_mode)
if not dmz_mode or (dmz_mode ~= 0 and dmz_mode < 2) then
dmz_mode = 2
elseif dmz_mode > 5 then
dmz_mode = 5
end
if dmz_mode ~= 0 then
local ipshift = (ip_to_decimal(wifi_ip) * math.pow(2, dmz_mode)) % 0x1000000
local a, b = decimal_to_ip(ipshift):match("(%d+%.%d+%.%d+%.)(%d+)")
dmz_lan_ip = "1" .. a .. (tonumber(b) + 1)
dmz_lan_mask = decimal_to_ip((0xffffffff * math.pow(2, dmz_mode)) % 0x100000000)
local octet = dmz_lan_ip:match("%d+%.%d+%.%d+%.(%d+)")
dmz_dhcp_start = octet + 1
dmz_dhcp_end = dmz_dhcp_start + math.pow(2, dmz_mode) - 4;
parms.dmz_lan_ip = dmz_lan_ip
parms.dmz_lan_mask = dmz_lan_mask
parms.dmz_dhcp_start = dmz_dhcp_start
parms.dmz_dhcp_end = dmz_dhcp_end
2024-04-16 17:28:46 -06:00
else
dmz_dhcp_end = dmz_dhcp_start
parms.dmz_dhcp_end = dmz_dhcp_end
2022-02-22 18:25:01 -07:00
end
parms.dhcp_limit = dhcp_end - dhcp_start + 1
parms.dmz_dhcp_limit = dmz_dhcp_end - dmz_dhcp_start + 1
-- get the active wifi settings on a fresh page load
2024-01-14 00:35:29 -07:00
if not parms.reload and wifi_intf ~= "br-nomesh" then
2023-05-25 22:27:59 -06:00
wifi_txpower = capture_and_match("iwinfo " .. wifi_intf .. " info", "Tx%-Power: (%d+)")
local doesiwoffset = capture_and_match("iwinfo " .. wifi_intf .. " info", "TX power offset: (%d+)")
2022-02-22 18:25:01 -07:00
if wifi_txpower then
wifi_txpower = tonumber(wifi_txpower)
if doesiwoffset then
wifi_txpower = wifi_txpower - tonumber(doesiwoffset)
end
end
end
2022-05-18 11:49:00 -06:00
-- lqm
local lqm_mode = false
if cursor:get("aredn", "@lqm[0]", "enable") == "1" then
lqm_mode = true
end
2022-02-22 18:25:01 -07:00
-- sanitize the active settings
2023-06-02 19:47:34 -06:00
if not wifi_txpower or wifi_txpower > aredn.hardware.wifi_maxpower(wifi_intf, wifi_channel) then
wifi_txpower = aredn.hardware.wifi_maxpower(wifi_intf, wifi_channel)
2022-02-22 18:25:01 -07:00
end
2024-01-14 00:35:29 -07:00
if not wifi_txpower or wifi_txpower < 1 then
wifi_txpower = 1
2022-02-22 18:25:01 -07:00
end
if not wifi_distance then
wifi_distance = 0
end
if tostring(wifi_distance):match("%D") then
wifi_distance = 0
end
-- stuff the sanitized data back into the parms tables
-- so they get saved correctly
parms.wifi_distance = wifi_distance
parms.wifi_txpower = wifi_txpower
-- apply the wifi settings
2022-05-18 11:49:00 -06:00
if (parms.button_apply or parms.button_save) and wifi_enable == "1" then
if not lqm_mode then
if phy then
if wifi_distance == 0 then
os.execute("iw phy " .. phy .. " set distance auto >/dev/null 2>&1")
else
os.execute("iw phy " .. phy .. " set distance " .. wifi_distance .. " >/dev/null 2>&1")
end
end
2022-06-17 15:09:31 -06:00
elseif parms.lqm_min_snr ~= nil then
2022-05-18 11:49:00 -06:00
-- validate values
local lqm_min_snr = tonumber(parms.lqm_min_snr)
local lqm_max_distance = tonumber(parms.lqm_max_distance)
local lqm_distance_unit = parms.lqm_distance_unit or "mile"
local lqm_min_quality = tonumber(parms.lqm_min_quality)
if not lqm_min_snr or lqm_min_snr < 0 or lqm_min_snr > 95 then
err("ERROR: Minimum SNR out of range (0-95)")
end
local distance_scale = 1000
if lqm_distance_unit == "mile" then
distance_scale = 1609.344
if not lqm_max_distance or lqm_max_distance < 0 or lqm_max_distance > 71 then
err("ERROR: Maximum Distance out of range (0-71)")
end
else
if not lqm_max_distance or lqm_max_distance < 0 or lqm_max_distance > 114 then
err("ERROR: Maximum Distance out of range (0-114)")
end
end
if not lqm_min_quality or lqm_min_quality < 0 or lqm_min_quality > 100 then
err("ERROR: Minimum Quality out of range (0-100)")
end
if #errors == 0 then
local cursorb = uci.cursor("/etc/config.mesh")
cursor:set("aredn", "@lqm[0]", "min_snr", parms.lqm_min_snr)
cursorb:set("aredn", "@lqm[0]", "min_snr", parms.lqm_min_snr)
cursor:set("aredn", "@lqm[0]", "max_distance", math.floor(parms.lqm_max_distance * distance_scale))
cursorb:set("aredn", "@lqm[0]", "max_distance", math.floor(parms.lqm_max_distance * distance_scale))
cursor:set("aredn", "@lqm[0]", "min_quality", parms.lqm_min_quality)
cursorb:set("aredn", "@lqm[0]", "min_quality", parms.lqm_min_quality)
cursor:commit("aredn")
cursorb:commit("aredn")
end
2022-02-22 18:25:01 -07:00
end
2023-05-25 22:27:59 -06:00
os.execute("iw dev " .. wifi_intf .. " set txpower fixed " .. wifi_txpower .. "00 >/dev/null 2>&1")
2022-02-22 18:25:01 -07:00
end
2023-12-06 11:12:11 -07:00
if (parms.button_updatelocation or parms.button_save) then
2022-02-22 18:25:01 -07:00
-- process gridsquare
2022-03-03 17:06:26 -07:00
local cursora = uci.cursor();
local cursorb = uci.cursor("/etc/config.mesh")
2023-12-06 11:12:11 -07:00
if (cursora:get("aredn", "@location[0]", "gridsquare") or "") ~= parms.gridsquare then
if parms.gridsquare ~= "" then
if parms.gridsquare:match("^[A-Z][A-Z]%d%d[a-z][a-z]$") then
cursora:set("aredn", "@location[0]", "gridsquare", parms.gridsquare)
cursorb:set("aredn", "@location[0]", "gridsquare", parms.gridsquare)
out("Gridsquare updated.")
else
err("ERROR: Gridsquare format is: 2-uppercase letters, 2-digits, 2-lowercase letters. (AB12cd)")
end
2022-02-22 18:25:01 -07:00
else
2023-12-06 11:12:11 -07:00
cursora:set("aredn", "@location[0]", "gridsquare", "")
cursorb:set("aredn", "@location[0]", "gridsquare", "")
out("Gridsquare purged.")
2022-02-22 18:25:01 -07:00
end
end
-- process lat/lng
2023-12-06 11:12:11 -07:00
if (cursora:get("aredn", "@location[0]", "lat") or "") ~= parms.latitude or (cursora:get("aredn", "@location[0]", "lon") or "") ~= parms.longitude then
if parms.latitude ~= "" and parms.longitude ~= "" then
if parms.latitude:match("^[-+]?%d%d?%.%d+$") and parms.longitude:match("^[-+]?%d%d?%d?%.%d+$") then
if tonumber(parms.latitude) >= -90 and tonumber(parms.latitude) <= 90 and tonumber(parms.longitude) >= -180 and tonumber(parms.longitude) <= 180 then
cursora:set("aredn", "@location[0]", "lat", parms.latitude)
cursorb:set("aredn", "@location[0]", "lat", parms.latitude)
cursora:set("aredn", "@location[0]", "lon", parms.longitude)
cursorb:set("aredn", "@location[0]", "lon", parms.longitude)
out("Lat/lon updated.")
else
err("ERROR: Lat/lon values must be between -90/90 and -180/180, respectively.")
end
2022-02-22 18:25:01 -07:00
else
2023-12-06 11:12:11 -07:00
err("ERROR: Lat/lon format is decimal: (ex. 30.121456 or -95.911154).")
2022-02-22 18:25:01 -07:00
end
else
2023-12-06 11:12:11 -07:00
cursora:set("aredn", "@location[0]", "lat", "")
cursorb:set("aredn", "@location[0]", "lat", "")
cursora:set("aredn", "@location[0]", "lon", "")
cursorb:set("aredn", "@location[0]", "lon", "")
out("Lat/lon purged.")
2022-02-22 18:25:01 -07:00
end
end
2023-12-06 13:30:23 -07:00
-- process antenna, azimuth and elevation
if wifi_enable == "1" then
2024-03-29 13:25:04 -06:00
local antenna = parms.antenna or ""
2023-12-06 13:30:23 -07:00
if (cursora:get("aredn", "@location[0]", "antenna") or "") ~= antenna then
cursora:set("aredn", "@location[0]", "antenna", antenna)
cursorb:set("aredn", "@location[0]", "antenna", antenna)
end
2024-03-29 13:25:04 -06:00
local antenna_aux = parms.antenna_aux or ""
if (cursora:get("aredn", "@location[0]", "antenna_aux") or "") ~= antenna_aux then
cursora:set("aredn", "@location[0]", "antenna_aux", antenna_aux)
cursorb:set("aredn", "@location[0]", "antenna_aux", antenna_aux)
end
2023-12-06 13:30:23 -07:00
if (cursora:get("aredn", "@location[0]", "azimuth") or "") ~= parms.azimuth then
local ant = aredn.hardware.get_current_antenna(wifi_intf)
if ant and ant.beamwidth == 360 then
parms.azimuth = ""
end
2024-03-29 13:25:04 -06:00
ant = aredn.hardware.get_current_antenna_aux(wifi_intf)
if ant and ant.beamwidth == 360 then
parms.azimuth = ""
end
2023-12-06 13:30:23 -07:00
local azimuth = tonumber(parms.azimuth)
if parms.azimuth == "" or (azimuth and azimuth >= 0 and azimuth < 360) then
cursora:set("aredn", "@location[0]", "azimuth", parms.azimuth)
cursorb:set("aredn", "@location[0]", "azimuth", parms.azimuth)
elseif parms.azimuth then
err("ERROR: Azimuth value must be blank or between 0 and 360.")
end
end
if (cursora:get("aredn", "@location[0]", "elevation") or "") ~= parms.elevation then
local elevation = tonumber(parms.elevation)
if parms.elevation == "" or (elevation and elevation >= -180 and elevation <= 180) then
cursora:set("aredn", "@location[0]", "elevation", parms.elevation)
cursorb:set("aredn", "@location[0]", "elevation", parms.elevation)
elseif parms.elevation then
err("ERROR: Elevation value must be blank or between -180 and 180.")
end
end
if (cursora:get("aredn", "@location[0]", "height") or "") ~= parms.height then
local height = tonumber(parms.height)
if parms.height == "" or (height and height >= 0 and height <= 500) then
cursora:set("aredn", "@location[0]", "height", parms.height)
cursorb:set("aredn", "@location[0]", "height", parms.height)
elseif parms.height then
err("ERROR: Height value must be blank or between 0 and 500.")
end
end
end
2022-03-03 17:06:26 -07:00
cursora:commit("aredn")
cursorb:commit("aredn")
2023-12-06 11:12:11 -07:00
cursor = cursora
2022-02-22 18:25:01 -07:00
end
-- retrieve location data
lat = cursor:get("aredn", "@location[0]", "lat")
if not lat then
lat = ""
end
lon = cursor:get("aredn", "@location[0]", "lon")
if not lon then
lon = ""
end
gridsquare = cursor:get("aredn", "@location[0]", "gridsquare")
if not gridsquare then
gridsquare = ""
end
2023-12-06 13:30:23 -07:00
local azimuth = cursor:get("aredn", "@location[0]", "azimuth") or ""
local elevation = cursor:get("aredn", "@location[0]", "elevation") or ""
local height = cursor:get("aredn", "@location[0]", "height") or ""
local antenna = cursor:get("aredn", "@location[0]", "antenna") or ""
2024-03-29 13:25:04 -06:00
local antenna_aux = cursor:get("aredn", "@location[0]", "antenna_aux") or ""
2022-02-22 18:25:01 -07:00
2022-10-11 08:14:46 -06:00
-- retrieve ntp_period
local cm = uci.cursor("/etc/config.mesh")
ntp_period = cm:get("aredn", "@ntp[0]", "period")
if not ntp_period then
ntp_period = "daily"
end
2022-12-06 13:24:44 -07:00
function is_vtun_client()
2022-12-10 07:51:26 -07:00
if nixio.fs.stat("/etc/config/vtun") then
for line in io.lines("/etc/config/vtun") do
if line:match("^config server") then
return true
end
2022-12-06 13:24:44 -07:00
end
end
return false
end
2022-02-22 18:25:01 -07:00
-- validate and save configuration
if parms.button_save then
for _,zone in ipairs(tz_db_names)
do
2022-03-01 22:40:11 -07:00
if zone.name == time_zone_name then
parms.time_zone = zone.tz
2022-02-22 18:25:01 -07:00
break
end
end
2023-04-22 07:24:20 -06:00
if wifi_enable == "1" then
if not validate_netmask(wifi_mask) then
err("invalid Mesh netmask")
elseif not validate_ip_netmask(wifi_ip, wifi_mask) then
err("invalid Mesh IP address")
end
2022-02-22 18:25:01 -07:00
2023-04-22 07:24:20 -06:00
if #wifi_ssid > 32 then
err("invalid Mesh RF SSID")
end
2022-02-22 18:25:01 -07:00
2023-05-25 22:27:59 -06:00
if wifi_intf:match("^br") then
wifi_intf = aredn.hardware.get_board_network_ifname("wifi")
phy = iwinfo.nl80211.phyname(wifi_intf)
2023-05-27 18:58:10 -06:00
local defaultwifi = aredn.hardware.get_default_channel(wifi_intf)
wifi_channel = defaultwifi.channel
wifi_chanbw = tostring(defaultwifi.bandwidth)
2023-04-22 07:24:20 -06:00
end
local valid = false
2023-05-25 22:27:59 -06:00
for _, c in ipairs(aredn.hardware.get_rfchannels(wifi_intf))
2023-04-22 07:24:20 -06:00
do
if c.number == wifi_channel then
valid = true
break
end
end
if not valid then
err("invalid Mesh RF channel")
end
2022-02-22 18:25:01 -07:00
2023-04-28 12:01:58 -06:00
local wifi_country_validated = false
local countries = { "00","HX","AD","AE","AL","AM","AN","AR","AT","AU","AW","AZ","BA","BB","BD","BE","BG","BH","BL","BN","BO","BR","BY","BZ","CA","CH","CL","CN","CO","CR","CY","CZ","DE","DK","DO","DZ","EC","EE","EG","ES","FI","FR","GE","GB","GD","GR","GL","GT","GU","HN","HK","HR","HT","HU","ID","IE","IL","IN","IS","IR","IT","JM","JP","JO","KE","KH","KP","KR","KW","KZ","LB","LI","LK","LT","LU","LV","MC","MA","MO","MK","MT","MY","MX","NL","NO","NP","NZ","OM","PA","PE","PG","PH","PK","PL","PT","PR","QA","RO","RS","RU","RW","SA","SE","SG","SI","SK","SV","SY","TW","TH","TT","TN","TR","UA","US","UY","UZ","VE","VN","YE","ZA","ZW" }
for _,country in ipairs(countries)
do
if country == wifi_country then
wifi_country_validated = true
break
end
end
if not wifi_country_validated then
wifi_country = "00"
err("Invalid country")
2022-02-22 18:25:01 -07:00
end
end
if lan_proto == "static" then
if not validate_netmask(lan_mask) then
err("invalid LAN netmask")
elseif not lan_mask:match("^255%.255%.255%.") then
err("LAN netmask must begin with 255.255.255")
elseif not validate_ip_netmask(lan_ip, lan_mask) then
err("invalid LAN IP address")
else
if lan_dhcp ~= "" then
2022-09-06 08:57:06 -06:00
local start_addr = lan_ip:match("^(.*%.)%d+$") .. dhcp_start
local end_addr = lan_ip:match("^(.*%.)%d+$") .. dhcp_end
2022-02-22 18:25:01 -07:00
if not (validate_ip_netmask(start_addr, lan_mask) and validate_same_subnet(start_addr, lan_ip, lan_mask)) then
err("invalid DHCP start address")
end
if not (validate_ip_netmask(end_addr, lan_mask) and validate_same_subnet(end_addr, lan_ip, lan_mask)) then
err("invalid DHCP end address")
end
if dhcp_start > dhcp_end then
err("invalid DHCP start/end addresses")
end
end
if lan_gw ~= "" and not (validate_ip_netmask(lan_gw, lan_mask) and validate_same_subnet(lan_ip, lan_gw, lan_mask)) then
err("invalid LAN gateway")
end
end
end
if wan_proto == "static" then
if not validate_netmask(wan_mask) then
err("invalid WAN netmask")
2022-03-01 23:19:02 -07:00
elseif not validate_ip_netmask(wan_ip, wan_mask) then
2022-02-22 18:25:01 -07:00
err("invalid WAN IP address")
elseif not (validate_ip_netmask(wan_gw, wan_mask) and validate_same_subnet(wan_ip, wan_gw, wan_mask)) then
err("invalid WAN gateway")
end
end
if not validate_ip(wan_dns1) then
err("invalid WAN DNS 1")
end
if wan_dns2 ~= '' and not validate_ip(wan_dns2) then
err("invaliud WAN DNS 2")
end
if passwd1 ~= "" or passwd2 ~= "" then
if passwd1 ~= passwd2 then
err("passwords do not match")
end
if passwd1:match("#") then
err("passwords cannot contain '#'")
end
if passwd1 == "hsmm" then
err("password must be changed")
end
elseif nixio.fs.stat("/etc/config/unconfigured") then
err("password must be changed during initial configuration")
end
2022-07-22 17:49:58 -06:00
local raw_node, raw_tactical = nodetac:match("^([^/]*)(.*)$")
node = validate_hostname(raw_node, "node")
tactical = raw_tactical ~= "" and validate_hostname(string.sub(raw_tactical, 2), "tactical") or ""
2022-02-22 18:25:01 -07:00
if not validate_fqdn(ntp_server) then
err("invalid ntp server")
end
2022-10-02 17:46:57 -06:00
-- move update-clock to correct location if necessary
if parms.ntp_period == "daily" then
if not nixio.fs.stat("/etc/cron.daily/update-clock") then
if nixio.fs.stat("/etc/cron.hourly/update-clock") then
os.execute("mv /etc/cron.hourly/update-clock /etc/cron.daily/update-clock")
2023-12-18 17:48:02 -07:00
ntp_period = parms.ntp_period
2022-10-02 17:46:57 -06:00
else
err("update-clock script not found")
end
end
elseif parms.ntp_period == "hourly" then
if not nixio.fs.stat("/etc/cron.hourly/update-clock") then
if nixio.fs.stat("/etc/cron.daily/update-clock") then
os.execute("mv /etc/cron.daily/update-clock /etc/cron.hourly/update-clock")
2023-12-18 17:48:02 -07:00
ntp_period = parms.ntp_period
2022-10-02 17:46:57 -06:00
else
err("update-clock script not found")
end
end
else
err("ntp_period not set")
end
2022-02-22 18:25:01 -07:00
if wifi2_enable == "1" then
if #wifi2_ssid > 32 then
err("LAN Access Point SSID musr be 32 or less characters")
end
if #wifi2_key < 8 or #wifi2_key > 64 then
err("LAN Access Point Password must be at least 8 characters, up to 64")
end
if wifi2_key:match("'") or wifi2_ssid:match("'") then
err("The LAN Access Point password and ssid may not contain a single quote character")
end
if wifi2_channel < 30 and wifi2_hwmode == "11a" then
err("Changed to 5GHz Mesh LAN AP, please review channel selection")
end
if wifi2_channel > 30 and wifi2_hwmode == "11g" then
err("Changed to 2GHz Mesh LAN AP, please review channel slection")
end
end
if wifi3_enable == "1" then
2023-02-19 13:11:41 -07:00
if #wifi3_key > 64 then
err("WAN Wifi Client Password must be 64 characters or less")
2022-02-22 18:25:01 -07:00
end
if wifi3_key:match("'") or wifi3_ssid:match("'") then
2023-02-19 13:11:41 -07:00
err("The WAN Wifi Client password and ssid cannot contain a single quote character")
2022-02-22 18:25:01 -07:00
end
end
2023-02-17 21:58:51 -07:00
if phycount > 1 and wifi_enable == "1" and wifi2_enable == "1" and (wifi_channel < 36) == (wifi2_channel < 36) then
2022-02-22 18:25:01 -07:00
err("Mesh RF and LAN Access Point can not both use the same wireless card, review LAN AP settings")
end
2022-12-27 19:06:30 -07:00
if phycount > 1 and wifi_enable == "0" and wifi2_enable == "1" and wifi3_enable == "1" and wifi2_hwmode == wifi3_hwmode then
2022-02-22 18:25:01 -07:00
err("Some settings auto updated to avoid conflicts, please review and save one more time")
end
if wifi_enable == "1" and wifi2_enable == "1" and wifi3_enable == "1" then
err("Can not enable Mesh RF, LAN AP, and WAN Wifi Client with only 2 wireless cards, WAN Wifi Client turned off")
wifi2_enable = "0"
end
if phycount == 1 and wifi_enable == "1" and (wifi2_enable == "1" or wifi3_enable == "1") then
err("Can not enable Mesh RF along with LAN AP or WAN Wifi Client. Only Mesh RF enabled now, please review settings.")
wifi2_enable = "0"
wifi3_enable = "0"
end
if #errors == 0 then
parms.node = node
parms.tactical = tactical
2022-12-06 13:24:44 -07:00
if is_vtun_client() then
local vtun_name
cursor:foreach("vtun", "server",
function(section)
vtun_name = section.node:sub(1, #section.node - (#section.netip + 1) )
end
)
if vtun_name and parms.node and (vtun_name:upper() ~= parms.node:upper()) then
cursor:foreach("vtun", "server",
function(section)
for k,v in pairs(section) do
if k == ".name" then
local servnum = "@" .. v:gsub("%_","%[") .. "]"
local newname = parms.node .. "-" .. section.netip:gsub("%.", "%-")
cursor:set("vtun", servnum, "node", newname)
break
end
end
end
)
cursor:commit("vtun")
write_all("/etc/config.mesh/vtun", read_all("/etc/config/vtun"))
end
end
2022-02-22 18:25:01 -07:00
if nixio.fs.stat("/etc/config/unconfigured") then
2022-03-03 16:01:57 -07:00
io.open("/tmp/unconfigured", "w"):close()
2022-02-22 18:25:01 -07:00
end
local function s2h(str)
local h = ""
for i = 1,#str
do
h = h .. string.format("%02x", string.byte(str, i))
end
return h
end
parms.wifi2_key = s2h(wifi2_key)
parms.wifi2_ssid = s2h(wifi2_ssid)
parms.wifi3_key = s2h(wifi3_key)
parms.wifi3_ssid = s2h(wifi3_ssid)
2022-03-13 09:11:22 -06:00
-- escape and limit description
parms.description_node = parms.description_node:sub(1,210):gsub('"',"""):gsub("'","'"):gsub("<","<"):gsub(">",">")
2023-05-25 22:27:59 -06:00
-- save the wifi interface
parms.wifi_intf = wifi_intf
2022-02-22 18:25:01 -07:00
-- save_setup
local f = io.open("/etc/config.mesh/_setup", "w")
if f then
for k, v in pairs(parms)
do
2022-12-22 13:22:49 -07:00
if k:match("^aprs_") or k:match("^dhcp_") or k:match("^dmz_") or k:match("^lan_") or k:match("^olsrd_") or k:match("^wan_") or k:match("^wifi_") or k:match("^wifi2_") or k:match("^wifi3_") or k:match("^dtdlink_") or k:match("^ntp_") or k:match("^time_") or k:match("^description_") or k:match("^compat_version") then
2022-02-22 18:25:01 -07:00
f:write(k .. " = " .. v .. "\n")
end
end
f:close()
end
2022-10-02 17:46:57 -06:00
-- commit new ntp_period value
2022-10-11 08:14:46 -06:00
local cm = uci.cursor("/etc/config.mesh")
if parms.ntp_period ~= cm:get("aredn", "@ntp[0]", "period") then
cm:set("aredn", "@ntp[0]", "period", parms.ntp_period)
cm:commit("aredn")
2022-10-02 17:46:57 -06:00
end
2024-04-01 23:15:45 -06:00
aredn.info.set_nvram("node", parms.node);
aredn.info.set_nvram("tactical", parms.tactical)
aredn.info.set_nvram("config", parms.config)
2022-03-05 20:52:41 -07:00
2022-02-22 18:25:01 -07:00
if not nixio.fs.stat("/tmp/web/save") then
nixio.fs.mkdir("/tmp/web/save")
end
2023-12-12 21:01:23 -07:00
os.execute("/usr/local/bin/node-setup > /tmp/web/save/node-setup.out 2>&1")
2022-02-22 18:25:01 -07:00
if nixio.fs.stat("/tmp/web/save/node-setup.out", "size") > 0 then
err(read_all("/tmp/web/save/node-setup.out"))
else
remove_all("/tmp/web/save")
-- set password
if passwd1 ~= "" then
2022-03-01 07:19:19 -07:00
local pw = passwd1:gsub("'", "\\'")
2022-02-22 18:25:01 -07:00
local f = io.popen("{ echo '" .. pw .. "'; sleep 1; echo '" .. pw .. "'; } | passwd")
f:read("*a")
f:close()
2022-03-05 20:52:41 -07:00
end
2023-12-12 21:01:23 -07:00
if nixio.fs.stat("/tmp/reboot-required") and not nixio.fs.stat("/tmp/reboot-required/reboot") and not nixio.fs.stat("/tmp/unconfigured") then
os.execute("/usr/local/bin/restart-services.sh > /dev/null 2>&1")
end
2022-02-22 18:25:01 -07:00
end
if nixio.fs.stat("/tmp/unconfigured") and #errors == 0 then
2024-03-25 20:52:27 -06:00
html.reboot()
2022-02-22 18:25:01 -07:00
end
end
end
remove_all("/tmp/web/save")
if parms.button_reboot then
2024-03-25 20:52:27 -06:00
html.reboot()
2022-02-22 18:25:01 -07:00
end
local desc = cursor:get("system", "@system[0]", "description")
if not desc then
desc = ""
end
local maptiles = cursor:get("aredn", "@map[0]", "maptiles")
if not maptiles then
maptiles = ""
end
local leafletcss = cursor:get("aredn", "@map[0]", "leafletcss")
if not leafletcss then
leafletcss = ""
end
local leafletjs = cursor:get("aredn", "@map[0]", "leafletjs")
if not leafletjs then
leafletjs = ""
end
-- generate page
http_header()
2024-04-01 23:15:45 -06:00
html.header(aredn.info.get_nvram("node") .. " setup", false)
2022-02-22 18:25:01 -07:00
html.print([[
<script>
2021-10-25 19:43:55 -06:00
function loadCSS(url, callback) {
var head = document.getElementsByTagName('head')[0];
var stylesheet = document.createElement('link');
stylesheet.rel = 'stylesheet';
stylesheet.type = 'text/css';
stylesheet.href = url;
stylesheet.onload = callback;
head.appendChild(stylesheet);
2022-03-05 20:52:41 -07:00
}
2021-10-25 19:43:55 -06:00
function loadScript(url, callback) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
script.onload = callback;
head.appendChild(script);
2020-04-04 08:31:07 -06:00
}
2021-10-25 19:43:55 -06:00
var map;
var marker;
2023-12-06 13:17:39 -07:00
var dotIcon;
2021-10-25 19:43:55 -06:00
var leafletLoad = function() {
map = L.map('map').setView([0.0, 0.0], 1);
2023-12-06 13:17:39 -07:00
dotIcon = L.icon({iconUrl: '/dot.png'});
2022-02-22 18:25:01 -07:00
]])
html.print("L.tileLayer('" .. maptiles .. "',")
html.print([[
2021-10-25 19:43:55 -06:00
{
maxZoom: 18,
2023-12-06 13:17:39 -07:00
attribution: 'Map data and images © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a>'
2021-10-25 19:43:55 -06:00
}).addTo(map);
2022-02-22 18:25:01 -07:00
]])
2016-01-04 21:41:27 -07:00
2022-03-17 19:35:35 -06:00
if tonumber(lat) and tonumber(lon) then
2023-12-06 13:17:39 -07:00
html.print("marker = new L.marker([" .. lat .. "," .. lon .. "],{draggable: true, icon: dotIcon});")
2022-02-22 18:25:01 -07:00
html.print("map.addLayer(marker);")
html.print("map.setView([" .. lat .. "," .. lon .. "],13);")
html.print("marker.on('drag', onMarkerDrag);")
else
html.print("map.on('click', onMapClick);")
end
html.print([[
2021-10-25 19:43:55 -06:00
}
function onMapClick(e) {
2023-12-06 13:17:39 -07:00
if (marker) {
marker.setLatLng(e.latlng.wrap());
}
else {
marker = new L.marker(e.latlng.wrap(),{draggable: true, icon: dotIcon});
map.addLayer(marker);
}
2021-10-25 19:43:55 -06:00
document.getElementsByName('latitude')[0].value=e.latlng.wrap().lat.toFixed(6).toString();
document.getElementsByName('longitude')[0].value=e.latlng.wrap().lng.toFixed(6).toString();
marker.on('drag', onMarkerDrag);
}
function onMarkerDrag(e) {
var m = e.target;
var p = m.getLatLng().wrap();
document.getElementsByName('latitude')[0].value=p.lat.toFixed(6).toString();
document.getElementsByName('longitude')[0].value=p.lng.toFixed(6).toString();
}
2022-02-22 18:25:01 -07:00
]])
2021-10-25 19:43:55 -06:00
2022-02-22 18:25:01 -07:00
if pingOK or (leafletcss:match("%.local%.mesh") and leafletjs:match("%.local%.mesh")) then
html.print("window.onload = function (event) { loadCSS('" .. leafletcss .. "',function () { loadScript('" .. leafletjs .."', leafletLoad); }); };")
end
2016-01-06 09:23:18 -07:00
2022-02-22 18:25:01 -07:00
html.print([[
2016-01-11 16:41:35 -07:00
function findLocation() {
navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
}
2021-10-25 19:43:55 -06:00
function foundLocation(position) {
2016-01-11 16:41:35 -07:00
var jlat = position.coords.latitude;
var jlon = position.coords.longitude;
2016-01-12 19:30:00 -07:00
// update the fields
2016-01-11 16:41:35 -07:00
document.getElementsByName('latitude')[0].value=jlat.toFixed(6).toString();
document.getElementsByName('longitude')[0].value=jlon.toFixed(6).toString();
2016-01-12 19:30:00 -07:00
// try to update the map if Javascript libs have been loaded
if (typeof L != 'undefined') {
var latlng = L.latLng(jlat, jlon);
2023-12-06 13:17:39 -07:00
if (marker) {
marker.setLatLng(latlng);
}
else {
marker = new L.marker(latlng.wrap(),{draggable: true, icon: dotIcon});
map.addLayer(marker);
}
2016-01-12 19:30:00 -07:00
map.setView(latlng,13);
}
2016-01-11 16:41:35 -07:00
}
2021-10-25 19:43:55 -06:00
function noLocation() {
2023-12-06 11:12:11 -07:00
const req = new XMLHttpRequest();
req.addEventListener("load", function() {
try {
const json = JSON.parse(this.responseText);
2024-08-15 21:28:45 -06:00
foundLocation({ coords: { latitude: json.lat, longitude: json.lon}})
2023-12-06 11:12:11 -07:00
}
catch (_) {
}
});
req.open("GET", "http://ip-api.com/json");
req.send();
2016-01-11 16:41:35 -07:00
}
2021-10-25 19:43:55 -06:00
2016-01-04 21:41:27 -07:00
function updDist(x) {
2016-02-04 16:55:57 -07:00
var dvs= calcDistance(x);
var xcm=dvs['miles'];
var xc=dvs['meters'];
var xck=dvs['kilometers'];
2016-06-29 20:43:43 -06:00
2016-01-04 21:41:27 -07:00
var distBox = document.getElementById('dist');
2016-02-04 16:55:57 -07:00
var dist_meters=document.getElementsByName('wifi_distance')[0];
document.getElementsByName('wifi_distance_disp_miles')[0].value = xcm;
document.getElementsByName('wifi_distance_disp_km')[0].value = xck;
document.getElementsByName('wifi_distance_disp_meters')[0].value = xc;
2016-06-29 20:43:43 -06:00
dist_meters.value = xc;
2019-04-01 21:48:41 -06:00
// default of 0 means 'auto', so full range is always dist-norm
distBox.className = 'dist-norm';
2016-01-04 21:41:27 -07:00
}
2016-02-04 16:55:57 -07:00
function calcDistance(x) {
// x is in KILOMETERS
var dvs = new Object();
dvs['miles']=(x*0.621371192).toFixed(2);
dvs['meters']=Math.ceil(x*1000);
dvs['kilometers']=x;
return dvs;
2021-10-25 19:43:55 -06:00
}
function doSubmit() {
var desc_text = document.mainForm.description_node.value;
var singleLine = desc_text.replace(new RegExp( "\\n", "g" ), " ");
document.mainForm.description_node.value = singleLine;
return true;
}
2016-01-06 09:23:18 -07:00
function toggleMap(toggleButton) {
var mapdiv=document.getElementById('map');
if(toggleButton.value=='hide') {
// HIDE IT
mapdiv.style.display='none';
toggleButton.value='show';
toggleButton.innerHTML='Show Map';
} else {
// SHOW IT
mapdiv.style.display='block';
toggleButton.value='hide';
toggleButton.innerHTML='Hide Map';
}
// force the map to redraw
2021-10-25 19:43:55 -06:00
if(typeof map !== 'undefined') map.invalidateSize();
2016-01-06 09:23:18 -07:00
return false;
2021-10-25 19:43:55 -06:00
}
</script>
2022-02-22 18:25:01 -07:00
]])
html.print("</head>")
html.print("<body><center>")
html.alert_banner()
html.print("<form onSubmit='doSubmit();' name='mainForm' method=post action=/cgi-bin/setup enctype='multipart/form-data'>\n")
-- navbar
2023-04-25 21:07:19 -06:00
html.navbar_admin("setup")
html.print("<table width=790>")
2022-02-22 18:25:01 -07:00
-- control buttons
html.print([[<tr><td align=center>
2013-11-14 23:11:16 -07:00
<a href='/help.html#setup' target='_blank'>Help</a>
<input type=submit name=button_save value='Save Changes' title='Store these settings'>
<input type=submit name=button_reset value='Reset Values' title='Revert to the last saved settings'>
<input type=submit name=button_default value='Default Values' title='Set all values to their default'>
<input type=submit name=button_reboot value=Reboot style='font-weight:bold' title='Immediately reboot this node'>
</td></tr>
2022-02-22 18:25:01 -07:00
<tr><td> </td></tr>]])
if #output > 0 then
html.print("<tr><td align=center><table>")
html.print("<tr><td><ul style='padding-left:0'>")
for _,o in ipairs(output)
do
html.print("<li>" .. o .. "</li>")
end
html.print("</ul></td></tr></table>")
html.print("</td></tr>")
end
if #errors > 0 then
html.print("<tr><th>Configuration NOT saved!</th></tr>")
html.print("<tr><td align=center><table>")
html.print("<tr><td><ul style='padding-left:0'>")
for _,e in ipairs(errors)
do
html.print("<li>" .. e .. "</li>")
end
html.print("</ul></td></tr></table>")
html.print("</td></tr>")
elseif parms.button_save then
html.print("<tr><td align=center>")
html.print("<b>Configuration saved.</b><br><br>")
html.print("</td></tr>")
end
if #errors == 0 and nixio.fs.stat("/tmp/reboot-required") then
html.print("<tr><td align=center><h3>Reboot is required for changes to take effect</h3></td></tr>")
end
2022-03-05 20:52:41 -07:00
-- node name and type, password
2022-02-22 18:25:01 -07:00
html.print([[
<tr><td align=center>
<table cellpadding=5 border=0>
2013-11-14 23:11:16 -07:00
<tr>
<td>Node Name</td>
2022-02-22 18:25:01 -07:00
<td><input type=text name=nodetac value=']] .. nodetac .. [[' tabindex=1 size='50'></td>
2013-11-14 23:11:16 -07:00
<td align=right>Password</td>
2022-08-02 17:55:08 -06:00
<td><input class='password-input' type=password name=passwd1 value=']] .. passwd1 .. [[' size=8 tabindex=2><i class='password-toggle'></i></td>
2022-02-22 18:25:01 -07:00
]])
html.print([[
2013-11-14 23:11:16 -07:00
</tr>
<tr>
2018-07-19 12:28:18 -06:00
<td>Node Description (optional)</td>
2022-02-22 18:25:01 -07:00
<td><textarea rows='2' cols='60' wrap='soft' maxlength='210' id='node_description_entry' name='description_node' tabindex='4'>]] .. desc .. [[</textarea></td>
]])
hidden[#hidden + 1] = "<input type=hidden name=config value='mesh'>"
2022-12-22 13:22:49 -07:00
hidden[#hidden + 1] = "<input type=hidden name=compat_version value='" .. (compat_version or "") .. "'>"
2022-02-22 18:25:01 -07:00
html.print([[
2024-03-29 13:25:04 -06:00
<td>Verify Password</td>
2022-08-02 17:55:08 -06:00
<td><input class='password-input' type=password name=passwd2 value=']] .. passwd2 .. [[' size=8 tabindex=3><i class='password-toggle'></i></td>
2013-11-14 23:11:16 -07:00
</tr>
</table>
2022-02-22 18:25:01 -07:00
</td></tr>
<tr><td><br>
2022-11-01 08:48:48 -06:00
<table cellpadding=5 border=1 style='border-collapse:collapse;' width=100%><tr><td valign=top width=33%>
2022-02-22 18:25:01 -07:00
]])
2023-02-21 16:25:18 -07:00
-- reset wifi channel/bandwidth to default
2023-05-08 23:31:10 -06:00
if phycount > 0 and (nixio.fs.stat("/etc/config/unconfigured") or parms.button_reset) then
2023-05-25 22:27:59 -06:00
local defaultwifi = aredn.hardware.get_default_channel(wifi_intf)
2023-02-21 16:25:18 -07:00
wifi_channel = defaultwifi.channel
wifi_chanbw = tostring(defaultwifi.bandwidth)
end
2022-02-22 18:25:01 -07:00
-- mesh rf settings
html.print("<table width=100% style='border-collapse: collapse;'>")
2023-05-25 22:27:59 -06:00
if phycount == 1 then
2023-04-28 12:01:58 -06:00
html.print("<tr><th colspan=2>Mesh RF (" .. (M3model and "3GHz" or M9model and "900MHz" or wifi_channel < 36 and "2GHz" or "5GHz") .. ")</th></tr>")
else
html.print("<tr><th colspan=2>Mesh</th></tr>")
end
2022-02-22 18:25:01 -07:00
hidden[#hidden + 1] = "<input type=hidden name=wifi_proto value='static'>"
-- add enable/disable
2023-05-08 23:31:10 -06:00
if phycount > 0 then
2023-04-28 12:01:58 -06:00
html.print("<tr><td>Enable</td><td><input type=checkbox name=wifi_enable value=1")
if wifi_enable == "1" then
html.print(" checked")
end
html.print("></td></tr>")
2023-05-27 18:58:10 -06:00
if phycount > 1 and wifi_enable == "1" then
2023-05-25 22:27:59 -06:00
local defaultwifi = aredn.hardware.get_default_channel(wifi_intf)
local alt_wifi = (not phy or phy == "phy0") and "wlan1" or "wlan0"
html.print("<tr><td>Band</td><td><select name=wifi_intf onChange='form.submit()'>")
if defaultwifi.channel == 149 then
html.print("<option value='" .. alt_wifi .. "'>2GHz</option>")
html.print("<option value='" .. wifi_intf .. "' selected>5GHz</option>")
else
html.print("<option value='" .. wifi_intf .. "' selected>2GHz</option>")
html.print("<option value='" .. alt_wifi .. "'>5GHz</option>")
end
html.print("</select></td></tr>")
end
2022-02-22 18:25:01 -07:00
end
html.print("<tr><td><nobr>IP Address</nobr></td><td><input type=text size=15 name=wifi_ip value='" .. wifi_ip .. "'></td></tr><tr><td>Netmask</td><td><input type=text size=15 name=wifi_mask value='" .. wifi_mask .. "'></td></tr>")
if wifi_enable == "1" then
html.print("<tr><td>SSID</td><td><input type=text size=15 name=wifi_ssid value='" .. wifi_ssid .. "'>-" .. wifi_chanbw .. "-v3</td></tr>")
hidden[#hidden + 1] = "<input type=hidden name=wifi_mode value='" .. wifi_mode .. "'>"
html.print("<tr><td>Channel</td><td><select name=wifi_channel>")
2023-05-25 22:27:59 -06:00
local rfchannels = aredn.hardware.get_rfchannels(wifi_intf)
2022-02-22 18:25:01 -07:00
table.sort(rfchannels, function(a, b) return a.number < b.number end)
for _, chan in ipairs(rfchannels)
do
html.print("<option value='" .. chan.number .. "' ".. (chan.number == tonumber(wifi_channel) and " selected" or "") .. ">" .. chan.label .. "</option>")
end
2022-05-23 06:45:16 -06:00
html.print("</select> <a href='/help.html#channel' target='_blank'><img src='/qmark.png'></a></td></tr>")
2022-02-22 18:25:01 -07:00
html.print("<tr><td>Channel Width</td><td><select name=wifi_chanbw>")
2023-05-25 22:27:59 -06:00
for _, width in ipairs(aredn.hardware.get_rfbandwidths(wifi_intf))
2022-12-22 13:22:49 -07:00
do
html.print("<option value='" .. width .. "'".. (wifi_chanbw == tostring(width) and " selected" or "") .. ">" .. width .. " MHz</option>")
end
2022-02-22 18:25:01 -07:00
html.print("</select></td></tr>")
hidden[#hidden + 1] = "<input type=hidden name=wifi_country value='HX'>"
2022-05-18 11:49:00 -06:00
if lqm_mode then
html.print("<tr><th colspan=2 align=center><hr><small>Power & Link Quality</small></th></tr>")
else
html.print("<tr><th colspan=2 align=center><hr><small>Power & Distance</small></th></tr>")
end
2022-02-22 18:25:01 -07:00
html.print("<tr><td><nobr>Tx Power</nobr></td><td><select name=wifi_txpower>")
2023-05-25 22:27:59 -06:00
local txpoweroffset = aredn.hardware.wifi_poweroffset(wifi_intf)
2023-06-02 19:47:34 -06:00
for i = aredn.hardware.wifi_maxpower(wifi_intf, wifi_channel),1,-1
2022-02-22 18:25:01 -07:00
do
2022-03-05 20:52:41 -07:00
html.print("<option value='" .. i .. "'".. (i == tonumber(wifi_txpower) and " selected" or "") .. ">" .. (txpoweroffset + i) .. " dBm</option>")
2022-02-22 18:25:01 -07:00
end
2022-05-23 06:45:16 -06:00
html.print("</select> <a href='/help.html#power' target='_blank'><img src='/qmark.png'></a></td></tr>")
2022-05-18 11:49:00 -06:00
if lqm_mode then
local lqm_max_distance = tonumber(cursor:get("aredn", "@lqm[0]", "max_distance")) or 114750
local lqm_min_snr = cursor:get("aredn", "@lqm[0]", "min_snr") or "15"
local lqm_min_quality = cursor:get("aredn", "@lqm[0]", "min_quality") or "50"
html.print([[
<tr><td>Max Distance</td><td>
<script>
var dm = ]] .. lqm_max_distance .. [[;
switch (navigator.language.split("-")[1] || "unknown") {
case "US":
case "GB":
document.write("<input type=hidden name='lqm_distance_unit' value='mile'><input type=text size=4 name='lqm_max_distance' value='" + (dm / 1609.344).toFixed(1) + "' title='Maximum distance to a neighbor before it will be ignored'> miles")
break;
default:
2022-05-23 06:45:16 -06:00
document.write("<input type=hidden name='lqm_distance_unit' value='kilometer'><input type=text size=4 name='lqm_max_distance' value='" + (dm / 1000).toFixed(1) + "' title='Maximum distance to a neighbor before it will be blocked'> km")
2022-05-18 11:49:00 -06:00
break;
}
</script>
2022-05-23 06:45:16 -06:00
<a href='/help.html#linkqual' target='_blank'><img src='/qmark.png'></a>
2022-05-18 11:49:00 -06:00
</td></tr>
]])
2022-09-04 10:05:54 -06:00
html.print("<tr><td>Min SNR</td><td><input type=text size=4 name='lqm_min_snr' value='" .. lqm_min_snr .. "' title='Minimum SNR of neighbor before it will be accepted'> dB</td></tr>")
2022-05-18 11:49:00 -06:00
html.print("<tr><td>Min Quality</td><td><input type=text size=4 name='lqm_min_quality' value='" .. lqm_min_quality .. "' title='Minimum acceptable link quality'> %</td></tr>")
else
html.print("<tr id='dist' class='dist-norm'><td>Distance to<br/>FARTHEST Neighbor<br/><h3>'0' is auto</h3></td>")
local wifi_distance = math.floor(tonumber(wifi_distance))
local wifi_distance_disp_km = math.floor(wifi_distance / 1000)
local wifi_distance_disp_miles = string.format("%.2f", wifi_distance_disp_km * 0.621371192)
2022-05-23 06:45:16 -06:00
html.print("<td><input disabled size=6 type=text name='wifi_distance_disp_miles' value='" .. wifi_distance_disp_miles .. "' title='Distance to the farthest neighbor'> mi <a href='/help.html#distance' target='_blank'><img src='/qmark.png'></a><br />")
2022-05-18 11:49:00 -06:00
html.print("<input disabled size=6 type=text size=4 name='wifi_distance_disp_km' value='" .. wifi_distance_disp_km .. "' title='Distance to the farthest neighbor'> km<br />")
html.print("<input disabled size=6 type=text size=4 name='wifi_distance_disp_meters' value='" .. wifi_distance .."' title='Distance to the farthest neighbor'> m<br />")
html.print("<input id='distance_slider' type='range' min='0' max='150' step='1' value='" .. wifi_distance_disp_km .."' oninput='updDist(this.value)' onchange='updDist(this.value)' /><br />")
html.print("<input type='hidden' size='6' name='wifi_distance' value='" .. wifi_distance .. "' />")
html.print("</td></tr>")
end
2022-02-22 18:25:01 -07:00
html.print("<tr><td></td><td><input type=submit name=button_apply value=Apply title='Immediately use these active settings'></td></tr>")
else
hidden[#hidden + 1] = "<input type=hidden name=wifi_ssid value='" .. wifi_ssid .."'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi_mode value='" .. wifi_mode .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi_txpower value='" .. wifi_txpower .."'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi_channel value='" .. wifi_channel .."'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi_chanbw value='" .. wifi_chanbw .."'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi_distance value='" .. wifi_distance .."'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi_country value='HX'>"
end
2016-01-04 21:41:27 -07:00
2022-02-22 18:25:01 -07:00
html.print("</table></td>")
2018-12-12 14:16:07 -07:00
2022-02-22 18:25:01 -07:00
-- lan settings
2013-11-14 23:11:16 -07:00
2022-02-22 18:25:01 -07:00
html.print([[
<td valign=top width=33%><table width=100%>
2013-11-14 23:11:16 -07:00
<tr><th colspan=2>LAN</th></tr>
<tr>
<td>LAN Mode</td>
2022-02-22 18:25:01 -07:00
<td><select name=dmz_mode onChange='form.submit()'">
]])
html.print("<option value='0'".. (dmz_mode == 0 and " selected" or "") .. ">NAT</option>")
html.print("<option value='2'".. (dmz_mode == 2 and " selected" or "") .. ">1 host Direct</option>")
html.print("<option value='3'".. (dmz_mode == 3 and " selected" or "") .. ">5 host Direct</option>")
html.print("<option value='4'".. (dmz_mode == 4 and " selected" or "") .. ">13 host Direct</option>")
html.print("<option value='5'".. (dmz_mode == 5 and " selected" or "") .. ">29 host Direct</option>")
2022-05-23 06:45:16 -06:00
html.print("</select> <a href='/help.html#lanmode' target='_blank'><img src='/qmark.png'></a></td></tr>")
2022-02-22 18:25:01 -07:00
hidden[#hidden + 1] = "<input type=hidden name=lan_proto value='static'>"
if dmz_mode ~= 0 then
html.print("<tr><td><nobr>IP Address</nobr></td><td>" .. dmz_lan_ip .."</td></tr>")
hidden[#hidden + 1] = "<input type=hidden name=dmz_lan_ip value='" .. dmz_lan_ip .. "'>"
html.print("<tr><td>Netmask</td><td>" .. dmz_lan_mask .. "</td></tr>")
hidden[#hidden + 1] = "<input type=hidden name=dmz_lan_mask value='" ..dmz_lan_mask .. "'>"
html.print("<tr><td><nobr>DHCP Server</nobr></td><td><input type=checkbox name=lan_dhcp value=1" .. (lan_dhcp ~= "0" and " checked" or "") .. "></td></tr>")
html.print("<tr><td><nobr>DHCP Start</nobr></td><td>" .. dmz_dhcp_start .. "</td></tr>")
hidden[#hidden + 1] = "<input type=hidden name=dmz_dhcp_start value='" .. dmz_dhcp_start .. "'>"
html.print("<tr><td><nobr>DHCP End</nobr></td><td>" .. dmz_dhcp_end .. "</td></tr>")
2022-03-30 14:14:01 -06:00
hidden[#hidden + 1] = "<input type=hidden name=dmz_dhcp_end value='" .. dmz_dhcp_end .. "'>"
2022-02-22 18:25:01 -07:00
hidden[#hidden + 1] = "<input type=hidden name=lan_ip value='" .. lan_ip .."'>"
hidden[#hidden + 1] = "<input type=hidden name=lan_mask value='" .. lan_mask .."'>"
hidden[#hidden + 1] = "<input type=hidden name=dhcp_start value='" .. dhcp_start .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=dhcp_end value='" .. dhcp_end .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=lan_gw value='" .. lan_gw .."'>"
2013-11-14 23:11:16 -07:00
else
2022-02-22 18:25:01 -07:00
html.print("<tr><td><nobr>IP Address</nobr></td><td><input type=text size=15 name=lan_ip value='" .. lan_ip .. "'></td></tr>")
html.print("<tr><td>Netmask</td><td><input type=text size=15 name=lan_mask value='" .. lan_mask .."'></td></tr>")
if wan_proto == "disabled" then
html.print("<tr><td>Gateway</td><td><input type=text size=15 name=lan_gw value='" .. lan_gw .. "' title='leave blank if not needed'></td></tr>")
2018-11-27 22:37:59 -07:00
else
2022-02-22 18:25:01 -07:00
hidden[#hidden + 1] = "<input type=hidden name=lan_gw value='" .. lan_gw .. "'>"
end
html.print("<tr><td><nobr>DHCP Server</nobr></td><td><input type=checkbox name=lan_dhcp value=1" .. (lan_dhcp ~= "0" and " checked" or "") .. "></td></tr>")
html.print("<tr><td><nobr>DHCP Start</nobr></td><td><input type=text size=4 name=dhcp_start value='" .. dhcp_start .. "'></td></tr>")
html.print("<tr><td><nobr>DHCP End</nobr></td><td><input type=text size=4 name=dhcp_end value='" .. dhcp_end .. "'></td></tr>")
hidden[#hidden + 1] = "<input type=hidden name=dmz_lan_ip value='" .. dmz_lan_ip .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=dmz_lan_mask value='" .. dmz_lan_mask .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=dmz_dhcp_start value='" .. dmz_dhcp_start .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=dmz_dhcp_end value='" .. dmz_dhcp_end .. "'>"
end
2022-12-22 13:22:49 -07:00
local APokay = nixio.fs.stat("/usr/sbin/wpad")
if APokay and ((phycount > 1 and (wifi_enable ~= "1" or wifi3_enable ~= "1")) or (phycount == 1 and wifi_enable ~= "1" and wifi3_enable ~= "1") and not M39model) then
2024-03-29 16:42:00 -06:00
html.print("<tr><td colspan=2><hr></hr></td></tr>")
2022-02-22 18:25:01 -07:00
-- lan ap shows as an option
-- determine hardware options and set band ahd channels accordingly
if phycount == 1 then
2023-04-22 07:24:20 -06:00
chan = aredn.hardware.get_rfchannels("wlan0")
if chan[1].frequency < 3000 then
2022-02-22 18:25:01 -07:00
wifi2_hwmode = "11g"
if wifi2_channel > 14 then
wifi2_channel = 1
end
else
wifi2_hwmode = "11a"
if wifi2_channel < 36 then
wifi2_channel = 36
end
end
2019-04-06 22:03:16 -06:00
else
2022-02-22 18:25:01 -07:00
-- 2 band device
if wifi_enable == "1" then
2023-04-22 07:24:20 -06:00
local alt_wifi = (not phy or phy == "phy0") and "wlan1" or "wlan0"
chan = aredn.hardware.get_rfchannels(alt_wifi)
2023-12-17 22:14:38 -07:00
if #chan == 0 then
-- Hardware device can crash after switching - so at least make the page render until a reboot
chan[1] = { frequency = 2412, number = 1, label = nil }
end
2023-04-22 07:24:20 -06:00
if chan[1].frequency < 3000 then
2023-02-17 21:58:51 -07:00
wifi2_hwmode = "11g"
if wifi2_channel > 14 then
wifi2_channel = 1
end
else
wifi2_hwmode = "11a"
if wifi2_channel < 36 then
wifi2_channel = 36
end
2022-02-22 18:25:01 -07:00
end
else
if wifi2_enable ~= "1" and wifi3_enable == "1" and wifi3_hwmode == "11a" then
wifi2_hwmode = "11g"
end
if wifi2_enable ~= "1" and wifi3_enable == "1" and wifi3_hwmode == "11g" then
wifi2_hwmode = "11a"
end
2023-04-22 07:24:20 -06:00
local chan0 = aredn.hardware.get_rfchannels("wlan0")
local chan1 = aredn.hardware.get_rfchannels("wlan1")
2022-02-22 18:25:01 -07:00
if wifi2_hwmode == "11a" then
2023-07-21 14:59:15 -06:00
if #chan0 >= 1 and chan0[1].frequency > 3000 then
2023-04-22 07:24:20 -06:00
chan = chan0
else
chan = chan1
end
2022-02-22 18:25:01 -07:00
if wifi2_channel < 36 then
wifi2_channel = 36
end
else
2023-07-21 14:59:15 -06:00
if #chan0 >= 1 and chan0[1].frequency < 3000 then
2023-04-22 07:24:20 -06:00
chan = chan0
else
chan = chan1
end
2022-02-22 18:25:01 -07:00
if wifi2_channel > 14 then
wifi2_channel = 1
end
end
end
end
2022-05-23 06:45:16 -06:00
html.print("<tr><th colspan=2><small>LAN Access Point</small></th></tr><tr><td>Enable</td><td><input type=checkbox name=wifi2_enable value=1" .. (wifi2_enable == "1" and " checked" or "") .. "> <a href='/help.html#lanap' target='_blank'><img src='/qmark.png'></a></td></tr>")
2022-02-22 18:25:01 -07:00
if phycount > 1 then
if wifi_enable ~= "1" then
2023-02-17 21:58:51 -07:00
html.print("<tr><td>AP band</td><td><select name=wifi2_hwmode>")
2022-02-22 18:25:01 -07:00
html.print("<option value='11g'".. (wifi2_hwmode == "11g" and " selected" or "") .. ">2GHz</option>")
2023-02-17 21:58:51 -07:00
html.print("<option value='11a'".. (wifi2_hwmode == "11a" and " selected" or "") .. ">5GHz</option>")
html.print("</select></td></tr>")
else
2023-02-19 00:09:23 -07:00
html.print("<tr><td>AP band</td><td>" .. (wifi2_hwmode == "11g" and "2GHz" or "5GHz") .. "</td></tr>")
2023-02-17 21:58:51 -07:00
hidden[#hidden + 1] = "<input type=hidden name=wifi2_hwmode value='" .. wifi2_hwmode .."'>"
2022-02-22 18:25:01 -07:00
end
2019-04-06 22:03:16 -06:00
else
2022-02-22 18:25:01 -07:00
hidden[#hidden + 1] = "<input type=hidden name=wifi2_hwmode value='" .. wifi2_hwmode .."'>"
end
2023-02-10 09:29:22 -07:00
html.print("<tr><td>SSID</td><td><input type=text size=15 name=wifi2_ssid value='" .. wifi2_ssid .."'></td></tr>")
html.print("<tr><td>Channel</td><td><select name=wifi2_channel>")
2023-04-22 07:24:20 -06:00
if chan[1].frequency > 3000 then
2023-02-10 09:29:22 -07:00
html.print("<optgroup label='Standard Channels'>")
2023-04-22 07:24:20 -06:00
for _, ch in ipairs(chan)
do
if ch.number < 163 or ch.number == 165 then
html.print("<option value='" .. ch.number .. "'" .. (wifi2_channel == ch.number and " selected" or "") .. ">" .. ch.number .. "</option>")
2023-02-10 09:29:22 -07:00
end
end
html.print("</optgroup>")
html.print("<optgroup label='Extended Channels'>")
2023-04-22 07:24:20 -06:00
for _, ch in ipairs(chan)
do
if ch.number == 163 or ch.number > 165 then
html.print("<option value='" .. ch.number .. "'" .. (wifi2_channel == ch.number and " selected" or "") .. ">" .. ch.number .. "</option>")
2023-02-10 09:29:22 -07:00
end
end
html.print("</optgroup>")
else
2023-04-22 07:24:20 -06:00
for _, ch in ipairs(chan)
2023-02-10 09:29:22 -07:00
do
2023-04-22 07:24:20 -06:00
html.print("<option value='" ..ch.number .. "'" .. (wifi2_channel == ch.number and " selected" or "") .. ">" .. ch.number .. "</option>")
2023-02-10 09:29:22 -07:00
end
2022-02-22 18:25:01 -07:00
end
html.print("</select></td></tr>")
html.print("<tr><td>Encryption</td><td><select name=wifi2_encryption>")
html.print("<option value='psk2'".. (wifi2_encryption == "psk2" and " selected" or "") .. ">WPA2 PSK</option>")
html.print("<option value='psk'".. (wifi2_encryption == "psk" and " selected" or "") .. ">WPA PSK</option>")
2022-08-02 17:55:08 -06:00
html.print("</select></td></tr><tr><td>Password</td><td><input class='password-input' type=password size=15 name=wifi2_key value='" .. wifi2_key .. "'><i class='password-toggle'></i></td></tr>")
2018-12-12 14:16:07 -07:00
else
2022-06-29 14:45:54 -06:00
hidden[#hidden + 1] = "<input type=hidden name=wifi2_enable value='" .. (wifi2_enable or "") .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi2_ssid value='" .. (wifi2_ssid or "") .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi2_key value='" .. (wifi2_key or "") .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi2_channel value='" .. (wifi2_channel or "") .."'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi2_encryption value='" .. (wifi2_encryption or "") .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi2_hwmode value='" .. (wifi2_hwmode or "") .."'>"
2022-02-22 18:25:01 -07:00
end
html.print("</table></td>")
-- wan settings
html.print("<td valign=top width=33%><table width=100%><tr><th colspan=2>WAN</th></tr><tr><td width=50%>Protocol</td><td><select name=wan_proto onChange='form.submit()'>")
html.print("<option value='static'".. (wan_proto == "static" and " selected" or "") .. ">Static</option>")
html.print("<option value='dhcp'".. (wan_proto == "dhcp" and " selected" or "") .. ">DHCP</option>")
html.print("<option value='disabled'".. (wan_proto == "disabled" and " selected" or "") .. ">disabled</option>")
html.print("</select></td></tr>")
if wan_proto == "static" then
html.print("<tr><td><nobr>IP Address</nobr></td>")
html.print("<td><input type=text size=15 name=wan_ip value='" .. wan_ip .."'></td></tr>")
html.print("<tr><td>Netmask</td>")
html.print("<td><input type=text size=15 name=wan_mask value='" .. wan_mask .. "'></td></tr>")
html.print("<tr><td>Gateway</td>")
html.print("<td><input type=text size=15 name=wan_gw value='" .. wan_gw .. "'></td></tr>")
2013-11-14 23:11:16 -07:00
else
2022-02-22 18:25:01 -07:00
hidden[#hidden + 1] = "<input type=hidden name=wan_ip value='" .. wan_ip .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=wan_mask value='" .. wan_mask .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=wan_gw value='" .. wan_gw .."'>"
end
2019-04-06 22:03:16 -06:00
2022-02-22 18:25:01 -07:00
html.print("<tr><td><nobr>DNS 1</nobr></td><td><input type=text size=15 name=wan_dns1 value='" .. wan_dns1 .. "'></td></tr>")
html.print("<tr><td><nobr>DNS 2</nobr></td><td><input type=text size=15 name=wan_dns2 value='" .. wan_dns2 .. "'></td></tr>")
2013-11-14 23:11:16 -07:00
2022-02-22 18:25:01 -07:00
-- wan wifi client
2022-12-22 13:22:49 -07:00
if APokay and ((phycount > 1 and (wifi_enable ~= "1" or wifi2_enable ~= "1")) or (phycount == 1 and wifi_enable ~= "1" and wifi2_enable ~= "1")) and not M39model then
2022-02-22 18:25:01 -07:00
-- wifi client shows as an option
-- determine hardware options and set band accordingly
2024-03-29 16:42:00 -06:00
html.print("<tr><th colspan=2><hr></td></tr>")
2022-02-22 18:25:01 -07:00
if phycount == 1 then
2022-06-07 22:31:51 -06:00
local rc3 = os.execute("iw phy phy0 info | grep -q '5180 MHz' > /dev/null")
if rc3 ~= 0 then
2022-02-22 18:25:01 -07:00
wifi3_hwmode = "11g"
else
wifi3_hwmode = "11a"
end
2019-04-06 22:03:16 -06:00
else
2022-02-22 18:25:01 -07:00
-- 2 band
if wifi_enable == "1" then
2023-09-04 23:30:58 -06:00
local defaultwifi = aredn.hardware.get_default_channel(wifi_intf)
if defaultwifi.channel == 149 then
wifi3_hwmode = "11g"
else
wifi3_hwmode = "11a"
end
2022-02-22 18:25:01 -07:00
else
if wifi2_hwmode == "11g" and wifi2_enable == "1" then
wifi3_hwmode = "11a"
end
if wifi2_hwmode == "11a" and wifi2_enable == "1" then
wifi3_hwmode = "11g"
end
end
end
2022-08-02 17:56:27 -06:00
local connected = "/notdone.png"
local cmessage = "Not connected."
local wanintf = aredn.hardware.get_iface_name("wan")
local essid = capture_and_match("iwinfo " .. wanintf .. " info", 'ESSID: "(.+)"')
if essid == wifi3_ssid then
if pingOK then
connected = "/donedone.png"
cmessage = "Connected to Wifi and Internet."
else
connected = "/done.png"
cmessage = "Connected to Wifi. Not connected to Internet."
end
end
2022-08-11 01:19:33 -06:00
html.print("<tr><th colspan=2><small>WAN Wifi Client <img style='vertical-align:text-bottom' src='" .. connected .. "' title='" .. cmessage .. "'></small></th></tr>")
2022-08-02 17:56:27 -06:00
html.print("<tr><td>Enable</td><td><input type=checkbox name=wifi3_enable value=1" .. (wifi3_enable == "1" and " checked" or "") .. "> <a href='/help.html#wanclient' target='_blank'><img src='/qmark.png'></a></td></tr>")
2022-02-22 18:25:01 -07:00
if wifi_enable ~= "1" and wifi2_enable ~= "1" and phycount > 1 then
html.print("<tr><td>WAN Wifi Client band</td><td><select name=wifi3_hwmode>")
html.print("<option value='11g'".. (wifi3_hwmode == "11g" and " selected" or "") .. ">2GHz</option>")
html.print("<option value='11a'".. (wifi3_hwmode == "11a" and " selected" or "") .. ">5GHz</option>")
html.print("</select></td></tr>")
2019-04-06 22:03:16 -06:00
else
2022-02-22 18:25:01 -07:00
hidden[#hidden + 1] = "<input type=hidden name=wifi3_hwmode value='" .. wifi3_hwmode .. "'>"
end
2019-04-06 22:03:16 -06:00
2022-02-22 18:25:01 -07:00
html.print("<tr><td>SSID</td><td><input type=text name=wifi3_ssid size=15 value='" .. wifi3_ssid .."'></select></td></tr>")
2022-08-02 17:55:08 -06:00
html.print("<tr><td>Password</td><td><input class='password-input' type=password size=15 name=wifi3_key value='" .. wifi3_key .. "'><i class='password-toggle'></i></td></tr>")
2019-04-06 22:03:16 -06:00
else
2022-02-22 18:25:01 -07:00
hidden[#hidden + 1] = "<input type=hidden name=wifi3_enable value='" .. wifi3_enable .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi3_ssid value='" .. wifi3_ssid .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi3_key value='" .. wifi3_key .. "'>"
hidden[#hidden + 1] = "<input type=hidden name=wifi3_hwmode value='" .. wifi3_hwmode .. "'>"
end
-- end wan wifi client
html.print("</table></td></tr></table></td></tr></table><br></td></tr>")
2024-03-29 13:25:04 -06:00
-- Location and antenna settings
2022-02-22 18:25:01 -07:00
html.print("<tr><td align=center>")
2024-03-29 19:32:36 -06:00
html.print("<table border=0 style='min-width:790px'>")
2024-03-29 16:42:00 -06:00
html.print("<tr><th colspan=4>Location Settings</th></tr>")
2022-02-22 18:25:01 -07:00
html.print("<tr><td colspan=4><hr /></td></tr>")
html.print("<tr><td align=left>Latitude</td><td><input type=text name=latitude size=10 value='" .. lat .."' title='Latitude value (in decimal) (ie. 30.312354)' /></td>")
2024-03-29 13:25:04 -06:00
html.print("<td align='left' colspan='2'>")
2023-12-06 11:12:11 -07:00
local locdisabled = pingOK and "" or "disabled"
html.print("<button " .. locdisabled .. " type='button' id='findlocation' value='findloc' onClick='findLocation();'>Find Me!</button> ")
2022-02-22 18:25:01 -07:00
html.print("<input type=submit name='button_updatelocation' value='Apply Location Settings' title='Immediately use these location settings'>")
2023-12-06 11:12:11 -07:00
html.print(" <button " .. locdisabled .. " type='button' id='hideshowmap' value='show' onClick='toggleMap(this);'>Show Map</button> ")
html.print("<input " .. locdisabled .. " type='submit' name='button_uploaddata' value='Upload data to AREDN Servers' /> ")
2022-02-22 18:25:01 -07:00
2023-12-06 13:30:23 -07:00
html.print("</td><tr><td align=left>Longitude</td><td><input type=text name=longitude size=10 value='" .. lon .. "' title='Longitude value (in decimal) (ie. -95.334454)' /></td><td align=left>Grid Square <input type=text name=gridsquare maxlength=6 size=6 value='" .. gridsquare .. "' title='Gridsquare value (ie. AB12cd)' /></td></tr>")
2024-03-29 16:42:00 -06:00
html.print("<tr><td colspan=4><div id='map' style='height: 200px; display: none;'></div></td></tr>")
2023-12-06 13:30:23 -07:00
if wifi_enable == "1" then
2024-03-29 16:42:00 -06:00
html.print("<tr><th colspan=4 style='padding-top:20px'>Antenna Settings (optional)</th></tr>")
html.print("<tr><td colspan=4><hr /></td></tr>")
2023-12-06 13:30:23 -07:00
local ants = aredn.hardware.get_antennas(wifi_intf)
2024-03-29 13:25:04 -06:00
local antsx = aredn.hardware.get_antennas_aux(wifi_intf)
2023-12-06 13:30:23 -07:00
local changeh = true
local changea = true
if ants and #ants == 1 then
changea = false
antenna = ants[1].description
if ants[1].beamwidth == 360 then
changeh = false
end
end
if not changeh then
html.print("<tr><td align=left>Azimuth</td><td>-</td>")
else
2023-12-17 22:33:27 -07:00
html.print("<tr><td align=left>Azimuth</td><td><input type=text name=azimuth size=10 value='" .. azimuth .. "' title='azimuth (degrees)' /> °</td>")
2023-12-06 13:30:23 -07:00
end
if not changea then
2024-03-29 19:32:36 -06:00
html.print("<td align=left colspan=2>Antenna <input disabled value='" .. antenna .. "'></td>")
2023-12-06 13:30:23 -07:00
elseif ants then
2024-03-29 13:25:04 -06:00
html.print("<td align=left colspan=2>Antenna <select name=antenna>")
2023-12-06 13:30:23 -07:00
for _, ant in ipairs(ants)
do
html.print("<option value='" .. ant.model .. "'" .. (ant.model == antenna and " selected" or "") .. ">" .. ant.description .. "</option>")
end
html.print("</select></td>")
end
if not changeh then
html.print("</tr><tr><td align=left>Elevation</td><td>-</td>")
else
2023-12-17 22:33:27 -07:00
html.print("</tr><tr><td align=left>Elevation</td><td><input type=text name=elevation size=10 value='" .. elevation .. "' title='elevation above ground level (degrees)' /> °</td>")
2023-12-06 13:30:23 -07:00
end
2024-03-29 13:25:04 -06:00
if antsx then
html.print("<td align=left colspan=2>Aux Antenna <select name=antenna_aux>")
for _, ant in ipairs(antsx)
do
html.print("<option value='" .. ant.model .. "'" .. (ant.model == antenna_aux and " selected" or "") .. ">" .. ant.description .. "</option>")
end
html.print("</select></td>")
end
html.print("</tr><tr><td align=left>Height</td><td><input type=text name=height size=10 value='" .. height .. "' title='height above ground level (meters)' /> m</tr>")
2023-12-06 13:30:23 -07:00
end
2024-03-29 16:42:00 -06:00
html.print("<tr><td colspan=4><hr /></td></tr>")
2024-03-29 13:25:04 -06:00
html.print("<tr><td colspan=2>Timezone <select name=time_zone_name tabindex=10>")
2022-02-22 18:25:01 -07:00
for _,zone in ipairs(tz_db_names)
do
2022-03-01 22:40:11 -07:00
html.print("<option value='" .. zone.name .. "'".. (zone.name == time_zone_name and " selected" or "") .. ">" .. zone.name .. "</option>")
2022-02-22 18:25:01 -07:00
end
2022-10-02 17:46:57 -06:00
html.print("</select></td>")
html.print("<td align=center>NTP Server <input type=text name=ntp_server size=20 value='" .. ntp_server .. "'></td>")
if ntp_period == "daily" or not ntp_period then
html.print("<td>NTP Updates <select name=ntp_period><option value='daily' selected>daily</option><option value='hourly'>hourly</option></select></td></table></td></tr></table>")
elseif ntp_period == "hourly" then
html.print("<td>NTP Updates <select name=ntp_period><option value='daily'>daily</option><option value='hourly' selected>hourly</option></select></td></table></td></tr></table>")
end
2022-02-22 18:25:01 -07:00
hidden[#hidden + 1] = "<input type=hidden name=reload value=1>"
hidden[#hidden + 1] = "<input type=hidden name=dtdlink_ip value='" .. dtdlink_ip .. "'>"
2022-04-27 18:38:16 -06:00
if wan_intf then
hidden[#hidden + 1] = "<input type=hidden name=wan_intf value='" .. wan_intf .. "'>"
end
2022-02-22 18:25:01 -07:00
for _,hid in ipairs(hidden)
do
html.print(hid)
end
html.print("</form></center>")
2022-08-02 17:55:08 -06:00
html.print([[<style>
.password-input {
padding-right: 21px;
}
.password-toggle {
display: inline-block;
width: 21px;
height: 15px;
margin-left: -24px;
cursor: pointer;
background-image: url(/viz.png);
background-size: contain;
2024-03-29 19:32:36 -06:00
vertical-align: middle;
2022-08-02 17:55:08 -06:00
}
</style>
<script>
function togglePassword(e) {
var target = e.target.previousSibling;
if (target.type === "password") {
target.type = "text";
}
else {
target.type = "password";
}
}
var fields = document.querySelectorAll(".password-toggle");
for (var i = 0; i < fields.length; i++) {
fields[i].addEventListener("click", togglePassword);
}
</script>]])
2022-02-22 18:25:01 -07:00
html.footer()
html.print("</body></html>")
http_footer()