Redesigned firewall configuration
[project/luci.git] / applications / luci-fw / luasrc / model / cbi / luci_fw / trule.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 arg[1] = arg[1] or ""
15 m = Map("firewall", translate("firewall_rule"), translate("firewall_rule_desc"))
16
17 s = m:section(NamedSection, arg[1], "rule", "")
18 s.anonymous = true
19
20 name = s:option(Value, "_name", translate("name")..translate("cbi_optional"))
21 name.rmempty = true
22
23 iface = s:option(ListValue, "src", translate("firewall_rule_src"))
24 iface.rmempty = true
25
26 oface = s:option(ListValue, "dest", translate("firewall_rule_dest"))
27 oface:value("")
28 oface.optional = true
29
30 luci.model.uci.cursor():foreach("firewall", "zone",
31         function (section)
32                 iface:value(section.name)
33                 oface:value(section.name)
34         end)
35
36 proto = s:option(ListValue, "proto", translate("protocol"))
37 proto.optional = true
38 proto:value("")
39 proto:value("tcpudp", "TCP+UDP")
40 proto:value("tcp", "TCP")
41 proto:value("udp", "UDP")
42 proto:value("icmp", "ICMP")
43
44 s:option(Value, "src_ip", translate("firewall_rule_srcip")).optional = true
45 s:option(Value, "dest_ip", translate("firewall_rule_destip")).optional = true
46 s:option(Value, "src_mac", translate("firewall_rule_srcmac")).optional = true
47
48 sport = s:option(Value, "src_port", translate("firewall_rule_srcport"))
49 sport.optional = true
50 sport:depends("proto", "tcp")
51 sport:depends("proto", "udp")
52 sport:depends("proto", "tcpudp")
53
54 dport = s:option(Value, "dest_port", translate("firewall_rule_destport"))
55 dport.optional = true
56 dport:depends("proto", "tcp")
57 dport:depends("proto", "udp")
58 dport:depends("proto", "tcpudp")
59
60 jump = s:option(ListValue, "target", translate("firewall_rule_target"))
61 jump.rmempty = true
62 jump.default = "ACCEPT"
63 jump:value("DROP", translate("fw_drop"))
64 jump:value("ACCEPT", translate("fw_accept"))
65 jump:value("REJECT", translate("fw_reject"))
66
67
68 return m