From 8ae45120481ed3bc5a6ea9db1cce6a95d66b5ac9 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 15 Nov 2023 17:38:14 -0500 Subject: [PATCH] More UI polish, easymesh.sh actually gets run now on apply --- luasrc/model/cbi/easymesh.lua | 60 ++++++++++++++--------------------- root/easymesh/easymesh.sh | 17 ++++++---- 2 files changed, 34 insertions(+), 43 deletions(-) mode change 100644 => 100755 root/easymesh/easymesh.sh diff --git a/luasrc/model/cbi/easymesh.lua b/luasrc/model/cbi/easymesh.lua index 16d78c9..7bf22fc 100755 --- a/luasrc/model/cbi/easymesh.lua +++ b/luasrc/model/cbi/easymesh.lua @@ -13,34 +13,28 @@ m = Map("easymesh", function detect_Node() - local data = {} - local lps = luci.util.execi(" batctl n 2>/dev/null | tail +2 | sed 's/^[ ][ ]*//g' | sed 's/[ ][ ]*/ /g' | sed 's/$/ /g' ") - for value in lps do - local row = {} - local pos = string.find(value, " ") - local IFA = string.sub(value, 1, pos - 1) - local value = string.sub(value, pos + 1, string.len(value)) - pos = string.find(value, " ") - local pos = string.find(value, " ") - local Neighbora = string.sub(value, 1, pos - 1) - local value = string.sub(value, pos + 1, string.len(value)) - pos = string.find(value, " ") - local pos = string.find(value, " ") - local lastseena = string.sub(value, 1, pos - 1) - local value = string.sub(value, pos + 1, string.len(value)) - pos = string.find(value, " ") - row["IF"] = IFA - row["Neighbor"] = Neighbora - row["lastseen"] = lastseena - table.insert(data, row) - end - return data + local data = {} + -- Streamline the command to retrieve node information + local lps = luci.util.execi("batctl n 2>/dev/null | tail +2 | sed 's/^[ ]*//;s/[ ]*/ /g'") + + for line in lps do + -- Split the line into parts using pattern matching + local ifa, neighbor, lastseen = string.match(line, "(%S+) (%S+) (%S+)") + + if ifa and neighbor and lastseen then + -- Construct the row and add it to the data table + local row = {["IF"] = ifa, ["Neighbor"] = neighbor, ["lastseen"] = lastseen} + table.insert(data, row) + end + end + return data end + function get_verbose_hw_info(iface) local type = iwinfo.type(iface) if not type then - return "Generic Wifi Device" + return "Generic" end local driver = iwinfo[type] @@ -68,17 +62,16 @@ function get_verbose_hw_info(iface) else supported_modes_str = table.concat(supported_modes, "/") end - local verbose_info = hw_name .. " (" .. supported_modes_str .. ")" return verbose_info end local Nodes = luci.sys.exec("batctl n 2>/dev/null| tail +3 | wc -l") local Node = detect_Node() -v = m:section(Table, Node, "" ,"" .. translate("Active node") .. "" .. Nodes .. "") -v:option(DummyValue, "IF", translate("IF")) -v:option(DummyValue, "Neighbor", translate("Neighbor")) -v:option(DummyValue, "lastseen", translate("lastseen")) +v = m:section(Table, Node, translate("Active Nodes") ,"" .. translate("Number of Active Nodes: ") .. Nodes .. "") +v:option(DummyValue, "IF", translate("Interface")) +v:option(DummyValue, "Neighbor", translate("Neighbor Nodes")) +v:option(DummyValue, "lastseen", translate("Last Seen Timestamp")) -- Basic s = m:section(TypedSection, "easymesh", translate("Mesh Gateway & Node WiFi Settings"), translate("Choose Mesh Gateway or Mesh Node WiFi Settings: Begin by completing this section on your mesh server and nodes. Ensure each radio's WiFi network name is consistent. For example: easymesh_AC, easymesh_N.")) @@ -226,17 +219,12 @@ function btnAPMode.write() end btnAPMode:depends("role", "off") --- MESH Node Control: apply mesh settings -ctrl = m:section(TypedSection, "easymesh", "Click Save Then Enable or Disable Your Mesh WiFi settings") -ctrl.anonymous = true -ctrl.addremove = false - m.on_before_apply = function(self) - local enabled = m:formvalue("cbid.easymesh.easymesh.enabled") + local enabled = m:formvalue("cbid.easymesh.config.enabled") if enabled and enabled == "1" then - luci.sys.call("/easymesh/easymesh.sh &") + luci.sys.call("/easymesh/easymesh.sh enable &") else - luci.sys.call("/easymesh/easymesh.sh &") + luci.sys.call("/easymesh/easymesh.sh disable &") end end diff --git a/root/easymesh/easymesh.sh b/root/easymesh/easymesh.sh old mode 100644 new mode 100755 index bfbbe4c..d7afdc9 --- a/root/easymesh/easymesh.sh +++ b/root/easymesh/easymesh.sh @@ -410,14 +410,17 @@ disable_easymesh() { uci del easymesh.config.running } -if [ "$1" = "dumbap" ]; then +sleep 5 +if [ "$1" = "enable" ]; then + enable_easymesh + exit 0 +elif [ "$1" = "disable" ]; then + disable_easymesh + exit 0 +elif [ "$1" = "dumbap" ]; then set_apmode exit 0 -fi - -# Check if enabled -if [ "$(uci -q get easymesh.config.enabled)" = 1 ]; then - enable_easymesh else - disable_easymesh + echo "Invalid argument. Please use 'start', 'stop' or 'dumbap'" + exit 1 fi