63e014444b62a95ea39e8dd6c510344230c86876
[project/luci.git] / applications / luci-firewall / luasrc / model / cbi / luci_fw / rrule.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 require("luci.sys")
15 arg[1] = arg[1] or ""
16
17 m = Map("firewall", translate("Traffic Redirection"),
18         translate("Traffic redirection allows you to change the " ..
19                 "destination address of forwarded packets."))
20
21
22 s = m:section(NamedSection, arg[1], "redirect", "")
23 s.anonymous = true
24 s.addremove = false
25
26 back = s:option(DummyValue, "_overview", translate("Overview"))
27 back.value = ""
28 back.titleref = luci.dispatcher.build_url("admin", "network", "firewall", "redirect")
29
30 name = s:option(Value, "_name", translate("Name"))
31 name.rmempty = true
32 name.size = 10
33
34 iface = s:option(ListValue, "src", translate("Source zone"))
35 iface.default = "wan"
36 luci.model.uci.cursor():foreach("firewall", "zone",
37         function (section)
38                 iface:value(section.name)
39         end)
40         
41 s:option(Value, "src_ip", translate("Source IP address")).optional = true
42 s:option(Value, "src_mac", translate("Source MAC-address")).optional = true
43
44 sport = s:option(Value, "src_port", translate("Source port"),
45         translate("Match incoming traffic originating from the given " ..
46                 "source port or port range on the client host"))
47 sport.optional = true
48 sport:depends("proto", "tcp")
49 sport:depends("proto", "udp")
50 sport:depends("proto", "tcpudp")
51
52 proto = s:option(ListValue, "proto", translate("Protocol"))
53 proto.optional = true
54 proto:value("")
55 proto:value("tcp", "TCP")
56 proto:value("udp", "UDP")
57 proto:value("tcpudp", "TCP+UDP")
58
59 dport = s:option(Value, "src_dport", translate("External port"),
60         translate("Match incoming traffic directed at the given " ..
61                 "destination port or port range on this host"))
62 dport.size = 5
63 dport:depends("proto", "tcp")
64 dport:depends("proto", "udp")
65 dport:depends("proto", "tcpudp")
66
67 to = s:option(Value, "dest_ip", translate("Internal IP address"),
68         translate("Redirect matched incoming traffic to the specified " ..
69                 "internal host"))
70 for i, dataset in ipairs(luci.sys.net.arptable()) do
71         to:value(dataset["IP address"])
72 end
73
74 toport = s:option(Value, "dest_port", translate("Internal port (optional)"),
75         translate("Redirect matched incoming traffic to the given port on " ..
76                 "the internal host"))
77 toport.optional = true
78 toport.size = 5
79
80 return m