1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#!/usr/bin/lua
--[[
OLSRd configuration generator
(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
$Id$
]]--
require("luci.fs")
require("luci.util")
require("luci.model.uci")
local uci = luci.model.uci.cursor()
local conf = uci:get_all("olsr")
local function _value(val)
if val:match("^[0-9%. \t]+$") or val == "yes" or val == "no" then
return val
else
return string.format( '"%s"', val )
end
end
local function _section(sect,sval,parstr)
local rv = ""
local pad = ""
if sval then
if sval == "Interface" then
rv = string.format( 'Interface "%s"\n{\n', uci:get("network",conf[sect][sval],"ifname") )
else
rv = string.format( '%s "%s"\n{\n', conf[sect][".type"], conf[sect][sval] )
end
pad = "\t"
end
for k, v in luci.util.spairs(conf[sect]) do
if k:sub(1,1) ~= '.' and k ~= sval then
if parstr then
rv = rv .. string.format(
'%s%s "%s"\t"%s"\n',
pad, parstr,
k:gsub( "_", "-" ), -- XXX: find a better solution for this
v
)
else
rv = rv .. string.format(
'%s%s\t%s\n',
pad, k, _value(v)
)
end
end
end
if sval then
rv = rv .. "}\n"
end
return rv
end
local function _hna(sval)
local rv = string.format( "%s\n{\n", sval )
for k, v in luci.util.spairs(conf) do
if conf[k][".type"] == sval and conf[k].NetAddr and conf[k].Prefix then
rv = rv .. string.format(
"\t%s\t%s\n",
conf[k].NetAddr,
conf[k].Prefix
)
end
end
return rv .. "}\n"
end
local function _ipc(sval)
local rv = string.format( "%s\n{\n", sval )
for k, v in luci.util.spairs(conf[sval]) do
if k:sub(1,1) ~= "." then
local vals = luci.util.split(v, "%s+", nil, true)
if k == "Net" then
for i = 1,#vals,2 do
rv = rv .. string.format(
"\tNet\t%s\t%s\n",
vals[i], vals[i+1]
)
end
elseif k == "Host" then
for i, v in ipairs(vals) do
rv = rv .. string.format(
"\t%s\t%s\n",
k, vals[i]
)
end
else
rv = rv .. string.format(
"\t%s\t%s\n",
k, v
)
end
end
end
return rv .. "}\n"
end
-- general config section
print( _section("general") )
-- plugin config sections
for k, v in luci.util.spairs(conf) do
if conf[k][".type"] == "LoadPlugin" then
if v.Library and luci.fs.access("/usr/lib/"..v.Library) then
print( _section( k, "Library", "PlParam" ) )
end
end
end
-- interface config sections
for k, v in luci.util.spairs(conf) do
if conf[k][".type"] == "Interface" then
print( _section( k, "Interface" ) )
end
end
-- write Hna4, Hna6 sections
print( _hna("Hna4") )
print( _hna("Hna6") )
-- write IpcConnect section
print( _ipc("IpcConnect") )
|