2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>
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
11 http://www.apache.org/licenses/LICENSE-2.0
21 mp = Map("olsrd", translate("olsrd_plugins", "OLSR - Plugins"))
23 p = mp:section(TypedSection, "LoadPlugin")
24 p:depends("library", arg[1])
27 ign = p:option(Flag, "ignore", "Enable")
31 function ign.cfgvalue(self, section)
32 return Flag.cfgvalue(self, section) or "0"
35 lib = p:option(DummyValue, "library", translate("library"))
38 local function Range(x,y)
40 for i = x, y do t[#t+1] = i end
44 local function Cidr2IpMask(val)
47 local cidr = luci.ip.IPv4(val[i]) or luci.ip.IPv6(val[i])
49 val[i] = cidr:network():string() .. " " .. cidr:mask():string()
56 local function IpMask2Cidr(val)
59 local ip, mask = val[i]:gmatch("([^%s+])%s+([^%s+])")()
61 if ip and mask and ip:match(":") then
62 cidr = luci.ip.IPv6(ip, mask)
63 elseif ip and mask then
64 cidr = luci.ip.IPv4(ip, mask)
68 val[i] = cidr:string()
76 local knownPlParams = {
77 ["olsrd_bmf.so.1.5.3"] = {
78 { Value, "BmfInterface", "bmf0" },
79 { Value, "BmfInterfaceIp", "10.10.10.234/24" },
80 { Flag, "DoLocalBroadcast", "no" },
81 { Flag, "CapturePacketsOnOlsrInterfaces", "yes" },
82 { ListValue, "BmfMechanism", { "UnicastPromiscuous", "Broadcast" } },
83 { Value, "BroadcastRetransmitCount", "2" },
84 { Value, "FanOutLimit", "4" },
85 { DynamicList, "NonOlsrIf", "br-lan" }
88 ["olsrd_dyn_gw.so.0.4"] = {
89 { Value, "Interval", "40" },
90 { DynamicList, "Ping", "141.1.1.1" },
91 { DynamicList, "HNA", "192.168.80.0/24", IpMask2Cidr, Cidr2IpMask }
94 ["olsrd_httpinfo.so.0.1"] = {
95 { Value, "port", "80" },
96 { DynamicList, "Host", "163.24.87.3" },
97 { DynamicList, "Net", "0.0.0.0/0", IpMask2Cidr, Cidr2IpMask }
100 ["olsrd_nameservice.so.0.3"] = {
101 { DynamicList, "name", "my-name.mesh" },
102 { DynamicList, "hosts", "1.2.3.4 name-for-other-interface.mesh" },
103 { Value, "suffix", ".olsr" },
104 { Value, "hosts_file", "/path/to/hosts_file" },
105 { Value, "add_hosts", "/path/to/file" },
106 { Value, "dns_server", "141.1.1.1" },
107 { Value, "resolv_file", "/path/to/resolv.conf" },
108 { Value, "interval", "120" },
109 { Value, "timeout", "240" },
110 { Value, "lat", "12.123" },
111 { Value, "lon", "12.123" },
112 { Value, "latlon_file", "/var/run/latlon.js" },
113 { Value, "latlon_infile", "/var/run/gps.txt" },
114 { Value, "sighup_pid_file", "/var/run/dnsmasq.pid" },
115 { Value, "name_change_script", "/usr/local/bin/announce_new_hosts.sh" },
116 { Value, "services_change_script", "/usr/local/bin/announce_new_services.sh" }
119 ["olsrd_quagga.so.0.2.2"] = {
120 { StaticList, "redistribute", {
121 "system", "kernel", "connect", "static", "rip", "ripng", "ospf",
122 "ospf6", "isis", "bgp", "hsls"
124 { ListValue, "ExportRoutes", { "only", "both" } },
125 { Flag, "LocalPref", "true" },
126 { Value, "Distance", Range(0,255) }
129 ["olsrd_secure.so.0.5"] = {
130 { Value, "Keyfile", "/etc/private-olsr.key" }
133 ["olsrd_txtinfo.so.0.1"] = {
134 { Value, "accept", "10.247.200.4" }
137 ["olsrd_watchdog.so.0.1"] = {
138 { Value, "file", "/var/run/olsrd.watchdog" },
139 { Value, "interval", "30" }
142 ["olsrd_mdns.so.1.0.0"] = {
143 { DynamicList, "NonOlsrIf", "br-lan" }
146 ["olsrd_arprefresh.so.0.1"] = {},
147 ["olsrd_dot_draw.so.0.3"] = {},
148 ["olsrd_dyn_gw_plain.so.0.4"] = {},
149 ["olsrd_pgraph.so.1.1"] = {},
150 ["olsrd_tas.so.0.1"] = {}
154 -- build plugin options with dependencies
155 if knownPlParams[arg[1]] then
156 for _, option in ipairs(knownPlParams[arg[1]]) do
157 local otype, name, default, uci2cbi, cbi2uci = unpack(option)
160 if type(default) == "table" then
165 if otype == Flag then
166 local bool = p:option( Flag, name )
167 if default == "yes" or default == "no" then
170 elseif default == "on" or default == "off" then
172 bool.disabled = "off"
173 elseif default == "1" or default == "0" then
177 bool.enabled = "true"
178 bool.disabled = "false"
181 bool.default = default
182 bool:depends({ library = plugin })
184 local field = p:option( otype, name )
186 for _, value in ipairs(values) do
190 if type(uci2cbi) == "function" then
191 function field.cfgvalue(self, section)
192 return uci2cbi(otype.cfgvalue(self, section))
195 if type(cbi2uci) == "function" then
196 function field.formvalue(self, section)
197 return cbi2uci(otype.formvalue(self, section))
200 field.optional = true
201 field.default = default
202 --field:depends({ library = arg[1] })
211 mpi = Map("olsrd", "OLSR - Plugins")
214 mpi.uci:foreach("olsrd", "LoadPlugin",
216 if section.library and not plugins[section.library] then
217 plugins[section.library] = true
222 -- create a loadplugin section for each found plugin
223 for k, v in pairs(luci.fs.dir("/usr/lib")) do
224 if v:sub(1, 6) == "olsrd_" then
225 if not plugins[v] then
227 "olsrd", "LoadPlugin", nil,
228 { library = v, ignore = 1 }
234 t = mpi:section( TypedSection, "LoadPlugin", "Plugins" )
236 t.template = "cbi/tblsection"
237 t.override_scheme = true
238 function t.extedit(self, section)
239 local lib = self.map:get(section, "library") or ""
240 return luci.dispatcher.build_url("admin", "services", "olsrd", "plugins") .. "/" .. lib
243 ign = t:option( Flag, "ignore", "Enabled" )
247 function ign.cfgvalue(self, section)
248 return Flag.cfgvalue(self, section) or "0"
251 t:option( DummyValue, "library", "Library" )