modules/admin-full: switch static lease page to /etc/config/dhcp, add better labels...
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / dhcp.lua
index b50b05c..13a00ab 100644 (file)
@@ -11,67 +11,73 @@ You may obtain a copy of the License at
 
 $Id$
 ]]--
+require("luci.tools.webadmin")
 require("luci.model.uci")
-require("luci.sys")
 require("luci.util")
 
-m = Map("dhcp", "DHCP")
+m = Map("dhcp",
+       translate("DHCP"),
+       translate("With <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr> network " ..
+               "members can automatically receive their network settings (<abbr title=" ..
+               "\"Internet Protocol\">IP</abbr>-address, netmask, <abbr title=\"Domain Name " ..
+               "System\">DNS</abbr>-server, ...)."))
 
 s = m:section(TypedSection, "dhcp", "")
 s.addremove = true
 s.anonymous = true
 
-iface = s:option(ListValue, "interface", translate("interface"))
-luci.model.uci.foreach("network", "interface",
+iface = s:option(ListValue, "interface", translate("Interface"))
+luci.tools.webadmin.cbi_add_networks(iface)
+
+local uci = luci.model.uci.cursor()
+uci:foreach("network", "interface",
        function (section)
                if section[".name"] ~= "loopback" then
                        iface.default = iface.default or section[".name"]
-                       iface:value(section[".name"])
                        s:depends("interface", section[".name"])
                end
        end)
 
-luci.model.uci.foreach("network", "alias",
+uci:foreach("network", "alias",
        function (section)
                iface:value(section[".name"])
                s:depends("interface", section[".name"])
        end)
 
-s:option(Value, "start", translate("start")).rmempty = true
+s:option(Value, "start", translate("Start")).rmempty = true
 
-s:option(Value, "limit", translate("limit")).rmempty = true
+s:option(Value, "limit", translate("Limit")).rmempty = true
 
-s:option(Value, "leasetime").rmempty = true
+s:option(Value, "leasetime", translate("Leasetime")).rmempty = true
 
-s:option(Flag, "dynamicdhcp").rmempty = true
+local dd = s:option(Flag, "dynamicdhcp",
+       translate("Dynamic <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr>"))
 
-s:option(Value, "name", translate("name")).optional = true
+dd.rmempty = false
+function dd.cfgvalue(self, section)
+       return Flag.cfgvalue(self, section) or "1"
+end
 
-s:option(Flag, "ignore").optional = true
+s:option(Value, "name", translate("Name")).optional = true
 
-s:option(Value, "netmask", translate("netmask")).optional = true
+ignore = s:option(Flag, "ignore",
+       translate("Ignore interface"),
+       translate("disable <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr> for " ..
+               "this interface"))
 
-s:option(Flag, "force").optional = true
+ignore.optional = true
 
-for i, line in pairs(luci.util.execl("dnsmasq --help dhcp")) do
-       k, v = line:match("([^ ]+) +([^ ]+)")
-       s:option(Value, "dhcp"..k, v).optional = true
-end
+s:option(Value, "netmask", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask")).optional = true
 
-m2 = Map("luci_ethers", translate("luci_ethers"))
+s:option(Flag, "force", translate("Force")).optional = true
 
-s = m2:section(TypedSection, "static_lease", "")
-s.addremove = true
-s.anonymous = true
-s.template = "cbi/tblsection"
-
-mac = s:option(Value, "macaddr", translate("macaddress"))
-ip = s:option(Value, "ipaddr", translate("ipaddress"))
-for i, dataset in ipairs(luci.sys.net.arptable()) do
-       ip:value(dataset["IP address"])
-       mac:value(dataset["HW address"],
-        dataset["HW address"] .. " (" .. dataset["IP address"] .. ")")
+s:option(DynamicList, "dhcp_option", translate("DHCP-Options")).optional = true
+
+
+for i, n in ipairs(s.children) do
+       if n ~= iface and n ~= ignore then
+               n:depends("ignore", "")
+       end
 end
 
-       
-return m, m2
+return m