* luci/app-olsr: improved plugin handling
This commit is contained in:
parent
2a88e23db5
commit
b00102c8b7
3 changed files with 210 additions and 149 deletions
|
@ -43,10 +43,24 @@ function index()
|
||||||
cbi("olsr/olsrdhna"), "HNA Announcements"
|
cbi("olsr/olsrdhna"), "HNA Announcements"
|
||||||
).i18n = "olsr"
|
).i18n = "olsr"
|
||||||
|
|
||||||
entry(
|
oplg = entry(
|
||||||
{"admin", "services", "olsrd", "plugins"},
|
{"admin", "services", "olsrd", "plugins"},
|
||||||
cbi("olsr/olsrdplugins"), "Plugins"
|
cbi("olsr/olsrdplugins"), "Plugins"
|
||||||
).i18n = "olsr"
|
)
|
||||||
|
oplg.i18n = "olsr"
|
||||||
|
oplg.leaf = true
|
||||||
|
|
||||||
|
local uci = require("luci.model.uci").cursor()
|
||||||
|
uci:foreach("olsrd", "LoadPlugin",
|
||||||
|
function (section)
|
||||||
|
local lib = section.library
|
||||||
|
entry(
|
||||||
|
{"admin", "services", "olsrd", "plugins", lib },
|
||||||
|
cbi("olsr/olsrdplugins"),
|
||||||
|
nil --'Plugin "%s"' % lib:gsub("^olsrd_",""):gsub("%.so.+$","")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function action_index()
|
function action_index()
|
||||||
|
|
|
@ -11,8 +11,8 @@ You may obtain a copy of the License at
|
||||||
|
|
||||||
$Id$
|
$Id$
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
require("luci.tools.webadmin")
|
require("luci.tools.webadmin")
|
||||||
require("luci.fs")
|
|
||||||
|
|
||||||
m = Map("olsrd", "OLSR")
|
m = Map("olsrd", "OLSR")
|
||||||
|
|
||||||
|
@ -97,9 +97,9 @@ i.anonymous = true
|
||||||
i.addremove = true
|
i.addremove = true
|
||||||
i.dynamic = true
|
i.dynamic = true
|
||||||
|
|
||||||
ign = i:option(Flag, "ignore")
|
ign = i:option(Flag, "ignore", "Enable")
|
||||||
ign.enabled = "1"
|
ign.enabled = "0"
|
||||||
ign.disabled = "0"
|
ign.disabled = "1"
|
||||||
|
|
||||||
network = i:option(ListValue, "interface", translate("network"))
|
network = i:option(ListValue, "interface", translate("network"))
|
||||||
luci.tools.webadmin.cbi_add_networks(network)
|
luci.tools.webadmin.cbi_add_networks(network)
|
||||||
|
|
|
@ -15,181 +15,228 @@ $Id$
|
||||||
require("luci.fs")
|
require("luci.fs")
|
||||||
require("luci.ip")
|
require("luci.ip")
|
||||||
|
|
||||||
mp = Map("olsrd", "OLSR - Plugins")
|
|
||||||
|
|
||||||
p = mp:section(TypedSection, "LoadPlugin")
|
if arg[1] then
|
||||||
p.addremove = true
|
mp = Map("olsrd", "OLSR - Plugins")
|
||||||
p.dynamic = true
|
|
||||||
p.anonymous = true
|
|
||||||
|
|
||||||
ign = p:option(Flag, "ignore")
|
p = mp:section(TypedSection, "LoadPlugin")
|
||||||
ign.enabled = "1"
|
p:depends("library", arg[1])
|
||||||
ign.disabled = "0"
|
p.anonymous = true
|
||||||
ign.optional = true
|
|
||||||
|
|
||||||
lib = p:option(ListValue, "library", translate("library"))
|
ign = p:option(Flag, "ignore", "Enable")
|
||||||
lib:value("")
|
ign.enabled = "0"
|
||||||
for k, v in pairs(luci.fs.dir("/usr/lib")) do
|
ign.disabled = "1"
|
||||||
if v:sub(1, 6) == "olsrd_" then
|
function ign.cfgvalue(self, section)
|
||||||
lib:value(v)
|
return Flag.cfgvalue(self, section) or "0"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local function Range(x,y)
|
lib = p:option(DummyValue, "library", translate("library"))
|
||||||
local t = {}
|
lib.default = arg[1]
|
||||||
for i = x, y do t[#t+1] = i end
|
|
||||||
return t
|
|
||||||
end
|
|
||||||
|
|
||||||
local function Cidr2IpMask(val)
|
local function Range(x,y)
|
||||||
if val then
|
local t = {}
|
||||||
for i = 1, #val do
|
for i = x, y do t[#t+1] = i end
|
||||||
local cidr = luci.ip.IPv4(val[i]) or luci.ip.IPv6(val[i])
|
return t
|
||||||
if cidr then
|
end
|
||||||
val[i] = cidr:network():string() .. " " .. cidr:mask():string()
|
|
||||||
|
local function Cidr2IpMask(val)
|
||||||
|
if val then
|
||||||
|
for i = 1, #val do
|
||||||
|
local cidr = luci.ip.IPv4(val[i]) or luci.ip.IPv6(val[i])
|
||||||
|
if cidr then
|
||||||
|
val[i] = cidr:network():string() .. " " .. cidr:mask():string()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
return val
|
||||||
end
|
end
|
||||||
return val
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local function IpMask2Cidr(val)
|
local function IpMask2Cidr(val)
|
||||||
if val then
|
if val then
|
||||||
for i = 1, #val do
|
for i = 1, #val do
|
||||||
local ip, mask = val[i]:gmatch("([^%s+])%s+([^%s+])")()
|
local ip, mask = val[i]:gmatch("([^%s+])%s+([^%s+])")()
|
||||||
local cidr
|
local cidr
|
||||||
if ip and mask and ip:match(":") then
|
if ip and mask and ip:match(":") then
|
||||||
cidr = luci.ip.IPv6(ip, mask)
|
cidr = luci.ip.IPv6(ip, mask)
|
||||||
elseif ip and mask then
|
elseif ip and mask then
|
||||||
cidr = luci.ip.IPv4(ip, mask)
|
cidr = luci.ip.IPv4(ip, mask)
|
||||||
end
|
end
|
||||||
|
|
||||||
if cidr then
|
if cidr then
|
||||||
val[i] = cidr:string()
|
val[i] = cidr:string()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
return val
|
||||||
end
|
end
|
||||||
return val
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local knownPlParams = {
|
local knownPlParams = {
|
||||||
["olsrd_bmf.so.1.5.3"] = {
|
["olsrd_bmf.so.1.5.3"] = {
|
||||||
{ Value, "BmfInterface", "bmf0" },
|
{ Value, "BmfInterface", "bmf0" },
|
||||||
{ Value, "BmfInterfaceIp", "10.10.10.234/24" },
|
{ Value, "BmfInterfaceIp", "10.10.10.234/24" },
|
||||||
{ Flag, "DoLocalBroadcast", "no" },
|
{ Flag, "DoLocalBroadcast", "no" },
|
||||||
{ Flag, "CapturePacketsOnOlsrInterfaces", "yes" },
|
{ Flag, "CapturePacketsOnOlsrInterfaces", "yes" },
|
||||||
{ ListValue, "BmfMechanism", { "UnicastPromiscuous", "Broadcast" } },
|
{ ListValue, "BmfMechanism", { "UnicastPromiscuous", "Broadcast" } },
|
||||||
{ Value, "BroadcastRetransmitCount", "2" },
|
{ Value, "BroadcastRetransmitCount", "2" },
|
||||||
{ Value, "FanOutLimit", "4" },
|
{ Value, "FanOutLimit", "4" },
|
||||||
{ DynamicList, "NonOlsrIf", "eth1" }
|
{ DynamicList, "NonOlsrIf", "eth1" }
|
||||||
},
|
},
|
||||||
|
|
||||||
["olsrd_dyn_gw.so.0.4"] = {
|
["olsrd_dyn_gw.so.0.4"] = {
|
||||||
{ Value, "Interval", "40" },
|
{ Value, "Interval", "40" },
|
||||||
{ DynamicList, "Ping", "141.1.1.1" },
|
{ DynamicList, "Ping", "141.1.1.1" },
|
||||||
{ DynamicList, "HNA", "192.168.80.0/24", IpMask2Cidr, Cidr2IpMask }
|
{ DynamicList, "HNA", "192.168.80.0/24", IpMask2Cidr, Cidr2IpMask }
|
||||||
},
|
},
|
||||||
|
|
||||||
["olsrd_httpinfo.so.0.1"] = {
|
["olsrd_httpinfo.so.0.1"] = {
|
||||||
{ Value, "port", "80" },
|
{ Value, "port", "80" },
|
||||||
{ DynamicList, "Host", "163.24.87.3" },
|
{ DynamicList, "Host", "163.24.87.3" },
|
||||||
{ DynamicList, "Net", "0.0.0.0/0", IpMask2Cidr, Cidr2IpMask }
|
{ DynamicList, "Net", "0.0.0.0/0", IpMask2Cidr, Cidr2IpMask }
|
||||||
},
|
},
|
||||||
|
|
||||||
["olsrd_nameservice.so.0.3"] = {
|
["olsrd_nameservice.so.0.3"] = {
|
||||||
{ DynamicList, "name", "my-name.mesh" },
|
{ DynamicList, "name", "my-name.mesh" },
|
||||||
{ DynamicList, "hosts", "1.2.3.4 name-for-other-interface.mesh" },
|
{ DynamicList, "hosts", "1.2.3.4 name-for-other-interface.mesh" },
|
||||||
{ Value, "suffix", ".olsr" },
|
{ Value, "suffix", ".olsr" },
|
||||||
{ Value, "hosts_file", "/path/to/hosts_file" },
|
{ Value, "hosts_file", "/path/to/hosts_file" },
|
||||||
{ Value, "add_hosts", "/path/to/file" },
|
{ Value, "add_hosts", "/path/to/file" },
|
||||||
{ Value, "dns_server", "141.1.1.1" },
|
{ Value, "dns_server", "141.1.1.1" },
|
||||||
{ Value, "resolv_file", "/path/to/resolv.conf" },
|
{ Value, "resolv_file", "/path/to/resolv.conf" },
|
||||||
{ Value, "interval", "120" },
|
{ Value, "interval", "120" },
|
||||||
{ Value, "timeout", "240" },
|
{ Value, "timeout", "240" },
|
||||||
{ Value, "lat", "12.123" },
|
{ Value, "lat", "12.123" },
|
||||||
{ Value, "lon", "12.123" },
|
{ Value, "lon", "12.123" },
|
||||||
{ Value, "latlon_file", "/var/run/latlon.js" },
|
{ Value, "latlon_file", "/var/run/latlon.js" },
|
||||||
{ Value, "latlon_infile", "/var/run/gps.txt" },
|
{ Value, "latlon_infile", "/var/run/gps.txt" },
|
||||||
{ Value, "sighup_pid_file", "/var/run/dnsmasq.pid" },
|
{ Value, "sighup_pid_file", "/var/run/dnsmasq.pid" },
|
||||||
{ Value, "name_change_script", "/usr/local/bin/announce_new_hosts.sh" },
|
{ Value, "name_change_script", "/usr/local/bin/announce_new_hosts.sh" },
|
||||||
{ Value, "services_change_script", "/usr/local/bin/announce_new_services.sh" }
|
{ Value, "services_change_script", "/usr/local/bin/announce_new_services.sh" }
|
||||||
},
|
},
|
||||||
|
|
||||||
["olsrd_quagga.so.0.2.2"] = {
|
["olsrd_quagga.so.0.2.2"] = {
|
||||||
{ StaticList, "redistribute", {
|
{ StaticList, "redistribute", {
|
||||||
"system", "kernel", "connect", "static", "rip", "ripng", "ospf",
|
"system", "kernel", "connect", "static", "rip", "ripng", "ospf",
|
||||||
"ospf6", "isis", "bgp", "hsls"
|
"ospf6", "isis", "bgp", "hsls"
|
||||||
} },
|
} },
|
||||||
{ ListValue, "ExportRoutes", { "only", "both" } },
|
{ ListValue, "ExportRoutes", { "only", "both" } },
|
||||||
{ Flag, "LocalPref", "true" },
|
{ Flag, "LocalPref", "true" },
|
||||||
{ Value, "Distance", Range(0,255) }
|
{ Value, "Distance", Range(0,255) }
|
||||||
},
|
},
|
||||||
|
|
||||||
["olsrd_secure.so.0.5"] = {
|
["olsrd_secure.so.0.5"] = {
|
||||||
{ Value, "Keyfile", "/etc/private-olsr.key" }
|
{ Value, "Keyfile", "/etc/private-olsr.key" }
|
||||||
},
|
},
|
||||||
|
|
||||||
["olsrd_txtinfo.so.0.1"] = {
|
["olsrd_txtinfo.so.0.1"] = {
|
||||||
{ Value, "accept", "10.247.200.4" }
|
{ Value, "accept", "10.247.200.4" }
|
||||||
|
},
|
||||||
|
|
||||||
|
["olsrd_arprefresh.so.0.1"] = {},
|
||||||
|
["olsrd_dot_draw.so.0.3"] = {},
|
||||||
|
["olsrd_dyn_gw_plain.so.0.4"] = {},
|
||||||
|
["olsrd_pgraph.so.1.1"] = {},
|
||||||
|
["olsrd_tas.so.0.1"] = {}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
-- build plugin options with dependencies
|
-- build plugin options with dependencies
|
||||||
for plugin, options in pairs(knownPlParams) do
|
if knownPlParams[arg[1]] then
|
||||||
for _, option in ipairs(options) do
|
for _, option in ipairs(knownPlParams[arg[1]]) do
|
||||||
local otype, name, default, uci2cbi, cbi2uci = unpack(option)
|
local otype, name, default, uci2cbi, cbi2uci = unpack(option)
|
||||||
local values
|
local values
|
||||||
|
|
||||||
if type(default) == "table" then
|
if type(default) == "table" then
|
||||||
values = default
|
values = default
|
||||||
default = default[1]
|
default = default[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
if otype == Flag then
|
if otype == Flag then
|
||||||
local bool = p:option( Flag, name )
|
local bool = p:option( Flag, name )
|
||||||
if default == "yes" or default == "no" then
|
if default == "yes" or default == "no" then
|
||||||
bool.enabled = "yes"
|
bool.enabled = "yes"
|
||||||
bool.disabled = "no"
|
bool.disabled = "no"
|
||||||
elseif default == "on" or default == "off" then
|
elseif default == "on" or default == "off" then
|
||||||
bool.enabled = "on"
|
bool.enabled = "on"
|
||||||
bool.disabled = "off"
|
bool.disabled = "off"
|
||||||
elseif default == "1" or default == "0" then
|
elseif default == "1" or default == "0" then
|
||||||
bool.enabled = "1"
|
bool.enabled = "1"
|
||||||
bool.disabled = "0"
|
bool.disabled = "0"
|
||||||
|
else
|
||||||
|
bool.enabled = "true"
|
||||||
|
bool.disabled = "false"
|
||||||
|
end
|
||||||
|
bool.optional = true
|
||||||
|
bool.default = default
|
||||||
|
bool:depends({ library = plugin })
|
||||||
else
|
else
|
||||||
bool.enabled = "true"
|
local field = p:option( otype, name )
|
||||||
bool.disabled = "false"
|
if values then
|
||||||
end
|
for _, value in ipairs(values) do
|
||||||
bool.optional = true
|
field:value( value )
|
||||||
bool.default = default
|
end
|
||||||
bool:depends({ library = plugin })
|
|
||||||
else
|
|
||||||
local field = p:option( otype, name )
|
|
||||||
if values then
|
|
||||||
for _, value in ipairs(values) do
|
|
||||||
field:value( value )
|
|
||||||
end
|
end
|
||||||
end
|
if type(uci2cbi) == "function" then
|
||||||
if type(uci2cbi) == "function" then
|
function field.cfgvalue(self, section)
|
||||||
function field.cfgvalue(self, section)
|
return uci2cbi(otype.cfgvalue(self, section))
|
||||||
return uci2cbi(otype.cfgvalue(self, section))
|
end
|
||||||
end
|
end
|
||||||
end
|
if type(cbi2uci) == "function" then
|
||||||
if type(cbi2uci) == "function" then
|
function field.formvalue(self, section)
|
||||||
function field.formvalue(self, section)
|
return cbi2uci(otype.formvalue(self, section))
|
||||||
return cbi2uci(otype.formvalue(self, section))
|
end
|
||||||
end
|
end
|
||||||
|
field.optional = true
|
||||||
|
field.default = default
|
||||||
|
--field:depends({ library = arg[1] })
|
||||||
end
|
end
|
||||||
if otype == DynamicList then
|
|
||||||
field:value( default )
|
|
||||||
end
|
|
||||||
field.optional = true
|
|
||||||
field.default = default
|
|
||||||
field:depends({ library = plugin })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
return mp
|
return mp
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
mpi = Map("olsrd", "OLSR - Plugins")
|
||||||
|
|
||||||
|
local plugins = {}
|
||||||
|
mpi.uci:foreach("olsrd", "LoadPlugin",
|
||||||
|
function(section)
|
||||||
|
if section.library and not plugins[section.library] then
|
||||||
|
plugins[section.library] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
-- create a loadplugin section for each found plugin
|
||||||
|
for k, v in pairs(luci.fs.dir("/usr/lib")) do
|
||||||
|
if v:sub(1, 6) == "olsrd_" then
|
||||||
|
if not plugins[v] then
|
||||||
|
mpi.uci:section(
|
||||||
|
"olsrd", "LoadPlugin", nil,
|
||||||
|
{ library = v, ignore = 1 }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
t = mpi:section( TypedSection, "LoadPlugin", "Plugins" )
|
||||||
|
t.anonymous = true
|
||||||
|
t.template = "cbi/tblsection"
|
||||||
|
t.override_scheme = true
|
||||||
|
function t.extedit(self, section)
|
||||||
|
local lib = self.map:get(section, "library") or ""
|
||||||
|
return luci.dispatcher.build_url("admin", "services", "olsrd", "plugins") .. "/" .. lib
|
||||||
|
end
|
||||||
|
|
||||||
|
ign = t:option( Flag, "ignore", "Enabled" )
|
||||||
|
ign.enabled = "0"
|
||||||
|
ign.disabled = "1"
|
||||||
|
function ign.cfgvalue(self, section)
|
||||||
|
return Flag.cfgvalue(self, section) or "0"
|
||||||
|
end
|
||||||
|
|
||||||
|
t:option( DummyValue, "library", "Library" )
|
||||||
|
|
||||||
|
return mpi
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue