root/luci/trunk/applications/luci-firewall/luasrc/model/cbi/firewall/forwards.lua @ 8112

Revision 8112, 3.6 KB (checked in by jow, 17 months ago)

applications/luci-firewall: make rule descriptions fully translateable

  • Property svn:keywords set to Id
Line 
1--[[
2LuCI - Lua Configuration Interface
3
4Copyright 2008 Steven Barth <steven@midlink.org>
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12$Id$
13]]--
14
15local ds = require "luci.dispatcher"
16local ft = require "luci.tools.firewall"
17
18m = Map("firewall", translate("Firewall - Port Forwards"),
19    translate("Port forwarding allows remote computers on the Internet to \
20               connect to a specific computer or service within the \
21               private LAN."))
22
23--
24-- Port Forwards
25--
26
27s = m:section(TypedSection, "redirect", translate("Port Forwards"))
28s.template  = "cbi/tblsection"
29s.addremove = true
30s.anonymous = true
31s.sortable  = true
32s.extedit   = ds.build_url("admin/network/firewall/forwards/%s")
33s.template_addremove = "firewall/cbi_addforward"
34
35function s.create(self, section)
36    local n = m:formvalue("_newfwd.name")
37    local p = m:formvalue("_newfwd.proto")
38    local e = m:formvalue("_newfwd.extport")
39    local a = m:formvalue("_newfwd.intaddr")
40    local i = m:formvalue("_newfwd.intport")
41
42    if p == "other" or (p and a) then
43        created = TypedSection.create(self, section)
44
45        self.map:set(created, "target",    "DNAT")
46        self.map:set(created, "src",       "wan")
47        self.map:set(created, "dest",      "lan")
48        self.map:set(created, "proto",     (p ~= "other") and p or "all")
49        self.map:set(created, "src_dport", e)
50        self.map:set(created, "dest_ip",   a)
51        self.map:set(created, "dest_port", i)
52        self.map:set(created, "_name",     n)
53    end
54
55    if p ~= "other" then
56        created = nil
57    end
58end
59
60function s.parse(self, ...)
61    TypedSection.parse(self, ...)
62    if created then
63        m.uci:save("firewall")
64        luci.http.redirect(ds.build_url(
65            "admin/network/firewall/redirect", created
66        ))
67    end
68end
69
70function s.filter(self, sid)
71    return (self.map:get(sid, "target") ~= "SNAT")
72end
73
74name = s:option(DummyValue, "_name", translate("Name"))
75function name.cfgvalue(self, s)
76    return self.map:get(s, "_name") or "-"
77end
78
79proto = s:option(DummyValue, "proto", translate("Protocol"))
80proto.rawhtml = true
81function proto.cfgvalue(self, s)
82    return ft.fmt_proto(self.map:get(s, "proto")) or "Any"
83end
84
85
86src = s:option(DummyValue, "src", translate("Source"))
87src.rawhtml = true
88src.width   = "20%"
89function src.cfgvalue(self, s)
90    local z = ft.fmt_zone(self.map:get(s, "src"), translate("any zone"))
91    local a = ft.fmt_ip(self.map:get(s, "src_ip"), translate("any host"))
92    local p = ft.fmt_port(self.map:get(s, "src_port"))
93    local m = ft.fmt_mac(self.map:get(s, "src_mac"))
94
95    if p and m then
96        return translatef("From %s in %s with source %s and %s", a, z, p, m)
97    elseif p or m then
98        return translatef("From %s in %s with source %s", a, z, p or m)
99    else
100        return translatef("From %s in %s", a, z)
101    end
102end
103
104via = s:option(DummyValue, "via", translate("Via"))
105via.rawhtml = true
106via.width   = "20%"
107function via.cfgvalue(self, s)
108    local a = ft.fmt_ip(self.map:get(s, "src_dip"), translate("any router IP"))
109    local p = ft.fmt_port(self.map:get(s, "src_dport"))
110
111    if p then
112        return translatef("To %s at %s", a, p)
113    else
114        return translatef("To %s", a)
115    end
116end
117
118dest = s:option(DummyValue, "dest", translate("Destination"))
119dest.rawhtml = true
120dest.width   = "30%"
121function dest.cfgvalue(self, s)
122    local z = ft.fmt_zone(self.map:get(s, "dest"), translate("any zone"))
123    local a = ft.fmt_ip(self.map:get(s, "dest_ip"), translate("any host"))
124    local p = ft.fmt_port(self.map:get(s, "dest_port")) or
125        ft.fmt_port(self.map:get(s, "src_dport"))
126
127    if p then
128        return translatef("Forward to %s, %s in %s", a, p, z)
129    else
130        return translatef("Forward to %s in %s", a, z)
131    end
132end
133
134return m
Note: See TracBrowser for help on using the browser.