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
14 $Id: olsr.lua 2516 2008-07-06 13:34:07Z jow $
19 require("luci.model.uci")
21 luci.model.uci.load_state("network")
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)
39 if sval == "Interface" then
40 val = luci.model.uci.get( "network", conf[sect][sval], "ifname" )
42 val = conf[sect][sval]
45 rv = string.format( '%s "%s"\n{\n', conf[sect][".type"], val )
49 for k, v in luci.util.spairs(conf[sect]) do
50 if k:sub(1,1) ~= '.' and k ~= sval then
52 rv = rv .. string.format(
55 k:gsub( "_", "-" ), -- XXX: find a better solution for this
59 rv = rv .. string.format(
74 local function _hna(sval)
75 local rv = string.format( "%s\n{\n", sval )
78 for k, v in luci.util.spairs(conf) do
79 if conf[k][".type"] == sval and conf[k].NetAddr and conf[k].Prefix then
81 rv = rv .. string.format(
89 return ( cnt > 0 and rv .. "}\n" or "" )
92 local function _ipc(sval)
93 if conf[sval] and ( conf[sval].MaxConnections == nil or tonumber(conf[sval].MaxConnections) > 0 ) then
94 local rv = string.format( "%s\n{\n", sval )
96 for k, v in luci.util.spairs(conf[sval]) do
97 if k:sub(1,1) ~= "." then
98 local vals = luci.util.split(v, "%s+", nil, true)
102 rv = rv .. string.format(
107 elseif k == "Host" then
108 for i, v in ipairs(vals) do
109 rv = rv .. string.format(
115 rv = rv .. string.format(
130 -- general config section
131 print( _section("general") )
133 -- plugin config sections
134 for k, v in luci.util.spairs(conf) do
135 if conf[k][".type"] == "LoadPlugin" then
136 print( _section( k, "Library", "PlParam" ) )
140 -- interface config sections
141 for k, v in luci.util.spairs(conf) do
142 if conf[k][".type"] == "Interface" then
143 print( _section( k, "Interface" ) )
147 -- write Hna4, Hna6 sections
148 print( _hna("Hna4") )
149 print( _hna("Hna6") )
151 -- write IpcConnect section
152 print( _ipc("IpcConnect") )