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