From 1b3930dd2df4efe62dfe5057da8579bb8e623ac6 Mon Sep 17 00:00:00 2001 From: riley Date: Thu, 16 Nov 2023 14:02:23 -0500 Subject: [PATCH 1/5] More verbose descriptions that look sexy, better input validation --- luasrc/model/cbi/easymesh.lua | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/luasrc/model/cbi/easymesh.lua b/luasrc/model/cbi/easymesh.lua index 5bcc2f7..54a3a7e 100755 --- a/luasrc/model/cbi/easymesh.lua +++ b/luasrc/model/cbi/easymesh.lua @@ -68,7 +68,7 @@ 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 Nodes") ,"" .. translate("Number of Active Nodes: ") .. Nodes .. "") +v = m:section(Table, Node, translate("Mesh Status") ,"" .. 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")) @@ -102,7 +102,7 @@ s:tab("apmode", translate("AP Mode")) s:tab("advanced", translate("Advanced Settings")) ---- Eanble -o = s:taboption("setup", Flag, "enabled", translate("Enable Mesh Network"), translate("Toggle this switch to activate or deactivate the Mesh Network on this device according to the settings specified in this configuration. Make sure to configure all necessary settings before enabling the Mesh Network. Changes will apply when you click Save and Apply")) +o = s:taboption("setup", Flag, "enabled", translate("Enable Mesh Networking"), translate('

Toggle this switch to activate or deactivate the Mesh Network on this device according to the settings specified in this configuration. Make sure to configure all necessary settings before enabling the Mesh Network.

Changes will apply when you click Save and Apply

')) o.default = 0 @@ -113,7 +113,7 @@ o:value("off", translate("Node")) o.default = "server" --o:value("client", translate("Client (advanced)")) -apRadio = s:taboption("setup", MultiValue, "apRadio", translate("Mesh Radio(s)"), translate('

Select one or multiple radio interfaces to be used for the mesh network. Each selected radio interface will be configured to participate in the mesh network, extending its range and improving its resilience. By using multiple radios, your mesh network can balance the network load and handle a larger number of connected devices.

')) +apRadio = s:taboption("setup", MultiValue, "apRadio", translate("Mesh Radio(s)"), translate('

Select one or multiple radio interfaces to be used for the mesh network. Each selected radio interface will be configured to participate in the mesh network, extending its range and improving its resilience. By using multiple radios, your mesh network can balance the network load and handle a larger number of connected devices.

Ensure the radios you select support mesh networking

')) uci:foreach("wireless", "wifi-device", function(s) @@ -125,33 +125,34 @@ uci:foreach("wireless", "wifi-device", apRadio.default = "radio0" apRadio.widget = "select" -o = s:taboption("setup", Value, "mesh_id", translate("Mesh SSID")) +o = s:taboption("setup", Value, "mesh_id", translate("Mesh Network SSID"), translate('

Ensure that the SSID is the same across all the servers/nodes in your mesh network.

')) o.default = "easymesh_AC" -encryption = s:taboption("setup", Flag, "encryption", translate("Enable Password"), translate("")) +encryption = s:taboption("setup", Flag, "encryption", translate("Password Protection"), translate('

Enable this switch to require a password to join your Mesh Network.

')) encryption.default = 0 o = s:taboption("setup", Value, "key", translate("Mesh Password")) o.default = "easymesh" o:depends("encryption", 1) o.password = true +o.datatype = "minlength(8)" -enable_kvr = s:taboption("advanced", Flag, "kvr", translate("K/V/R"), translate("Enable Key Value Roaming")) +enable_kvr = s:taboption("advanced", Flag, "kvr", translate("K/V/R"), translate('

Leave these settings as default unless you know what you\'re doing

')) enable_kvr.default = 1 -mobility_domain = s:taboption("advanced", Value, "mobility_domain", translate("Mobility Domain"), translate("4-character hexadecimal ID")) +mobility_domain = s:taboption("advanced", Value, "mobility_domain", translate("Mobility Domain")) mobility_domain.default = "4f57" ---mobility_domain.datatype = "and(hexstring,rangelength(4,4))" +mobility_domain.datatype = "and(hexstring,rangelength(4,4))" -rssi_val = s:taboption("advanced", Value, "rssi_val", translate("Threshold for a good RSSI")) +rssi_val = s:taboption("advanced", Value, "rssi_val", translate("Good RSSI Threshold")) rssi_val.default = "-60" ---rssi_val.datatype = "range(-1,-120)" +rssi_val.datatype = "range(-120,-1)" -low_rssi_val = s:taboption("advanced", Value, "low_rssi_val", translate("Threshold for a bad RSSI")) +low_rssi_val = s:taboption("advanced", Value, "low_rssi_val", translate("Bad RSSI Threshold")) low_rssi_val.default = "-88" ---low_rssi_val.datatype = "range(-1,-120)" +low_rssi_val.datatype = "range(-120,-1)" From 895d07f3c35bbb82e24bbfb02589a79aa3aec883 Mon Sep 17 00:00:00 2001 From: riley Date: Thu, 16 Nov 2023 14:13:28 -0500 Subject: [PATCH 2/5] refactored radio hardware info --- luasrc/model/cbi/easymesh.lua | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/luasrc/model/cbi/easymesh.lua b/luasrc/model/cbi/easymesh.lua index 54a3a7e..933f4a8 100755 --- a/luasrc/model/cbi/easymesh.lua +++ b/luasrc/model/cbi/easymesh.lua @@ -31,39 +31,24 @@ function detect_Node() end -function get_verbose_hw_info(iface) +local function get_verbose_hw_info(iface) local type = iwinfo.type(iface) - if not type then - return "Generic" - end + if not type then return "Generic" end local driver = iwinfo[type] - if not driver then - return "Driver not supported" - end + if not driver then return "Driver not supported" end - local hw_name = driver.hardware_name and driver.hardware_name(iface) - if not hw_name or hw_name == "" then - hw_name = "Unknown hardware" - end - - local hw_modes = driver.hwmodelist and driver.hwmodelist(iface) + local hw_name = driver.hardware_name and driver.hardware_name(iface) or "Unknown hardware" + local hw_modes = driver.hwmodelist and driver.hwmodelist(iface) or {} local supported_modes = {} - if hw_modes then - for mode, supported in pairs(hw_modes) do - if supported then - table.insert(supported_modes, mode) - end + + for mode, supported in pairs(hw_modes) do + if supported then + supported_modes[#supported_modes + 1] = mode end end - if #supported_modes == 0 then - supported_modes_str = "No mode information" - else - supported_modes_str = table.concat(supported_modes, "/") - end - local verbose_info = hw_name .. " (" .. supported_modes_str .. ")" - return verbose_info + return hw_name .. " (" .. (#supported_modes > 0 and table.concat(supported_modes, "/") or "No mode information") .. ")" end local Nodes = luci.sys.exec("batctl n 2>/dev/null| tail +3 | wc -l") From 763e8350b3248afcd47378e0210585948e8deb93 Mon Sep 17 00:00:00 2001 From: riley Date: Thu, 16 Nov 2023 14:18:05 -0500 Subject: [PATCH 3/5] code readability cleanup, removed some unused comments --- luasrc/model/cbi/easymesh.lua | 45 ----------------------------------- 1 file changed, 45 deletions(-) diff --git a/luasrc/model/cbi/easymesh.lua b/luasrc/model/cbi/easymesh.lua index 933f4a8..005e7f8 100755 --- a/luasrc/model/cbi/easymesh.lua +++ b/luasrc/model/cbi/easymesh.lua @@ -58,30 +58,9 @@ 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 Settings")) s.anonymous = true --- Connection Type Dropdown ---o = s:option(ListValue, "backbone", translate("Connection Type"), translate("Choose if Node or Gateway is connected to internet by LAN or WiFi")) ---o:value("lan", translate("LAN")) ---o:value("wifi", translate("WiFi")) ---o.default = "lan" ---o.rmempty = false - --- AP Name ---apn = s:option(Value, "apname", translate("AP Name"), translate("Enter the client WiFi AP name")) ---apn:depends("backbone", "wifi") ---apn.placeholder = "easymesh_AC" ---apn.rmempty = true - --- AP Password ---app = s:option(Value, "appass", translate("AP Password"), translate("Enter the client WiFi AP password")) ---app:depends("backbone", "wifi") ---app.password = true ---app.placeholder = "easymesh" ---app.rmempty = true - s:tab("setup", translate("Basic Setup")) s:tab("apmode", translate("AP Mode")) s:tab("advanced", translate("Advanced Settings")) @@ -90,7 +69,6 @@ s:tab("advanced", translate("Advanced Settings")) o = s:taboption("setup", Flag, "enabled", translate("Enable Mesh Networking"), translate('

Toggle this switch to activate or deactivate the Mesh Network on this device according to the settings specified in this configuration. Make sure to configure all necessary settings before enabling the Mesh Network.

Changes will apply when you click Save and Apply

')) o.default = 0 - -- Move basic settings under the "Setup" tab o = s:taboption("setup", ListValue, "role", translate("Mesh Mode"), translate('

Choose the role this device will play in your mesh network. There are two options available:

1. Server: If you select this option, this device will act as the Mesh Gateway Server. The server manages the routing of data in the network and handles connections to the internet. It is the central point of your mesh network.

2. Node: The device functions as a Mesh Node if this option is selected. Nodes connect to the Mesh Gateway Server and other nodes to extend the range of the network. Nodes can also route traffic between each other to increase network efficiency.

Remember to set up the Mesh Gateway Server first before setting up the nodes.

')) o:value("server", translate("Server")) @@ -129,37 +107,14 @@ mobility_domain = s:taboption("advanced", Value, "mobility_domain", translate("M mobility_domain.default = "4f57" mobility_domain.datatype = "and(hexstring,rangelength(4,4))" - rssi_val = s:taboption("advanced", Value, "rssi_val", translate("Good RSSI Threshold")) rssi_val.default = "-60" rssi_val.datatype = "range(-120,-1)" - low_rssi_val = s:taboption("advanced", Value, "low_rssi_val", translate("Bad RSSI Threshold")) low_rssi_val.default = "-88" low_rssi_val.datatype = "range(-120,-1)" - - ----- Apply MESH settings ---ctrl = m:section(TypedSection, "easymesh", "Apply Mesh WiFi Settings to Server or Node") ---ctrl.anonymous = true ---ctrl.addremove = false - -----btnStop = ctrl:option(Button, "_btn_start", translate("Apply Mesh WiFi Settings")) ---function btnStop.write() --- io.popen("/etc/init.d/easymesh start") ---end - ----- 802.11F ---enable = s:option(Flag, "iapp", translate("inter-access point protocol"), translate("Wireless Access Points (APs) running on different vendors can communicate with each other")) ---enable.default = 0 ---enable.rmempty = false - --- NodeMode --- s = m:section(TypedSection, "easymesh", translate("Enable Router as DHCP Mesh Node"), translate("Set up Easy Mesh WiFi on your server and nodes first. All mesh nodes will utilize your mesh server for DHCP. ")) --- s.anonymous = true - ---- ap_mode o = s:taboption("apmode", Value, "hostname", translate("Node Hostname")) o.default = "node2" From cfbf87fbc9c4cc3e8f82bf3273afd9c96f1e1012 Mon Sep 17 00:00:00 2001 From: Jason Hawks Date: Thu, 16 Nov 2023 23:01:08 -0500 Subject: [PATCH 4/5] Small fix for if then --- root/easymesh/easymesh.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/easymesh/easymesh.sh b/root/easymesh/easymesh.sh index fc2baa9..d4bca59 100755 --- a/root/easymesh/easymesh.sh +++ b/root/easymesh/easymesh.sh @@ -23,7 +23,7 @@ set_apmode() { fi done - if [ $(uci -q get easymesh.config.ipmode) == "static" ]; then + if [ "$(uci -q get easymesh.config.ipmode)" == "static" ]; then # Set static IP uci set network.lan.proto='static' uci set network.lan.ipaddr=$(uci -q get easymesh.config.ipaddr) From e53320cfe9582bfd8abaa91ac37a6d14de245430 Mon Sep 17 00:00:00 2001 From: Jason Hawks Date: Thu, 16 Nov 2023 23:41:17 -0500 Subject: [PATCH 5/5] Make the apply/reapply to be done by button since some devices are slow --- Makefile | 2 +- luasrc/model/cbi/easymesh.lua | 18 +++++++----------- root/easymesh/easymesh.sh | 17 ++++++++--------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 9394995..fdc148c 100755 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk LUCI_TITLE:=LuCI Support for easymesh LUCI_DEPENDS:= +kmod-cfg80211 +batctl-default +kmod-batman-adv +dawn +bash -PKG_VERSION:=2.8.9 +PKG_VERSION:=2.8.10 include $(TOPDIR)/feeds/luci/luci.mk diff --git a/luasrc/model/cbi/easymesh.lua b/luasrc/model/cbi/easymesh.lua index 005e7f8..9ac67e5 100755 --- a/luasrc/model/cbi/easymesh.lua +++ b/luasrc/model/cbi/easymesh.lua @@ -73,8 +73,8 @@ o.default = 0 o = s:taboption("setup", ListValue, "role", translate("Mesh Mode"), translate('

Choose the role this device will play in your mesh network. There are two options available:

1. Server: If you select this option, this device will act as the Mesh Gateway Server. The server manages the routing of data in the network and handles connections to the internet. It is the central point of your mesh network.

2. Node: The device functions as a Mesh Node if this option is selected. Nodes connect to the Mesh Gateway Server and other nodes to extend the range of the network. Nodes can also route traffic between each other to increase network efficiency.

Remember to set up the Mesh Gateway Server first before setting up the nodes.

')) o:value("server", translate("Server")) o:value("off", translate("Node")) +o:value("client", translate("Client")) o.default = "server" ---o:value("client", translate("Client (advanced)")) apRadio = s:taboption("setup", MultiValue, "apRadio", translate("Mesh Radio(s)"), translate('

Select one or multiple radio interfaces to be used for the mesh network. Each selected radio interface will be configured to participate in the mesh network, extending its range and improving its resilience. By using multiple radios, your mesh network can balance the network load and handle a larger number of connected devices.

Ensure the radios you select support mesh networking

')) @@ -100,6 +100,11 @@ o:depends("encryption", 1) o.password = true o.datatype = "minlength(8)" +btnReapply = s:taboption("setup", Button, "_btn_reapply", translate("Reapply EasyMesh Settings"), translate('

Use this button to apply/reapply EasyMesh configuration after you Save & Apply.

')) +function btnReapply.write() + io.popen("/easymesh/easymesh.sh &") +end + enable_kvr = s:taboption("advanced", Flag, "kvr", translate("K/V/R"), translate('

Leave these settings as default unless you know what you\'re doing

')) enable_kvr.default = 1 @@ -127,7 +132,7 @@ o:value("node7", "node7") o:value("node8", "node8") o:value("node9", "node9") o.datatype = "string" -o:depends("role", "off") +o:depends({role="off",role="client"}) -- IP Mode (DHCP or Static) ipmode = s:taboption("apmode", ListValue, "ipmode", translate("IP Mode"), translate("Choose if the node uses DHCP or a Static IP")) @@ -166,13 +171,4 @@ function btnAPMode.write() end btnAPMode:depends("role", "off") -m.on_before_apply = function(self) - local enabled = m:formvalue("cbid.easymesh.config.enabled") - if enabled and enabled == "1" then - luci.sys.call("/easymesh/easymesh.sh enable &") - else - luci.sys.call("/easymesh/easymesh.sh disable &") - end -end - return m \ No newline at end of file diff --git a/root/easymesh/easymesh.sh b/root/easymesh/easymesh.sh index d4bca59..14b4234 100755 --- a/root/easymesh/easymesh.sh +++ b/root/easymesh/easymesh.sh @@ -492,19 +492,18 @@ disable_easymesh() { uci del easymesh.config.running } -if [ "$1" = "enable" ]; then - enable_easymesh - exit 0 -elif [ "$1" = "disable" ]; then - disable_easymesh - exit 0 -elif [ "$1" = "dumbap" ]; then +if [ "$1" = "dumbap" ]; then set_apmode exit 0 elif [ "$1" = "undumb" ]; then disable_apmode exit 0 +# If no params passed, we disable or enable easymesh based on config else - echo "Invalid argument. Please use 'start', 'stop' or 'dumbap'" - exit 1 + # Check if easymesh is enabled + if [ "$(uci -q get easymesh.config.enabled)" = 1 ]; then + enable_easymesh + else + disable_easymesh + fi fi