You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
5.6 KiB
Lua

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

-- PrivateRouter Easy Mesh
local m,s,o
local sys = require "luci.sys"
local uci = require "luci.model.uci".cursor()
m = Map("easymesh",
translate("Easy Mesh WiFi Setup"),
translate("Powered by Batman-adv (Better Approach To Mobile Adhoc Networking - Advanced). First setup your Mesh Gateway Server then setup the nodes. When configuring a Mesh Node, first activate your mesh WiFi on the radio device and establish a connection. Then enable it as a DHCP node. The default settings are typically adequate for most Mesh WiFi configurations.")
.. "<br/>" .. translate("Official website:") .. ' <a href="https://www.open-mesh.org/projects/batman-adv/wiki" target="_blank">https://www.open-mesh.org/projects/batman-adv/wiki</a>'
)
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
end
local Nodes = luci.sys.exec("batctl n 2>/dev/null| tail +3 | wc -l")
local Node = detect_Node()
v = m:section(Table, Node, "" ,"<b>" .. translate("Active node") .. "" .. Nodes .. "</b>")
v:option(DummyValue, "IF", translate("IF"))
v:option(DummyValue, "Neighbor", translate("Neighbor"))
v:option(DummyValue, "lastseen", translate("lastseen"))
-- Basic
s = m:section(TypedSection, "easymesh", translate("Mesh Gateway & Node Settings"), translate("Choose Mesh Gateway or Mesh Node WiFi Settings"))
s.anonymous = true
---- Eanble
o = s:option(Flag, "enabled", translate("Enable"), translate("Enable or disable Easy Mesh"))
o.default = 0
o.rmempty = false
function o.write(self, section, value)
Flag.write(self, section, value)
-- Run init start
luci.sys.call("uci commit")
luci.sys.call("/etc/init.d/easymesh start")
end
o = s:option(ListValue, "role", translate("Mesh Device Type"))
o:value("off", translate("Mesh Node"))
o:value("server", translate("Mesh Server"))
o:value("client", translate("Mesh Client"))
o.rmempty = false
apRadio = s:option(ListValue, "apRadio", translate("Mesh Radio device"), translate("The WiFi radio device Mesh will use"))
uci:foreach("wireless", "wifi-device",
function(s)
apRadio:value(s['.name'])
end)
apRadio:value("all", translate("ALL"))
o.default = "radio0"
o.rmempty = false
---- mesh
o = s:option(Value, "mesh_id", translate("Mesh ID"))
o.default = "easymesh"
o.description = translate("Mesh ID")
enable = s:option(Flag, "encryption", translate("Encryption"), translate(""))
enable.default = 0
enable.rmempty = false
o = s:option(Value, "key", translate("Key"))
o.default = "easymesh"
o:depends("encryption", 1)
---- kvr
enable = s:option(Flag, "kvr", translate("K/V/R"), translate(""))
enable.default = 1
enable.rmempty = false
o = s:option(Value, "mobility_domain", translate("Mobility Domain"), translate("4-character hexadecimal ID"))
o.default = "4f57"
o.datatype = "and(hexstring,rangelength(4,4))"
o:depends("kvr", 1)
o = s:option(Value, "rssi_val", translate("Threshold for an good RSSI"))
o.default = "-60"
o.atatype = "range(-1,-120)"
o:depends("kvr", 1)
o = s:option(Value, "low_rssi_val", translate("Threshold for an bad RSSI"))
o.default = "-88"
o.atatype = "range(-1,-120)"
o:depends("kvr", 1)
---- 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 Mesh Node"), translate("Add Mesh WiFi on Gateway and Node first. Mesh Node will use your gateway for DHCP. "))
s.anonymous = true
---- ap_mode
enable = s:option(Flag, "ap_mode", translate("Enable as DHCP Mesh Node"), translate("Important: Connect to your mesh gateway WiFi before enabling."))
enable.default = 0
enable.rmempty = false
---- static ip
--o = s:option(Value, "ipaddr", translate("IPv4-Address"))
--o.default = "192.168.8.101"
--o.datatype = "ip4addr"
--o:depends("ap_mode", 1)
---- so = s:option(Value, "netmask", translate("IPv4 netmask"))
--o.default = "255.255.255.0"
--o.datatype = "ip4addr"
--o:depends("ap_mode", 1)
o = s:option(Value, "gateway", translate("Set Hostname for this DHCP Mesh Node"))
o.default = "node1"
o.datatype = "string"
o:depends("ap_mode", 1)
-- MESH Node Control: Start/Stop DHCP MESH Node
ctrl = m:section(TypedSection, "easymesh", "Node Control: Start/Stop Mesh Node")
ctrl.anonymous = true
ctrl.addremove = false
btnStop = ctrl:option(Button, "_btn_start", translate("Enable Mesh Node"))
function btnStop.write()
io.popen("/etc/init.d/easymesh start")
end
btnStart = ctrl:option(Button, "_btn_stop", translate("Disable Mesh Node"))
function btnStart.write()
io.popen("/etc/init.d/easymesh stop")
end
---- o = s:option(Value, "dns", translate("Mesh IPv4 DNS"))
--o.default = "192.168.8.1"
--o.datatype = "ip4addr"
--o:depends("ap_mode", 1)
function m.on_commit(self)
luci.sys.call("uci commit")
luci.sys.call("/etc/init.d/easymesh start &")
end
return m