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
19 require("luci.model.uci")
21 local conf = luci.model.uci.get_all("olsr")
23 local function _value(val)
24 if val:match("^[0-9%. \t]+$") or val == "yes" or val == "no" then
27 return string.format( '"%s"', val )
31 local function _section(sect,sval,parstr)
36 rv = string.format( '%s "%s"\n{\n', conf[sect][".type"], conf[sect][sval] )
40 for k, v in luci.util.spairs(conf[sect]) do
41 if k:sub(1,1) ~= '.' and k ~= sval then
43 rv = rv .. string.format(
46 k:gsub( "_", "-" ), -- XXX: find a better solution for this
50 rv = rv .. string.format(
65 local function _hna(sval)
66 local rv = string.format( "%s\n{\n", sval )
68 for k, v in luci.util.spairs(conf) do
69 if conf[k][".type"] == sval and conf[k].NetAddr and conf[k].Prefix then
70 rv = rv .. string.format(
81 local function _ipc(sval)
82 local rv = string.format( "%s\n{\n", sval )
84 for k, v in luci.util.spairs(conf[sval]) do
85 if k:sub(1,1) ~= "." then
86 local vals = luci.util.split(v, "%s+", nil, true)
90 rv = rv .. string.format(
95 elseif k == "Host" then
96 for i, v in ipairs(vals) do
97 rv = rv .. string.format(
103 rv = rv .. string.format(
115 -- general config section
116 print( _section("general") )
118 -- plugin config sections
119 for k, v in luci.util.spairs(conf) do
120 if conf[k][".type"] == "LoadPlugin" then
121 print( _section( k, "Library", "PlParam" ) )
125 -- interface config sections
126 for k, v in luci.util.spairs(conf) do
127 if conf[k][".type"] == "Interface" then
128 print( _section( k, "Interface" ) )
132 -- write Hna4, Hna6 sections
133 print( _hna("Hna4") )
134 print( _hna("Hna6") )
136 -- write IpcConnect section
137 print( _ipc("IpcConnect") )