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

197 lines
5.4 KiB
JSON
Raw Normal View History

#!/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")
local aredn_info = require("aredn.info")
local aredn_olsr = require("aredn.olsr")
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
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
info['api_version']="1.11"
-- 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()
-- 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()
else
info['meshrf']['status']="off"
end
-- Tunnel info
info['tunnels']={}
-- ACTIVE TUNNELS
local atc=""
atc=os.capture("ifconfig|grep tun|wc -l")
info['tunnels']['active_tunnel_count']=atc:chomp()
-- 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
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"),
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
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")
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 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
-- Output the HTTP header for JSON
json_header()
-- Output the info table as json
print(json.stringify(info,true))