applications/luci-firewall: offer zone selection in redirect quickadd (#483)
[project/luci.git] / applications / luci-firewall / luasrc / model / cbi / firewall / forwards.lua
index 3ab3658..5f7a69b 100644 (file)
@@ -2,6 +2,7 @@
 LuCI - Lua Configuration Interface
 
 Copyright 2008 Steven Barth <steven@midlink.org>
+Copyright 2010-2012 Jo-Philipp Wich <xm@subsignal.org>
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
@@ -9,7 +10,6 @@ You may obtain a copy of the License at
 
        http://www.apache.org/licenses/LICENSE-2.0
 
-$Id$
 ]]--
 
 local ds = require "luci.dispatcher"
@@ -35,7 +35,9 @@ s.template_addremove = "firewall/cbi_addforward"
 function s.create(self, section)
        local n = m:formvalue("_newfwd.name")
        local p = m:formvalue("_newfwd.proto")
+       local E = m:formvalue("_newfwd.extzone")
        local e = m:formvalue("_newfwd.extport")
+       local I = m:formvalue("_newfwd.intzone")
        local a = m:formvalue("_newfwd.intaddr")
        local i = m:formvalue("_newfwd.intport")
 
@@ -43,13 +45,13 @@ function s.create(self, section)
                created = TypedSection.create(self, section)
 
                self.map:set(created, "target",    "DNAT")
-               self.map:set(created, "src",       "wan")
-               self.map:set(created, "dest",      "lan")
+               self.map:set(created, "src",       E or "wan")
+               self.map:set(created, "dest",      I or "lan")
                self.map:set(created, "proto",     (p ~= "other") and p or "all")
                self.map:set(created, "src_dport", e)
                self.map:set(created, "dest_ip",   a)
                self.map:set(created, "dest_port", i)
-               self.map:set(created, "_name",     n)
+               self.map:set(created, "name",      n)
        end
 
        if p ~= "other" then
@@ -62,7 +64,7 @@ function s.parse(self, ...)
        if created then
                m.uci:save("firewall")
                luci.http.redirect(ds.build_url(
-                       "admin", "network", "firewall", "redirect", created
+                       "admin/network/firewall/redirect", created
                ))
        end
 end
@@ -71,71 +73,72 @@ function s.filter(self, sid)
        return (self.map:get(sid, "target") ~= "SNAT")
 end
 
-name = s:option(DummyValue, "_name", translate("Name"))
-function name.cfgvalue(self, s)
-       return self.map:get(s, "_name") or "-"
-end
 
-proto = s:option(DummyValue, "proto", translate("Protocol"))
-proto.rawhtml = true
-function proto.cfgvalue(self, s)
-       return ft.fmt_proto(self.map:get(s, "proto")) or "Any"
-end
+ft.opt_name(s, DummyValue, translate("Name"))
 
 
-src = s:option(DummyValue, "src", translate("Source"))
-src.rawhtml = true
-src.width   = "20%"
-function src.cfgvalue(self, s)
-       local z = ft.fmt_zone(self.map:get(s, "src"))
-       local a = ft.fmt_ip(self.map:get(s, "src_ip"))
+local function forward_proto_txt(self, s)
+       return "%s-%s" %{
+               translate("IPv4"),
+               ft.fmt_proto(self.map:get(s, "proto"),
+                        self.map:get(s, "icmp_type")) or "TCP+UDP"
+       }
+end
+
+local function forward_src_txt(self, s)
+       local z = ft.fmt_zone(self.map:get(s, "src"), translate("any zone"))
+       local a = ft.fmt_ip(self.map:get(s, "src_ip"), translate("any host"))
        local p = ft.fmt_port(self.map:get(s, "src_port"))
        local m = ft.fmt_mac(self.map:get(s, "src_mac"))
 
-       local s = "From %s in %s " %{
-               (a or "<var>any host</var>"),
-               (z or "<var>any zone</var>")
-       }
-
        if p and m then
-               s = s .. "with source %s and %s" %{ p, m }
+               return translatef("From %s in %s with source %s and %s", a, z, p, m)
        elseif p or m then
-               s = s .. "with source %s" %( p or m )
+               return translatef("From %s in %s with source %s", a, z, p or m)
+       else
+               return translatef("From %s in %s", a, z)
        end
-
-       return s
 end
 
-via = s:option(DummyValue, "via", translate("Via"))
-via.rawhtml = true
-via.width   = "20%"
-function via.cfgvalue(self, s)
-       local a = ft.fmt_ip(self.map:get(s, "src_dip"))
+local function forward_via_txt(self, s)
+       local a = ft.fmt_ip(self.map:get(s, "src_dip"), translate("any router IP"))
        local p = ft.fmt_port(self.map:get(s, "src_dport"))
 
-       --local z = self.map:get(s, "src")
-       --local s = "To %s " %(a or "<var>any %s IP</var>" %( z or "router" ))
+       if p then
+               return translatef("Via %s at %s", a, p)
+       else
+               return translatef("Via %s", a)
+       end
+end
 
-       return "To %s%s" %{
-               (a or "<var>any router IP</var>"),
-               (p and " at %s" % p or "")
+match = s:option(DummyValue, "match", translate("Match"))
+match.rawhtml = true
+match.width   = "50%"
+function match.cfgvalue(self, s)
+       return "<small>%s<br />%s<br />%s</small>" % {
+               forward_proto_txt(self, s),
+               forward_src_txt(self, s),
+               forward_via_txt(self, s)
        }
 end
 
-dest = s:option(DummyValue, "dest", translate("Destination"))
+
+dest = s:option(DummyValue, "dest", translate("Forward to"))
 dest.rawhtml = true
-dest.width   = "30%"
+dest.width   = "40%"
 function dest.cfgvalue(self, s)
-       local z = ft.fmt_zone(self.map:get(s, "dest"))
-       local a = ft.fmt_ip(self.map:get(s, "dest_ip"))
+       local z = ft.fmt_zone(self.map:get(s, "dest"), translate("any zone"))
+       local a = ft.fmt_ip(self.map:get(s, "dest_ip"), translate("any host"))
        local p = ft.fmt_port(self.map:get(s, "dest_port")) or
                ft.fmt_port(self.map:get(s, "src_dport"))
 
-       return "Forward to %s%s in %s " %{
-               (a or "<var>any host</var>"),
-               (p and ", %s" % p or ""),
-               (z or "<var>any zone</var>")
-       }
+       if p then
+               return translatef("%s, %s in %s", a, p, z)
+       else
+               return translatef("%s in %s", a, z)
+       end
 end
 
+ft.opt_enabled(s, Flag, translate("Enable")).width = "1%"
+
 return m