2 Copyright
2011 Manuel Munz
<freifunk at somakoma dot de
>
3 Licensed to the public under the Apache License
2.0.
7 local fs = require
"nixio.fs"
8 local utl = require
"luci.util"
13 local services_file_empty = true
14 local has_services = false
15 local uci = require
"luci.model.uci".cursor()
16 local ip = require
"luci.ip"
18 uci:foreach(
"olsrd",
"LoadPlugin", function(s)
19 if s.library ==
"olsrd_nameservice.so.0.3" then
20 local services_file=s.services_file
21 if services_file and fs.access(services_file) then
23 rawdata = fs.readfile(s.services_file)
25 services_file=
"/var/run/services_olsr"
26 if fs.access(services_file) then
28 rawdata = fs.readfile(services_file)
31 services_file=services_file..
".ipv6"
32 if services_file and fs.access(services_file) then
34 rawdata6 = fs.readfile(services_file)
36 services_file=
"/var/run/services_olsr.ipv6"
37 if fs.access(services_file) then
39 rawdata6 = fs.readfile(services_file)
42 if rawdata and #rawdata ~=
0 then
43 services_file_empty = nil
45 if rawdata6 and #rawdata6 ~=
0 then
46 services_file_empty = nil
52 if not has_services or services_file_empty then
56 <%:No services can be shown, because olsrd is not running or the olsrd-nameservice Plugin is not loaded.%
>
62 function fetch_services()
64 if rawdata and #rawdata ~=
0 then
65 tables = utl.split(utl.trim(rawdata),
"\n", nil, true)
66 -- remove first
3 lines
68 table.remove(tables,
1)
72 if rawdata6 and #rawdata6 ~=
0 then
73 tables6 = utl.split(utl.trim(rawdata6),
"\n", nil, true)
74 -- remove first
3 lines
76 table.remove(tables6,
1)
80 -- store last line in last_update and remove it, then remove another empty line at the end
81 last_update=table.remove(tables)
83 last_update=table.remove(tables6)
85 for k, v in ipairs(tables6) do
86 table.insert(tables, v)
90 local services = fetch_services()
92 if luci.http.formvalue(
"status") ==
"1" then
94 for k, line in ipairs(services) do
95 local field = utl.split(line,
"[#|]", split, true)
96 local origin_lnk = ip.IPv6(pcdata(field[
4]))
97 local origin_link =
""
98 if origin_lnk and origin_lnk:is6() then
99 origin_link =
"["..origin_lnk:string()..
"]"
101 origin_link = pcdata(field[
4])
103 local url, proto, descr, origin = pcdata(field[
1]), pcdata(field[
2]), utl.trim(pcdata(field[
3])), pcdata(field[
4])
108 origin_link = origin_link,
112 luci.http.prepare_content(
"application/json")
113 luci.http.write_json(rv)
121 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
122 <script type=
"text/javascript">//<![CDATA[
124 XHR.poll(
10 , '<%=REQUEST_URI%
>', { status:
1 },
127 var tbody = document.getElementById('olsr_services');
131 for (var idx =
0; idx < info.length; idx++)
133 var service = info[idx];
135 '
<tr class=
"cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+'">' +
136 '
<td class=
"cbi-section-table-titles"><a href=
"%s">%s
</a></td>' +
137 '
<td class=
"cbi-section-table-titles">%s
</td>' +
138 '
<td class=
"cbi-section-table-titles"><a href=
"http://%s/cgi-bin-status.html">%s
</a></td>' +
140 service.url, service.descr, service.proto, service.origin_link, service.origin || '?'
152 <h2><a id=
"content" name=
"content"><%:Services%
></a></h2>
154 <fieldset class=
"cbi-section">
155 <legend><%:Internal services%
></legend>
156 <table class=
"cbi-section-table">
158 <tr class=
"cbi-section-table-titles">
159 <th class=
"cbi-section-table-cell"><%:Url%
></th>
160 <th class=
"cbi-section-table-cell"><%:Protocol%
></th>
161 <th class=
"cbi-section-table-cell"><%:Source%
></th>
165 <tbody id=
"olsr_services">
167 for k, line in ipairs(services) do
169 -- split line at # and |,
1=url,
2=proto,
3=description,
4=source
170 local field = utl.split(line,
"[#|]", split, true)
171 local origin_lnk = ip.IPv6(pcdata(field[
4]))
173 if origin_lnk and origin_lnk:is6() then
174 origin_link =
"["..origin_lnk:string()..
"]"
176 origin_link = pcdata(field[
4])
178 local url, proto, descr, origin = pcdata(field[
1]), pcdata(field[
2]), utl.trim(pcdata(field[
3])), pcdata(field[
4])
181 <tr class=
"cbi-section-table-row cbi-rowstyle-<%=i%>">
182 <td class=
"cbi-section-table-titles"><a href=
"<%=url%>"><%=descr%
></a></td>
183 <td class=
"cbi-section-table-titles"><%=proto%
></td>
184 <td class=
"cbi-section-table-titles"><a href=
"http://<%=origin_link%>/cgi-bin-status.html"><%=origin%
></a></td>