2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
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
10 http://www.apache.org/licenses/LICENSE-2.0
20 mp = Map("olsrd", translate("olsrd_plugins", "OLSR - Plugins"))
22 p = mp:section(TypedSection, "LoadPlugin")
23 p:depends("library", arg[1])
26 ign = p:option(Flag, "ignore", "Enable")
29 function ign.cfgvalue(self, section)
30 return Flag.cfgvalue(self, section) or "0"
33 lib = p:option(DummyValue, "library", translate("library"))
36 local function Range(x,y)
38 for i = x, y do t[#t+1] = i end
42 local function Cidr2IpMask(val)
45 local cidr = luci.ip.IPv4(val[i]) or luci.ip.IPv6(val[i])
47 val[i] = cidr:network():string() .. " " .. cidr:mask():string()
54 local function IpMask2Cidr(val)
57 local ip, mask = val[i]:gmatch("([^%s+])%s+([^%s+])")()
59 if ip and mask and ip:match(":") then
60 cidr = luci.ip.IPv6(ip, mask)
61 elseif ip and mask then
62 cidr = luci.ip.IPv4(ip, mask)
66 val[i] = cidr:string()
74 local knownPlParams = {
75 ["olsrd_bmf.so.1.5.3"] = {
76 { Value, "BmfInterface", "bmf0" },
77 { Value, "BmfInterfaceIp", "10.10.10.234/24" },
78 { Flag, "DoLocalBroadcast", "no" },
79 { Flag, "CapturePacketsOnOlsrInterfaces", "yes" },
80 { ListValue, "BmfMechanism", { "UnicastPromiscuous", "Broadcast" } },
81 { Value, "BroadcastRetransmitCount", "2" },
82 { Value, "FanOutLimit", "4" },
83 { DynamicList, "NonOlsrIf", "eth1" }
86 ["olsrd_dyn_gw.so.0.4"] = {
87 { Value, "Interval", "40" },
88 { DynamicList, "Ping", "141.1.1.1" },
89 { DynamicList, "HNA", "192.168.80.0/24", IpMask2Cidr, Cidr2IpMask }
92 ["olsrd_httpinfo.so.0.1"] = {
93 { Value, "port", "80" },
94 { DynamicList, "Host", "163.24.87.3" },
95 { DynamicList, "Net", "0.0.0.0/0", IpMask2Cidr, Cidr2IpMask }
98 ["olsrd_nameservice.so.0.3"] = {
99 { DynamicList, "name", "my-name.mesh" },
100 { DynamicList, "hosts", "1.2.3.4 name-for-other-interface.mesh" },
101 { Value, "suffix", ".olsr" },
102 { Value, "hosts_file", "/path/to/hosts_file" },
103 { Value, "add_hosts", "/path/to/file" },
104 { Value, "dns_server", "141.1.1.1" },
105 { Value, "resolv_file", "/path/to/resolv.conf" },
106 { Value, "interval", "120" },
107 { Value, "timeout", "240" },
108 { Value, "lat", "12.123" },
109 { Value, "lon", "12.123" },
110 { Value, "latlon_file", "/var/run/latlon.js" },
111 { Value, "latlon_infile", "/var/run/gps.txt" },
112 { Value, "sighup_pid_file", "/var/run/dnsmasq.pid" },
113 { Value, "name_change_script", "/usr/local/bin/announce_new_hosts.sh" },
114 { Value, "services_change_script", "/usr/local/bin/announce_new_services.sh" }
117 ["olsrd_quagga.so.0.2.2"] = {
118 { StaticList, "redistribute", {
119 "system", "kernel", "connect", "static", "rip", "ripng", "ospf",
120 "ospf6", "isis", "bgp", "hsls"
122 { ListValue, "ExportRoutes", { "only", "both" } },
123 { Flag, "LocalPref", "true" },
124 { Value, "Distance", Range(0,255) }
127 ["olsrd_secure.so.0.5"] = {
128 { Value, "Keyfile", "/etc/private-olsr.key" }
131 ["olsrd_txtinfo.so.0.1"] = {
132 { Value, "accept", "10.247.200.4" }
135 ["olsrd_arprefresh.so.0.1"] = {},
136 ["olsrd_dot_draw.so.0.3"] = {},
137 ["olsrd_dyn_gw_plain.so.0.4"] = {},
138 ["olsrd_pgraph.so.1.1"] = {},
139 ["olsrd_tas.so.0.1"] = {}
143 -- build plugin options with dependencies
144 if knownPlParams[arg[1]] then
145 for _, option in ipairs(knownPlParams[arg[1]]) do
146 local otype, name, default, uci2cbi, cbi2uci = unpack(option)
149 if type(default) == "table" then
154 if otype == Flag then
155 local bool = p:option( Flag, name )
156 if default == "yes" or default == "no" then
159 elseif default == "on" or default == "off" then
161 bool.disabled = "off"
162 elseif default == "1" or default == "0" then
166 bool.enabled = "true"
167 bool.disabled = "false"
170 bool.default = default
171 bool:depends({ library = plugin })
173 local field = p:option( otype, name )
175 for _, value in ipairs(values) do
179 if type(uci2cbi) == "function" then
180 function field.cfgvalue(self, section)
181 return uci2cbi(otype.cfgvalue(self, section))
184 if type(cbi2uci) == "function" then
185 function field.formvalue(self, section)
186 return cbi2uci(otype.formvalue(self, section))
189 field.optional = true
190 field.default = default
191 --field:depends({ library = arg[1] })
200 mpi = Map("olsrd", "OLSR - Plugins")
203 mpi.uci:foreach("olsrd", "LoadPlugin",
205 if section.library and not plugins[section.library] then
206 plugins[section.library] = true
211 -- create a loadplugin section for each found plugin
212 for k, v in pairs(luci.fs.dir("/usr/lib")) do
213 if v:sub(1, 6) == "olsrd_" then
214 if not plugins[v] then
216 "olsrd", "LoadPlugin", nil,
217 { library = v, ignore = 1 }
223 t = mpi:section( TypedSection, "LoadPlugin", "Plugins" )
225 t.template = "cbi/tblsection"
226 t.override_scheme = true
227 function t.extedit(self, section)
228 local lib = self.map:get(section, "library") or ""
229 return luci.dispatcher.build_url("admin", "services", "olsrd", "plugins") .. "/" .. lib
232 ign = t:option( Flag, "ignore", "Enabled" )
235 function ign.cfgvalue(self, section)
236 return Flag.cfgvalue(self, section) or "0"
239 t:option( DummyValue, "library", "Library" )