From e27831d568f5689602abae58f5ae92f060421ada Mon Sep 17 00:00:00 2001 From: Aedan ARFETT Renner Date: Sat, 4 Oct 2014 15:56:28 -0700 Subject: [PATCH] mwan3-luci: update to 1.3-5 new naming/wording - more generically mwan than mwan3 renamed cryptic variables/functions/etc everywhere removed unused and unnecessary variables everywhere cleaned up ugly and inefficient Lua and Javascript Signed-off-by: Aedan Renner chipdankly@gmail.com --- net/mwan3-luci/Makefile | 4 +- .../{16-mwan3custombak => 16-mwancustombak} | 10 +- .../uci-defaults/{mwan3-luci => mwan-luci} | 2 +- .../usr/lib/lua/luci/controller/mwan3.lua | 397 ++++++++---------- .../advanced_hotplugscript.lua} | 14 +- .../advanced_mwanconfig.lua} | 10 +- .../advanced_networkconfig.lua} | 8 +- .../lib/lua/luci/model/cbi/mwan/interface.lua | 266 ++++++++++++ .../interfaceconfig.lua} | 109 +++-- .../mwan3_member.lua => mwan/member.lua} | 10 +- .../memberconfig.lua} | 4 +- .../mwan3_policy.lua => mwan/policy.lua} | 40 +- .../policyconfig.lua} | 28 +- .../{mwan3/mwan3_rule.lua => mwan/rule.lua} | 37 +- .../ruleconfig.lua} | 40 +- .../luci/model/cbi/mwan3/mwan3_interface.lua | 266 ------------ .../lua/luci/view/admin_status/index/mwan.htm | 1 + .../luci/view/admin_status/index/mwan3.htm | 1 - .../advanced_diagnostics.htm} | 55 ++- .../advanced_hotplugscript.htm} | 12 +- .../advanced_mwanconfig.htm} | 12 +- .../advanced_networkconfig.htm} | 12 +- .../view/mwan/advanced_troubleshooting.htm | 71 ++++ .../config_css.htm} | 12 +- .../openwrt_overview_status.htm} | 43 +- .../lua/luci/view/mwan/overview_detailed.htm | 51 +++ .../lua/luci/view/mwan/overview_interface.htm | 122 ++++++ .../view/mwan3/mwan3_adv_troubleshoot.htm | 75 ---- .../lua/luci/view/mwan3/mwan3_over_detail.htm | 56 --- .../luci/view/mwan3/mwan3_over_interface.htm | 136 ------ 30 files changed, 915 insertions(+), 989 deletions(-) rename net/mwan3-luci/files/etc/hotplug.d/iface/{16-mwan3custombak => 16-mwancustombak} (60%) rename net/mwan3-luci/files/etc/uci-defaults/{mwan3-luci => mwan-luci} (84%) rename net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/{mwan3/mwan3_adv_hotplug.lua => mwan/advanced_hotplugscript.lua} (81%) rename net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/{mwan3/mwan3_adv_mwan3.lua => mwan/advanced_mwanconfig.lua} (60%) rename net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/{mwan3/mwan3_adv_network.lua => mwan/advanced_networkconfig.lua} (65%) create mode 100644 net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/interface.lua rename net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/{mwan3/mwan3_interfaceconfig.lua => mwan/interfaceconfig.lua} (57%) rename net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/{mwan3/mwan3_member.lua => mwan/member.lua} (77%) rename net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/{mwan3/mwan3_memberconfig.lua => mwan/memberconfig.lua} (87%) rename net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/{mwan3/mwan3_policy.lua => mwan/policy.lua} (69%) rename net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/{mwan3/mwan3_policyconfig.lua => mwan/policyconfig.lua} (65%) rename net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/{mwan3/mwan3_rule.lua => mwan/rule.lua} (70%) rename net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/{mwan3/mwan3_ruleconfig.lua => mwan/ruleconfig.lua} (67%) delete mode 100644 net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_interface.lua create mode 100644 net/mwan3-luci/files/usr/lib/lua/luci/view/admin_status/index/mwan.htm delete mode 100644 net/mwan3-luci/files/usr/lib/lua/luci/view/admin_status/index/mwan3.htm rename net/mwan3-luci/files/usr/lib/lua/luci/view/{mwan3/mwan3_adv_diagnostics.htm => mwan/advanced_diagnostics.htm} (64%) rename net/mwan3-luci/files/usr/lib/lua/luci/view/{mwan3/mwan3_adv_network.htm => mwan/advanced_hotplugscript.htm} (56%) rename net/mwan3-luci/files/usr/lib/lua/luci/view/{mwan3/mwan3_adv_mwan3.htm => mwan/advanced_mwanconfig.htm} (55%) rename net/mwan3-luci/files/usr/lib/lua/luci/view/{mwan3/mwan3_adv_hotplug.htm => mwan/advanced_networkconfig.htm} (56%) create mode 100644 net/mwan3-luci/files/usr/lib/lua/luci/view/mwan/advanced_troubleshooting.htm rename net/mwan3-luci/files/usr/lib/lua/luci/view/{mwan3/mwan3_config_css.htm => mwan/config_css.htm} (53%) rename net/mwan3-luci/files/usr/lib/lua/luci/view/{mwan3/mwan3_status.htm => mwan/openwrt_overview_status.htm} (59%) create mode 100644 net/mwan3-luci/files/usr/lib/lua/luci/view/mwan/overview_detailed.htm create mode 100644 net/mwan3-luci/files/usr/lib/lua/luci/view/mwan/overview_interface.htm delete mode 100644 net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_adv_troubleshoot.htm delete mode 100644 net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_over_detail.htm delete mode 100644 net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_over_interface.htm diff --git a/net/mwan3-luci/Makefile b/net/mwan3-luci/Makefile index 49a3f02d81..eed2348752 100644 --- a/net/mwan3-luci/Makefile +++ b/net/mwan3-luci/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-mwan3 PKG_VERSION:=1.3 -PKG_RELEASE:=4 +PKG_RELEASE:=5 PKG_MAINTAINER:=Aedan Renner PKG_LICENSE:=GPLv2 @@ -20,7 +20,7 @@ define Package/luci-app-mwan3 CATEGORY:=LuCI SUBMENU:=3. Applications TITLE:=LuCI support for the MWAN3 multiwan hotplug script - DEPENDS:=+mwan3 +luci-mod-admin-full +luci-lib-nixio + DEPENDS:=+mwan3 +luci-mod-admin-full +luci-app-firewall +luci-lib-nixio PKGARCH:=all MAINTAINER:=Aedan Renner endef diff --git a/net/mwan3-luci/files/etc/hotplug.d/iface/16-mwan3custombak b/net/mwan3-luci/files/etc/hotplug.d/iface/16-mwancustombak similarity index 60% rename from net/mwan3-luci/files/etc/hotplug.d/iface/16-mwan3custombak rename to net/mwan3-luci/files/etc/hotplug.d/iface/16-mwancustombak index fabd5f3fc6..b8f6605832 100755 --- a/net/mwan3-luci/files/etc/hotplug.d/iface/16-mwan3custombak +++ b/net/mwan3-luci/files/etc/hotplug.d/iface/16-mwancustombak @@ -1,11 +1,11 @@ #!/bin/sh # to enable this script uncomment the case loop at the bottom -# to report mwan3 status on interface hotplug ifup/ifdown events modify the lines in the send_alert function +# to report mwan status on interface hotplug ifup/ifdown events modify the lines in the send_alert function send_alert() { - # variable "$1" stores the mwan3 status information + # variable "$1" stores the MWAN status information # insert your code here to send the contents of "$1" echo "$1" } @@ -18,11 +18,11 @@ gather_event_info() # get current interface, policy and rule status local CURRENT_STATUS="$(/usr/sbin/mwan3 status)" - # get last 50 mwan3 systemlog messages - local MWAN3_LOG="$(echo -e "Last 50 MWAN3 systemlog entries. Newest entries sorted at the top:\n$(logread | grep mwan3 | tail -n 50 | sed 'x;1!H;$!d;x')")" + # get last 50 MWAN systemlog messages + local MWAN_LOG="$(echo -e "Last 50 MWAN systemlog entries. Newest entries sorted at the top:\n$(logread | grep mwan3 | tail -n 50 | sed 'x;1!H;$!d;x')")" # pass event info to send_alert function - send_alert "$(echo -e "$EVENT_INFO\n\n$CURRENT_STATUS\n\n$MWAN3_LOG")" + send_alert "$(echo -e "$EVENT_INFO\n\n$CURRENT_STATUS\n\n$MWAN_LOG")" } #case "$ACTION" in diff --git a/net/mwan3-luci/files/etc/uci-defaults/mwan3-luci b/net/mwan3-luci/files/etc/uci-defaults/mwan-luci similarity index 84% rename from net/mwan3-luci/files/etc/uci-defaults/mwan3-luci rename to net/mwan3-luci/files/etc/uci-defaults/mwan-luci index 2b74d63b52..ff9a229edd 100755 --- a/net/mwan3-luci/files/etc/uci-defaults/mwan3-luci +++ b/net/mwan3-luci/files/etc/uci-defaults/mwan-luci @@ -1,6 +1,6 @@ #!/bin/sh -# replace existing mwan3-luci ucitrack entry +# replace existing mwan ucitrack entry uci -q batch <<-EOF >/dev/null del ucitrack.@mwan3[-1] add ucitrack mwan3 diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/controller/mwan3.lua b/net/mwan3-luci/files/usr/lib/lua/luci/controller/mwan3.lua index 33dbcf44a1..d40ad0116d 100644 --- a/net/mwan3-luci/files/usr/lib/lua/luci/controller/mwan3.lua +++ b/net/mwan3-luci/files/usr/lib/lua/luci/controller/mwan3.lua @@ -8,348 +8,311 @@ function index() return end - entry({"admin", "network", "mwan3"}, - alias("admin", "network", "mwan3", "overview"), + entry({"admin", "network", "mwan"}, + alias("admin", "network", "mwan", "overview"), _("Load Balancing"), 600) - entry({"admin", "network", "mwan3", "overview"}, - alias("admin", "network", "mwan3", "overview", "over_iface"), + entry({"admin", "network", "mwan", "overview"}, + alias("admin", "network", "mwan", "overview", "overview_interface"), _("Overview"), 10) - entry({"admin", "network", "mwan3", "overview", "over_iface"}, - template("mwan3/mwan3_over_interface")) - entry({"admin", "network", "mwan3", "overview", "iface_status"}, - call("mwan3_iface_status")) - entry({"admin", "network", "mwan3", "overview", "over_detail"}, - template("mwan3/mwan3_over_detail")) - entry({"admin", "network", "mwan3", "overview", "detail_status"}, - call("mwan3_detail_status")) + entry({"admin", "network", "mwan", "overview", "overview_interface"}, + template("mwan/overview_interface")) + entry({"admin", "network", "mwan", "overview", "interface_status"}, + call("interfaceStatus")) + entry({"admin", "network", "mwan", "overview", "overview_detailed"}, + template("mwan/overview_detailed")) + entry({"admin", "network", "mwan", "overview", "detailed_status"}, + call("detailedStatus")) - entry({"admin", "network", "mwan3", "configuration"}, - alias("admin", "network", "mwan3", "configuration", "interface"), + entry({"admin", "network", "mwan", "configuration"}, + alias("admin", "network", "mwan", "configuration", "interface"), _("Configuration"), 20) - entry({"admin", "network", "mwan3", "configuration", "interface"}, - arcombine(cbi("mwan3/mwan3_interface"), cbi("mwan3/mwan3_interfaceconfig")), + entry({"admin", "network", "mwan", "configuration", "interface"}, + arcombine(cbi("mwan/interface"), cbi("mwan/interfaceconfig")), _("Interfaces"), 10).leaf = true - entry({"admin", "network", "mwan3", "configuration", "member"}, - arcombine(cbi("mwan3/mwan3_member"), cbi("mwan3/mwan3_memberconfig")), + entry({"admin", "network", "mwan", "configuration", "member"}, + arcombine(cbi("mwan/member"), cbi("mwan/memberconfig")), _("Members"), 20).leaf = true - entry({"admin", "network", "mwan3", "configuration", "policy"}, - arcombine(cbi("mwan3/mwan3_policy"), cbi("mwan3/mwan3_policyconfig")), + entry({"admin", "network", "mwan", "configuration", "policy"}, + arcombine(cbi("mwan/policy"), cbi("mwan/policyconfig")), _("Policies"), 30).leaf = true - entry({"admin", "network", "mwan3", "configuration", "rule"}, - arcombine(cbi("mwan3/mwan3_rule"), cbi("mwan3/mwan3_ruleconfig")), + entry({"admin", "network", "mwan", "configuration", "rule"}, + arcombine(cbi("mwan/rule"), cbi("mwan/ruleconfig")), _("Rules"), 40).leaf = true - entry({"admin", "network", "mwan3", "advanced"}, - alias("admin", "network", "mwan3", "advanced", "hotplug"), + entry({"admin", "network", "mwan", "advanced"}, + alias("admin", "network", "mwan", "advanced", "hotplugscript"), _("Advanced"), 100) - entry({"admin", "network", "mwan3", "advanced", "hotplug"}, - form("mwan3/mwan3_adv_hotplug")) - entry({"admin", "network", "mwan3", "advanced", "mwan3"}, - form("mwan3/mwan3_adv_mwan3")) - entry({"admin", "network", "mwan3", "advanced", "network"}, - form("mwan3/mwan3_adv_network")) - entry({"admin", "network", "mwan3", "advanced", "diag"}, - template("mwan3/mwan3_adv_diagnostics")) - entry({"admin", "network", "mwan3", "advanced", "diag_display"}, - call("mwan3_diag_data"), nil).leaf = true - entry({"admin", "network", "mwan3", "advanced", "tshoot"}, - template("mwan3/mwan3_adv_troubleshoot")) - entry({"admin", "network", "mwan3", "advanced", "tshoot_display"}, - call("mwan3_tshoot_data")) + entry({"admin", "network", "mwan", "advanced", "hotplugscript"}, + form("mwan/advanced_hotplugscript")) + entry({"admin", "network", "mwan", "advanced", "mwanconfig"}, + form("mwan/advanced_mwanconfig")) + entry({"admin", "network", "mwan", "advanced", "networkconfig"}, + form("mwan/advanced_networkconfig")) + entry({"admin", "network", "mwan", "advanced", "diagnostics"}, + template("mwan/advanced_diagnostics")) + entry({"admin", "network", "mwan", "advanced", "diagnostics_display"}, + call("diagnosticsData"), nil).leaf = true + entry({"admin", "network", "mwan", "advanced", "troubleshooting"}, + template("mwan/advanced_troubleshooting")) + entry({"admin", "network", "mwan", "advanced", "troubleshooting_display"}, + call("troubleshootingData")) end -function mwan3_get_iface_status(rulenum, ifname) - if ut.trim(sys.exec("uci get -p /var/state mwan3." .. ifname .. ".enabled")) == "1" then - if ut.trim(sys.exec("ip route list table " .. rulenum)) ~= "" then - if ut.trim(sys.exec("uci get -p /var/state mwan3." .. ifname .. ".track_ip")) ~= "" then - return "on" +function getInterfaceStatus(ruleNumber, interfaceName) + if ut.trim(sys.exec("uci get -p /var/state mwan3." .. interfaceName .. ".enabled")) == "1" then + if ut.trim(sys.exec("ip route list table " .. ruleNumber)) ~= "" then + if ut.trim(sys.exec("uci get -p /var/state mwan3." .. interfaceName .. ".track_ip")) ~= "" then + return "online" else - return "nm" + return "notMonitored" end else - return "off" + return "offline" end else - return "ne" + return "notEnabled" end end -function mwan3_get_iface() - local rulenum, str = 0, "" +function getInterfaceName() + local ruleNumber, status = 0, "" uci.cursor():foreach("mwan3", "interface", function (section) - rulenum = rulenum+1 - str = str .. section[".name"] .. "[" .. mwan3_get_iface_status(rulenum, section[".name"]) .. "]" + ruleNumber = ruleNumber+1 + status = status .. section[".name"] .. "[" .. getInterfaceStatus(ruleNumber, section[".name"]) .. "]" end ) - return str + return status end -function mwan3_iface_status() +function interfaceStatus() local ntm = require "luci.model.network".init() - local rv = { } + local mArray = {} -- overview status - local statstr = mwan3_get_iface() - if statstr ~= "" then - rv.wans = { } + local statusString = getInterfaceName() + if statusString ~= "" then + mArray.wans = {} wansid = {} - for wanname, ifstat in string.gfind(statstr, "([^%[]+)%[([^%]]+)%]") do - local wanifname = ut.trim(sys.exec("uci get -p /var/state network." .. wanname .. ".ifname")) - if wanifname == "" then - wanifname = "X" + for wanName, interfaceState in string.gfind(statusString, "([^%[]+)%[([^%]]+)%]") do + local wanInterfaceName = ut.trim(sys.exec("uci get -p /var/state network." .. wanName .. ".ifname")) + if wanInterfaceName == "" then + wanInterfaceName = "X" end - local wanlink = ntm:get_interface(wanifname) - wanlink = wanlink and wanlink:get_network() - wanlink = wanlink and wanlink:adminlink() or "#" - wansid[wanname] = #rv.wans + 1 - rv.wans[wansid[wanname]] = { name = wanname, link = wanlink, ifname = wanifname, status = ifstat } + local wanDeviceLink = ntm:get_interface(wanInterfaceName) + wanDeviceLink = wanDeviceLink and wanDeviceLink:get_network() + wanDeviceLink = wanDeviceLink and wanDeviceLink:adminlink() or "#" + wansid[wanName] = #mArray.wans + 1 + mArray.wans[wansid[wanName]] = { name = wanName, link = wanDeviceLink, ifname = wanInterfaceName, status = interfaceState } end end -- overview status log - local mwlg = ut.trim(sys.exec("logread | grep mwan3 | tail -n 50 | sed 'x;1!H;$!d;x'")) - if mwlg ~= "" then - rv.mwan3log = { } - mwlog = {} - mwlog[mwlg] = #rv.mwan3log + 1 - rv.mwan3log[mwlog[mwlg]] = { mwanlog = mwlg } + local mwanLog = ut.trim(sys.exec("logread | grep mwan3 | tail -n 50 | sed 'x;1!H;$!d;x'")) + if mwanLog ~= "" then + mArray.mwanlog = { mwanLog } end luci.http.prepare_content("application/json") - luci.http.write_json(rv) + luci.http.write_json(mArray) end -function mwan3_detail_status() - local rv = { } +function detailedStatus() + local mArray = {} - -- detailed mwan3 status - local dst = ut.trim(sys.exec("mwan3 status")) - if dst ~= "" then - rv.mwan3dst = { } - dstat = {} - dstat[dst] = #rv.mwan3dst + 1 - rv.mwan3dst[dstat[dst]] = { detailstat = dst } + -- detailed mwan status + local detailStatusInfo = ut.trim(sys.exec("/usr/sbin/mwan3 status")) + if detailStatusInfo ~= "" then + mArray.mwandetail = { detailStatusInfo } end luci.http.prepare_content("application/json") - luci.http.write_json(rv) + luci.http.write_json(mArray) end -function mwan3_diag_data(iface, tool, alt) - function get_ifnum() - local num = 0 +function diagnosticsData(interface, tool, task) + function getInterfaceNumber() + local number = 0 uci.cursor():foreach("mwan3", "interface", function (section) - num = num+1 - if section[".name"] == iface then - ifnum = num + number = number+1 + if section[".name"] == interface then + interfaceNumber = number end end ) end - local rv = { } + local mArray = {} - local res = "" + local results = "" if tool == "service" then - os.execute("mwan3 " .. alt) - if alt == "restart" then - res = "MWAN3 restarted" - elseif alt == "stop" then - res = "MWAN3 stopped" + os.execute("/usr/sbin/mwan3 " .. task) + if task == "restart" then + results = "MWAN3 restarted" + elseif task == "stop" then + results = "MWAN3 stopped" else - res = "MWAN3 started" + results = "MWAN3 started" end else - local ifdev = ut.trim(sys.exec("uci get -p /var/state network." .. iface .. ".ifname")) - if ifdev ~= "" then + local interfaceDevice = ut.trim(sys.exec("uci get -p /var/state network." .. interface .. ".ifname")) + if interfaceDevice ~= "" then if tool == "ping" then - local gateway = ut.trim(sys.exec("route -n | awk '{ if ($8 == \"" .. ifdev .. "\" && $1 == \"0.0.0.0\" && $3 == \"0.0.0.0\") print $2 }'")) + local gateway = ut.trim(sys.exec("route -n | awk '{if ($8 == \"" .. interfaceDevice .. "\" && $1 == \"0.0.0.0\" && $3 == \"0.0.0.0\") print $2}'")) if gateway ~= "" then - if alt == "gateway" then - local cmd = "ping -c 3 -W 2 -I " .. ifdev .. " " .. gateway - res = cmd .. "\n\n" .. sys.exec(cmd) + if task == "gateway" then + local pingCommand = "ping -c 3 -W 2 -I " .. interfaceDevice .. " " .. gateway + results = pingCommand .. "\n\n" .. sys.exec(pingCommand) else - local str = ut.trim(sys.exec("uci get -p /var/state mwan3." .. iface .. ".track_ip")) - if str ~= "" then - for z in str:gmatch("[^ ]+") do - local cmd = "ping -c 3 -W 2 -I " .. ifdev .. " " .. z - res = res .. cmd .. "\n\n" .. sys.exec(cmd) .. "\n\n" + local tracked = ut.trim(sys.exec("uci get -p /var/state mwan3." .. interface .. ".track_ip")) + if tracked ~= "" then + for z in tracked:gmatch("[^ ]+") do + local pingCommand = "ping -c 3 -W 2 -I " .. interfaceDevice .. " " .. z + results = results .. pingCommand .. "\n\n" .. sys.exec(pingCommand) .. "\n\n" end else - res = "No tracking IP addresses configured on " .. iface + results = "No tracking IP addresses configured on " .. interface end end else - res = "No default gateway for " .. iface .. " found. Default route does not exist or is configured incorrectly" + results = "No default gateway for " .. interface .. " found. Default route does not exist or is configured incorrectly" end elseif tool == "rulechk" then - get_ifnum() - local rule1 = sys.exec("ip rule | grep $(echo $((" .. ifnum .. " + 1000)))") - local rule2 = sys.exec("ip rule | grep $(echo $((" .. ifnum .. " + 2000)))") + getInterfaceNumber() + local rule1 = sys.exec("ip rule | grep $(echo $((" .. interfaceNumber .. " + 1000)))") + local rule2 = sys.exec("ip rule | grep $(echo $((" .. interfaceNumber .. " + 2000)))") if rule1 ~= "" and rule2 ~= "" then - res = "All required interface IP rules found:\n\n" .. rule1 .. rule2 + results = "All required interface IP rules found:\n\n" .. rule1 .. rule2 elseif rule1 ~= "" or rule2 ~= "" then - res = "Missing 1 of the 2 required interface IP rules\n\n\nRules found:\n\n" .. rule1 .. rule2 + results = "Missing 1 of the 2 required interface IP rules\n\n\nRules found:\n\n" .. rule1 .. rule2 else - res = "Missing both of the required interface IP rules" + results = "Missing both of the required interface IP rules" end elseif tool == "routechk" then - get_ifnum() - local table = sys.exec("ip route list table " .. ifnum) - if table ~= "" then - res = "Interface routing table " .. ifnum .. " was found:\n\n" .. table + getInterfaceNumber() + local routeTable = sys.exec("ip route list table " .. interfaceNumber) + if routeTable ~= "" then + results = "Interface routing table " .. interfaceNumber .. " was found:\n\n" .. routeTable else - res = "Missing required interface routing table " .. ifnum + results = "Missing required interface routing table " .. interfaceNumber end elseif tool == "hotplug" then - if alt == "ifup" then - os.execute("mwan3 ifup " .. iface) - res = "Hotplug ifup sent to interface " .. iface .. "..." + if task == "ifup" then + os.execute("/usr/sbin/mwan3 ifup " .. interface) + results = "Hotplug ifup sent to interface " .. interface .. "..." else - os.execute("mwan3 ifdown " .. iface) - res = "Hotplug ifdown sent to interface " .. iface .. "..." + os.execute("/usr/sbin/mwan3 ifdown " .. interface) + results = "Hotplug ifdown sent to interface " .. interface .. "..." end end else - res = "Unable to perform diagnostic tests on " .. iface .. ". There is no physical or virtual device associated with this interface" + results = "Unable to perform diagnostic tests on " .. interface .. ". There is no physical or virtual device associated with this interface" end end - if res ~= "" then - res = ut.trim(res) - rv.diagres = { } - dres = {} - dres[res] = #rv.diagres + 1 - rv.diagres[dres[res]] = { diagresult = res } + if results ~= "" then + results = ut.trim(results) + mArray.diagnostics = { results } end luci.http.prepare_content("application/json") - luci.http.write_json(rv) + luci.http.write_json(mArray) end -function mwan3_tshoot_data() - local rv = { } +function troubleshootingData() + local mArray = {} -- software versions - local wrtrelease = ut.trim(luci.version.distversion) - if wrtrelease ~= "" then - wrtrelease = "OpenWrt - " .. wrtrelease + local wrtRelease = ut.trim(luci.version.distversion) + if wrtRelease ~= "" then + wrtRelease = "OpenWrt - " .. wrtRelease else - wrtrelease = "OpenWrt - unknown" + wrtRelease = "OpenWrt - unknown" end - local lucirelease = ut.trim(luci.version.luciversion) - if lucirelease ~= "" then - lucirelease = "\nLuCI - " .. lucirelease + local luciRelease = ut.trim(luci.version.luciversion) + if luciRelease ~= "" then + luciRelease = "\nLuCI - " .. luciRelease else - lucirelease = "\nLuCI - unknown" + luciRelease = "\nLuCI - unknown" end - local mwan3version = ut.trim(sys.exec("opkg info mwan3 | grep Version | awk '{ print $2 }'")) - if mwan3version ~= "" then - mwan3version = "\n\nmwan3 - " .. mwan3version + local mwanVersion = ut.trim(sys.exec("opkg info mwan3 | grep Version | awk '{print $2}'")) + if mwanVersion ~= "" then + mwanVersion = "\n\nmwan3 - " .. mwanVersion else - mwan3version = "\nmwan3 - unknown" + mwanVersion = "\n\nmwan3 - unknown" end - local mwan3lversion = ut.trim(sys.exec("opkg info luci-app-mwan3 | grep Version | awk '{ print $2 }'")) - if mwan3lversion ~= "" then - mwan3lversion = "\nmwan3-luci - " .. mwan3lversion + local mwanLuciVersion = ut.trim(sys.exec("opkg info luci-app-mwan3 | grep Version | awk '{print $2}'")) + if mwanLuciVersion ~= "" then + mwanLuciVersion = "\nmwan3-luci - " .. mwanLuciVersion else - mwan3lversion = "\nmwan3-luci - unknown" + mwanLuciVersion = "\nmwan3-luci - unknown" end - local softrev = wrtrelease .. lucirelease .. mwan3version .. mwan3lversion - rv.mw3ver = { } - mwv = {} - mwv[softrev] = #rv.mw3ver + 1 - rv.mw3ver[mwv[softrev]] = { mwan3v = softrev } + mArray.versions = { wrtRelease .. luciRelease .. mwanVersion .. mwanLuciVersion } - -- mwan3 config - local mwcg = ut.trim(sys.exec("cat /etc/config/mwan3")) - if mwcg == "" then - mwcg = "No data found" + -- mwan config + local mwanConfig = ut.trim(sys.exec("cat /etc/config/mwan3")) + if mwanConfig == "" then + mwanConfig = "No data found" end - rv.mwan3config = { } - mwan3cfg = {} - mwan3cfg[mwcg] = #rv.mwan3config + 1 - rv.mwan3config[mwan3cfg[mwcg]] = { mwn3cfg = mwcg } + mArray.mwanconfig = { mwanConfig } -- network config - local netcg = ut.trim(sys.exec("cat /etc/config/network | sed -e 's/.*username.*/ USERNAME HIDDEN/' -e 's/.*password.*/ PASSWORD HIDDEN/'")) - if netcg == "" then - netcg = "No data found" + local networkConfig = ut.trim(sys.exec("cat /etc/config/network | sed -e 's/.*username.*/ USERNAME HIDDEN/' -e 's/.*password.*/ PASSWORD HIDDEN/'")) + if networkConfig == "" then + networkConfig = "No data found" end - rv.netconfig = { } - ncfg = {} - ncfg[netcg] = #rv.netconfig + 1 - rv.netconfig[ncfg[netcg]] = { netcfg = netcg } + mArray.netconfig = { networkConfig } -- ifconfig - local ifcg = ut.trim(sys.exec("ifconfig")) - if ifcg == "" then - ifcg = "No data found" + local ifconfig = ut.trim(sys.exec("ifconfig")) + if ifconfig == "" then + ifconfig = "No data found" end - rv.ifconfig = { } - icfg = {} - icfg[ifcg] = #rv.ifconfig + 1 - rv.ifconfig[icfg[ifcg]] = { ifcfg = ifcg } + mArray.ifconfig = { ifconfig } -- route -n - local routeshow = ut.trim(sys.exec("route -n")) - if routeshow == "" then - routeshow = "No data found" + local routeShow = ut.trim(sys.exec("route -n")) + if routeShow == "" then + routeShow = "No data found" end - rv.rtshow = { } - rshw = {} - rshw[routeshow] = #rv.rtshow + 1 - rv.rtshow[rshw[routeshow]] = { iprtshow = routeshow } + mArray.routeshow = { routeShow } -- ip rule show - local ipr = ut.trim(sys.exec("ip rule show")) - if ipr == "" then - ipr = "No data found" + local ipRuleShow = ut.trim(sys.exec("ip rule show")) + if ipRuleShow == "" then + ipRuleShow = "No data found" end - rv.iprule = { } - ipruleid = {} - ipruleid[ipr] = #rv.iprule + 1 - rv.iprule[ipruleid[ipr]] = { rule = ipr } + mArray.iprule = { ipRuleShow } -- ip route list table 1-250 - local routelisting, rlstr = ut.trim(sys.exec("ip rule | sed 's/://g' | awk '$1>=2001 && $1<=2250' | awk '{ print $NF }'")), "" - if routelisting ~= "" then - for line in routelisting:gmatch("[^\r\n]+") do - rlstr = rlstr .. line .. "\n" .. sys.exec("ip route list table " .. line) + local routeList, routeString = ut.trim(sys.exec("ip rule | sed 's/://g' | awk '$1>=2001 && $1<=2250' | awk '{print $NF}'")), "" + if routeList ~= "" then + for line in routeList:gmatch("[^\r\n]+") do + routeString = routeString .. line .. "\n" .. sys.exec("ip route list table " .. line) end - rlstr = ut.trim(rlstr) + routeString = ut.trim(routeString) else - rlstr = "No data found" + routeString = "No data found" end - rv.routelist = { } - rtlist = {} - rtlist[rlstr] = #rv.routelist + 1 - rv.routelist[rtlist[rlstr]] = { iprtlist = rlstr } + mArray.routelist = { routeString } -- default firewall output policy - local defout = ut.trim(sys.exec("uci get -p /var/state firewall.@defaults[0].output")) - if defout == "" then - defout = "No data found" + local firewallOut = ut.trim(sys.exec("uci get -p /var/state firewall.@defaults[0].output")) + if firewallOut == "" then + firewallOut = "No data found" end - rv.fidef = { } - fwdf = {} - fwdf[defout] = #rv.fidef + 1 - rv.fidef[fwdf[defout]] = { firedef = defout } + mArray.firewallout = { firewallOut } -- iptables - local iptbl = ut.trim(sys.exec("iptables -L -t mangle -v -n")) - if iptbl == "" then - iptbl = "No data found" + local iptables = ut.trim(sys.exec("iptables -L -t mangle -v -n")) + if iptables == "" then + iptables = "No data found" end - rv.iptables = { } - tables = {} - tables[iptbl] = #rv.iptables + 1 - rv.iptables[tables[iptbl]] = { iptbls = iptbl } + mArray.iptables = { iptables } luci.http.prepare_content("application/json") - luci.http.write_json(rv) + luci.http.write_json(mArray) end diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_adv_hotplug.lua b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/advanced_hotplugscript.lua similarity index 81% rename from net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_adv_hotplug.lua rename to net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/advanced_hotplugscript.lua index 93e125cf36..0e7b8b11d0 100644 --- a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_adv_hotplug.lua +++ b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/advanced_hotplugscript.lua @@ -4,21 +4,21 @@ fs = require "nixio.fs" sys = require "luci.sys" ut = require "luci.util" -script = "/etc/hotplug.d/iface/16-mwan3custom" -scriptbak = "/etc/hotplug.d/iface/16-mwan3custombak" +script = "/etc/hotplug.d/iface/16-mwancustom" +scriptBackup = "/etc/hotplug.d/iface/16-mwancustombak" if luci.http.formvalue("cbid.luci.1._restorebak") then -- restore button has been clicked - luci.http.redirect(luci.dispatcher.build_url("admin/network/mwan3/advanced/hotplug") .. "?restore=yes") + luci.http.redirect(luci.dispatcher.build_url("admin/network/mwan/advanced/hotplugscript") .. "?restore=yes") elseif luci.http.formvalue("restore") == "yes" then -- restore script from backup - os.execute("cp -f " .. scriptbak .. " " .. script) + os.execute("cp -f " .. scriptBackup .. " " .. script) end m5 = SimpleForm("luci", nil) - m5:append(Template("mwan3/mwan3_adv_hotplug")) -- highlight current tab + m5:append(Template("mwan/advanced_hotplugscript")) -- highlight current tab f = m5:section(SimpleSection, nil, - translate("This section allows you to modify the contents of /etc/hotplug.d/iface/16-mwan3custom
" .. + translate("This section allows you to modify the contents of /etc/hotplug.d/iface/16-mwancustom
" .. "This is useful for running system commands and/or scripts based on interface ifup or ifdown hotplug events

" .. "Notes:
" .. "The first line of the script must be "#!/bin/sh" without quotes
" .. @@ -40,7 +40,7 @@ t = f:option(TextValue, "lines") function t.cfgvalue() local hps = fs.readfile(script) if not hps or hps == "" then -- if script does not exist or is blank restore from backup - sys.call("cp -f " .. scriptbak .. " " .. script) + sys.call("cp -f " .. scriptBackup .. " " .. script) return fs.readfile(script) else return hps diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_adv_mwan3.lua b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/advanced_mwanconfig.lua similarity index 60% rename from net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_adv_mwan3.lua rename to net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/advanced_mwanconfig.lua index 9eb0df52cc..e0a99e8366 100644 --- a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_adv_mwan3.lua +++ b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/advanced_mwanconfig.lua @@ -1,12 +1,12 @@ --- ------ mwan3 configuration ------ -- +-- ------ mwan configuration ------ -- ut = require "luci.util" -mwan3file = "/etc/config/mwan3" +mwanConfig = "/etc/config/mwan3" m5 = SimpleForm("luci", nil) - m5:append(Template("mwan3/mwan3_adv_mwan3")) -- highlight current tab + m5:append(Template("mwan/advanced_mwanconfig")) -- highlight current tab f = m5:section(SimpleSection, nil, @@ -17,11 +17,11 @@ t = f:option(TextValue, "lines") t.rows = 20 function t.cfgvalue() - return nixio.fs.readfile(mwan3file) or "" + return nixio.fs.readfile(mwanConfig) or "" end function t.write(self, section, data) -- format and write new data to script - return nixio.fs.writefile(mwan3file, "\n" .. ut.trim(data:gsub("\r\n", "\n")) .. "\n") + return nixio.fs.writefile(mwanConfig, "\n" .. ut.trim(data:gsub("\r\n", "\n")) .. "\n") end function f.handle(self, state, data) diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_adv_network.lua b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/advanced_networkconfig.lua similarity index 65% rename from net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_adv_network.lua rename to net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/advanced_networkconfig.lua index fee6a07d2a..b93d89751b 100644 --- a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_adv_network.lua +++ b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/advanced_networkconfig.lua @@ -2,11 +2,11 @@ ut = require "luci.util" -netfile = "/etc/config/network" +networkConfig = "/etc/config/network" m5 = SimpleForm("networkconf", nil) - m5:append(Template("mwan3/mwan3_adv_network")) -- highlight current tab + m5:append(Template("mwan/advanced_networkconfig")) -- highlight current tab f = m5:section(SimpleSection, nil, @@ -17,11 +17,11 @@ t = f:option(TextValue, "lines") t.rows = 20 function t.cfgvalue() - return nixio.fs.readfile(netfile) or "" + return nixio.fs.readfile(networkConfig) or "" end function t.write(self, section, data) -- format and write new data to script - return nixio.fs.writefile(netfile, "\n" .. ut.trim(data:gsub("\r\n", "\n")) .. "\n") + return nixio.fs.writefile(networkConfig, "\n" .. ut.trim(data:gsub("\r\n", "\n")) .. "\n") end function f.handle(self, state, data) diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/interface.lua b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/interface.lua new file mode 100644 index 0000000000..5b31390b66 --- /dev/null +++ b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/interface.lua @@ -0,0 +1,266 @@ +-- ------ extra functions ------ -- + +function interfaceCheck() -- find issues with too many interfaces, reliability and metric + uci.cursor():foreach("mwan3", "interface", + function (section) + local interfaceName = section[".name"] + interfaceNumber = interfaceNumber+1 -- count number of mwan interfaces configured + -- create list of metrics for none and duplicate checking + local metricValue = ut.trim(sys.exec("uci get -p /var/state network." .. interfaceName .. ".metric")) + if metricValue == "" then + errorFound = 1 + errorNoMetricList = errorNoMetricList .. interfaceName .. " " + else + metricList = metricList .. interfaceName .. " " .. metricValue .. "\n" + end + -- check if any interfaces have a higher reliability requirement than tracking IPs configured + local trackingNumber = tonumber(ut.trim(sys.exec("echo $(uci get -p /var/state mwan3." .. interfaceName .. ".track_ip) | wc -w"))) + if trackingNumber > 0 then + local reliabilityNumber = tonumber(ut.trim(sys.exec("uci get -p /var/state mwan3." .. interfaceName .. ".reliability"))) + if reliabilityNumber and reliabilityNumber > trackingNumber then + errorFound = 1 + errorReliabilityList = errorReliabilityList .. interfaceName .. " " + end + end + -- check if any interfaces are not properly configured in /etc/config/network or have no default route in main routing table + if ut.trim(sys.exec("uci get -p /var/state network." .. interfaceName)) == "interface" then + local interfaceDevice = ut.trim(sys.exec("uci get -p /var/state network." .. interfaceName .. ".ifname")) + if interfaceDevice == "uci: Entry not found" or interfaceDevice == "" then + errorFound = 1 + errorNetConfigList = errorNetConfigList .. interfaceName .. " " + errorRouteList = errorRouteList .. interfaceName .. " " + else + local routeCheck = ut.trim(sys.exec("route -n | awk '{if ($8 == \"" .. interfaceDevice .. "\" && $1 == \"0.0.0.0\" && $3 == \"0.0.0.0\") print $1}'")) + if routeCheck == "" then + errorFound = 1 + errorRouteList = errorRouteList .. interfaceName .. " " + end + end + else + errorFound = 1 + errorNetConfigList = errorNetConfigList .. interfaceName .. " " + errorRouteList = errorRouteList .. interfaceName .. " " + end + end + ) + -- check if any interfaces have duplicate metrics + local metricDuplicateNumbers = sys.exec("echo '" .. metricList .. "' | awk '{print $2}' | uniq -d") + if metricDuplicateNumbers ~= "" then + errorFound = 1 + local metricDuplicates = "" + for line in metricDuplicateNumbers:gmatch("[^\r\n]+") do + metricDuplicates = sys.exec("echo '" .. metricList .. "' | grep '" .. line .. "' | awk '{print $1}'") + errorDuplicateMetricList = errorDuplicateMetricList .. metricDuplicates + end + errorDuplicateMetricList = sys.exec("echo '" .. errorDuplicateMetricList .. "' | tr '\n' ' '") + end +end + +function interfaceWarnings() -- display status and warning messages at the top of the page + local warnings = "" + if interfaceNumber <= 250 then + warnings = "There are currently " .. interfaceNumber .. " of 250 supported interfaces configured" + else + warnings = "WARNING: " .. interfaceNumber .. " interfaces are configured exceeding the maximum of 250!" + end + if errorReliabilityList ~= " " then + warnings = warnings .. "

WARNING: some interfaces have a higher reliability requirement than there are tracking IP addresses!" + end + if errorRouteList ~= " " then + warnings = warnings .. "

WARNING: some interfaces have no default route in the main routing table!" + end + if errorNetConfigList ~= " " then + warnings = warnings .. "

WARNING: some interfaces are configured incorrectly or not at all in /etc/config/network!" + end + if errorNoMetricList ~= " " then + warnings = warnings .. "

WARNING: some interfaces have no metric configured in /etc/config/network!" + end + if errorDuplicateMetricList ~= " " then + warnings = warnings .. "

WARNING: some interfaces have duplicate metrics configured in /etc/config/network!" + end + return warnings +end + +-- ------ interface configuration ------ -- + +dsp = require "luci.dispatcher" +sys = require "luci.sys" +ut = require "luci.util" + +interfaceNumber = 0 +metricList = "" +errorFound = 0 +errorDuplicateMetricList = " " +errorNetConfigList = " " +errorNoMetricList = " " +errorReliabilityList = " " +errorRouteList = " " +interfaceCheck() + + +m5 = Map("mwan3", translate("MWAN Interface Configuration"), + translate(interfaceWarnings())) + m5:append(Template("mwan/config_css")) + + +mwan_interface = m5:section(TypedSection, "interface", translate("Interfaces"), + translate("MWAN supports up to 250 physical and/or logical interfaces
" .. + "MWAN requires that all interfaces have a unique metric configured in /etc/config/network
" .. + "Names must match the interface name found in /etc/config/network (see advanced tab)
" .. + "Names may contain characters A-Z, a-z, 0-9, _ and no spaces
" .. + "Interfaces may not share the same name as configured members, policies or rules")) + mwan_interface.addremove = true + mwan_interface.dynamic = false + mwan_interface.sectionhead = "Interface" + mwan_interface.sortable = true + mwan_interface.template = "cbi/tblsection" + mwan_interface.extedit = dsp.build_url("admin", "network", "mwan", "configuration", "interface", "%s") + function mwan_interface.create(self, section) + TypedSection.create(self, section) + m5.uci:save("mwan3") + luci.http.redirect(dsp.build_url("admin", "network", "mwan", "configuration", "interface", section)) + end + + +enabled = mwan_interface:option(DummyValue, "enabled", translate("Enabled")) + enabled.rawhtml = true + function enabled.cfgvalue(self, s) + if self.map:get(s, "enabled") == "1" then + return "Yes" + else + return "No" + end + end + +track_ip = mwan_interface:option(DummyValue, "track_ip", translate("Tracking IP")) + track_ip.rawhtml = true + function track_ip.cfgvalue(self, s) + tracked = self.map:get(s, "track_ip") + if tracked then + local ipList = "" + for k,v in pairs(tracked) do + ipList = ipList .. v .. "
" + end + return ipList + else + return "—" + end + end + +reliability = mwan_interface:option(DummyValue, "reliability", translate("Tracking reliability")) + reliability.rawhtml = true + function reliability.cfgvalue(self, s) + if tracked then + return self.map:get(s, "reliability") or "—" + else + return "—" + end + end + +count = mwan_interface:option(DummyValue, "count", translate("Ping count")) + count.rawhtml = true + function count.cfgvalue(self, s) + if tracked then + return self.map:get(s, "count") or "—" + else + return "—" + end + end + +timeout = mwan_interface:option(DummyValue, "timeout", translate("Ping timeout")) + timeout.rawhtml = true + function timeout.cfgvalue(self, s) + if tracked then + local timeoutValue = self.map:get(s, "timeout") + if timeoutValue then + return timeoutValue .. "s" + else + return "—" + end + else + return "—" + end + end + +interval = mwan_interface:option(DummyValue, "interval", translate("Ping interval")) + interval.rawhtml = true + function interval.cfgvalue(self, s) + if tracked then + local intervalValue = self.map:get(s, "interval") + if intervalValue then + return intervalValue .. "s" + else + return "—" + end + else + return "—" + end + end + +down = mwan_interface:option(DummyValue, "down", translate("Interface down")) + down.rawhtml = true + function down.cfgvalue(self, s) + if tracked then + return self.map:get(s, "down") or "—" + else + return "—" + end + end + +up = mwan_interface:option(DummyValue, "up", translate("Interface up")) + up.rawhtml = true + function up.cfgvalue(self, s) + if tracked then + return self.map:get(s, "up") or "—" + else + return "—" + end + end + +metric = mwan_interface:option(DummyValue, "metric", translate("Metric")) + metric.rawhtml = true + function metric.cfgvalue(self, s) + local metricValue = sys.exec("uci get -p /var/state network." .. s .. ".metric") + if metricValue ~= "" then + return metricValue + else + return "—" + end + end + +errors = mwan_interface:option(DummyValue, "errors", translate("Errors")) + errors.rawhtml = true + function errors.cfgvalue(self, s) + if errorFound == 1 then + local mouseOver, lineBreak = "", "" + if string.find(errorReliabilityList, " " .. s .. " ") then + mouseOver = "Higher reliability requirement than there are tracking IP addresses" + lineBreak = " " + end + if string.find(errorRouteList, " " .. s .. " ") then + mouseOver = mouseOver .. lineBreak .. "No default route in the main routing table" + lineBreak = " " + end + if string.find(errorNetConfigList, " " .. s .. " ") then + mouseOver = mouseOver .. lineBreak .. "Configured incorrectly or not at all in /etc/config/network" + lineBreak = " " + end + if string.find(errorNoMetricList, " " .. s .. " ") then + mouseOver = mouseOver .. lineBreak .. "No metric configured in /etc/config/network" + lineBreak = " " + end + if string.find(errorDuplicateMetricList, " " .. s .. " ") then + mouseOver = mouseOver .. lineBreak .. "Duplicate metric configured in /etc/config/network" + end + if mouseOver == "" then + return "" + else + return "\"error\"" + end + else + return "" + end + end + + +return m5 diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_interfaceconfig.lua b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/interfaceconfig.lua similarity index 57% rename from net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_interfaceconfig.lua rename to net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/interfaceconfig.lua index 3da1e53491..16a7ec394e 100644 --- a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_interfaceconfig.lua +++ b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/interfaceconfig.lua @@ -1,70 +1,70 @@ -- ------ extra functions ------ -- -function iface_check() - metcheck = ut.trim(sys.exec("uci get -p /var/state network." .. arg[1] .. ".metric")) - if metcheck == "" then -- no metric - err_nomet = 1 +function interfaceCheck() + metricValue = ut.trim(sys.exec("uci get -p /var/state network." .. arg[1] .. ".metric")) + if metricValue == "" then -- no metric + errorNoMetric = 1 else -- if metric exists create list of interface metrics to compare against for duplicates uci.cursor():foreach("mwan3", "interface", function (section) - local metlkp = ut.trim(sys.exec("uci get -p /var/state network." .. section[".name"] .. ".metric")) - metric_list = metric_list .. section[".name"] .. " " .. metlkp .. "\n" + local metricValue = ut.trim(sys.exec("uci get -p /var/state network." .. section[".name"] .. ".metric")) + metricList = metricList .. section[".name"] .. " " .. metricValue .. "\n" end ) -- compare metric against list - local metric_dupnums, metric_dupes = sys.exec("echo '" .. metric_list .. "' | awk '{ print $2 }' | uniq -d"), "" - for line in metric_dupnums:gmatch("[^\r\n]+") do - metric_dupes = sys.exec("echo '" .. metric_list .. "' | grep '" .. line .. "' | awk '{ print $1 }'") - err_dupmet_list = err_dupmet_list .. metric_dupes + local metricDuplicateNumbers, metricDuplicates = sys.exec("echo '" .. metricList .. "' | awk '{print $2}' | uniq -d"), "" + for line in metricDuplicateNumbers:gmatch("[^\r\n]+") do + metricDuplicates = sys.exec("echo '" .. metricList .. "' | grep '" .. line .. "' | awk '{print $1}'") + errorDuplicateMetricList = errorDuplicateMetricList .. metricDuplicates end - if sys.exec("echo '" .. err_dupmet_list .. "' | grep -w " .. arg[1]) ~= "" then - err_dupmet = 1 + if sys.exec("echo '" .. errorDuplicateMetricList .. "' | grep -w " .. arg[1]) ~= "" then + errorDuplicateMetric = 1 end end -- check if this interface has a higher reliability requirement than track IPs configured - local tipnum = tonumber(ut.trim(sys.exec("echo $(uci get -p /var/state mwan3." .. arg[1] .. ".track_ip) | wc -w"))) - if tipnum > 0 then - local relnum = tonumber(ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".reliability"))) - if relnum and relnum > tipnum then - err_reliability = 1 + local trackingNumber = tonumber(ut.trim(sys.exec("echo $(uci get -p /var/state mwan3." .. arg[1] .. ".track_ip) | wc -w"))) + if trackingNumber > 0 then + local reliabilityNumber = tonumber(ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".reliability"))) + if reliabilityNumber and reliabilityNumber > trackingNumber then + errorReliability = 1 end end -- check if any interfaces are not properly configured in /etc/config/network or have no default route in main routing table if ut.trim(sys.exec("uci get -p /var/state network." .. arg[1])) == "interface" then - local ifdev = ut.trim(sys.exec("uci get -p /var/state network." .. arg[1] .. ".ifname")) - if ifdev == "uci: Entry not found" or ifdev == "" then - err_netcfg = 1 - err_route = 1 + local interfaceDevice = ut.trim(sys.exec("uci get -p /var/state network." .. arg[1] .. ".ifname")) + if interfaceDevice == "uci: Entry not found" or interfaceDevice == "" then + errorNetConfig = 1 + errorRoute = 1 else - local rtcheck = ut.trim(sys.exec("route -n | awk '{ if ($8 == \"" .. ifdev .. "\" && $1 == \"0.0.0.0\" && $3 == \"0.0.0.0\") print $1 }'")) - if rtcheck == "" then - err_route = 1 + local routeCheck = ut.trim(sys.exec("route -n | awk '{if ($8 == \"" .. interfaceDevice .. "\" && $1 == \"0.0.0.0\" && $3 == \"0.0.0.0\") print $1}'")) + if routeCheck == "" then + errorRoute = 1 end end else - err_netcfg = 1 - err_route = 1 + errorNetConfig = 1 + errorRoute = 1 end end -function iface_warn() -- display warning messages at the top of the page - local warns, linebrk = "", "" - if err_reliability == 1 then +function interfaceWarnings() -- display warning messages at the top of the page + local warns, lineBreak = "", "" + if errorReliability == 1 then warns = "WARNING: this interface has a higher reliability requirement than there are tracking IP addresses!" - linebrk = "

" + lineBreak = "

" end - if err_route == 1 then - warns = warns .. linebrk .. "WARNING: this interface has no default route in the main routing table!" - linebrk = "

" + if errorRoute == 1 then + warns = warns .. lineBreak .. "WARNING: this interface has no default route in the main routing table!" + lineBreak = "

" end - if err_netcfg == 1 then - warns = warns .. linebrk .. "WARNING: this interface is configured incorrectly or not at all in /etc/config/network!" - linebrk = "

" + if errorNetConfig == 1 then + warns = warns .. lineBreak .. "WARNING: this interface is configured incorrectly or not at all in /etc/config/network!" + lineBreak = "

" end - if err_nomet == 1 then - warns = warns .. linebrk .. "WARNING: this interface has no metric configured in /etc/config/network!" - elseif err_dupmet == 1 then - warns = warns .. linebrk .. "WARNING: this and other interfaces have duplicate metrics configured in /etc/config/network!" + if errorNoMetric == 1 then + warns = warns .. lineBreak .. "WARNING: this interface has no metric configured in /etc/config/network!" + elseif errorDuplicateMetric == 1 then + warns = warns .. lineBreak .. "WARNING: this and other interfaces have duplicate metrics configured in /etc/config/network!" end return warns end @@ -76,21 +76,20 @@ sys = require "luci.sys" ut = require "luci.util" arg[1] = arg[1] or "" -metcheck = "" -metric_list = "" -err_dupmet_list = "" -err_rel_list = "" -err_nomet = 0 -err_dupmet = 0 -err_route = 0 -err_netcfg = 0 -err_reliability = 0 -iface_check() +metricValue = "" +metricList = "" +errorDuplicateMetricList = "" +errorNoMetric = 0 +errorDuplicateMetric = 0 +errorRoute = 0 +errorNetConfig = 0 +errorReliability = 0 +interfaceCheck() -m5 = Map("mwan3", translate("MWAN3 Multi-WAN Interface Configuration - " .. arg[1]), - translate(iface_warn())) - m5.redirect = dsp.build_url("admin", "network", "mwan3", "configuration", "interface") +m5 = Map("mwan3", translate("MWAN Interface Configuration - " .. arg[1]), + translate(interfaceWarnings())) + m5.redirect = dsp.build_url("admin", "network", "mwan", "configuration", "interface") mwan_interface = m5:section(NamedSection, arg[1], "interface", "") @@ -180,8 +179,8 @@ metric = mwan_interface:option(DummyValue, "metric", translate("Metric"), translate("This displays the metric assigned to this interface in /etc/config/network")) metric.rawhtml = true function metric.cfgvalue(self, s) - if err_nomet == 0 then - return metcheck + if errorNoMetric == 0 then + return metricValue else return "—" end diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_member.lua b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/member.lua similarity index 77% rename from net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_member.lua rename to net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/member.lua index 68b9549e10..3bccbd942f 100644 --- a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_member.lua +++ b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/member.lua @@ -3,12 +3,12 @@ ds = require "luci.dispatcher" -m5 = Map("mwan3", translate("MWAN3 Multi-WAN Member Configuration")) - m5:append(Template("mwan3/mwan3_config_css")) +m5 = Map("mwan3", translate("MWAN Member Configuration")) + m5:append(Template("mwan/config_css")) mwan_member = m5:section(TypedSection, "member", translate("Members"), - translate("Members are profiles attaching a metric and weight to an MWAN3 interface
" .. + translate("Members are profiles attaching a metric and weight to an MWAN interface
" .. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces
" .. "Members may not share the same name as configured interfaces, policies or rules")) mwan_member.addremove = true @@ -16,11 +16,11 @@ mwan_member = m5:section(TypedSection, "member", translate("Members"), mwan_member.sectionhead = "Member" mwan_member.sortable = true mwan_member.template = "cbi/tblsection" - mwan_member.extedit = ds.build_url("admin", "network", "mwan3", "configuration", "member", "%s") + mwan_member.extedit = ds.build_url("admin", "network", "mwan", "configuration", "member", "%s") function mwan_member.create(self, section) TypedSection.create(self, section) m5.uci:save("mwan3") - luci.http.redirect(ds.build_url("admin", "network", "mwan3", "configuration", "member", section)) + luci.http.redirect(ds.build_url("admin", "network", "mwan", "configuration", "member", section)) end diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_memberconfig.lua b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/memberconfig.lua similarity index 87% rename from net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_memberconfig.lua rename to net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/memberconfig.lua index 8ea7d9824d..181d22e06f 100644 --- a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_memberconfig.lua +++ b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/memberconfig.lua @@ -14,8 +14,8 @@ dsp = require "luci.dispatcher" arg[1] = arg[1] or "" -m5 = Map("mwan3", translate("MWAN3 Multi-WAN Member Configuration - ") .. arg[1]) - m5.redirect = dsp.build_url("admin", "network", "mwan3", "configuration", "member") +m5 = Map("mwan3", translate("MWAN Member Configuration - ") .. arg[1]) + m5.redirect = dsp.build_url("admin", "network", "mwan", "configuration", "member") mwan_member = m5:section(NamedSection, arg[1], "member", "") diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_policy.lua b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/policy.lua similarity index 69% rename from net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_policy.lua rename to net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/policy.lua index 84d610f619..e141d696a9 100644 --- a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_policy.lua +++ b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/policy.lua @@ -1,18 +1,18 @@ -- ------ extra functions ------ -- -function policy_check() -- check to see if any policy names exceed the maximum of 15 characters +function policyCheck() -- check to see if any policy names exceed the maximum of 15 characters uci.cursor():foreach("mwan3", "policy", function (section) if string.len(section[".name"]) > 15 then - toolong = 1 + nameTooLong = 1 err_name_list = err_name_list .. section[".name"] .. " " end end ) end -function policy_warn() -- display status and warning messages at the top of the page - if toolong == 1 then +function policyWarn() -- display status and warning messages at the top of the page + if nameTooLong == 1 then return "WARNING: Some policies have names exceeding the maximum of 15 characters!" else return "" @@ -24,18 +24,18 @@ end ds = require "luci.dispatcher" sys = require "luci.sys" -toolong = 0 +nameTooLong = 0 err_name_list = " " -policy_check() +policyCheck() -m5 = Map("mwan3", translate("MWAN3 Multi-WAN Policy Configuration"), - translate(policy_warn())) - m5:append(Template("mwan3/mwan3_config_css")) +m5 = Map("mwan3", translate("MWAN Policy Configuration"), + translate(policyWarn())) + m5:append(Template("mwan/config_css")) mwan_policy = m5:section(TypedSection, "policy", translate("Policies"), - translate("Policies are profiles grouping one or more members controlling how MWAN3 distributes traffic
" .. + translate("Policies are profiles grouping one or more members controlling how MWAN distributes traffic
" .. "Member interfaces with lower metrics are used first. Interfaces with the same metric load-balance
" .. "Load-balanced member interfaces distribute more traffic out those with higher weights
" .. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces. Names must be 15 characters or less
" .. @@ -45,23 +45,23 @@ mwan_policy = m5:section(TypedSection, "policy", translate("Policies"), mwan_policy.sectionhead = "Policy" mwan_policy.sortable = true mwan_policy.template = "cbi/tblsection" - mwan_policy.extedit = ds.build_url("admin", "network", "mwan3", "configuration", "policy", "%s") + mwan_policy.extedit = ds.build_url("admin", "network", "mwan", "configuration", "policy", "%s") function mwan_policy.create(self, section) TypedSection.create(self, section) m5.uci:save("mwan3") - luci.http.redirect(ds.build_url("admin", "network", "mwan3", "configuration", "policy", section)) + luci.http.redirect(ds.build_url("admin", "network", "mwan", "configuration", "policy", section)) end use_member = mwan_policy:option(DummyValue, "use_member", translate("Members assigned")) use_member.rawhtml = true function use_member.cfgvalue(self, s) - local tab, str = self.map:get(s, "use_member"), "" - if tab then - for k,v in pairs(tab) do - str = str .. v .. "
" + local memberConfig, memberList = self.map:get(s, "use_member"), "" + if memberConfig then + for k,v in pairs(memberConfig) do + memberList = memberList .. v .. "
" end - return str + return memberList else return "—" end @@ -71,10 +71,10 @@ use_member = mwan_policy:option(DummyValue, "use_member", translate("Members ass last_resort = mwan_policy:option(DummyValue, "last_resort", translate("Last resort")) last_resort.rawhtml = true function last_resort.cfgvalue(self, s) - local str = self.map:get(s, "last_resort") - if str == "blackhole" then + local action = self.map:get(s, "last_resort") + if action == "blackhole" then return "blackhole (drop)" - elseif str == "default" then + elseif action == "default" then return "default (use main routing table)" else return "unreachable (reject)" diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_policyconfig.lua b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/policyconfig.lua similarity index 65% rename from net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_policyconfig.lua rename to net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/policyconfig.lua index ddcff57940..f48a104c67 100644 --- a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_policyconfig.lua +++ b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/policyconfig.lua @@ -1,21 +1,21 @@ -- ------ extra functions ------ -- -function policy_check() -- check to see if this policy's name exceed the maximum of 15 characters - polchar = string.len(arg[1]) - if polchar > 15 then - toolong = 1 +function policyCheck() -- check to see if this policy's name exceed the maximum of 15 characters + policyNameLength = string.len(arg[1]) + if policyNameLength > 15 then + nameTooLong = 1 end end -function policy_warn() -- display status and warning messages at the top of the page - if toolong == 1 then - return "WARNING: this policy's name is " .. polchar .. " characters exceeding the maximum of 15!" +function policyWarn() -- display status and warning messages at the top of the page + if nameTooLong == 1 then + return "WARNING: this policy's name is " .. policyNameLength .. " characters exceeding the maximum of 15!" else return "" end end -function cbi_add_member(field) +function cbiAddMember(field) uci.cursor():foreach("mwan3", "member", function (section) field:value(section[".name"]) @@ -28,13 +28,13 @@ end dsp = require "luci.dispatcher" arg[1] = arg[1] or "" -toolong = 0 -policy_check() +nameTooLong = 0 +policyCheck() -m5 = Map("mwan3", translate("MWAN3 Multi-WAN Policy Configuration - " .. arg[1]), - translate(policy_warn())) - m5.redirect = dsp.build_url("admin", "network", "mwan3", "configuration", "policy") +m5 = Map("mwan3", translate("MWAN Policy Configuration - " .. arg[1]), + translate(policyWarn())) + m5.redirect = dsp.build_url("admin", "network", "mwan", "configuration", "policy") mwan_policy = m5:section(NamedSection, arg[1], "policy", "") @@ -43,7 +43,7 @@ mwan_policy = m5:section(NamedSection, arg[1], "policy", "") use_member = mwan_policy:option(DynamicList, "use_member", translate("Member used")) - cbi_add_member(use_member) + cbiAddMember(use_member) last_resort = mwan_policy:option(ListValue, "last_resort", translate("Last resort"), translate("When all policy members are offline use this behavior for matched traffic")) diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_rule.lua b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/rule.lua similarity index 70% rename from net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_rule.lua rename to net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/rule.lua index efae81b2a4..bf524d1df7 100644 --- a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_rule.lua +++ b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/rule.lua @@ -1,22 +1,22 @@ -- ------ extra functions ------ -- -function rule_check() -- determine if rules needs a proper protocol configured +function ruleCheck() -- determine if rules needs a proper protocol configured uci.cursor():foreach("mwan3", "rule", function (section) - local sport = ut.trim(sys.exec("uci get -p /var/state mwan3." .. section[".name"] .. ".src_port")) - local dport = ut.trim(sys.exec("uci get -p /var/state mwan3." .. section[".name"] .. ".dest_port")) - if sport ~= "" or dport ~= "" then -- ports configured - local proto = ut.trim(sys.exec("uci get -p /var/state mwan3." .. section[".name"] .. ".proto")) - if proto == "" or proto == "all" then -- no or improper protocol - err_proto_list = err_proto_list .. section[".name"] .. " " + local sourcePort = ut.trim(sys.exec("uci get -p /var/state mwan3." .. section[".name"] .. ".src_port")) + local destPort = ut.trim(sys.exec("uci get -p /var/state mwan3." .. section[".name"] .. ".dest_port")) + if sourcePort ~= "" or destPort ~= "" then -- ports configured + local protocol = ut.trim(sys.exec("uci get -p /var/state mwan3." .. section[".name"] .. ".proto")) + if protocol == "" or protocol == "all" then -- no or improper protocol + error_protocol_list = error_protocol_list .. section[".name"] .. " " end end end ) end -function rule_warn() -- display warning messages at the top of the page - if err_proto_list ~= " " then +function ruleWarn() -- display warning messages at the top of the page + if error_protocol_list ~= " " then return "WARNING: some rules have a port configured with no or improper protocol specified! Please configure a specific protocol!" else return "" @@ -29,18 +29,17 @@ dsp = require "luci.dispatcher" sys = require "luci.sys" ut = require "luci.util" -err_proto = 0 -err_proto_list = " " -rule_check() +error_protocol_list = " " +ruleCheck() -m5 = Map("mwan3", translate("MWAN3 Multi-WAN Traffic Rule Configuration"), - translate(rule_warn())) - m5:append(Template("mwan3/mwan3_config_css")) +m5 = Map("mwan3", translate("MWAN Rule Configuration"), + translate(ruleWarn())) + m5:append(Template("mwan/config_css")) mwan_rule = m5:section(TypedSection, "rule", translate("Traffic Rules"), - translate("Rules specify which traffic will use a particular MWAN3 policy based on IP address, port or protocol
" .. + translate("Rules specify which traffic will use a particular MWAN policy based on IP address, port or protocol
" .. "Rules are matched from top to bottom. Rules below a matching rule are ignored. Traffic not matching any rule is routed using the main routing table
" .. "Traffic destined for known (other than default) networks is handled by the main routing table. Traffic matching a rule, but all WAN interfaces for that policy are down will be blackholed
" .. "Names may contain characters A-Z, a-z, 0-9, _ and no spaces
" .. @@ -51,11 +50,11 @@ mwan_rule = m5:section(TypedSection, "rule", translate("Traffic Rules"), mwan_rule.sectionhead = "Rule" mwan_rule.sortable = true mwan_rule.template = "cbi/tblsection" - mwan_rule.extedit = dsp.build_url("admin", "network", "mwan3", "configuration", "rule", "%s") + mwan_rule.extedit = dsp.build_url("admin", "network", "mwan", "configuration", "rule", "%s") function mwan_rule.create(self, section) TypedSection.create(self, section) m5.uci:save("mwan3") - luci.http.redirect(dsp.build_url("admin", "network", "mwan3", "configuration", "rule", section)) + luci.http.redirect(dsp.build_url("admin", "network", "mwan", "configuration", "rule", section)) end @@ -98,7 +97,7 @@ use_policy = mwan_rule:option(DummyValue, "use_policy", translate("Policy assign errors = mwan_rule:option(DummyValue, "errors", translate("Errors")) errors.rawhtml = true function errors.cfgvalue(self, s) - if not string.find(err_proto_list, " " .. s .. " ") then + if not string.find(error_protocol_list, " " .. s .. " ") then return "" else return "\"error\"" diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_ruleconfig.lua b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/ruleconfig.lua similarity index 67% rename from net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_ruleconfig.lua rename to net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/ruleconfig.lua index 404c27f8ba..831ab35b91 100644 --- a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_ruleconfig.lua +++ b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan/ruleconfig.lua @@ -1,25 +1,25 @@ -- ------ extra functions ------ -- -function rule_check() -- determine if rule needs a protocol specified - local sport = ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".src_port")) - local dport = ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".dest_port")) - if sport ~= "" or dport ~= "" then -- ports configured - local proto = ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".proto")) - if proto == "" or proto == "all" then -- no or improper protocol - err_proto = 1 +function ruleCheck() -- determine if rule needs a protocol specified + local sourcePort = ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".src_port")) + local destPort = ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".dest_port")) + if sourcePort ~= "" or destPort ~= "" then -- ports configured + local protocol = ut.trim(sys.exec("uci get -p /var/state mwan3." .. arg[1] .. ".proto")) + if protocol == "" or protocol == "all" then -- no or improper protocol + error_protocol = 1 end end end -function rule_warn() -- display warning message at the top of the page - if err_proto == 1 then +function ruleWarn() -- display warning message at the top of the page + if error_protocol == 1 then return "WARNING: this rule is incorrectly configured with no or improper protocol specified! Please configure a specific protocol!" else return "" end end -function cbi_add_policy(field) +function cbiAddPolicy(field) uci.cursor():foreach("mwan3", "policy", function (section) field:value(section[".name"]) @@ -27,9 +27,9 @@ function cbi_add_policy(field) ) end -function cbi_add_protocol(field) - local protos = ut.trim(sys.exec("cat /etc/protocols | grep ' # ' | awk '{print $1}' | grep -vw -e 'ip' -e 'tcp' -e 'udp' -e 'icmp' -e 'esp' | grep -v 'ipv6' | sort | tr '\n' ' '")) - for p in string.gmatch(protos, "%S+") do +function cbiAddProtocol(field) + local protocols = ut.trim(sys.exec("cat /etc/protocols | grep ' # ' | awk '{print $1}' | grep -vw -e 'ip' -e 'tcp' -e 'udp' -e 'icmp' -e 'esp' | grep -v 'ipv6' | sort | tr '\n' ' '")) + for p in string.gmatch(protocols, "%S+") do field:value(p) end end @@ -41,13 +41,13 @@ sys = require "luci.sys" ut = require "luci.util" arg[1] = arg[1] or "" -err_proto = 0 -rule_check() +error_protocol = 0 +ruleCheck() -m5 = Map("mwan3", translate("MWAN3 Multi-WAN Rule Configuration - ") .. arg[1], - translate(rule_warn())) - m5.redirect = dsp.build_url("admin", "network", "mwan3", "configuration", "rule") +m5 = Map("mwan3", translate("MWAN Rule Configuration - ") .. arg[1], + translate(ruleWarn())) + m5.redirect = dsp.build_url("admin", "network", "mwan", "configuration", "rule") mwan_rule = m5:section(NamedSection, arg[1], "rule", "") @@ -79,10 +79,10 @@ proto = mwan_rule:option(Value, "proto", translate("Protocol"), proto:value("udp") proto:value("icmp") proto:value("esp") - cbi_add_protocol(proto) + cbiAddProtocol(proto) use_policy = mwan_rule:option(Value, "use_policy", translate("Policy assigned")) - cbi_add_policy(use_policy) + cbiAddPolicy(use_policy) use_policy:value("unreachable", translate("unreachable (reject)")) use_policy:value("blackhole", translate("blackhole (drop)")) use_policy:value("default", translate("default (use main routing table)")) diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_interface.lua b/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_interface.lua deleted file mode 100644 index 101bcea9db..0000000000 --- a/net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_interface.lua +++ /dev/null @@ -1,266 +0,0 @@ --- ------ extra functions ------ -- - -function iface_check() -- find issues with too many interfaces, reliability and metric - uci.cursor():foreach("mwan3", "interface", - function (section) - local ifname = section[".name"] - ifnum = ifnum+1 -- count number of mwan3 interfaces configured - -- create list of metrics for none and duplicate checking - local metlkp = ut.trim(sys.exec("uci get -p /var/state network." .. ifname .. ".metric")) - if metlkp == "" then - err_found = 1 - err_nomet_list = err_nomet_list .. ifname .. " " - else - metric_list = metric_list .. ifname .. " " .. metlkp .. "\n" - end - -- check if any interfaces have a higher reliability requirement than tracking IPs configured - local tipnum = tonumber(ut.trim(sys.exec("echo $(uci get -p /var/state mwan3." .. ifname .. ".track_ip) | wc -w"))) - if tipnum > 0 then - local relnum = tonumber(ut.trim(sys.exec("uci get -p /var/state mwan3." .. ifname .. ".reliability"))) - if relnum and relnum > tipnum then - err_found = 1 - err_rel_list = err_rel_list .. ifname .. " " - end - end - -- check if any interfaces are not properly configured in /etc/config/network or have no default route in main routing table - if ut.trim(sys.exec("uci get -p /var/state network." .. ifname)) == "interface" then - local ifdev = ut.trim(sys.exec("uci get -p /var/state network." .. ifname .. ".ifname")) - if ifdev == "uci: Entry not found" or ifdev == "" then - err_found = 1 - err_netcfg_list = err_netcfg_list .. ifname .. " " - err_route_list = err_route_list .. ifname .. " " - else - local rtcheck = ut.trim(sys.exec("route -n | awk '{ if ($8 == \"" .. ifdev .. "\" && $1 == \"0.0.0.0\" && $3 == \"0.0.0.0\") print $1 }'")) - if rtcheck == "" then - err_found = 1 - err_route_list = err_route_list .. ifname .. " " - end - end - else - err_found = 1 - err_netcfg_list = err_netcfg_list .. ifname .. " " - err_route_list = err_route_list .. ifname .. " " - end - end - ) - -- check if any interfaces have duplicate metrics - local metric_dupnums = sys.exec("echo '" .. metric_list .. "' | awk '{ print $2 }' | uniq -d") - if metric_dupnums ~= "" then - err_found = 1 - local metric_dupes = "" - for line in metric_dupnums:gmatch("[^\r\n]+") do - metric_dupes = sys.exec("echo '" .. metric_list .. "' | grep '" .. line .. "' | awk '{ print $1 }'") - err_dupmet_list = err_dupmet_list .. metric_dupes - end - err_dupmet_list = sys.exec("echo '" .. err_dupmet_list .. "' | tr '\n' ' '") - end -end - -function iface_warn() -- display status and warning messages at the top of the page - local warns = "" - if ifnum <= 250 then - warns = "There are currently " .. ifnum .. " of 250 supported interfaces configured" - else - warns = "WARNING: " .. ifnum .. " interfaces are configured exceeding the maximum of 250!" - end - if err_rel_list ~= " " then - warns = warns .. "

WARNING: some interfaces have a higher reliability requirement than there are tracking IP addresses!" - end - if err_route_list ~= " " then - warns = warns .. "

WARNING: some interfaces have no default route in the main routing table!" - end - if err_netcfg_list ~= " " then - warns = warns .. "

WARNING: some interfaces are configured incorrectly or not at all in /etc/config/network!" - end - if err_nomet_list ~= " " then - warns = warns .. "

WARNING: some interfaces have no metric configured in /etc/config/network!" - end - if err_dupmet_list ~= " " then - warns = warns .. "

WARNING: some interfaces have duplicate metrics configured in /etc/config/network!" - end - return warns -end - --- ------ interface configuration ------ -- - -dsp = require "luci.dispatcher" -sys = require "luci.sys" -ut = require "luci.util" - -ifnum = 0 -metric_list = "" -err_found = 0 -err_dupmet_list = " " -err_netcfg_list = " " -err_nomet_list = " " -err_rel_list = " " -err_route_list = " " -iface_check() - - -m5 = Map("mwan3", translate("MWAN3 Multi-WAN Interface Configuration"), - translate(iface_warn())) - m5:append(Template("mwan3/mwan3_config_css")) - - -mwan_interface = m5:section(TypedSection, "interface", translate("Interfaces"), - translate("MWAN3 supports up to 250 physical and/or logical interfaces
" .. - "MWAN3 requires that all interfaces have a unique metric configured in /etc/config/network
" .. - "Names must match the interface name found in /etc/config/network (see advanced tab)
" .. - "Names may contain characters A-Z, a-z, 0-9, _ and no spaces
" .. - "Interfaces may not share the same name as configured members, policies or rules")) - mwan_interface.addremove = true - mwan_interface.dynamic = false - mwan_interface.sectionhead = "Interface" - mwan_interface.sortable = true - mwan_interface.template = "cbi/tblsection" - mwan_interface.extedit = dsp.build_url("admin", "network", "mwan3", "configuration", "interface", "%s") - function mwan_interface.create(self, section) - TypedSection.create(self, section) - m5.uci:save("mwan3") - luci.http.redirect(dsp.build_url("admin", "network", "mwan3", "configuration", "interface", section)) - end - - -enabled = mwan_interface:option(DummyValue, "enabled", translate("Enabled")) - enabled.rawhtml = true - function enabled.cfgvalue(self, s) - if self.map:get(s, "enabled") == "1" then - return "Yes" - else - return "No" - end - end - -track_ip = mwan_interface:option(DummyValue, "track_ip", translate("Tracking IP")) - track_ip.rawhtml = true - function track_ip.cfgvalue(self, s) - local str = "" - tracked = self.map:get(s, "track_ip") - if tracked then - for k,v in pairs(tracked) do - str = str .. v .. "
" - end - return str - else - return "—" - end - end - -reliability = mwan_interface:option(DummyValue, "reliability", translate("Tracking reliability")) - reliability.rawhtml = true - function reliability.cfgvalue(self, s) - if tracked then - return self.map:get(s, "reliability") or "—" - else - return "—" - end - end - -count = mwan_interface:option(DummyValue, "count", translate("Ping count")) - count.rawhtml = true - function count.cfgvalue(self, s) - if tracked then - return self.map:get(s, "count") or "—" - else - return "—" - end - end - -timeout = mwan_interface:option(DummyValue, "timeout", translate("Ping timeout")) - timeout.rawhtml = true - function timeout.cfgvalue(self, s) - if tracked then - local tcheck = self.map:get(s, "timeout") - if tcheck then - return tcheck .. "s" - else - return "—" - end - else - return "—" - end - end - -interval = mwan_interface:option(DummyValue, "interval", translate("Ping interval")) - interval.rawhtml = true - function interval.cfgvalue(self, s) - if tracked then - local icheck = self.map:get(s, "interval") - if icheck then - return icheck .. "s" - else - return "—" - end - else - return "—" - end - end - -down = mwan_interface:option(DummyValue, "down", translate("Interface down")) - down.rawhtml = true - function down.cfgvalue(self, s) - if tracked then - return self.map:get(s, "down") or "—" - else - return "—" - end - end - -up = mwan_interface:option(DummyValue, "up", translate("Interface up")) - up.rawhtml = true - function up.cfgvalue(self, s) - if tracked then - return self.map:get(s, "up") or "—" - else - return "—" - end - end - -metric = mwan_interface:option(DummyValue, "metric", translate("Metric")) - metric.rawhtml = true - function metric.cfgvalue(self, s) - local metcheck = sys.exec("uci get -p /var/state network." .. s .. ".metric") - if metcheck ~= "" then - return metcheck - else - return "—" - end - end - -errors = mwan_interface:option(DummyValue, "errors", translate("Errors")) - errors.rawhtml = true - function errors.cfgvalue(self, s) - if err_found == 1 then - local mouseover, linebrk = "", "" - if string.find(err_rel_list, " " .. s .. " ") then - mouseover = "Higher reliability requirement than there are tracking IP addresses" - linebrk = " " - end - if string.find(err_route_list, " " .. s .. " ") then - mouseover = mouseover .. linebrk .. "No default route in the main routing table" - linebrk = " " - end - if string.find(err_netcfg_list, " " .. s .. " ") then - mouseover = mouseover .. linebrk .. "Configured incorrectly or not at all in /etc/config/network" - linebrk = " " - end - if string.find(err_nomet_list, " " .. s .. " ") then - mouseover = mouseover .. linebrk .. "No metric configured in /etc/config/network" - linebrk = " " - end - if string.find(err_dupmet_list, " " .. s .. " ") then - mouseover = mouseover .. linebrk .. "Duplicate metric configured in /etc/config/network" - end - if mouseover == "" then - return "" - else - return "\"error\"" - end - else - return "" - end - end - - -return m5 diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/view/admin_status/index/mwan.htm b/net/mwan3-luci/files/usr/lib/lua/luci/view/admin_status/index/mwan.htm new file mode 100644 index 0000000000..53b997af90 --- /dev/null +++ b/net/mwan3-luci/files/usr/lib/lua/luci/view/admin_status/index/mwan.htm @@ -0,0 +1 @@ +<%+mwan/openwrt_overview_status%> diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/view/admin_status/index/mwan3.htm b/net/mwan3-luci/files/usr/lib/lua/luci/view/admin_status/index/mwan3.htm deleted file mode 100644 index f510f158c5..0000000000 --- a/net/mwan3-luci/files/usr/lib/lua/luci/view/admin_status/index/mwan3.htm +++ /dev/null @@ -1 +0,0 @@ -<%+mwan3/mwan3_status%> diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_adv_diagnostics.htm b/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan/advanced_diagnostics.htm similarity index 64% rename from net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_adv_diagnostics.htm rename to net/mwan3-luci/files/usr/lib/lua/luci/view/mwan/advanced_diagnostics.htm index f0ceb1261a..19615695dd 100644 --- a/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_adv_diagnostics.htm +++ b/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan/advanced_diagnostics.htm @@ -1,20 +1,20 @@ <%+header%> <% local uci = require "luci.model.uci" - str = "" + interfaceNames = "" uci.cursor():foreach("mwan3", "interface", function (section) - str = str .. section[".name"] .. " " + interfaceNames = interfaceNames .. section[".name"] .. " " end ) %> @@ -23,16 +23,16 @@ -
+
- <%:MWAN3 Interface Diagnostics%> - + <% for z in interfaceNames:gmatch("[^ ]+") do -%><%- end %>
@@ -81,11 +78,11 @@
- <%:MWAN3 Service Control%> + <%:MWAN Service Control%>
- - - + + +
+ +<%+footer%> diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_config_css.htm b/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan/config_css.htm similarity index 53% rename from net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_config_css.htm rename to net/mwan3-luci/files/usr/lib/lua/luci/view/mwan/config_css.htm index 303fa20941..99da4875b0 100644 --- a/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_config_css.htm +++ b/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan/config_css.htm @@ -1,28 +1,28 @@ + +<%+footer%> diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan/overview_interface.htm b/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan/overview_interface.htm new file mode 100644 index 0000000000..776fd4ce22 --- /dev/null +++ b/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan/overview_interface.htm @@ -0,0 +1,122 @@ +<%+header%> + + + + + + +
+
+ <%:MWAN Interface Live Status%> +
<%:Loading%> Collecting data...
+
+
+ <%:MWAN Interface Systemlog%> +
<%:Loading%> Collecting data...
+
+
+ + + +<%+footer%> diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_adv_troubleshoot.htm b/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_adv_troubleshoot.htm deleted file mode 100644 index 7a27d66194..0000000000 --- a/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_adv_troubleshoot.htm +++ /dev/null @@ -1,75 +0,0 @@ -<%+header%> - - - - - - -
-
- <%:Troubleshooting Data%> -
<%:Loading%> Collecting data...
-
-
- - - -<%+footer%> diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_over_detail.htm b/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_over_detail.htm deleted file mode 100644 index 1d204467d5..0000000000 --- a/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_over_detail.htm +++ /dev/null @@ -1,56 +0,0 @@ -<%+header%> - - - - - - -
-
- <%:MWAN3 Multi-WAN Detailed Status%> -
<%:Loading%> Collecting data...
-
-
- - - -<%+footer%> diff --git a/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_over_interface.htm b/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_over_interface.htm deleted file mode 100644 index 06129d92f0..0000000000 --- a/net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_over_interface.htm +++ /dev/null @@ -1,136 +0,0 @@ -<%+header%> - - - - - - -
-
- <%:MWAN3 Multi-WAN Interface Live Status%> -
<%:Loading%> Collecting data...
-
-
- <%:MWAN3 Multi-WAN Interface Systemlog%> -
<%:Loading%> Collecting data...
-
-
- - - -<%+footer%>