modules/admin-full: Reworked DHCP configuration
[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", "DHCP")
19
20 s = m:section(TypedSection, "dhcp", "")
21 s.addremove = true
22 s.anonymous = true
23
24 iface = s:option(ListValue, "interface", translate("interface"))
25 luci.tools.webadmin.cbi_add_networks(iface)
26
27 luci.model.uci.foreach("network", "interface",
28         function (section)
29                 if section[".name"] ~= "loopback" then
30                         iface.default = iface.default or section[".name"]
31                         s:depends("interface", section[".name"])
32                 end
33         end)
34
35 luci.model.uci.foreach("network", "alias",
36         function (section)
37                 iface:value(section[".name"])
38                 s:depends("interface", section[".name"])
39         end)
40
41 s:option(Value, "start", translate("start")).rmempty = true
42
43 s:option(Value, "limit", translate("limit")).rmempty = true
44
45 s:option(Value, "leasetime").rmempty = true
46
47 s:option(Flag, "dynamicdhcp").rmempty = true
48
49 s:option(Value, "name", translate("name")).optional = true
50
51 ignore = s:option(Flag, "ignore")
52 ignore.optional = true
53
54 s:option(Value, "netmask", translate("netmask")).optional = true
55
56 s:option(Flag, "force").optional = true
57
58 for i, line in pairs(luci.util.execl("dnsmasq --help dhcp")) do
59         k, v = line:match("([^ ]+) +([^ ]+)")
60         s:option(Value, "dhcp"..k, v).optional = true
61 end
62
63
64 for i, n in ipairs(s.children) do
65         if n ~= iface and n ~= ignore then
66                 n:depends("ignore", "")
67         end
68 end
69
70 return m