aredn/files/www/cgi-bin/sysinfo.json

216 lines
6.1 KiB
JSON
Raw Normal View History

#!/usr/bin/lua
--[[
2024-05-29 01:45:25 -06:00
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:
2024-05-29 01:45:25 -06:00
Additional use restrictions exist on the AREDN® trademark and logo.
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.
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.
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")
require("aredn.info")
require("aredn.olsr")
require("aredn.hardware")
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
info['api_version']="1.13"
-- NODE name
info['node']=aredn.info.getNodeName()
info['node_details']={}
-- MODEL
info['node_details']['model']=aredn.info.getModel()
-- DESCRIPTION
info['node_details']['description']=aredn.info.getNodeDescription()
-- BOARD ID
info['node_details']['board_id']=hardware_boardid()
-- Firmware Manufacturer
local fw_mfg="AREDN"
if not file_exists("/www/AREDN.png") then
fw_mfg = "Other"
end
info['node_details']['firmware_mfg']=fw_mfg
-- Firmware version
info['node_details']['firmware_version']=aredn.info.getFirmwareVersion()
-- Mesh Gatway
info['node_details']['mesh_gateway']=aredn.info.getMeshGatewaySetting()
-- Supernode
if ctx:get("aredn", "@supernode[0]", "enable") == "1" then
info['node_details']['mesh_supernode']=true
end
-- Mesh RF info
info['meshrf']={}
local radio=aredn.info.getMeshRadioDevice()
if ( radio ~= nil and radio ~= "" ) then
info['meshrf']['status']="on"
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()
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)
else
info['meshrf']['status']="off"
end
-- Tunnel info
info['tunnels']={}
-- ACTIVE TUNNELS
local atc=os.capture("ifconfig|grep tun|wc -l"):chomp()
local awc=0
if nixio.fs.stat("/usr/bin/wg") then
awc=os.capture("wg|grep interface|wc -l"):chomp()
end
info['tunnels']['active_tunnel_count']=tonumber(atc) + tonumber(awc)
-- Location info
-- LAT/LON
local lat, lon = aredn.info.getLatLon()
info['lat']=lat
info['lon']=lon
-- GRID SQUARE
info["grid_square"]=aredn.info.getGridSquare()
-- 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
-- INTERFACES
local tif={}
local ift=get_interfaces()
for pos, i in pairs(ift) do
local nim={}
local ipv4=""
if (i.name ~= "lo" and i.name ~= "wlan0-1" and i.name ~= "wlan1-1") then
--table.print(i)
nim['name']=i.name
ipv4=tostring(i.ipaddrs[1])
nim['ip']=ipFromCIDR(ipv4)
if i.macaddr~=nil then -- ie. tunXX interfaces have nil for macaddr
nim['mac']=i.macaddr:upper()
end
table.insert(tif,nim)
end
end
info['interfaces']=tif
-- HOSTS
if string.find(nixio.getenv("QUERY_STRING"):lower(),"hosts=1") then
info['hosts']=aredn.info.all_hosts()
end
-- SERVICES
if string.find(nixio.getenv("QUERY_STRING"):lower(),"services=1") then
info['services']=aredn.info.all_services()
end
-- LOCALLY HOSTED SERVICES ONLY
if string.find(nixio.getenv("QUERY_STRING"):lower(),"services_local=1") then
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
Link Quality Management (#360) * Link Quality Management experiment (built in) * Protect LQM pages * Omit "empty" mac addresses * Integrate LQM v0.2 Includes proposed UI if this were built-in. When LQM is enabled (advanced settings) the usual distance inputs are replaced with "min snr' and "max distance" inputs which are the major ones you might tweak, as well as a link to the LQM status page. Other controls are now available (so protected) in advanced settings. * Improve LQM updating * Use running snr averages * Merge app changes * AREDN-ize the UI * Improve status language * Improved DtD detection * Improve quality reporting * Link Quality category * Enable by default * Better intergration * Link => Neighbor * Formatting * Make sure initial page is populated without extra fetch * Handle empty lqm.info * Update with latest experiment algorithm changes * Validate LQM settings before applying them * Algorithm updates * Improve quality reporting * %% -> % * Default max distance now 50 miles * Get actual noise if radio will provide it * low_snr => min_snr * Dont print node description if we dont have one * Remove properties duplicated from setup page * Localize max distance. Miles in GB and US, Kilometers everywhere else. * Ping link quality testing * UDP 'ping' for quality check * Change Active Settings title * Expand ping test * Improve messaging * Add a ping penalty for neighbors which cannot be contacted in a timely manner. * Remove user_blocks config option. No one needs to use this anymore. * Localize distances on lqm page * Improve status reporting * First run emergency node setup. When a node first runs LQM, if the default settings fail to connect to a node we will now adjust them so that at least one node is viable. * Restore blocking of mac addresses * LQM now off by default fixed #47
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"))
Link Quality Management (#360) * Link Quality Management experiment (built in) * Protect LQM pages * Omit "empty" mac addresses * Integrate LQM v0.2 Includes proposed UI if this were built-in. When LQM is enabled (advanced settings) the usual distance inputs are replaced with "min snr' and "max distance" inputs which are the major ones you might tweak, as well as a link to the LQM status page. Other controls are now available (so protected) in advanced settings. * Improve LQM updating * Use running snr averages * Merge app changes * AREDN-ize the UI * Improve status language * Improved DtD detection * Improve quality reporting * Link Quality category * Enable by default * Better intergration * Link => Neighbor * Formatting * Make sure initial page is populated without extra fetch * Handle empty lqm.info * Update with latest experiment algorithm changes * Validate LQM settings before applying them * Algorithm updates * Improve quality reporting * %% -> % * Default max distance now 50 miles * Get actual noise if radio will provide it * low_snr => min_snr * Dont print node description if we dont have one * Remove properties duplicated from setup page * Localize max distance. Miles in GB and US, Kilometers everywhere else. * Ping link quality testing * UDP 'ping' for quality check * Change Active Settings title * Expand ping test * Improve messaging * Add a ping penalty for neighbors which cannot be contacted in a timely manner. * Remove user_blocks config option. No one needs to use this anymore. * Localize distances on lqm page * Improve status reporting * First run emergency node setup. When a node first runs LQM, if the default settings fail to connect to a node we will now adjust them so that at least one node is viable. * Restore blocking of mac addresses * LQM now off by default fixed #47
2022-05-18 11:49:00 -06:00
end
info['lqm']=lqm
end
-- MESH NODES COUNT
if string.find(nixio.getenv("QUERY_STRING"):lower(),"nodes=1") then
info['nodes']=aredn.info.getOLSRInfo()
end
-- Output the HTTP header for JSON
json_header()
-- Output the info table as json
print(json.stringify(info,true))