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