#!/usr/bin/lua --! LibreMesh --! Copyright (C) 2023 Javier Jorge --! Copyright (C) 2023 AsociaciĆ³n Civil Altermundi --! --! This program is free software: you can redistribute it and/or modify --! it under the terms of the GNU Affero General Public License as --! published by the Free Software Foundation, either version 3 of the --! License, or (at your option) any later version. --! --! 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 Affero General Public License for more details. --! --! You should have received a copy of the GNU Affero General Public License --! along with this program. If not, see . local JSON = require("luci.jsonc") local network = require ("lime.network") local location = require("lime.location") local utils = require('lime.utils') local config = require("lime.config") local hostname = utils.hostname() function get_node_info() local uci = config.get_uci_cursor() local coords = location.get_node() or location.get_community() or {lat="FIXME", long="FIXME"} local fw_version = "no version" pcall(function () fw_version = utils.release_info()['DISTRIB_RELEASE'] end) local board = "no board" pcall(function () board = utils.current_board() end) local ipv4 = uci:get("network", "lan", "ipaddr") local ipv6 = uci:get("network", "lan", "ip6addr") if ipv6 then ipv6 = ipv6:gsub("/.*$", "") end local uptime = utils.uptime_s() local macs = network.get_own_macs("*") return {hostname=hostname, firmware_version=fw_version, board=board, ipv4=ipv4, ipv6=ipv6,coordinates=coords,macs= macs,uptime = uptime, device = "Router" } end local result = { [hostname] = get_node_info() } io.popen("shared-state insert node_info", "w"):write(JSON.stringify(result))