2016-10-05 19:58:39 -06:00
|
|
|
#!/usr/bin/lua
|
|
|
|
--[[
|
|
|
|
|
2024-05-29 01:45:25 -06:00
|
|
|
Part of AREDN® -- Used for creating Amateur Radio Emergency Data Networks
|
2016-10-05 19:58:39 -06:00
|
|
|
Copyright (C) 2016 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:
|
|
|
|
|
2024-05-29 01:45:25 -06:00
|
|
|
Additional use restrictions exist on the AREDN® trademark and logo.
|
2016-10-05 19:58:39 -06: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.
|
2016-10-05 19:58:39 -06: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.
|
2016-10-05 19:58:39 -06: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("uci")
|
|
|
|
require("aredn.utils")
|
2024-04-01 23:15:45 -06:00
|
|
|
require("aredn.info")
|
|
|
|
require("aredn.olsr")
|
2023-12-06 13:30:23 -07:00
|
|
|
require("aredn.hardware")
|
2016-10-05 19:58:39 -06:00
|
|
|
require("nixio")
|
|
|
|
local ipc = require("luci.ip")
|
|
|
|
local json = require ("luci.jsonc")
|
|
|
|
|
|
|
|
-- Function extensions
|
|
|
|
os.capture = capture
|
|
|
|
|
|
|
|
-- ==== MAIN =====
|
|
|
|
ctx = uci.cursor()
|
|
|
|
if not ctx then
|
|
|
|
error("Failed to get uci cursor")
|
|
|
|
end
|
|
|
|
|
|
|
|
info={}
|
|
|
|
|
|
|
|
-- API version
|
2023-12-06 13:30:23 -07:00
|
|
|
info['api_version']="1.13"
|
2016-10-05 19:58:39 -06:00
|
|
|
|
2018-09-17 12:41:29 -06:00
|
|
|
|
2016-10-05 19:58:39 -06:00
|
|
|
-- NODE name
|
2024-04-01 23:15:45 -06:00
|
|
|
info['node']=aredn.info.getNodeName()
|
2016-10-05 19:58:39 -06:00
|
|
|
|
2018-09-17 12:41:29 -06:00
|
|
|
info['node_details']={}
|
2016-10-05 19:58:39 -06:00
|
|
|
-- MODEL
|
2024-04-01 23:15:45 -06:00
|
|
|
info['node_details']['model']=aredn.info.getModel()
|
2016-10-05 19:58:39 -06:00
|
|
|
|
2018-08-26 12:03:26 -06:00
|
|
|
-- DESCRIPTION
|
2024-04-01 23:15:45 -06:00
|
|
|
info['node_details']['description']=aredn.info.getNodeDescription()
|
2018-08-26 12:03:26 -06:00
|
|
|
|
2016-10-05 19:58:39 -06:00
|
|
|
-- BOARD ID
|
2018-09-10 12:37:50 -06:00
|
|
|
info['node_details']['board_id']=hardware_boardid()
|
2016-10-05 19:58:39 -06:00
|
|
|
|
|
|
|
-- Firmware Manufacturer
|
|
|
|
local fw_mfg="AREDN"
|
|
|
|
if not file_exists("/www/AREDN.png") then
|
|
|
|
fw_mfg = "Other"
|
|
|
|
end
|
2018-09-10 12:37:50 -06:00
|
|
|
info['node_details']['firmware_mfg']=fw_mfg
|
2016-10-05 19:58:39 -06:00
|
|
|
|
|
|
|
-- Firmware version
|
2024-04-01 23:15:45 -06:00
|
|
|
info['node_details']['firmware_version']=aredn.info.getFirmwareVersion()
|
2018-09-10 12:37:50 -06:00
|
|
|
|
2021-03-15 08:39:27 -06:00
|
|
|
-- Mesh Gatway
|
2024-04-01 23:15:45 -06:00
|
|
|
info['node_details']['mesh_gateway']=aredn.info.getMeshGatewaySetting()
|
2021-03-15 08:39:27 -06:00
|
|
|
|
2023-09-19 21:06:09 -06:00
|
|
|
-- Supernode
|
|
|
|
if ctx:get("aredn", "@supernode[0]", "enable") == "1" then
|
|
|
|
info['node_details']['mesh_supernode']=true
|
|
|
|
end
|
|
|
|
|
2018-09-10 12:37:50 -06:00
|
|
|
-- Mesh RF info
|
2018-12-22 10:26:31 -07:00
|
|
|
info['meshrf']={}
|
2024-04-01 23:15:45 -06:00
|
|
|
local radio=aredn.info.getMeshRadioDevice()
|
2019-04-29 21:43:37 -06:00
|
|
|
|
2021-04-06 20:15:50 -06:00
|
|
|
if ( radio ~= nil and radio ~= "" ) then
|
2018-12-22 10:26:31 -07:00
|
|
|
info['meshrf']['status']="on"
|
2024-04-01 23:15:45 -06:00
|
|
|
info['meshrf']['ssid']=aredn.info.getSSID()
|
|
|
|
info['meshrf']['channel']=aredn.info.getChannel(radio)
|
|
|
|
info['meshrf']['chanbw']=aredn.info.getChannelBW(radio)
|
|
|
|
info['meshrf']['freq']=aredn.info.getFreq(radio)
|
|
|
|
info['meshrf']['azimuth'] = aredn.info.getAzimuth()
|
|
|
|
info['meshrf']['elevation'] = aredn.info.getElevation()
|
|
|
|
info['meshrf']['height'] = aredn.info.getHeight()
|
2023-12-06 13:30:23 -07:00
|
|
|
info['meshrf']['antenna'] = aredn.hardware.get_current_antenna(radio)
|
2024-03-29 13:25:04 -06:00
|
|
|
info['meshrf']['antenna_aux'] = aredn.hardware.get_current_antenna_aux(radio)
|
2018-12-22 10:26:31 -07:00
|
|
|
else
|
|
|
|
info['meshrf']['status']="off"
|
|
|
|
end
|
2016-10-05 19:58:39 -06:00
|
|
|
|
2018-09-10 12:37:50 -06:00
|
|
|
-- Tunnel info
|
|
|
|
info['tunnels']={}
|
2016-10-05 19:58:39 -06:00
|
|
|
-- ACTIVE TUNNELS
|
2024-05-12 15:53:37 -06:00
|
|
|
local atc=os.capture("ifconfig|grep tun|wc -l"):chomp()
|
2024-05-26 17:42:48 -06:00
|
|
|
local awc=0
|
|
|
|
if nixio.fs.stat("/usr/bin/wg") then
|
|
|
|
awc=os.capture("wg|grep interface|wc -l"):chomp()
|
|
|
|
end
|
2024-05-12 15:53:37 -06:00
|
|
|
info['tunnels']['active_tunnel_count']=tonumber(atc) + tonumber(awc)
|
2016-10-05 19:58:39 -06:00
|
|
|
|
2018-09-10 12:37:50 -06:00
|
|
|
-- Location info
|
2016-10-05 19:58:39 -06:00
|
|
|
-- LAT/LON
|
2024-04-01 23:15:45 -06:00
|
|
|
local lat, lon = aredn.info.getLatLon()
|
2018-09-17 12:41:29 -06:00
|
|
|
info['lat']=lat
|
|
|
|
info['lon']=lon
|
2016-10-05 19:58:39 -06:00
|
|
|
|
|
|
|
-- GRID SQUARE
|
2024-04-01 23:15:45 -06:00
|
|
|
info["grid_square"]=aredn.info.getGridSquare()
|
2016-10-05 19:58:39 -06:00
|
|
|
|
2018-07-13 22:44:28 -06:00
|
|
|
-- UPTIME AND LOADAVGS
|
|
|
|
mynix=nixio.sysinfo()
|
|
|
|
info['sysinfo']={}
|
|
|
|
upsecs=mynix['uptime']
|
|
|
|
info['sysinfo']['uptime']=secondsToClock(upsecs)
|
|
|
|
info['sysinfo']['loads']=mynix['loads']
|
|
|
|
for n,x in ipairs(info['sysinfo']['loads']) do
|
|
|
|
info['sysinfo']['loads'][n]=round2(x,2)
|
|
|
|
end
|
|
|
|
|
2016-10-05 19:58:39 -06:00
|
|
|
-- INTERFACES
|
|
|
|
local tif={}
|
|
|
|
local ift=get_interfaces()
|
|
|
|
|
|
|
|
for pos, i in pairs(ift) do
|
|
|
|
local nim={}
|
|
|
|
local ipv4=""
|
2018-09-01 17:39:19 -06:00
|
|
|
if (i.name ~= "lo" and i.name ~= "wlan0-1" and i.name ~= "wlan1-1") then
|
2016-10-05 19:58:39 -06:00
|
|
|
--table.print(i)
|
|
|
|
nim['name']=i.name
|
|
|
|
ipv4=tostring(i.ipaddrs[1])
|
|
|
|
nim['ip']=ipFromCIDR(ipv4)
|
2016-12-30 21:47:56 -07:00
|
|
|
if i.macaddr~=nil then -- ie. tunXX interfaces have nil for macaddr
|
|
|
|
nim['mac']=i.macaddr:upper()
|
|
|
|
end
|
2016-10-05 19:58:39 -06:00
|
|
|
table.insert(tif,nim)
|
|
|
|
end
|
|
|
|
end
|
2018-12-22 10:26:31 -07:00
|
|
|
info['interfaces']=tif
|
2016-10-05 19:58:39 -06:00
|
|
|
|
|
|
|
-- HOSTS
|
|
|
|
if string.find(nixio.getenv("QUERY_STRING"):lower(),"hosts=1") then
|
2024-04-01 23:15:45 -06:00
|
|
|
info['hosts']=aredn.info.all_hosts()
|
2016-10-05 19:58:39 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
-- SERVICES
|
|
|
|
if string.find(nixio.getenv("QUERY_STRING"):lower(),"services=1") then
|
2024-04-01 23:15:45 -06:00
|
|
|
info['services']=aredn.info.all_services()
|
2016-10-05 19:58:39 -06:00
|
|
|
end
|
|
|
|
|
2018-07-18 15:48:31 -06:00
|
|
|
-- LOCALLY HOSTED SERVICES ONLY
|
|
|
|
if string.find(nixio.getenv("QUERY_STRING"):lower(),"services_local=1") then
|
2024-04-01 23:15:45 -06:00
|
|
|
info['services_local']=aredn.info.local_services()
|
2019-04-29 21:43:37 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
-- LOCAL NEIGHBORS LINK INFO
|
|
|
|
if string.find(nixio.getenv("QUERY_STRING"):lower(),"link_info=1") then
|
2024-04-01 23:15:45 -06:00
|
|
|
info['link_info']=aredn.olsr.getCurrentNeighbors(true)
|
2019-04-29 21:43:37 -06:00
|
|
|
end
|
|
|
|
|
2022-05-18 11:49:00 -06:00
|
|
|
-- LQM INFO
|
|
|
|
if string.find(nixio.getenv("QUERY_STRING"):lower(),"lqm=1") then
|
|
|
|
local lqm = { enabled = false }
|
|
|
|
if ctx:get("aredn", "@lqm[0]", "enable") == "1" then
|
|
|
|
lqm.enabled = true
|
2024-09-10 11:18:58 -06:00
|
|
|
end
|
|
|
|
lqm.config = {
|
|
|
|
min_snr = tonumber(ctx:get("aredn", "@lqm[0]", "min_snr")),
|
|
|
|
margin_snr = tonumber(ctx:get("aredn", "@lqm[0]", "margin_snr")),
|
|
|
|
min_distance = tonumber(ctx:get("aredn", "@lqm[0]", "min_distance")),
|
|
|
|
max_distance = tonumber(ctx:get("aredn", "@lqm[0]", "max_distance")),
|
|
|
|
auto_distance = tonumber(ctx:get("aredn", "@lqm[0]", "auto_distance") or "0"),
|
|
|
|
min_quality = tonumber(ctx:get("aredn", "@lqm[0]", "min_quality")),
|
|
|
|
margin_quality = tonumber(ctx:get("aredn", "@lqm[0]", "margin_quality")),
|
|
|
|
ping_penalty = tonumber(ctx:get("aredn", "@lqm[0]", "ping_penalty")),
|
|
|
|
user_blocks = ctx:get("aredn", "@lqm[0]", "user_blocks"),
|
|
|
|
user_allows = ctx:get("aredn", "@lqm[0]", "user_allows")
|
|
|
|
}
|
|
|
|
lqm.info = {}
|
|
|
|
if nixio.fs.stat("/tmp/lqm.info") then
|
|
|
|
lqm.info = json.parse(io.open("/tmp/lqm.info", "r"):read("*a"))
|
2022-05-18 11:49:00 -06:00
|
|
|
end
|
|
|
|
info['lqm']=lqm
|
|
|
|
end
|
|
|
|
|
2023-09-29 21:08:49 -06:00
|
|
|
-- MESH NODES COUNT
|
|
|
|
if string.find(nixio.getenv("QUERY_STRING"):lower(),"nodes=1") then
|
2024-04-01 23:15:45 -06:00
|
|
|
info['nodes']=aredn.info.getOLSRInfo()
|
2023-09-29 21:08:49 -06:00
|
|
|
end
|
|
|
|
|
2024-10-16 19:04:52 -06:00
|
|
|
-- TOPOLOGY
|
|
|
|
if string.find(nixio.getenv("QUERY_STRING"):lower(),"topology=1") then
|
|
|
|
info['topology']=aredn.olsr.getOLSRTopology()
|
|
|
|
end
|
|
|
|
|
2016-10-05 19:58:39 -06:00
|
|
|
-- Output the HTTP header for JSON
|
2024-10-12 00:03:20 -06:00
|
|
|
print("Content-type: application/json\r")
|
|
|
|
print("Cache-Control: no-store\r")
|
|
|
|
print("Access-Control-Allow-Origin: *\r")
|
|
|
|
print("\n")
|
2016-10-05 19:58:39 -06:00
|
|
|
|
|
|
|
-- Output the info table as json
|
|
|
|
print(json.stringify(info,true))
|