luci-olsr split IPv6/4 configuration in 2 sections
[project/luci.git] / applications / luci-olsr / luasrc / model / cbi / olsr / olsrdplugins6.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 local ip = require "luci.ip"
17 local fs = require "nixio.fs"
18
19 if arg[1] then
20 mp = Map("olsrd", translate("OLSR - Plugins"))
21
22 p = mp:section(TypedSection, "LoadPlugin", translate("Plugin configuration"))
23 p:depends("library", arg[1])
24 p.anonymous = true
25
26 ign = p:option(Flag, "ignore", translate("Enable"))
27 ign.enabled = "0"
28 ign.disabled = "1"
29 ign.rmempty = false
30 function ign.cfgvalue(self, section)
31 return Flag.cfgvalue(self, section) or "0"
32 end
33
34 lib = p:option(DummyValue, "library", translate("Library"))
35 lib.default = arg[1]
36
37 local function Range(x,y)
38 local t = {}
39 for i = x, y do t[#t+1] = i end
40 return t
41 end
42
43 local function Cidr2IpMask(val)
44 if val then
45 for i = 1, #val do
46 local cidr = ip.IPv4(val[i]) or ip.IPv6(val[i])
47 if cidr then
48 val[i] = cidr:network():string() .. " " .. cidr:mask():string()
49 end
50 end
51 return val
52 end
53 end
54
55 local function IpMask2Cidr(val)
56 if val then
57 for i = 1, #val do
58 local ip, mask = val[i]:gmatch("([^%s]+)%s+([^%s]+)")()
59 local cidr
60 if ip and mask and ip:match(":") then
61 cidr = ip.IPv6(ip, mask)
62 elseif ip and mask then
63 cidr = ip.IPv4(ip, mask)
64 end
65
66 if cidr then
67 val[i] = cidr:string()
68 end
69 end
70 return val
71 end
72 end
73
74
75 local knownPlParams = {
76 ["olsrd_bmf.so.1.5.3"] = {
77 { Value, "BmfInterface", "bmf0" },
78 { Value, "BmfInterfaceIp", "10.10.10.234/24" },
79 { Flag, "DoLocalBroadcast", "no" },
80 { Flag, "CapturePacketsOnOlsrInterfaces", "yes" },
81 { ListValue, "BmfMechanism", { "UnicastPromiscuous", "Broadcast" } },
82 { Value, "BroadcastRetransmitCount", "2" },
83 { Value, "FanOutLimit", "4" },
84 { DynamicList, "NonOlsrIf", "br-lan" }
85 },
86
87 ["olsrd_dyn_gw.so.0.4"] = {
88 { Value, "Interval", "40" },
89 { DynamicList, "Ping", "141.1.1.1" },
90 { DynamicList, "HNA", "192.168.80.0/24", IpMask2Cidr, Cidr2IpMask }
91 },
92
93 ["olsrd_httpinfo.so.0.1"] = {
94 { Value, "port", "80" },
95 { DynamicList, "Host", "163.24.87.3" },
96 { DynamicList, "Net", "0.0.0.0/0", Cidr2IpMask }
97 },
98
99 ["olsrd_nameservice.so.0.3"] = {
100 { DynamicList, "name", "my-name.mesh" },
101 { DynamicList, "hosts", "1.2.3.4 name-for-other-interface.mesh" },
102 { Value, "suffix", ".olsr" },
103 { Value, "hosts_file", "/path/to/hosts_file" },
104 { Value, "add_hosts", "/path/to/file" },
105 { Value, "dns_server", "141.1.1.1" },
106 { Value, "resolv_file", "/path/to/resolv.conf" },
107 { Value, "interval", "120" },
108 { Value, "timeout", "240" },
109 { Value, "lat", "12.123" },
110 { Value, "lon", "12.123" },
111 { Value, "latlon_file", "/var/run/latlon.js.ipv6" },
112 { Value, "latlon_infile", "/var/run/gps.txt" },
113 { Value, "sighup_pid_file", "/var/run/dnsmasq.pid" },
114 { Value, "name_change_script", "/usr/local/bin/announce_new_hosts.sh" },
115 { DynamicList, "service", "http://me.olsr:80|tcp|my little homepage" },
116 { Value, "services_file", "/var/run/services_olsr" },
117 { Value, "services_change_script", "/usr/local/bin/announce_new_services.sh" },
118 { DynamicList, "mac", "xx:xx:xx:xx:xx:xx[,0-255]" },
119 { Value, "macs_file", "/path/to/macs_file" },
120 { Value, "macs_change_script", "/path/to/script" }
121 },
122
123 ["olsrd_quagga.so.0.2.2"] = {
124 { StaticList, "redistribute", {
125 "system", "kernel", "connect", "static", "rip", "ripng", "ospf",
126 "ospf6", "isis", "bgp", "hsls"
127 } },
128 { ListValue, "ExportRoutes", { "only", "both" } },
129 { Flag, "LocalPref", "true" },
130 { Value, "Distance", Range(0,255) }
131 },
132
133 ["olsrd_secure.so.0.5"] = {
134 { Value, "Keyfile", "/etc/private-olsr.key" }
135 },
136
137 ["olsrd_txtinfo.so.0.1"] = {
138 { Value, "accept", "::1/128" }
139 },
140
141 ["olsrd_jsoninfo.so.0.0"] = {
142 { Value, "accept", "::1/128" },
143 { Value, "port", "9090" },
144 { Value, "UUIDFile", "/etc/olsrd/olsrd.uuid.ipv6" },
145
146 },
147
148 ["olsrd_watchdog.so.0.1"] = {
149 { Value, "file", "/var/run/olsrd.watchdog.ipv6" },
150 { Value, "interval", "30" }
151 },
152
153 ["olsrd_mdns.so.1.0.0"] = {
154 { DynamicList, "NonOlsrIf", "lan" }
155 },
156
157 ["olsrd_p2pd.so.0.1.0"] = {
158 { DynamicList, "NonOlsrIf", "lan" },
159 { Value, "P2pdTtl", "10" }
160 },
161
162 ["olsrd_arprefresh.so.0.1"] = {},
163 ["olsrd_dot_draw.so.0.3"] = {},
164 ["olsrd_dyn_gw_plain.so.0.4"] = {},
165 ["olsrd_pgraph.so.1.1"] = {},
166 ["olsrd_tas.so.0.1"] = {}
167 }
168
169
170 -- build plugin options with dependencies
171 if knownPlParams[arg[1]] then
172 for _, option in ipairs(knownPlParams[arg[1]]) do
173 local otype, name, default, uci2cbi, cbi2uci = unpack(option)
174 local values
175
176 if type(default) == "table" then
177 values = default
178 default = default[1]
179 end
180
181 if otype == Flag then
182 local bool = p:option( Flag, name, name )
183 if default == "yes" or default == "no" then
184 bool.enabled = "yes"
185 bool.disabled = "no"
186 elseif default == "on" or default == "off" then
187 bool.enabled = "on"
188 bool.disabled = "off"
189 elseif default == "1" or default == "0" then
190 bool.enabled = "1"
191 bool.disabled = "0"
192 else
193 bool.enabled = "true"
194 bool.disabled = "false"
195 end
196 bool.optional = true
197 bool.default = default
198 bool:depends({ library = plugin })
199 else
200 local field = p:option( otype, name, name )
201 if values then
202 for _, value in ipairs(values) do
203 field:value( value )
204 end
205 end
206 if type(uci2cbi) == "function" then
207 function field.cfgvalue(self, section)
208 return uci2cbi(otype.cfgvalue(self, section))
209 end
210 end
211 if type(cbi2uci) == "function" then
212 function field.formvalue(self, section)
213 return cbi2uci(otype.formvalue(self, section))
214 end
215 end
216 field.optional = true
217 field.default = default
218 --field:depends({ library = arg[1] })
219 end
220 end
221 end
222
223 return mp
224
225 else
226
227 mpi = Map("olsrd6", translate("OLSR - Plugins"))
228
229 local plugins = {}
230 mpi.uci:foreach("olsrd6", "LoadPlugin",
231 function(section)
232 if section.library and not plugins[section.library] then
233 plugins[section.library] = true
234 end
235 end
236 )
237
238 -- create a loadplugin section for each found plugin
239 for v in fs.dir("/usr/lib") do
240 if v:sub(1, 6) == "olsrd_" then
241 if not plugins[v] then
242 mpi.uci:section(
243 "olsrd6", "LoadPlugin", nil,
244 { library = v, ignore = 1 }
245 )
246 end
247 end
248 end
249
250 t = mpi:section( TypedSection, "LoadPlugin", translate("Plugins") )
251 t.anonymous = true
252 t.template = "cbi/tblsection"
253 t.override_scheme = true
254 function t.extedit(self, section)
255 local lib = self.map:get(section, "library") or ""
256 return luci.dispatcher.build_url("admin", "services", "olsrd6", "plugins") .. "/" .. lib
257 end
258
259 ign = t:option( Flag, "ignore", translate("Enabled") )
260 ign.enabled = "0"
261 ign.disabled = "1"
262 ign.rmempty = false
263 function ign.cfgvalue(self, section)
264 return Flag.cfgvalue(self, section) or "0"
265 end
266
267 t:option( DummyValue, "library", translate("Library") )
268
269 return mpi
270 end