2018-01-23 12:12:53 +00:00
-- Copyright 2014 Aedan Renner <chipdankly@gmail.com>
-- Copyright 2018 Florian Eckert <fe@dev.tdt.de>
-- Licensed to the public under the GNU General Public License v2.
2019-01-17 10:12:52 +00:00
local dsp = require " luci.dispatcher "
2019-01-16 13:25:38 +00:00
local util = require ( " luci.util " )
2019-01-17 10:12:52 +00:00
local m , mwan_rule , src_ip , src_port , dest_ip , dest_port , proto , sticky
2019-01-08 14:45:44 +00:00
local timeout , ipset , logging , policy
2017-02-17 10:22:01 +00:00
2019-01-17 10:12:52 +00:00
arg [ 1 ] = arg [ 1 ] or " "
2018-01-18 06:26:27 +00:00
2019-01-16 13:25:38 +00:00
local ipsets = util.split ( util.trim ( util.exec ( " ipset -n -L 2>/dev/null | grep -v mwan3_ | sort " ) ) , " \n " , nil , true ) or { }
2019-01-17 10:12:52 +00:00
m = Map ( " mwan3 " , translatef ( " MWAN Rule Configuration - %s " , arg [ 1 ] ) )
m.redirect = dsp.build_url ( " admin " , " network " , " mwan " , " rule " )
2017-02-17 10:22:01 +00:00
2019-01-17 10:12:52 +00:00
mwan_rule = m : section ( NamedSection , arg [ 1 ] , " rule " , " " )
2018-01-18 06:41:41 +00:00
mwan_rule.addremove = false
mwan_rule.dynamic = false
2017-02-17 10:22:01 +00:00
src_ip = mwan_rule : option ( Value , " src_ip " , translate ( " Source address " ) ,
translate ( " Supports CIDR notation (eg \" 192.168.100.0/24 \" ) without quotes " ) )
2018-01-18 06:41:41 +00:00
src_ip.datatype = ipaddr
2017-02-17 10:22:01 +00:00
src_port = mwan_rule : option ( Value , " src_port " , translate ( " Source port " ) ,
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 " ) )
dest_ip = mwan_rule : option ( Value , " dest_ip " , translate ( " Destination address " ) ,
translate ( " Supports CIDR notation (eg \" 192.168.100.0/24 \" ) without quotes " ) )
2018-01-18 06:41:41 +00:00
dest_ip.datatype = ipaddr
2017-02-17 10:22:01 +00:00
dest_port = mwan_rule : option ( Value , " dest_port " , translate ( " Destination port " ) ,
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 " ) )
proto = mwan_rule : option ( Value , " proto " , translate ( " Protocol " ) ,
2018-01-17 15:27:09 +00:00
translate ( " View the content of /etc/protocols for protocol description " ) )
2018-01-18 06:41:41 +00:00
proto.default = " all "
proto.rmempty = false
proto : value ( " all " )
proto : value ( " tcp " )
proto : value ( " udp " )
proto : value ( " icmp " )
proto : value ( " esp " )
2017-02-17 10:22:01 +00:00
sticky = mwan_rule : option ( ListValue , " sticky " , translate ( " Sticky " ) ,
translate ( " Traffic from the same source IP address that previously matched this rule within the sticky timeout period will use the same WAN interface " ) )
2018-01-18 06:41:41 +00:00
sticky.default = " 0 "
sticky : value ( " 1 " , translate ( " Yes " ) )
sticky : value ( " 0 " , translate ( " No " ) )
2017-02-17 10:22:01 +00:00
timeout = mwan_rule : option ( Value , " timeout " , translate ( " Sticky timeout " ) ,
translate ( " Seconds. Acceptable values: 1-1000000. Defaults to 600 if not set " ) )
2018-01-18 06:41:41 +00:00
timeout.datatype = " range(1, 1000000) "
2017-02-17 10:22:01 +00:00
ipset = mwan_rule : option ( Value , " ipset " , translate ( " IPset " ) ,
translate ( " Name of IPset rule. Requires IPset rule in /etc/dnsmasq.conf (eg \" ipset=/youtube.com/youtube \" ) " ) )
2019-01-31 10:03:27 +00:00
ipset : value ( " " , translate ( " -- Please choose -- " ) )
2019-01-16 13:25:38 +00:00
for _ , z in ipairs ( ipsets ) do
ipset : value ( z )
end
2017-02-17 10:22:01 +00:00
2019-01-08 14:45:44 +00:00
logging = mwan_rule : option ( Flag , " logging " , translate ( " Logging " ) ,
translate ( " Enables firewall rule logging (global mwan3 logging must also be enabled) " ) )
2018-01-17 15:27:09 +00:00
policy = mwan_rule : option ( Value , " use_policy " , translate ( " Policy assigned " ) )
2019-01-17 10:12:52 +00:00
m.uci : foreach ( " mwan3 " , " policy " ,
2018-01-17 15:27:09 +00:00
function ( s )
policy : value ( s [ ' .name ' ] , s [ ' .name ' ] )
end
)
policy : value ( " unreachable " , translate ( " unreachable (reject) " ) )
policy : value ( " blackhole " , translate ( " blackhole (drop) " ) )
policy : value ( " default " , translate ( " default (use main routing table) " ) )
2017-02-17 10:22:01 +00:00
2019-01-17 10:12:52 +00:00
return m