modules/admin-full: make interface configuration modular
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / proto_ahcp.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2011 Jo-Philipp Wich <xm@subsignal.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
13 local map, section, net = ...
14
15 local device, apn, service, pincode, username, password
16 local ipv6, maxwait, defaultroute, metric, peerdns, dns,
17 keepalive_failure, keepalive_interval, demand
18
19
20 mca = s:taboption("ahcp", Value, "multicast_address", translate("Multicast address"))
21 mca.optional = true
22 mca.placeholder = "ff02::cca6:c0f9:e182:5359"
23 mca.datatype = "ip6addr"
24 mca:depends("proto", "ahcp")
25
26 port = s:taboption("ahcp", Value, "port", translate("Port"))
27 port.optional = true
28 port.placeholder = 5359
29 port.datatype = "port"
30 port:depends("proto", "ahcp")
31
32 fam = s:taboption("ahcp", ListValue, "_family", translate("Protocol family"))
33 fam:value("", translate("IPv4 and IPv6"))
34 fam:value("ipv4", translate("IPv4 only"))
35 fam:value("ipv6", translate("IPv6 only"))
36 fam:depends("proto", "ahcp")
37
38 function fam.cfgvalue(self, section)
39 local v4 = m.uci:get_bool("network", section, "ipv4_only")
40 local v6 = m.uci:get_bool("network", section, "ipv6_only")
41 if v4 then
42 return "ipv4"
43 elseif v6 then
44 return "ipv6"
45 end
46 return ""
47 end
48
49 function fam.write(self, section, value)
50 if value == "ipv4" then
51 m.uci:set("network", section, "ipv4_only", "true")
52 m.uci:delete("network", section, "ipv6_only")
53 elseif value == "ipv6" then
54 m.uci:set("network", section, "ipv6_only", "true")
55 m.uci:delete("network", section, "ipv4_only")
56 end
57 end
58
59 function fam.remove(self, section)
60 m.uci:delete("network", section, "ipv4_only")
61 m.uci:delete("network", section, "ipv6_only")
62 end
63
64 nodns = s:taboption("ahcp", Flag, "no_dns", translate("Disable DNS setup"))
65 nodns.optional = true
66 nodns.enabled = "true"
67 nodns.disabled = "false"
68 nodns.default = nodns.disabled
69 nodns:depends("proto", "ahcp")
70
71 ltime = s:taboption("ahcp", Value, "lease_time", translate("Lease validity time"))
72 ltime.optional = true
73 ltime.placeholder = 3666
74 ltime.datatype = "uinteger"
75 ltime:depends("proto", "ahcp")
76