modules/admin-full: fix dhcp section creation logic on interfaces page
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / ifaces.lua
index 798b388..84d7ba5 100644 (file)
@@ -2,7 +2,7 @@
 LuCI - Lua Configuration Interface
 
 Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@subsignal.org>
+Copyright 2008-2011 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.
@@ -103,6 +103,9 @@ if not ( has_pppd and has_pppoe and has_pppoa and has_3g and has_pptp ) then
        p.description = translate("You need to install \"comgt\" for UMTS/GPRS, \"ppp-mod-pppoe\" for PPPoE, \"ppp-mod-pppoa\" for PPPoA or \"pptp\" for PPtP support")
 end
 
+auto = s:taboption("physical", Flag, "auto", translate("Bring up on boot"))                                                                                            
+auto.default = (m.uci:get("network", arg[1], "proto") == "none") and auto.disabled or auto.enabled
+
 br = s:taboption("physical", Flag, "type", translate("Bridge interfaces"), translate("creates a bridge over specified interface(s)"))
 br.enabled = "bridge"
 br.rmempty = true
@@ -659,19 +662,23 @@ end
 
 if has_dnsmasq and net:proto() == "static" then
        m2 = Map("dhcp", "", "")
+       
+       local section_id
        function m2.on_parse()
-               local has_section = false
-
                m2.uci:foreach("dhcp", "dhcp", function(s)
                        if s.interface == arg[1] then
-                               has_section = true
+                               section_id = s['.name']
                                return false
                        end
                end)
 
-               if not has_section then
-                       m2.uci:section("dhcp", "dhcp", nil, { interface = arg[1], ignore = "1" })
-                       m2.uci:save("dhcp")
+               if not section_id then
+                       local c = 1
+                       section_id = arg[1]
+                       while m2.uci:get("dhcp", section_id) do
+                               section_id = arg[1] .. c
+                               c = c + 1
+                       end
                end
        end
 
@@ -681,8 +688,8 @@ if has_dnsmasq and net:proto() == "static" then
        s:tab("general",  translate("General Setup"))
        s:tab("advanced", translate("Advanced Settings"))
 
-       function s.filter(self, section)
-               return m2.uci:get("dhcp", section, "interface") == arg[1]
+       function s.cfgsections(self)
+               return { section_id }
        end
 
        local ignore = s:taboption("general", Flag, "ignore",
@@ -691,6 +698,17 @@ if has_dnsmasq and net:proto() == "static" then
                        "this interface."))
 
        ignore.rmempty = false
+       ignore.default = ignore.enabled
+
+       function ignore.write(self, section, value)
+               if m2.uci:get("dhcp", section) ~= "dhcp" then
+                       m2.uci:section("dhcp", "dhcp", section, {
+                               interface = arg[1]
+                       })
+               end
+               m2.uci:set("dhcp", section, "ignore", (value == "1") and "1" or "0")
+       end
+
 
        local start = s:taboption("general", Value, "start", translate("Start"),
                translate("Lowest leased address as offset from the network address."))
@@ -734,6 +752,7 @@ if has_dnsmasq and net:proto() == "static" then
                translate("Define additional DHCP options, for example \"<code>6,192.168.2.1," ..
                        "192.168.2.2</code>\" which advertises different DNS servers to clients."))
 
+
        for i, n in ipairs(s.children) do
                if n ~= ignore then
                        n:depends("ignore", "")