4ff9f116734138ed804cfdb1a886319dfc2cd861
[project/luci.git] / applications / luci-app-mwan3 / luasrc / model / cbi / mwan / ruleconfig.lua
1 dsp = require "luci.dispatcher"
2 sys = require "luci.sys"
3 ut = require "luci.util"
4 arg[1] = arg[1] or ""
5
6 function cbiAddPolicy(field)
7 uci.cursor():foreach("mwan3", "policy",
8 function (section)
9 field:value(section[".name"])
10 end
11 )
12 end
13
14 function cbiAddProtocol(field)
15 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' ' '"))
16 for p in string.gmatch(protocols, "%S+") do
17 field:value(p)
18 end
19 end
20
21 m5 = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1]))
22 m5.redirect = dsp.build_url("admin", "network", "mwan", "rule")
23
24
25 mwan_rule = m5:section(NamedSection, arg[1], "rule", "")
26 mwan_rule.addremove = false
27 mwan_rule.dynamic = false
28
29
30 src_ip = mwan_rule:option(Value, "src_ip", translate("Source address"),
31 translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes"))
32 src_ip.datatype = ipaddr
33
34 src_port = mwan_rule:option(Value, "src_port", translate("Source port"),
35 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"))
36
37 dest_ip = mwan_rule:option(Value, "dest_ip", translate("Destination address"),
38 translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes"))
39 dest_ip.datatype = ipaddr
40
41 dest_port = mwan_rule:option(Value, "dest_port", translate("Destination port"),
42 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"))
43
44 proto = mwan_rule:option(Value, "proto", translate("Protocol"),
45 translate("View the contents of /etc/protocols for protocol descriptions"))
46 proto.default = "all"
47 proto.rmempty = false
48 proto:value("all")
49 proto:value("ip")
50 proto:value("tcp")
51 proto:value("udp")
52 proto:value("icmp")
53 proto:value("esp")
54 cbiAddProtocol(proto)
55
56 sticky = mwan_rule:option(ListValue, "sticky", translate("Sticky"),
57 translate("Traffic from the same source IP address that previously matched this rule within the sticky timeout period will use the same WAN interface"))
58 sticky.default = "0"
59 sticky:value("1", translate("Yes"))
60 sticky:value("0", translate("No"))
61
62 timeout = mwan_rule:option(Value, "timeout", translate("Sticky timeout"),
63 translate("Seconds. Acceptable values: 1-1000000. Defaults to 600 if not set"))
64 timeout.datatype = "range(1, 1000000)"
65
66 ipset = mwan_rule:option(Value, "ipset", translate("IPset"),
67 translate("Name of IPset rule. Requires IPset rule in /etc/dnsmasq.conf (eg \"ipset=/youtube.com/youtube\")"))
68
69 use_policy = mwan_rule:option(Value, "use_policy", translate("Policy assigned"))
70 cbiAddPolicy(use_policy)
71 use_policy:value("unreachable", translate("unreachable (reject)"))
72 use_policy:value("blackhole", translate("blackhole (drop)"))
73 use_policy:value("default", translate("default (use main routing table)"))
74
75 return m5