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
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("DHCP"),
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",
54         translate("Dynamic <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr>"))
55
56 dd.rmempty = false
57 function dd.cfgvalue(self, section)
58         return Flag.cfgvalue(self, section) or "1"
59 end
60
61 s:option(Value, "name", translate("Name")).optional = true
62
63 ignore = s:option(Flag, "ignore",
64         translate("Ignore interface"),
65         translate("disable <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr> for " ..
66                 "this interface"))
67
68 ignore.optional = true
69
70 s:option(Value, "netmask", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask")).optional = true
71
72 s:option(Flag, "force", translate("Force")).optional = true
73
74 s:option(DynamicList, "dhcp_option", translate("DHCP-Options")).optional = true
75
76
77 for i, n in ipairs(s.children) do
78         if n ~= iface and n ~= ignore then
79                 n:depends("ignore", "")
80         end
81 end
82
83 return m