5 OLSRd configuration generator
6 (c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
20 require("luci.model.uci")
22 local conf = luci.model.uci.get_all("olsr")
24 local function _value(val)
25 if val:match("^[0-9%. \t]+$") or val == "yes" or val == "no" then
28 return string.format( '"%s"', val )
32 local function _section(sect,sval,parstr)
37 rv = string.format( '%s "%s"\n{\n', conf[sect][".type"], conf[sect][sval] )
41 for k, v in luci.util.spairs(conf[sect]) do
42 if k:sub(1,1) ~= '.' and k ~= sval then
44 rv = rv .. string.format(
47 k:gsub( "_", "-" ), -- XXX: find a better solution for this
51 rv = rv .. string.format(
66 local function _hna(sval)
67 local rv = string.format( "%s\n{\n", sval )
69 for k, v in luci.util.spairs(conf) do
70 if conf[k][".type"] == sval and conf[k].NetAddr and conf[k].Prefix then
71 rv = rv .. string.format(
82 local function _ipc(sval)
83 local rv = string.format( "%s\n{\n", sval )
85 for k, v in luci.util.spairs(conf[sval]) do
86 if k:sub(1,1) ~= "." then
87 local vals = luci.util.split(v, "%s+", nil, true)
91 rv = rv .. string.format(
96 elseif k == "Host" then
97 for i, v in ipairs(vals) do
98 rv = rv .. string.format(
104 rv = rv .. string.format(
116 -- general config section
117 print( _section("general") )
119 -- plugin config sections
120 for k, v in luci.util.spairs(conf) do
121 if conf[k][".type"] == "LoadPlugin" then
122 if v.Library and luci.fs.access("/usr/lib/"..v.Library) then
123 print( _section( k, "Library", "PlParam" ) )
128 -- interface config sections
129 for k, v in luci.util.spairs(conf) do
130 if conf[k][".type"] == "Interface" then
131 print( _section( k, "Interface" ) )
135 -- write Hna4, Hna6 sections
136 print( _hna("Hna4") )
137 print( _hna("Hna6") )
139 -- write IpcConnect section
140 print( _ipc("IpcConnect") )