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
16 local ip = require "luci.ip"
17 local fs = require "nixio.fs"
20 mp = Map("olsrd", translate("OLSR - Plugins"))
22 p = mp:section(TypedSection, "LoadPlugin", translate("Plugin configuration"))
23 p:depends("library", arg[1])
26 ign = p:option(Flag, "ignore", translate("Enable"))
30 function ign.cfgvalue(self, section)
31 return Flag.cfgvalue(self, section) or "0"
34 lib = p:option(DummyValue, "library", translate("Library"))
37 local function Range(x,y)
39 for i = x, y do t[#t+1] = i end
43 local function Cidr2IpMask(val)
46 local cidr = ip.IPv4(val[i]) or ip.IPv6(val[i])
48 val[i] = cidr:network():string() .. " " .. cidr:mask():string()
55 local function IpMask2Cidr(val)
58 local ip, mask = val[i]:gmatch("([^%s]+)%s+([^%s]+)")()
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)
67 val[i] = cidr:string()
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" }
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 }
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", IpMask2Cidr, Cidr2IpMask }
97 { DynamicList, "Net", "0.0.0.0/0", 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 { DynamicList, "service", "http://me.olsr:80|tcp|my little homepage" },
117 { Value, "services_file", "/var/run/services_olsr" },
118 { Value, "services_change_script", "/usr/local/bin/announce_new_services.sh" },
119 { DynamicList, "mac", "xx:xx:xx:xx:xx:xx[,0-255]" },
120 { Value, "macs_file", "/path/to/macs_file" },
121 { Value, "macs_change_script", "/path/to/script" }
124 ["olsrd_quagga.so.0.2.2"] = {
125 { StaticList, "redistribute", {
126 "system", "kernel", "connect", "static", "rip", "ripng", "ospf",
127 "ospf6", "isis", "bgp", "hsls"
129 { ListValue, "ExportRoutes", { "only", "both" } },
130 { Flag, "LocalPref", "true" },
131 { Value, "Distance", Range(0,255) }
134 ["olsrd_secure.so.0.5"] = {
135 { Value, "Keyfile", "/etc/private-olsr.key" }
138 ["olsrd_txtinfo.so.0.1"] = {
139 { Value, "accept", "10.247.200.4" }
142 ["olsrd_watchdog.so.0.1"] = {
143 { Value, "file", "/var/run/olsrd.watchdog" },
144 { Value, "interval", "30" }
147 ["olsrd_mdns.so.1.0.0"] = {
148 { DynamicList, "NonOlsrIf", "lan" }
151 ["olsrd_p2pd.so.0.1.0"] = {
152 { DynamicList, "NonOlsrIf", "lan" },
153 { Value, "P2pdTtl", "10" }
156 ["olsrd_arprefresh.so.0.1"] = {},
157 ["olsrd_dot_draw.so.0.3"] = {},
158 ["olsrd_dyn_gw_plain.so.0.4"] = {},
159 ["olsrd_pgraph.so.1.1"] = {},
160 ["olsrd_tas.so.0.1"] = {}
164 -- build plugin options with dependencies
165 if knownPlParams[arg[1]] then
166 for _, option in ipairs(knownPlParams[arg[1]]) do
167 local otype, name, default, uci2cbi, cbi2uci = unpack(option)
170 if type(default) == "table" then
175 if otype == Flag then
176 local bool = p:option( Flag, name, name )
177 if default == "yes" or default == "no" then
180 elseif default == "on" or default == "off" then
182 bool.disabled = "off"
183 elseif default == "1" or default == "0" then
187 bool.enabled = "true"
188 bool.disabled = "false"
191 bool.default = default
192 bool:depends({ library = plugin })
194 local field = p:option( otype, name, name )
196 for _, value in ipairs(values) do
200 if type(uci2cbi) == "function" then
201 function field.cfgvalue(self, section)
202 return uci2cbi(otype.cfgvalue(self, section))
205 if type(cbi2uci) == "function" then
206 function field.formvalue(self, section)
207 return cbi2uci(otype.formvalue(self, section))
210 field.optional = true
211 field.default = default
212 --field:depends({ library = arg[1] })
221 mpi = Map("olsrd", translate("OLSR - Plugins"))
224 mpi.uci:foreach("olsrd", "LoadPlugin",
226 if section.library and not plugins[section.library] then
227 plugins[section.library] = true
232 -- create a loadplugin section for each found plugin
233 for v in fs.dir("/usr/lib") do
234 if v:sub(1, 6) == "olsrd_" then
235 if not plugins[v] then
237 "olsrd", "LoadPlugin", nil,
238 { library = v, ignore = 1 }
244 t = mpi:section( TypedSection, "LoadPlugin", translate("Plugins") )
246 t.template = "cbi/tblsection"
247 t.override_scheme = true
248 function t.extedit(self, section)
249 local lib = self.map:get(section, "library") or ""
250 return luci.dispatcher.build_url("admin", "services", "olsrd", "plugins") .. "/" .. lib
253 ign = t:option( Flag, "ignore", translate("Enabled") )
257 function ign.cfgvalue(self, section)
258 return Flag.cfgvalue(self, section) or "0"
261 t:option( DummyValue, "library", translate("Library") )