| 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 | local uci = luci.model.uci.cursor() |
|---|
| 28 | uci:foreach("network", "interface", |
|---|
| 29 | function (section) |
|---|
| 30 | if section[".name"] ~= "loopback" then |
|---|
| 31 | iface.default = iface.default or section[".name"] |
|---|
| 32 | s:depends("interface", section[".name"]) |
|---|
| 33 | end |
|---|
| 34 | end) |
|---|
| 35 | |
|---|
| 36 | uci:foreach("network", "alias", |
|---|
| 37 | function (section) |
|---|
| 38 | iface:value(section[".name"]) |
|---|
| 39 | s:depends("interface", section[".name"]) |
|---|
| 40 | end) |
|---|
| 41 | |
|---|
| 42 | s:option(Value, "start", translate("start")).rmempty = true |
|---|
| 43 | |
|---|
| 44 | s:option(Value, "limit", translate("limit")).rmempty = true |
|---|
| 45 | |
|---|
| 46 | s:option(Value, "leasetime").rmempty = true |
|---|
| 47 | |
|---|
| 48 | local dd = s:option(Flag, "dynamicdhcp") |
|---|
| 49 | dd.rmempty = false |
|---|
| 50 | function dd.cfgvalue(self, section) |
|---|
| 51 | return Flag.cfgvalue(self, section) or "1" |
|---|
| 52 | end |
|---|
| 53 | |
|---|
| 54 | s:option(Value, "name", translate("name")).optional = true |
|---|
| 55 | |
|---|
| 56 | ignore = s:option(Flag, "ignore") |
|---|
| 57 | ignore.optional = true |
|---|
| 58 | |
|---|
| 59 | s:option(Value, "netmask", translate("netmask")).optional = true |
|---|
| 60 | |
|---|
| 61 | s:option(Flag, "force").optional = true |
|---|
| 62 | |
|---|
| 63 | s:option(DynamicList, "dhcp_option").optional = true |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | for i, n in ipairs(s.children) do |
|---|
| 67 | if n ~= iface and n ~= ignore then |
|---|
| 68 | n:depends("ignore", "") |
|---|
| 69 | end |
|---|
| 70 | end |
|---|
| 71 | |
|---|
| 72 | return m |
|---|