2016-10-05 19:58:39 -06:00
|
|
|
#!/usr/bin/lua
|
|
|
|
--[[
|
|
|
|
|
|
|
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
|
|
|
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:
|
|
|
|
|
|
|
|
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("uci")
|
|
|
|
require("aredn.utils")
|
2019-01-21 14:41:31 -07:00
|
|
|
local aredn_info = require("aredn.info")
|
2019-04-29 21:43:37 -06:00
|
|
|
local aredn_olsr = require("aredn.olsr")
|
2016-10-05 19:58:39 -06:00
|
|
|
require("aredn.http")
|
|
|
|
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
|
2022-05-18 11:49:00 -06:00
|
|
|
info['api_version']="1.11"
|
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
|
2019-01-21 14:41:31 -07: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
|
2019-01-21 14:41:31 -07: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
|
2019-01-21 14:41:31 -07: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
|
2019-01-21 14:41:31 -07: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
|
|
|
|
info['node_details']['mesh_gateway']=aredn_info.getMeshGatewaySetting()
|
|
|
|
|
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']={}
|
2019-01-21 14:41:31 -07: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"
|
2019-01-21 14:41:31 -07:00
|
|
|
info['meshrf']['ssid']=aredn_info.getSSID()
|
|
|
|
info['meshrf']['channel']=aredn_info.getChannel(radio)
|
|
|
|
info['meshrf']['chanbw']=aredn_info.getChannelBW(radio)
|
2023-06-02 19:47:34 -06:00
|
|
|
info['meshrf']['freq']=aredn_info.getFreq(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
|
|
|
|
local atc=""
|
|
|
|
atc=os.capture("ifconfig|grep tun|wc -l")
|
2018-12-22 10:26:31 -07:00
|
|
|
info['tunnels']['active_tunnel_count']=atc:chomp()
|
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
|
2019-01-21 14:41:31 -07: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
|
2019-01-21 14:41:31 -07: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
|
2019-04-29 21:43:37 -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
|
2019-04-29 21:43:37 -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
|
2019-04-29 21:43:37 -06:00
|
|
|
info['services_local']=aredn_info.local_services()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- LOCAL NEIGHBORS LINK INFO
|
|
|
|
if string.find(nixio.getenv("QUERY_STRING"):lower(),"link_info=1") then
|
|
|
|
info['link_info']=aredn_olsr.getCurrentNeighbors(true)
|
|
|
|
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
|
|
|
|
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")),
|
2022-06-27 15:31:43 -06:00
|
|
|
auto_distance = tonumber(ctx:get("aredn", "@lqm[0]", "auto_distance") or "0"),
|
2022-05-18 11:49:00 -06:00
|
|
|
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")),
|
2022-06-12 22:01:12 -06:00
|
|
|
user_blocks = ctx:get("aredn", "@lqm[0]", "user_blocks"),
|
|
|
|
user_allows = ctx:get("aredn", "@lqm[0]", "user_allows")
|
2022-05-18 11:49:00 -06:00
|
|
|
}
|
|
|
|
lqm.info = {}
|
|
|
|
if nixio.fs.stat("/tmp/lqm.info") then
|
|
|
|
lqm.info = json.parse(io.open("/tmp/lqm.info", "r"):read("*a"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
info['lqm']=lqm
|
|
|
|
end
|
|
|
|
|
2016-10-05 19:58:39 -06:00
|
|
|
-- Output the HTTP header for JSON
|
|
|
|
json_header()
|
|
|
|
|
|
|
|
-- Output the info table as json
|
|
|
|
print(json.stringify(info,true))
|