3bdc6db4c56b780e4f3d09545d37279eddefaf9b
[project/luci.git] / applications / luci-firewall / luasrc / model / cbi / luci_fw / traffic.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 m = Map("firewall", translate("Traffic Control"))
17 s = m:section(TypedSection, "forwarding", translate("Zone-to-Zone traffic"),
18         translate("Here you can specify which network traffic is allowed " ..
19                 "to flow between network zones. Only new connections will " ..
20                 "be matched.  Packets belonging to already open " ..
21                 "connections are automatically allowed to pass the " ..
22                 "firewall. If you experience occasional connection " ..
23                 "problems try enabling MSS Clamping otherwise disable it " ..
24                 "for performance reasons."))
25 s.template  = "cbi/tblsection"
26 s.addremove = true
27 s.anonymous = true
28
29 iface = s:option(ListValue, "src", translate("Source"))
30 oface = s:option(ListValue, "dest", translate("Destination"))
31
32 luci.model.uci.cursor():foreach("firewall", "zone",
33         function (section)
34                         iface:value(section.name)
35                         oface:value(section.name)
36         end)
37
38
39
40 s = m:section(TypedSection, "rule", translate("Rules"))
41 s.addremove = true
42 s.anonymous = true
43 s.template = "cbi/tblsection"
44 s.extedit   = luci.dispatcher.build_url("admin", "network", "firewall", "rule", "%s")
45 s.defaults.target = "ACCEPT"
46
47 local created = nil
48
49 function s.create(self, section)
50         created = TypedSection.create(self, section)
51 end
52
53 function s.parse(self, ...)
54         TypedSection.parse(self, ...)
55         if created then
56                 m.uci:save("firewall")
57                 luci.http.redirect(luci.dispatcher.build_url(
58                         "admin", "network", "firewall", "rule", created
59                 ))
60         end
61 end
62
63 s:option(DummyValue, "_name", translate("Name"))
64 s:option(DummyValue, "proto", translate("Protocol"))
65
66 src = s:option(DummyValue, "src", translate("Source"))
67 function src.cfgvalue(self, s)
68         return "%s:%s:%s" % {
69                 self.map:get(s, "src") or "*",
70                 self.map:get(s, "src_ip") or "0.0.0.0/0",
71                 self.map:get(s, "src_port") or "*"
72         } 
73 end
74
75 dest = s:option(DummyValue, "dest", translate("Destination"))
76 function dest.cfgvalue(self, s)
77         return "%s:%s:%s" % {
78                 self.map:get(s, "dest") or translate("Device"),
79                 self.map:get(s, "dest_ip") or "0.0.0.0/0",
80                 self.map:get(s, "dest_port") or "*"
81         } 
82 end
83
84
85 s:option(DummyValue, "target", translate("Action"))
86
87
88 return m