applications/luci-firewall: cope with both tables and strings when processing zone...
[project/luci.git] / applications / luci-firewall / luasrc / model / cbi / firewall / rule-details.lua
index cd34030..d29879c 100644 (file)
@@ -2,7 +2,7 @@
 LuCI - Lua Configuration Interface
 
 Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2010 Jo-Philipp Wich <xm@subsignal.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.
@@ -10,10 +10,10 @@ You may obtain a copy of the License at
 
        http://www.apache.org/licenses/LICENSE-2.0
 
-$Id$
 ]]--
 
 local sys = require "luci.sys"
+local utl = require "luci.util"
 local dsp = require "luci.dispatcher"
 local nxo = require "nixio"
 
@@ -63,7 +63,7 @@ elseif rule_type == "redirect" then
                        local n = s.network or s.name
                        if n then
                                local i
-                               for i in n:gmatch("%S+") do
+                               for i in utl.imatch(n) do
                                        if i == "wan" then
                                                wan_zone = s.name
                                                return false
@@ -107,17 +107,15 @@ elseif rule_type == "redirect" then
        o.template = "cbi/firewall_zonelist"
 
 
-       o = s:option(DynamicList, "src_mac", translate("Source MAC address"))
-       o.rmempty = true
-       o.datatype = "neg(macaddr)"
-       o.placeholder = translate("any")
-
-
        o = s:option(Value, "src_ip", translate("Source IP address"))
        o.rmempty = true
        o.datatype = "neg(ipaddr)"
        o.placeholder = translate("any")
 
+       luci.sys.net.ipv4_hints(function(ip, name)
+               o:value(ip, "%s (%s)" %{ ip, name })
+       end)
+
 
        o = s:option(Value, "src_port",
                translate("Source port"),
@@ -137,9 +135,9 @@ elseif rule_type == "redirect" then
        o = s:option(Value, "dest_ip", translate("Destination IP address"))
        o.datatype = "neg(ip4addr)"
 
-       for i, dataset in ipairs(luci.sys.net.arptable()) do
-               o:value(dataset["IP address"])
-       end
+       luci.sys.net.ipv4_hints(function(ip, name)
+               o:value(ip, "%s (%s)" %{ ip, name })
+       end)
 
 
        o = s:option(Value, "dest_port",
@@ -149,7 +147,7 @@ elseif rule_type == "redirect" then
 
        o.rmempty = true
        o.placeholder = translate("any")
-       o.datatype = "portrange"
+       o.datatype = "neg(portrange)"
 
 
        o = s:option(Value, "src_dip",
@@ -275,11 +273,19 @@ else
        o.datatype = "list(macaddr)"
        o.placeholder = translate("any")
 
+       luci.sys.net.mac_hints(function(mac, name)
+               o:value(mac, "%s (%s)" %{ mac, name })
+       end)
+
 
        o = s:option(Value, "src_ip", translate("Source address"))
        o.datatype = "neg(ipaddr)"
        o.placeholder = translate("any")
 
+       luci.sys.net.ipv4_hints(function(ip, name)
+               o:value(ip, "%s (%s)" %{ ip, name })
+       end)
+
 
        o = s:option(Value, "src_port", translate("Source port"))
        o.datatype = "list(neg(portrange))"
@@ -297,6 +303,10 @@ else
        o.datatype = "neg(ipaddr)"
        o.placeholder = translate("any")
 
+       luci.sys.net.ipv4_hints(function(ip, name)
+               o:value(ip, "%s (%s)" %{ ip, name })
+       end)
+
 
        o = s:option(Value, "dest_port", translate("Destination port"))
        o.datatype = "list(neg(portrange))"