c3efdd8557141996453c79228a1aedada0adb7a6
[project/luci.git] / applications / luci-fw / 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("fw_traffic"))
17 s = m:section(TypedSection, "forwarding", translate("fw_forwarding"), translate("fw_forwarding1"))
18 s.template  = "cbi/tblsection"
19 s.addremove = true
20 s.anonymous = true
21
22 iface = s:option(ListValue, "src", translate("fw_src"))
23 oface = s:option(ListValue, "dest", translate("fw_dest"))
24 s:option(Flag, "mtu_fix", translate("fw_mtufix"))
25
26 luci.model.uci.cursor():foreach("firewall", "zone",
27         function (section)
28                         iface:value(section.name)
29                         oface:value(section.name)
30         end)
31
32
33
34 s = m:section(TypedSection, "rule")
35 s.addremove = true
36 s.anonymous = true
37 s.template = "cbi/tblsection"
38 s.extedit   = luci.dispatcher.build_url("admin", "network", "firewall", "rule", "%s")
39 s.defaults.target = "ACCEPT"
40
41 local created = nil
42
43 function s.create(self, section)
44         created = TypedSection.create(self, section)
45 end
46
47 function s.parse(self, ...)
48         TypedSection.parse(self, ...)
49         if created then
50                 m.uci:save("firewall")
51                 luci.http.redirect(luci.dispatcher.build_url(
52                         "admin", "network", "firewall", "rule", created
53                 ))
54         end
55 end
56
57 s:option(DummyValue, "_name", translate("name"))
58 s:option(DummyValue, "proto", translate("protocol"))
59
60 src = s:option(DummyValue, "src", translate("fw_src"))
61 function src.cfgvalue(self, s)
62         return "%s:%s:%s" % {
63                 self.map:get(s, "src") or "*",
64                 self.map:get(s, "src_ip") or "0.0.0.0/0",
65                 self.map:get(s, "src_port") or "*"
66         } 
67 end
68
69 dest = s:option(DummyValue, "dest", translate("fw_dest"))
70 function dest.cfgvalue(self, s)
71         return "%s:%s:%s" % {
72                 self.map:get(s, "dest") or translate("device", "device"),
73                 self.map:get(s, "dest_ip") or "0.0.0.0/0",
74                 self.map:get(s, "dest_port") or "*"
75         } 
76 end
77
78
79 s:option(DummyValue, "target")
80
81
82 return m