Merge pull request #2462 from cshoredaniel/luci-rad2-pass-go-fix
[project/luci.git] / applications / luci-app-mwan3 / luasrc / model / cbi / mwan / ruleconfig.lua
1 -- Copyright 2014 Aedan Renner <chipdankly@gmail.com>
2 -- Copyright 2018 Florian Eckert <fe@dev.tdt.de>
3 -- Licensed to the public under the GNU General Public License v2.
4
5 local dsp = require "luci.dispatcher"
6 local util = require("luci.util")
7
8 local m, mwan_rule, src_ip, src_port, dest_ip, dest_port, proto, sticky
9 local timeout, ipset, logging, policy
10
11 arg[1] = arg[1] or ""
12
13 local ipsets = util.split(util.trim(util.exec("ipset -n -L 2>/dev/null | grep -v mwan3_ | sort")), "\n", nil, true) or {}
14
15 m = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1]))
16 m.redirect = dsp.build_url("admin", "network", "mwan", "rule")
17
18 mwan_rule = m:section(NamedSection, arg[1], "rule", "")
19 mwan_rule.addremove = false
20 mwan_rule.dynamic = false
21
22 src_ip = mwan_rule:option(Value, "src_ip", translate("Source address"),
23 translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes"))
24 src_ip.datatype = ipaddr
25
26 src_port = mwan_rule:option(Value, "src_port", translate("Source port"),
27 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"))
28
29 dest_ip = mwan_rule:option(Value, "dest_ip", translate("Destination address"),
30 translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes"))
31 dest_ip.datatype = ipaddr
32
33 dest_port = mwan_rule:option(Value, "dest_port", translate("Destination port"),
34 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"))
35
36 proto = mwan_rule:option(Value, "proto", translate("Protocol"),
37 translate("View the content of /etc/protocols for protocol description"))
38 proto.default = "all"
39 proto.rmempty = false
40 proto:value("all")
41 proto:value("tcp")
42 proto:value("udp")
43 proto:value("icmp")
44 proto:value("esp")
45
46 sticky = mwan_rule:option(ListValue, "sticky", translate("Sticky"),
47 translate("Traffic from the same source IP address that previously matched this rule within the sticky timeout period will use the same WAN interface"))
48 sticky.default = "0"
49 sticky:value("1", translate("Yes"))
50 sticky:value("0", translate("No"))
51
52 timeout = mwan_rule:option(Value, "timeout", translate("Sticky timeout"),
53 translate("Seconds. Acceptable values: 1-1000000. Defaults to 600 if not set"))
54 timeout.datatype = "range(1, 1000000)"
55
56 ipset = mwan_rule:option(Value, "ipset", translate("IPset"),
57 translate("Name of IPset rule. Requires IPset rule in /etc/dnsmasq.conf (eg \"ipset=/youtube.com/youtube\")"))
58 for _, z in ipairs(ipsets) do
59 ipset:value(z)
60 end
61
62 logging = mwan_rule:option(Flag, "logging", translate("Logging"),
63 translate("Enables firewall rule logging (global mwan3 logging must also be enabled)"))
64
65 policy = mwan_rule:option(Value, "use_policy", translate("Policy assigned"))
66 m.uci:foreach("mwan3", "policy",
67 function(s)
68 policy:value(s['.name'], s['.name'])
69 end
70 )
71 policy:value("unreachable", translate("unreachable (reject)"))
72 policy:value("blackhole", translate("blackhole (drop)"))
73 policy:value("default", translate("default (use main routing table)"))
74
75 return m