modules/admin-full: fix dhcp page
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / dhcp.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 require("luci.tools.webadmin")
15 require("luci.model.uci")
16 require("luci.util")
17
18 m = Map("dhcp",
19 translate("Dynamic <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr>"),
20 translate("With <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr> network " ..
21 "members can automatically receive their network settings (<abbr title=" ..
22 "\"Internet Protocol\">IP</abbr>-address, netmask, <abbr title=\"Domain Name " ..
23 "System\">DNS</abbr>-server, ...)."))
24
25 s = m:section(TypedSection, "dhcp", "")
26 s.addremove = true
27 s.anonymous = true
28
29 iface = s:option(ListValue, "interface", translate("Interface"))
30 luci.tools.webadmin.cbi_add_networks(iface)
31
32 local uci = luci.model.uci.cursor()
33 uci:foreach("network", "interface",
34 function (section)
35 if section[".name"] ~= "loopback" then
36 iface.default = iface.default or section[".name"]
37 s:depends("interface", section[".name"])
38 end
39 end)
40
41 uci:foreach("network", "alias",
42 function (section)
43 iface:value(section[".name"])
44 s:depends("interface", section[".name"])
45 end)
46
47 s:option(Value, "start", translate("Start")).rmempty = true
48
49 s:option(Value, "limit", translate("Limit")).rmempty = true
50
51 s:option(Value, "leasetime", translate("Leasetime")).rmempty = true
52
53 local dd = s:option(Flag, "dynamicdhcp", translate("dynamic"))
54 dd.rmempty = false
55 function dd.cfgvalue(self, section)
56 return Flag.cfgvalue(self, section) or "1"
57 end
58
59 s:option(Value, "name", translate("Name")).optional = true
60
61 ignore = s:option(Flag, "ignore",
62 translate("Ignore interface"),
63 translate("disable <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr> for " ..
64 "this interface"))
65
66 ignore.optional = true
67
68 s:option(Value, "netmask", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask")).optional = true
69
70 s:option(Flag, "force", translate("Force")).optional = true
71
72 s:option(DynamicList, "dhcp_option", translate("DHCP-Options")).optional = true
73
74
75 for i, n in ipairs(s.children) do
76 if n ~= iface and n ~= ignore then
77 n:depends("ignore", "")
78 end
79 end
80
81 return m