#!/usr/bin/lua
--[[
Part of AREDN® -- Used for creating Amateur Radio Emergency Data Networks
Copyright (C) 2021 Tim Wilkinson
Original Perl Copyright (C) 2015 Conrad Lara
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 .
Additional Terms:
Additional use restrictions exist on the AREDN® 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")
require("aredn.html")
require("uci")
require("aredn.info")
require("ubus")
require("luci.jsonc")
local html = aredn.html
local cursor = uci.cursor()
local conn = ubus.connect()
-- handle firmware updates
local fw_install = false
local fw_output = {}
local fw_versions = {}
local fw_names = {}
local fw_version = ""
function fwout(msg)
fw_output[#fw_output + 1] = msg
end
function get_default_gw()
-- a node with a wired default gw will route via this
local p = io.popen("ip route list table 254")
if p then
for line in p:lines()
do
local gw = line:match("^default%svia%s([%d%.]+)")
if gw then
p:close()
return gw
end
end
p:close()
end
-- table 31 is populated by OLSR
p = io.popen("ip route list table 31")
if p then
for line in p:lines()
do
local gw = line:match("^default%svia%s([%d%.]+)")
if gw then
p:close()
return gw
end
end
p:close()
end
return "none"
end
function word_wrap(len, lines)
local output = ""
for _, str in ipairs(lines)
do
while #str > len
do
local str1 = str:sub(1, len)
local str2 = str:sub(len + 1)
local m, x = str1:match("^(.*)%s(%S+)$")
if m then
output = output .. m .. "\n"
str = x .. str2
else
output = output .. str1 .. "\n"
str = str2
end
end
output = output .. str .. "\n"
end
return output:sub(1, #output - 1)
end
function print_firmware_notice(reboot_when, href_addr, text_addr)
html.print([[
Firmware will be written in the background.
If your computer is connected to the LAN of this node you may need to acquire
a new IP address and reset any name service caches you may be using.
The node will reboot ]] .. reboot_when .. [[.
When the node has finished booting you should ensure your computer has
received a new IP address and reconnect with http://]] .. text_addr .. [[:8080/
This page will automatically reload once the upgrade has completed