applications: add luci-ahcp, support for the AHCP server package
[project/luci.git] / applications / luci-ahcp / luasrc / model / cbi / 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 $Id: init.lua 5764 2010-03-08 19:05:34Z jow $
13 ]]--
14
15 m = Map("ahcpd", translate("AHCP Server"), translate("AHCP is an autoconfiguration protocol " ..
16 "for IPv6 and dual-stack IPv6/IPv4 networks designed to be used in place of router " ..
17 "discovery and DHCP on networks where it is difficult or impossible to configure a " ..
18 "server within every link-layer broadcast domain, for example mobile ad-hoc networks."))
19
20
21 m:section(SimpleSection).template = "ahcp_status"
22
23 s = m:section(TypedSection, "ahcpd")
24 s:tab("general", translate("General Setup"))
25 s:tab("advanced", translate("Advanced Settings"))
26 s.addremove = false
27 s.anonymous = true
28
29
30 mode = s:taboption("general", ListValue, "mode", translate("Operation mode"))
31 mode:value("server", translate("Server"))
32 mode:value("forwarder", translate("Forwarder"))
33
34 net = s:taboption("general", Value, "interface", translate("Served interfaces"))
35 net.template = "cbi/network_netlist"
36 net.widget = "checkbox"
37 net.nocreate = true
38
39 function net.cfgvalue(self, section)
40 return m.uci:get("ahcpd", section, "interface")
41 end
42
43 pfx = s:taboption("general", DynamicList, "prefix", translate("Announced prefixes"),
44 translate("Specifies the announced IPv4 and IPv6 network prefixes in CIDR notation"))
45 pfx.optional = true
46 pfx.datatype = "ipaddr"
47 pfx:depends("mode", "server")
48
49 nss = s:taboption("general", DynamicList, "name_server", translate("Announced DNS servers"),
50 translate("Specifies the announced IPv4 and IPv6 name servers"))
51 nss.optional = true
52 nss.datatype = "ipaddr"
53 nss:depends("mode", "server")
54
55 ntp = s:taboption("general", DynamicList, "ntp_server", translate("Announced NTP servers"),
56 translate("Specifies the announced IPv4 and IPv6 NTP servers"))
57 ntp.optional = true
58 ntp.datatype = "ipaddr"
59 ntp:depends("mode", "server")
60
61 mca = s:taboption("general", Value, "multicast_address", translate("Multicast address"))
62 mca.optional = true
63 mca.placeholder = "ff02::cca6:c0f9:e182:5359"
64 mca.datatype = "ip6addr"
65
66 port = s:taboption("general", Value, "port", translate("Port"))
67 port.optional = true
68 port.placeholder = 5359
69 port.datatype = "port"
70
71 fam = s:taboption("general", ListValue, "_family", translate("Protocol family"))
72 fam:value("", translate("IPv4 and IPv6"))
73 fam:value("ipv4", translate("IPv4 only"))
74 fam:value("ipv6", translate("IPv6 only"))
75
76 function fam.cfgvalue(self, section)
77 local v4 = m.uci:get_bool("ahcpd", section, "ipv4_only")
78 local v6 = m.uci:get_bool("ahcpd", section, "ipv6_only")
79 if v4 then
80 return "ipv4"
81 elseif v6 then
82 return "ipv6"
83 end
84 return ""
85 end
86
87 function fam.write(self, section, value)
88 if value == "ipv4" then
89 m.uci:set("ahcpd", section, "ipv4_only", "true")
90 m.uci:delete("ahcpd", section, "ipv6_only")
91 elseif value == "ipv6" then
92 m.uci:set("ahcpd", section, "ipv6_only", "true")
93 m.uci:delete("ahcpd", section, "ipv4_only")
94 end
95 end
96
97 function fam.remove(self, section)
98 m.uci:delete("ahcpd", section, "ipv4_only")
99 m.uci:delete("ahcpd", section, "ipv6_only")
100 end
101
102 ltime = s:taboption("general", Value, "lease_time", translate("Lease validity time"))
103 ltime.optional = true
104 ltime.placeholder = 3666
105 ltime.datatype = "uinteger"
106
107
108 ld = s:taboption("advanced", Value, "lease_dir", translate("Lease directory"))
109 ld.datatype = "directory"
110 ld.placeholder = "/var/lib/leases"
111
112 id = s:taboption("advanced", Value, "id_file", translate("Unique ID file"))
113 --id.datatype = "file"
114 id.placeholder = "/var/lib/ahcpd-unique-id"
115
116 log = s:taboption("advanced", Value, "log_file", translate("Log file"))
117 --log.datatype = "file"
118 log.placeholder = "/var/log/ahcpd.log"
119
120
121 return m