luci-app-ddns: fix next_update error
[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(ListValue, "family", translate("Internet Protocol"))
22 o.default = ""
23 o:value("", translate("IPv4 and IPv6"))
24 o:value("ipv4", translate("IPv4 only"))
25 o:value("ipv6", translate("IPv6 only"))
26
27 o = s:option(Value, "src_ip", translate("Source address"),
28 translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes"))
29 o.datatype = ipaddr
30
31 o = s:option(Value, "src_port", translate("Source port"),
32 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"))
33 o:depends("proto", "tcp")
34 o:depends("proto", "udp")
35
36 o = s:option(Value, "dest_ip", translate("Destination address"),
37 translate("Supports CIDR notation (eg \"192.168.100.0/24\") without quotes"))
38 o.datatype = ipaddr
39
40 o = s:option(Value, "dest_port", translate("Destination port"),
41 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"))
42 o:depends("proto", "tcp")
43 o:depends("proto", "udp")
44
45 o = s:option(Value, "proto", translate("Protocol"),
46 translate("View the content of /etc/protocols for protocol description"))
47 o.default = "all"
48 o.rmempty = false
49 o:value("all")
50 o:value("tcp")
51 o:value("udp")
52 o:value("icmp")
53 o:value("esp")
54
55 o = s:option(ListValue, "sticky", translate("Sticky"),
56 translate("Traffic from the same source IP address that previously matched this rule within the sticky timeout period will use the same WAN interface"))
57 o.default = "0"
58 o:value("1", translate("Yes"))
59 o:value("0", translate("No"))
60
61 o = s:option(Value, "timeout", translate("Sticky timeout"),
62 translate("Seconds. Acceptable values: 1-1000000. Defaults to 600 if not set"))
63 o.datatype = "range(1, 1000000)"
64
65 o = s:option(Value, "ipset", translate("IPset"),
66 translate("Name of IPset rule. Requires IPset rule in /etc/dnsmasq.conf (eg \"ipset=/youtube.com/youtube\")"))
67 o:value("", translate("-- Please choose --"))
68 for _, z in ipairs(ipsets) do
69 o:value(z)
70 end
71
72 o = s:option(Flag, "logging", translate("Logging"),
73 translate("Enables firewall rule logging (global mwan3 logging must also be enabled)"))
74
75 o = s:option(Value, "use_policy", translate("Policy assigned"))
76 m.uci:foreach("mwan3", "policy",
77 function(s)
78 o:value(s['.name'], s['.name'])
79 end
80 )
81 o:value("unreachable", translate("unreachable (reject)"))
82 o:value("blackhole", translate("blackhole (drop)"))
83 o:value("default", translate("default (use main routing table)"))
84
85 return m