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.
5 local dsp = require "luci.dispatcher"
6 local util = require("luci.util")
8 local m, mwan_rule, src_ip, src_port, dest_ip, dest_port, proto, sticky
9 local timeout, ipset, logging, policy
13 local ipsets = util.split(util.trim(util.exec("ipset -n -L 2>/dev/null | grep -v mwan3_ | sort")), "\n", nil, true) or {}
15 m = Map("mwan3", translatef("MWAN Rule Configuration - %s", arg[1]))
16 m.redirect = dsp.build_url("admin", "network", "mwan", "rule")
18 mwan_rule = m:section(NamedSection, arg[1], "rule", "")
19 mwan_rule.addremove = false
20 mwan_rule.dynamic = false
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
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"))
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
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"))
36 proto = mwan_rule:option(Value, "proto", translate("Protocol"),
37 translate("View the content of /etc/protocols for protocol description"))
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"))
49 sticky:value("1", translate("Yes"))
50 sticky:value("0", translate("No"))
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)"
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
62 logging = mwan_rule:option(Flag, "logging", translate("Logging"),
63 translate("Enables firewall rule logging (global mwan3 logging must also be enabled)"))
65 policy = mwan_rule:option(Value, "use_policy", translate("Policy assigned"))
66 m.uci:foreach("mwan3", "policy",
68 policy:value(s['.name'], s['.name'])
71 policy:value("unreachable", translate("unreachable (reject)"))
72 policy:value("blackhole", translate("blackhole (drop)"))
73 policy:value("default", translate("default (use main routing table)"))