1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>
3 -- Licensed to the public under the Apache License 2.0.
5 local ip = require "luci.ip"
6 local fs = require "nixio.fs"
9 mp = Map("olsrd", translate("OLSR - Plugins"))
11 p = mp:section(TypedSection, "LoadPlugin", translate("Plugin configuration"))
12 p:depends("library", arg[1])
15 ign = p:option(Flag, "ignore", translate("Enable"))
19 function ign.cfgvalue(self, section)
20 return Flag.cfgvalue(self, section) or "0"
23 lib = p:option(DummyValue, "library", translate("Library"))
26 local function Range(x,y)
28 for i = x, y do t[#t+1] = i end
32 local function Cidr2IpMask(val)
35 local cidr = ip.IPv4(val[i]) or ip.IPv6(val[i])
37 val[i] = cidr:network():string() .. " " .. cidr:mask():string()
44 local function IpMask2Cidr(val)
47 local ip, mask = val[i]:gmatch("([^%s]+)%s+([^%s]+)")()
49 if ip and mask and ip:match(":") then
50 cidr = ip.IPv6(ip, mask)
51 elseif ip and mask then
52 cidr = ip.IPv4(ip, mask)
56 val[i] = cidr:string()
64 local knownPlParams = {
65 ["olsrd_bmf.so.1.5.3"] = {
66 { Value, "BmfInterface", "bmf0" },
67 { Value, "BmfInterfaceIp", "10.10.10.234/24" },
68 { Flag, "DoLocalBroadcast", "no" },
69 { Flag, "CapturePacketsOnOlsrInterfaces", "yes" },
70 { ListValue, "BmfMechanism", { "UnicastPromiscuous", "Broadcast" } },
71 { Value, "BroadcastRetransmitCount", "2" },
72 { Value, "FanOutLimit", "4" },
73 { DynamicList, "NonOlsrIf", "br-lan" }
76 ["olsrd_dyn_gw.so.0.4"] = {
77 { Value, "Interval", "40" },
78 { DynamicList, "Ping", "141.1.1.1" },
79 { DynamicList, "HNA", "192.168.80.0/24", IpMask2Cidr, Cidr2IpMask }
82 ["olsrd_httpinfo.so.0.1"] = {
83 { Value, "port", "80" },
84 { DynamicList, "Host", "163.24.87.3" },
85 { DynamicList, "Net", "0.0.0.0/0", Cidr2IpMask }
88 ["olsrd_nameservice.so.0.3"] = {
89 { DynamicList, "name", "my-name.mesh" },
90 { DynamicList, "hosts", "1.2.3.4 name-for-other-interface.mesh" },
91 { Value, "suffix", ".olsr" },
92 { Value, "hosts_file", "/path/to/hosts_file" },
93 { Value, "add_hosts", "/path/to/file" },
94 { Value, "dns_server", "141.1.1.1" },
95 { Value, "resolv_file", "/path/to/resolv.conf" },
96 { Value, "interval", "120" },
97 { Value, "timeout", "240" },
98 { Value, "lat", "12.123" },
99 { Value, "lon", "12.123" },
100 { Value, "latlon_file", "/var/run/latlon.js" },
101 { Value, "latlon_infile", "/var/run/gps.txt" },
102 { Value, "sighup_pid_file", "/var/run/dnsmasq.pid" },
103 { Value, "name_change_script", "/usr/local/bin/announce_new_hosts.sh" },
104 { DynamicList, "service", "http://me.olsr:80|tcp|my little homepage" },
105 { Value, "services_file", "/var/run/services_olsr" },
106 { Value, "services_change_script", "/usr/local/bin/announce_new_services.sh" },
107 { DynamicList, "mac", "xx:xx:xx:xx:xx:xx[,0-255]" },
108 { Value, "macs_file", "/path/to/macs_file" },
109 { Value, "macs_change_script", "/path/to/script" }
112 ["olsrd_quagga.so.0.2.2"] = {
113 { StaticList, "redistribute", {
114 "system", "kernel", "connect", "static", "rip", "ripng", "ospf",
115 "ospf6", "isis", "bgp", "hsls"
117 { ListValue, "ExportRoutes", { "only", "both" } },
118 { Flag, "LocalPref", "true" },
119 { Value, "Distance", Range(0,255) }
122 ["olsrd_secure.so.0.5"] = {
123 { Value, "Keyfile", "/etc/private-olsr.key" }
126 ["olsrd_txtinfo.so.0.1"] = {
127 { Value, "accept", "127.0.0.1" }
130 ["olsrd_jsoninfo.so.0.0"] = {
131 { Value, "accept", "127.0.0.1" },
132 { Value, "port", "9090" },
133 { Value, "UUIDFile", "/etc/olsrd/olsrd.uuid" },
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", "lan" }
146 ["olsrd_p2pd.so.0.1.0"] = {
147 { DynamicList, "NonOlsrIf", "lan" },
148 { Value, "P2pdTtl", "10" }
151 ["olsrd_arprefresh.so.0.1"] = {},
152 ["olsrd_dot_draw.so.0.3"] = {},
153 ["olsrd_dyn_gw_plain.so.0.4"] = {},
154 ["olsrd_pgraph.so.1.1"] = {},
155 ["olsrd_tas.so.0.1"] = {}
159 -- build plugin options with dependencies
160 if knownPlParams[arg[1]] then
161 for _, option in ipairs(knownPlParams[arg[1]]) do
162 local otype, name, default, uci2cbi, cbi2uci = unpack(option)
165 if type(default) == "table" then
170 if otype == Flag then
171 local bool = p:option( Flag, name, name )
172 if default == "yes" or default == "no" then
175 elseif default == "on" or default == "off" then
177 bool.disabled = "off"
178 elseif default == "1" or default == "0" then
182 bool.enabled = "true"
183 bool.disabled = "false"
186 bool.default = default
187 bool:depends({ library = plugin })
189 local field = p:option( otype, name, name )
191 for _, value in ipairs(values) do
195 if type(uci2cbi) == "function" then
196 function field.cfgvalue(self, section)
197 return uci2cbi(otype.cfgvalue(self, section))
200 if type(cbi2uci) == "function" then
201 function field.formvalue(self, section)
202 return cbi2uci(otype.formvalue(self, section))
205 field.optional = true
206 field.default = default
207 --field:depends({ library = arg[1] })
216 mpi = Map("olsrd", translate("OLSR - Plugins"))
219 mpi.uci:foreach("olsrd", "LoadPlugin",
221 if section.library and not plugins[section.library] then
222 plugins[section.library] = true
227 -- create a loadplugin section for each found plugin
228 for v in fs.dir("/usr/lib") do
229 if v:sub(1, 6) == "olsrd_" then
230 if not plugins[v] then
232 "olsrd", "LoadPlugin", nil,
233 { library = v, ignore = 1 }
239 t = mpi:section( TypedSection, "LoadPlugin", translate("Plugins") )
241 t.template = "cbi/tblsection"
242 t.override_scheme = true
243 function t.extedit(self, section)
244 local lib = self.map:get(section, "library") or ""
245 return luci.dispatcher.build_url("admin", "services", "olsrd", "plugins") .. "/" .. lib
248 ign = t:option( Flag, "ignore", translate("Enabled") )
252 function ign.cfgvalue(self, section)
253 return Flag.cfgvalue(self, section) or "0"
256 t:option( DummyValue, "library", translate("Library") )