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 uci = luci.model.uci.cursor()
23 local conf = uci:get_all("olsr")
25 local function _value(val)
26 if val:match("^[0-9%. \t]+$") or val == "yes" or val == "no" then
29 return string.format( '"%s"', val )
33 local function _section(sect,sval,parstr)
38 if sval == "Interface" then
39 rv = string.format( 'Interface "%s"\n{\n', uci:get("network",conf[sect][sval],"ifname") )
41 rv = string.format( '%s "%s"\n{\n', conf[sect][".type"], conf[sect][sval] )
46 for k, v in luci.util.spairs(conf[sect]) do
47 if k:sub(1,1) ~= '.' and k ~= sval then
49 rv = rv .. string.format(
52 k:gsub( "_", "-" ), -- XXX: find a better solution for this
56 rv = rv .. string.format(
71 local function _hna(sval)
72 local rv = string.format( "%s\n{\n", sval )
74 for k, v in luci.util.spairs(conf) do
75 if conf[k][".type"] == sval and conf[k].NetAddr and conf[k].Prefix then
76 rv = rv .. string.format(
87 local function _ipc(sval)
88 local rv = string.format( "%s\n{\n", sval )
90 for k, v in luci.util.spairs(conf[sval]) do
91 if k:sub(1,1) ~= "." then
92 local vals = luci.util.split(v, "%s+", nil, true)
96 rv = rv .. string.format(
101 elseif k == "Host" then
102 for i, v in ipairs(vals) do
103 rv = rv .. string.format(
109 rv = rv .. string.format(
121 -- general config section
122 print( _section("general") )
124 -- plugin config sections
125 for k, v in luci.util.spairs(conf) do
126 if conf[k][".type"] == "LoadPlugin" then
127 if v.Library and luci.fs.access("/usr/lib/"..v.Library) then
128 print( _section( k, "Library", "PlParam" ) )
133 -- interface config sections
134 for k, v in luci.util.spairs(conf) do
135 if conf[k][".type"] == "Interface" then
136 print( _section( k, "Interface" ) )
140 -- write Hna4, Hna6 sections
141 print( _hna("Hna4") )
142 print( _hna("Hna6") )
144 -- write IpcConnect section
145 print( _ipc("IpcConnect") )