mwan3-luci: update to 1.3-2 381/head
authorAedan ARFETT Renner <chipdankly@gmail.com>
Tue, 30 Sep 2014 02:32:02 +0000 (19:32 -0700)
committerAedan ARFETT Renner <chipdankly@gmail.com>
Tue, 30 Sep 2014 07:03:10 +0000 (00:03 -0700)
added support for new last_resort option for policy configuration
added dependencies for luci-mod-admin-full and luci-lib-nixio
shortened length of menuconfig description lines
reworded things on various pages
changed date formatting in custom hotplug script
default route checks now verify both destination/netmask are 0.0.0.0
condensed messy javascript lines and removed -F' ' from awk commands

Signed-off-by: Aedan Renner <chipdankly@gmail.com>
15 files changed:
net/mwan3-luci/Makefile
net/mwan3-luci/files/etc/hotplug.d/iface/16-mwan3custombak [changed mode: 0644->0755]
net/mwan3-luci/files/etc/uci-defaults/mwan3 [deleted file]
net/mwan3-luci/files/etc/uci-defaults/mwan3-luci [new file with mode: 0755]
net/mwan3-luci/files/usr/lib/lua/luci/controller/mwan3.lua
net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_interface.lua
net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_interfaceconfig.lua
net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_policy.lua
net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_policyconfig.lua
net/mwan3-luci/files/usr/lib/lua/luci/model/cbi/mwan3/mwan3_ruleconfig.lua
net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_adv_diagnostics.htm
net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_adv_troubleshoot.htm
net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_over_detail.htm
net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_over_interface.htm
net/mwan3-luci/files/usr/lib/lua/luci/view/mwan3/mwan3_status.htm

index 465363326aac623e82562d4a4635bca238cc0f74..25ae76763a6f46a15f338329d91b0c4aa0829e83 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=luci-app-mwan3
 PKG_VERSION:=1.3
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 PKG_MAINTAINER:=Aedan Renner <chipdankly@gmail.com>
 PKG_LICENSE:=GPLv2
 
@@ -20,14 +20,15 @@ define Package/luci-app-mwan3
   CATEGORY:=LuCI
   SUBMENU:=3. Applications
   TITLE:=LuCI support for the MWAN3 multiwan hotplug script
-  DEPENDS:=+mwan3
+  DEPENDS:=+mwan3 +luci-mod-admin-full +luci-lib-nixio
   PKGARCH:=all
   MAINTAINER:=Aedan Renner <chipdankly@gmail.com>
 endef
 
 define Package/luci-app-mwan3/description
-Hotplug script which makes configuration of multiple WAN interfaces simple and manageable
-With loadbalancing/failover support for up to 250 WAN interfaces, connection tracking and an easy to manage traffic ruleset
+Hotplug script which makes configuration of multiple WAN interfaces simple and
+manageable with loadbalancing/failover support for up to 250 physical or logical
+WAN interfaces, connection tracking and an easy to manage traffic ruleset
 endef
 
 define Build/Compile
old mode 100644 (file)
new mode 100755 (executable)
index 9bd0bee..954d1ad
@@ -1,22 +1,21 @@
 #!/bin/sh
 
 # to enable this script uncomment the case loop at the bottom
-# to report MWAN3 status on interface up/down events modify the lines in the send_reportdata function
+# to report mwan3 status on interface hotplug ifup/ifdown events modify the lines in the send_alert function
 
 send_alert()
 {
-       # $1 stores the mwan3 status information
-       # insert your code here to send the contents of $1
-       echo "$1"
+       # variable "$1" stores the mwan3 status information
+       # insert your code here to send the contents of "$1"
 }
 
 gather_event_info()
 {
        # create event information message
-       local EVENT_INFO="Interface [ "$INTERFACE" ($DEVICE) ] on router [ "$(uci get -p /var/state system.@system[0].hostname)" ] has triggered an [ "$ACTION" ] hotplug event on "$(date)""
+       local EVENT_INFO="Interface [ "$INTERFACE" ($DEVICE) ] on router [ "$(uci get -p /var/state system.@system[0].hostname)" ] has triggered a hotplug [ "$ACTION" ] event on "$(date +"%a %b %d %Y %T %Z")""
 
        # get current interface, policy and rule status
-       local CURRENT_STATUS="$(mwan3 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')")"
diff --git a/net/mwan3-luci/files/etc/uci-defaults/mwan3 b/net/mwan3-luci/files/etc/uci-defaults/mwan3
deleted file mode 100755 (executable)
index a19d4cb..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-
-# delete existing mwan3 ucitrack entry and add new entry
-uci -q batch <<-EOF >/dev/null
-       del ucitrack.@mwan3[-1]
-       add ucitrack mwan3
-       set ucitrack.@mwan3[-1].exec="/etc/init.d/mwan3 restart"
-       commit ucitrack
-EOF
-
-# make controller file addition take effect without system restart
-rm -rf /tmp/luci-indexcache /tmp/luci-modulecache
-
-exit 0
diff --git a/net/mwan3-luci/files/etc/uci-defaults/mwan3-luci b/net/mwan3-luci/files/etc/uci-defaults/mwan3-luci
new file mode 100755 (executable)
index 0000000..2b74d63
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+# replace existing mwan3-luci ucitrack entry
+uci -q batch <<-EOF >/dev/null
+       del ucitrack.@mwan3[-1]
+       add ucitrack mwan3
+       set ucitrack.@mwan3[-1].exec="/usr/sbin/mwan3 restart"
+       commit ucitrack
+EOF
+
+# remove LuCI cache
+rm -rf /tmp/luci-indexcache /tmp/luci-modulecache
+
+exit 0
index 13ff0902e118f37d2c72e1e68361a0ab395a21de..33dbcf44a1f7f82652a696696956ab825566f930 100644 (file)
@@ -168,7 +168,7 @@ function mwan3_diag_data(iface, tool, alt)
                local ifdev = ut.trim(sys.exec("uci get -p /var/state network." .. iface .. ".ifname"))
                if ifdev ~= "" then
                        if tool == "ping" then
-                               local gateway = ut.trim(sys.exec("route -n | awk -F' ' '{ if ($8 == \"" .. ifdev .. "\" && $1 == \"0.0.0.0\") print $2 }'"))
+                               local gateway = ut.trim(sys.exec("route -n | awk '{ if ($8 == \"" .. ifdev .. "\" && $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
@@ -247,17 +247,17 @@ function mwan3_tshoot_data()
                else
                        lucirelease = "\nLuCI - unknown"
                end
-       local mwan3version = ut.trim(sys.exec("opkg info mwan3 | grep Version | awk -F' ' '{ print $2 }'"))
+       local mwan3version = ut.trim(sys.exec("opkg info mwan3 | grep Version | awk '{ print $2 }'"))
                if mwan3version ~= "" then
                        mwan3version = "\n\nmwan3 - " .. mwan3version
                else
                        mwan3version = "\nmwan3 - unknown"
                end
-       local mwan3lversion = ut.trim(sys.exec("opkg info luci-app-mwan3 | grep Version | awk -F' ' '{ print $2 }'"))
+       local mwan3lversion = ut.trim(sys.exec("opkg info luci-app-mwan3 | grep Version | awk '{ print $2 }'"))
                if mwan3lversion ~= "" then
-                       mwan3lversion = "\nluci-app-mwan3 - " .. mwan3lversion
+                       mwan3lversion = "\nmwan3-luci - " .. mwan3lversion
                else
-                       mwan3lversion = "\nluci-app-mwan3 - unknown"
+                       mwan3lversion = "\nmwan3-luci - unknown"
                end
        local softrev = wrtrelease .. lucirelease .. mwan3version .. mwan3lversion
        rv.mw3ver = { }
@@ -316,7 +316,7 @@ function mwan3_tshoot_data()
        rv.iprule[ipruleid[ipr]] = { rule = ipr }
 
        -- ip route list table 1-250
-       local routelisting, rlstr = ut.trim(sys.exec("ip rule | sed 's/://g' | awk -F' ' '$1>=2001 && $1<=2250' | awk -F' ' '{ print $NF }'")), ""
+       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)
index 3d504a24f88fdf6708d3051554a5a6f2b7b3a273..101bcea9db5fcdea8c37219c860bde6a19fe1c27 100644 (file)
@@ -30,7 +30,7 @@ function iface_check() -- find issues with too many interfaces, reliability and
                                        err_netcfg_list = err_netcfg_list .. ifname .. " "
                                        err_route_list = err_route_list .. ifname .. " "
                                else
-                                       local rtcheck = ut.trim(sys.exec("route -n | awk -F' ' '{ if ($8 == \"" .. ifdev .. "\" && $1 == \"0.0.0.0\") print $1 }'"))
+                                       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 .. " "
@@ -44,12 +44,12 @@ function iface_check() -- find issues with too many interfaces, reliability and
                end
        )
        -- check if any interfaces have duplicate metrics
-       local metric_dupnums = sys.exec("echo '" .. metric_list .. "' | awk -F' ' '{ print $2 }' | uniq -d")
+       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 -F' ' '{ print $1 }'")
+                       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' ' '")
index 2119c048ba6163c00cbc3cb87d828de5fb0d9f7c..3da1e534914939ee5616304a290653160f5bd504 100644 (file)
@@ -12,9 +12,9 @@ function iface_check()
                        end
                )
                -- compare metric against list
-               local metric_dupnums, metric_dupes = sys.exec("echo '" .. metric_list .. "' | awk -F' ' '{ print $2 }' | uniq -d"), ""
+               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 -F' ' '{ print $1 }'")
+                       metric_dupes = sys.exec("echo '" .. metric_list .. "' | grep '" .. line .. "' | awk '{ print $1 }'")
                        err_dupmet_list = err_dupmet_list .. metric_dupes
                end
                if sys.exec("echo '" .. err_dupmet_list .. "' | grep -w " .. arg[1]) ~= "" then
@@ -36,7 +36,7 @@ function iface_check()
                        err_netcfg = 1
                        err_route = 1
                else
-                       local rtcheck = ut.trim(sys.exec("route -n | awk -F' ' '{ if ($8 == \"" .. ifdev .. "\" && $1 == \"0.0.0.0\") print $1 }'"))
+                       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
                        end
index 02471b9927a6c5aba3d3652a43e0c24113b0b280..ef09451fbd8212b43eb084fbce67c6f7d56491f1 100644 (file)
@@ -68,6 +68,19 @@ use_member = mwan_policy:option(DummyValue, "use_member", translate("Members ass
                
        end
 
+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 == "unreachable" or str == "" or str == null then
+                       return "unreachable (reject)"
+               elseif str == "blackhole" then
+                       return "blackhole (drop)"
+               elseif str == "main" then
+                       return "main (use main routing table)"
+               end
+       end
+
 errors = mwan_policy:option(DummyValue, "errors", translate("Errors"))
        errors.rawhtml = true
        function errors.cfgvalue(self, s)
index a6523ad8e18f52494243c59087526aad61f3a51a..dfd7253378834f91b7b58f327965303893b3c128 100644 (file)
@@ -45,6 +45,13 @@ mwan_policy = m5:section(NamedSection, arg[1], "policy", "")
 use_member = mwan_policy:option(DynamicList, "use_member", translate("Member used"))
        cbi_add_member(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"))
+       last_resort.default = "unreachable"
+       last_resort:value("unreachable", translate("unreachable (reject)"))
+       last_resort:value("blackhole", translate("blackhole (drop)"))
+       last_resort:value("main", translate("main (use main routing table)"))
+
 
 -- ------ currently configured members ------ --
 
index e83fa629fc1256247b8ec48fbaa6a085df45e68a..21a01b86388c880e3c07058ef21ff2782fc5f794 100644 (file)
@@ -28,7 +28,7 @@ function cbi_add_policy(field)
 end
 
 function cbi_add_protocol(field)
-       local protos = ut.trim(sys.exec("cat /etc/protocols | grep '    # ' | awk -F' ' '{print $1}' | grep -vw -e 'ip' -e 'tcp' -e 'udp' -e 'icmp' -e 'esp' | grep -v 'ipv6' | sort | tr '\n' ' '"))
+       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
                field:value(p)
        end
index 6d9abcbed09ddc8b1c71b6ec83e8dbed78004a5e..f0ceb1261a80e2696dea17c1db0bd6cac3214b73 100644 (file)
                                {
                                        var temp = '';
                                        var ncint = 'No diagnostic results returned';
-                                       temp = String.format(
-                                               '<pre id="diag_output_css"><strong>%s</strong></pre>',
-                                                       ncint
-                                       );
+                                       temp = String.format('<pre id="diag_output_css"><strong>%s</strong></pre>', ncint);
                                        output.innerHTML = temp;
                                }
                        }
index 1a92ebd02f2dd57411af17c3ca21d9b319c5d5ca..7a27d66194afd95b8eb87f2ff6f313aaa5249556 100644 (file)
@@ -29,7 +29,7 @@
 
                                temp = String.format(
                                        '<pre><span class="tsht">%s</span>%s<span class="tsht">%s</span>%s<span class="tsht">%s</span>%s<span class="tsht">%s</span>%s<span class="tsht">%s</span>%s<span class="tsht">%s</span>%s<span class="tsht">%s</span>%s<span class="tsht">%s</span>%s<span class="tsht">%s</span>%s</pre>',
-                                               mwanvers, st.mw3ver[0].mwan3v, mwan3cnfg, st.mwan3config[0].mwn3cfg, netcnfg, st.netconfig[0].netcfg, ifcnfg, st.ifconfig[0].ifcfg, iproute, st.rtshow[0].iprtshow, iprulesh, st.iprule[0].rule, routelisttbl, st.routelist[0].iprtlist, firewalldef, st.fidef[0].firedef, iptable, st.iptables[0].iptbls
+                                       mwanvers, st.mw3ver[0].mwan3v, mwan3cnfg, st.mwan3config[0].mwn3cfg, netcnfg, st.netconfig[0].netcfg, ifcnfg, st.ifconfig[0].ifcfg, iproute, st.rtshow[0].iprtshow, iprulesh, st.iprule[0].rule, routelisttbl, st.routelist[0].iprtlist, firewalldef, st.fidef[0].firedef, iptable, st.iptables[0].iptbls
                                );
                                tx.innerHTML = temp;
                        }
                        {
                                var temp = '';
                                var terror = 'Error collecting troubleshooting information';
-                               temp = String.format(
-                                       '<strong>%s</strong>',
-                                               terror
-                               );
+                               temp = String.format('<strong>%s</strong>', terror);
                                tx.innerHTML = temp;
                        }
                }
@@ -53,6 +50,7 @@
                <div id="mwan3_tshoot_text"><img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> Collecting data...</div>
        </fieldset>
 </div>
+
 <style type="text/css">
   .container {  /*container for entire page. fixes bootstrap theme's ridiculously small page width*/
        max-width: none;
index 920a20bda812a0048790ce77d38bc9ae65d9f542..1d204467d58db1c3c22193f6c5293becef23a1a1 100644 (file)
                        if (st.mwan3dst)
                        {
                                var temp = '';
-                               temp = String.format(
-                                       '<pre>%s</pre>',
-                                               st.mwan3dst[0].detailstat
-                               );
+                               temp = String.format('<pre>%s</pre>', st.mwan3dst[0].detailstat);
                                tx.innerHTML = temp;
                        }
                        else
                        {
                                var temp = '';
                                var nslg = 'No detailed status information available';
-                               temp = String.format(
-                                       '<strong>%s</strong>',
-                                               nslg
-                               );
+                               temp = String.format('<strong>%s</strong>', nslg);
                                tx.innerHTML = temp;
                        }
                }
index 2e846a71e386583125f38bb41c2ac4b804bbc6d9..06129d92f0eebf017e2982d32ba6401c868a7b96 100644 (file)
@@ -45,7 +45,7 @@
 
                                        temp += String.format(
                                                '<span class="%s"><strong>%s (<a href="%q">%s</a>)</strong><br />%s</span>',
-                                                       cssc, st.wans[i].name, st.wans[i].link, st.wans[i].ifname, stat
+                                               cssc, st.wans[i].name, st.wans[i].link, st.wans[i].ifname, stat
                                        );
                                }
                                tx.innerHTML = temp;
                        {
                                var temp = '';
                                var ncint = 'No MWAN3 interfaces found';
-                               temp = String.format(
-                                       '<strong>%s</strong>',
-                                               ncint
-                               );
+                               temp = String.format('<strong>%s</strong>', ncint);
                                tx.innerHTML = temp;
                        }
 
                        {
                                var temp = '';
                                var mwan3lg = 'Last 50 MWAN3 systemlog entries. Newest entries sorted at the top :';
-
-                               temp = String.format(
-                                       '<pre>%s<br /><br />%s</pre>',
-                                               mwan3lg, st.mwan3log[0].mwanlog
-                               );
+                               temp = String.format('<pre>%s<br /><br />%s</pre>', mwan3lg, st.mwan3log[0].mwanlog);
                                tx.innerHTML = temp;
                        }
                        else
                        {
                                var temp = '';
                                var nslg = 'No MWAN3 systemlog history found';
-                               temp = String.format(
-                                       '<strong>%s</strong>',
-                                               nslg
-                               );
+                               temp = String.format('<strong>%s</strong>', nslg);
                                tx.innerHTML = temp;
                        }
                }
index 9315a850ca2ca33890076007f8d85604a6c5d6c9..4cd3899564585a37316b2e80177a9ad4678add86 100644 (file)
@@ -37,7 +37,7 @@
 
                                        temp += String.format(
                                                '<span class="%s"><strong>%s (<a href="%q">%s</a>)</strong><br />%s</span>',
-                                                       cssc, st.wans[i].name, st.wans[i].link, st.wans[i].ifname, stat
+                                               cssc, st.wans[i].name, st.wans[i].link, st.wans[i].ifname, stat
                                        );
                                }
                                tx.innerHTML = temp;
                        {
                                var temp = '';
                                var ncint = 'No MWAN3 interfaces found';
-                               temp += String.format(
-                                       '<strong>%s</strong>',
-                                               ncint
-                               );
+                               temp += String.format('<strong>%s</strong>', ncint );
                                tx.innerHTML = temp;
                        }
                }