X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;ds=sidebyside;f=applications%2Fluci-app-mwan3%2Fluasrc%2Fmodel%2Fcbi%2Fmwan%2Fruleconfig.lua;h=e12639e33dd2169acd52804200a063f7460ebf39;hb=831bd71eb387973a25277e3fa7391c6a4af83597;hp=f7fb341e1f991dcd0772d3169f150402123cc2a5;hpb=c69622e5afb31490044e975c760daf81debd390e;p=project%2Fluci.git diff --git a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua index f7fb341e1..e12639e33 100644 --- a/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua +++ b/applications/luci-app-mwan3/luasrc/model/cbi/mwan/ruleconfig.lua @@ -1,54 +1,9 @@ --- ------ extra functions ------ -- - -function ruleCheck() -- determine if rule needs a protocol specified - local sourcePort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. arg[1] .. ".src_port")) - local destPort = ut.trim(sys.exec("uci -p /var/state get mwan3." .. arg[1] .. ".dest_port")) - if sourcePort ~= "" or destPort ~= "" then -- ports configured - local protocol = ut.trim(sys.exec("uci -p /var/state get mwan3." .. arg[1] .. ".proto")) - if protocol == "" or protocol == "all" then -- no or improper protocol - error_protocol = 1 - end - end -end - -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 cbiAddPolicy(field) - uci.cursor():foreach("mwan3", "policy", - function (section) - field:value(section[".name"]) - end - ) -end - -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 - --- ------ rule configuration ------ -- - dsp = require "luci.dispatcher" -sys = require "luci.sys" -ut = require "luci.util" arg[1] = arg[1] or "" -error_protocol = 0 -ruleCheck() - - -m5 = Map("mwan3", translate("MWAN Rule Configuration - ") .. arg[1], - translate(ruleWarn())) - m5.redirect = dsp.build_url("admin", "network", "mwan", "configuration", "rule") +m5 = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1])) +m5.redirect = dsp.build_url("admin", "network", "mwan", "rule") mwan_rule = m5:section(NamedSection, arg[1], "rule", "") mwan_rule.addremove = false @@ -70,16 +25,14 @@ dest_port = mwan_rule:option(Value, "dest_port", translate("Destination port"), translate("May be entered as a single or multiple port(s) (eg \"22\" or \"80,443\") or as a portrange (eg \"1024:2048\") without quotes")) proto = mwan_rule:option(Value, "proto", translate("Protocol"), - translate("View the contents of /etc/protocols for protocol descriptions")) + translate("View the content of /etc/protocols for protocol description")) proto.default = "all" proto.rmempty = false proto:value("all") - proto:value("ip") proto:value("tcp") proto:value("udp") proto:value("icmp") proto:value("esp") - cbiAddProtocol(proto) sticky = mwan_rule:option(ListValue, "sticky", translate("Sticky"), translate("Traffic from the same source IP address that previously matched this rule within the sticky timeout period will use the same WAN interface")) @@ -94,20 +47,14 @@ timeout = mwan_rule:option(Value, "timeout", translate("Sticky timeout"), ipset = mwan_rule:option(Value, "ipset", translate("IPset"), translate("Name of IPset rule. Requires IPset rule in /etc/dnsmasq.conf (eg \"ipset=/youtube.com/youtube\")")) -use_policy = mwan_rule:option(Value, "use_policy", translate("Policy assigned")) - 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)")) - - --- ------ currently configured policies ------ -- - -mwan_policy = m5:section(TypedSection, "policy", translate("Currently Configured Policies")) - mwan_policy.addremove = false - mwan_policy.dynamic = false - mwan_policy.sortable = false - mwan_policy.template = "cbi/tblsection" - +policy = mwan_rule:option(Value, "use_policy", translate("Policy assigned")) +m5.uci:foreach("mwan3", "policy", + function(s) + policy:value(s['.name'], s['.name']) + end +) +policy:value("unreachable", translate("unreachable (reject)")) +policy:value("blackhole", translate("blackhole (drop)")) +policy:value("default", translate("default (use main routing table)")) return m5