X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=applications%2Fluci-app-mwan3%2Fluasrc%2Fmodel%2Fcbi%2Fmwan%2Frule.lua;h=5c6329e3397d66a5231d8a1dbeb64b83710ec30a;hp=412f369eb06f6cec831d7d0a3680dd5687c26ca2;hb=831bd71eb387973a25277e3fa7391c6a4af83597;hpb=7f256e257c98a6e81dca448532acb4d6d0cf9d1d diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua index 412f369eb..5c6329e33 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/rule.lua @@ -1,60 +1,63 @@ --- ------ extra functions ------ -- +dsp = require "luci.dispatcher" + -function ruleCheck() -- determine if rules needs a proper protocol configured +function ruleCheck() + local rule_error = {} uci.cursor():foreach("mwan3", "rule", function (section) - local sourcePort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. section[".name"] .. ".src_port")) - local destPort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. section[".name"] .. ".dest_port")) - if sourcePort ~= "" or destPort ~= "" then -- ports configured - local protocol = ut.trim(sys.exec("uci -p /var/state get mwan3." .. section[".name"] .. ".proto")) - if protocol == "" or protocol == "all" then -- no or improper protocol - error_protocol_list = error_protocol_list .. section[".name"] .. " " + rule_error[section[".name"]] = false + local uci = uci.cursor(nil, "/var/state") + local sourcePort = uci:get("mwan3", section[".name"], "src_port") + local destPort = uci:get("mwan3", section[".name"], "dest_port") + if sourcePort ~= nil or destPort ~= nil then + local protocol = uci:get("mwan3", section[".name"], "proto") + if protocol == nil or protocol == "all" then + rule_error[section[".name"]] = true end end end ) + return rule_error end -function ruleWarn() -- display warning messages at the top of the page - if error_protocol_list ~= " " then - return "" .. translate("WARNING: some rules have a port configured with no or improper protocol specified! Please configure a specific protocol!") .. "" - else - return "" +function ruleWarn(rule_error) + local warnings = "" + for i, k in pairs(rule_error) do + if rule_error[i] == true then + warnings = warnings .. string.format("%s
", + translatef("WARNING: Rule %s have a port configured with no or improper protocol specified!", i) + ) + end end -end - --- ------ rule configuration ------ -- - -dsp = require "luci.dispatcher" -sys = require "luci.sys" -ut = require "luci.util" - -error_protocol_list = " " -ruleCheck() - -m5 = Map("mwan3", translate("MWAN Rule Configuration"), - ruleWarn()) - m5:append(Template("mwan/config_css")) + return warnings +end +m5 = Map("mwan3", translate("MWAN - Rules"), + ruleWarn(ruleCheck()) + ) -mwan_rule = m5:section(TypedSection, "rule", translate("Traffic Rules"), - 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
" .. +mwan_rule = m5:section(TypedSection, "rule", nil, + translate("Rules specify which traffic will use a particular MWAN policy
" .. + "Rules are 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
" .. "Rules may not share the same name as configured interfaces, members or policies")) mwan_rule.addremove = true mwan_rule.anonymous = false mwan_rule.dynamic = false - mwan_rule.sectionhead = "Rule" + mwan_rule.sectionhead = translate("Rule") mwan_rule.sortable = true mwan_rule.template = "cbi/tblsection" - mwan_rule.extedit = dsp.build_url("admin", "network", "mwan", "configuration", "rule", "%s") + mwan_rule.extedit = dsp.build_url("admin", "network", "mwan", "rule", "%s") function mwan_rule.create(self, section) TypedSection.create(self, section) m5.uci:save("mwan3") - luci.http.redirect(dsp.build_url("admin", "network", "mwan", "configuration", "rule", section)) + luci.http.redirect(dsp.build_url("admin", "network", "mwan", "rule", section)) end @@ -88,54 +91,10 @@ proto = mwan_rule:option(DummyValue, "proto", translate("Protocol")) return self.map:get(s, "proto") or "all" end -sticky = mwan_rule:option(DummyValue, "sticky", translate("Sticky")) - sticky.rawhtml = true - function sticky.cfgvalue(self, s) - if self.map:get(s, "sticky") == "1" then - stickied = 1 - return "Yes" - else - stickied = nil - return "No" - end - end - -timeout = mwan_rule:option(DummyValue, "timeout", translate("Sticky timeout")) - timeout.rawhtml = true - function timeout.cfgvalue(self, s) - if stickied then - local timeoutValue = self.map:get(s, "timeout") - if timeoutValue then - return timeoutValue .. "s" - else - return "600s" - end - else - return "—" - end - end - -ipset = mwan_rule:option(DummyValue, "ipset", translate("IPset")) - ipset.rawhtml = true - function ipset.cfgvalue(self, s) - return self.map:get(s, "ipset") or "—" - end - use_policy = mwan_rule:option(DummyValue, "use_policy", translate("Policy assigned")) use_policy.rawhtml = true function use_policy.cfgvalue(self, s) return self.map:get(s, "use_policy") or "—" end -errors = mwan_rule:option(DummyValue, "errors", translate("Errors")) - errors.rawhtml = true - function errors.cfgvalue(self, s) - if not string.find(error_protocol_list, " " .. s .. " ") then - return "" - else - return "\"error\"" - end - end - - return m5