2008-08-04 23:36:33 +00:00
|
|
|
--[[
|
|
|
|
LuCI - Lua Configuration Interface
|
|
|
|
|
|
|
|
Copyright 2008 Steven Barth <steven@midlink.org>
|
2010-11-01 19:45:54 +00:00
|
|
|
Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
|
2008-08-04 23:36:33 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
]]--
|
2010-11-01 19:45:54 +00:00
|
|
|
|
|
|
|
local sys = require "luci.sys"
|
|
|
|
local dsp = require "luci.dispatcher"
|
|
|
|
|
2008-10-03 16:04:09 +00:00
|
|
|
arg[1] = arg[1] or ""
|
2008-08-04 23:36:33 +00:00
|
|
|
|
2010-04-05 01:16:25 +00:00
|
|
|
m = Map("firewall", translate("Traffic Redirection"),
|
|
|
|
translate("Traffic redirection allows you to change the " ..
|
|
|
|
"destination address of forwarded packets."))
|
2008-08-04 23:36:33 +00:00
|
|
|
|
2010-11-01 19:45:54 +00:00
|
|
|
m.redirect = dsp.build_url("admin", "network", "firewall")
|
|
|
|
|
|
|
|
if not m.uci:get(arg[1]) == "redirect" then
|
|
|
|
luci.http.redirect(m.redirect)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local has_v2 = nixio.fs.access("/lib/firewall/fw.sh")
|
|
|
|
local wan_zone = nil
|
|
|
|
|
|
|
|
m.uci:foreach("firewall", "zone",
|
|
|
|
function(s)
|
|
|
|
local n = s.network or s.name
|
|
|
|
if n then
|
|
|
|
local i
|
|
|
|
for i in n:gmatch("%S+") do
|
|
|
|
if i == "wan" then
|
|
|
|
wan_zone = s.name
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
2008-10-03 16:04:09 +00:00
|
|
|
|
|
|
|
s = m:section(NamedSection, arg[1], "redirect", "")
|
2008-08-04 23:36:33 +00:00
|
|
|
s.anonymous = true
|
2008-10-04 17:56:02 +00:00
|
|
|
s.addremove = false
|
2008-08-04 23:36:33 +00:00
|
|
|
|
2010-11-01 19:45:54 +00:00
|
|
|
s:tab("general", translate("General Settings"))
|
|
|
|
s:tab("advanced", translate("Advanced Settings"))
|
|
|
|
|
|
|
|
name = s:taboption("general", Value, "_name", translate("Name"))
|
2008-08-04 23:36:33 +00:00
|
|
|
name.rmempty = true
|
|
|
|
name.size = 10
|
|
|
|
|
2010-11-01 19:45:54 +00:00
|
|
|
src = s:taboption("general", Value, "src", translate("Source zone"))
|
|
|
|
src.nocreate = true
|
|
|
|
src.default = "wan"
|
|
|
|
src.template = "cbi/firewall_zonelist"
|
2008-08-04 23:36:33 +00:00
|
|
|
|
2010-11-20 17:23:44 +00:00
|
|
|
proto = s:taboption("general", Value, "proto", translate("Protocol"))
|
2008-08-04 23:36:33 +00:00
|
|
|
proto.optional = true
|
2010-11-01 19:45:54 +00:00
|
|
|
proto:value("tcpudp", "TCP+UDP")
|
2008-08-04 23:36:33 +00:00
|
|
|
proto:value("tcp", "TCP")
|
|
|
|
proto:value("udp", "UDP")
|
|
|
|
|
2010-11-01 19:45:54 +00:00
|
|
|
dport = s:taboption("general", Value, "src_dport", translate("External port"),
|
2010-04-05 01:16:25 +00:00
|
|
|
translate("Match incoming traffic directed at the given " ..
|
|
|
|
"destination port or port range on this host"))
|
2010-11-01 19:45:54 +00:00
|
|
|
dport.datatype = "portrange"
|
2008-08-04 23:36:33 +00:00
|
|
|
dport:depends("proto", "tcp")
|
|
|
|
dport:depends("proto", "udp")
|
2008-09-02 11:27:00 +00:00
|
|
|
dport:depends("proto", "tcpudp")
|
2008-08-04 23:36:33 +00:00
|
|
|
|
2010-11-01 19:45:54 +00:00
|
|
|
to = s:taboption("general", Value, "dest_ip", translate("Internal IP address"),
|
2010-04-05 01:16:25 +00:00
|
|
|
translate("Redirect matched incoming traffic to the specified " ..
|
|
|
|
"internal host"))
|
2010-11-01 19:45:54 +00:00
|
|
|
to.datatype = "ip4addr"
|
2008-08-04 23:36:33 +00:00
|
|
|
for i, dataset in ipairs(luci.sys.net.arptable()) do
|
|
|
|
to:value(dataset["IP address"])
|
|
|
|
end
|
|
|
|
|
2010-11-01 19:45:54 +00:00
|
|
|
toport = s:taboption("general", Value, "dest_port", translate("Internal port (optional)"),
|
2010-04-05 01:16:25 +00:00
|
|
|
translate("Redirect matched incoming traffic to the given port on " ..
|
|
|
|
"the internal host"))
|
2008-08-04 23:36:33 +00:00
|
|
|
toport.optional = true
|
2010-11-07 20:01:56 +00:00
|
|
|
toport.placeholder = "0-65535"
|
2010-11-20 17:23:44 +00:00
|
|
|
toport.datatype = "portrange"
|
|
|
|
toport:depends("proto", "tcp")
|
|
|
|
toport:depends("proto", "udp")
|
|
|
|
toport:depends("proto", "tcpudp")
|
2010-11-01 19:45:54 +00:00
|
|
|
|
|
|
|
target = s:taboption("advanced", ListValue, "target", translate("Redirection type"))
|
|
|
|
target:value("DNAT")
|
|
|
|
target:value("SNAT")
|
|
|
|
|
|
|
|
dest = s:taboption("advanced", Value, "dest", translate("Destination zone"))
|
|
|
|
dest.nocreate = true
|
|
|
|
dest.default = "lan"
|
|
|
|
dest.template = "cbi/firewall_zonelist"
|
|
|
|
|
|
|
|
src_dip = s:taboption("advanced", Value, "src_dip",
|
|
|
|
translate("Intended destination address"),
|
|
|
|
translate(
|
|
|
|
"For DNAT, match incoming traffic directed at the given destination "..
|
|
|
|
"ip address. For SNAT rewrite the source address to the given address."
|
|
|
|
))
|
|
|
|
|
|
|
|
src_dip.optional = true
|
|
|
|
src_dip.datatype = "ip4addr"
|
2010-11-07 20:01:56 +00:00
|
|
|
src_dip.placeholder = translate("any")
|
2010-11-01 19:45:54 +00:00
|
|
|
|
|
|
|
src_mac = s:taboption("advanced", Value, "src_mac", translate("Source MAC address"))
|
|
|
|
src_mac.optional = true
|
|
|
|
src_mac.datatype = "macaddr"
|
2010-11-07 20:01:56 +00:00
|
|
|
src_mac.placeholder = translate("any")
|
2010-11-01 19:45:54 +00:00
|
|
|
|
|
|
|
src_ip = s:taboption("advanced", Value, "src_ip", translate("Source IP address"))
|
|
|
|
src_ip.optional = true
|
2011-04-13 00:33:42 +00:00
|
|
|
src_ip.datatype = "neg_ip4addr"
|
2010-11-07 20:01:56 +00:00
|
|
|
src_ip.placeholder = translate("any")
|
2010-11-01 19:45:54 +00:00
|
|
|
|
|
|
|
sport = s:taboption("advanced", Value, "src_port", translate("Source port"),
|
|
|
|
translate("Match incoming traffic originating from the given " ..
|
|
|
|
"source port or port range on the client host"))
|
|
|
|
sport.optional = true
|
|
|
|
sport.datatype = "portrange"
|
2010-11-07 20:01:56 +00:00
|
|
|
sport.placeholder = "0-65536"
|
2010-11-01 19:45:54 +00:00
|
|
|
sport:depends("proto", "tcp")
|
|
|
|
sport:depends("proto", "udp")
|
|
|
|
sport:depends("proto", "tcpudp")
|
|
|
|
|
|
|
|
reflection = s:taboption("advanced", Flag, "reflection", translate("Enable NAT Loopback"))
|
|
|
|
reflection.rmempty = true
|
2011-07-30 20:02:58 +00:00
|
|
|
reflection.default = reflection.enabled
|
2010-11-01 19:45:54 +00:00
|
|
|
reflection:depends({ target = "DNAT", src = wan_zone })
|
|
|
|
reflection.cfgvalue = function(...)
|
|
|
|
return Flag.cfgvalue(...) or "1"
|
|
|
|
end
|
|
|
|
|
2008-08-04 23:36:33 +00:00
|
|
|
return m
|