* luci/app-olsr: improved plugin handling

This commit is contained in:
Jo-Philipp Wich 2008-09-13 17:24:35 +00:00
parent 2a88e23db5
commit b00102c8b7
3 changed files with 210 additions and 149 deletions

View file

@ -43,10 +43,24 @@ function index()
cbi("olsr/olsrdhna"), "HNA Announcements"
).i18n = "olsr"
entry(
oplg = entry(
{"admin", "services", "olsrd", "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
function action_index()

View file

@ -11,8 +11,8 @@ You may obtain a copy of the License at
$Id$
]]--
require("luci.tools.webadmin")
require("luci.fs")
m = Map("olsrd", "OLSR")
@ -97,9 +97,9 @@ i.anonymous = true
i.addremove = true
i.dynamic = true
ign = i:option(Flag, "ignore")
ign.enabled = "1"
ign.disabled = "0"
ign = i:option(Flag, "ignore", "Enable")
ign.enabled = "0"
ign.disabled = "1"
network = i:option(ListValue, "interface", translate("network"))
luci.tools.webadmin.cbi_add_networks(network)

View file

@ -15,33 +15,31 @@ $Id$
require("luci.fs")
require("luci.ip")
mp = Map("olsrd", "OLSR - Plugins")
p = mp:section(TypedSection, "LoadPlugin")
p.addremove = true
p.dynamic = true
p.anonymous = true
if arg[1] then
mp = Map("olsrd", "OLSR - Plugins")
ign = p:option(Flag, "ignore")
ign.enabled = "1"
ign.disabled = "0"
ign.optional = true
p = mp:section(TypedSection, "LoadPlugin")
p:depends("library", arg[1])
p.anonymous = true
lib = p:option(ListValue, "library", translate("library"))
lib:value("")
for k, v in pairs(luci.fs.dir("/usr/lib")) do
if v:sub(1, 6) == "olsrd_" then
lib:value(v)
ign = p:option(Flag, "ignore", "Enable")
ign.enabled = "0"
ign.disabled = "1"
function ign.cfgvalue(self, section)
return Flag.cfgvalue(self, section) or "0"
end
end
local function Range(x,y)
lib = p:option(DummyValue, "library", translate("library"))
lib.default = arg[1]
local function Range(x,y)
local t = {}
for i = x, y do t[#t+1] = i end
return t
end
end
local function Cidr2IpMask(val)
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])
@ -51,9 +49,9 @@ local function Cidr2IpMask(val)
end
return val
end
end
end
local function IpMask2Cidr(val)
local function IpMask2Cidr(val)
if val then
for i = 1, #val do
local ip, mask = val[i]:gmatch("([^%s+])%s+([^%s+])")()
@ -70,10 +68,10 @@ local function IpMask2Cidr(val)
end
return val
end
end
end
local knownPlParams = {
local knownPlParams = {
["olsrd_bmf.so.1.5.3"] = {
{ Value, "BmfInterface", "bmf0" },
{ Value, "BmfInterfaceIp", "10.10.10.234/24" },
@ -132,13 +130,19 @@ local knownPlParams = {
["olsrd_txtinfo.so.0.1"] = {
{ 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
for plugin, options in pairs(knownPlParams) do
for _, option in ipairs(options) do
-- build plugin options with dependencies
if knownPlParams[arg[1]] then
for _, option in ipairs(knownPlParams[arg[1]]) do
local otype, name, default, uci2cbi, cbi2uci = unpack(option)
local values
@ -182,14 +186,57 @@ for plugin, options in pairs(knownPlParams) do
return cbi2uci(otype.formvalue(self, section))
end
end
if otype == DynamicList then
field:value( default )
end
field.optional = true
field.default = default
field:depends({ library = plugin })
--field:depends({ library = arg[1] })
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