2 LuCI - Lua Configuration Interface
4 Copyright
2011 Manuel Munz
<freifunk at somakoma dot de
>
6 Licensed under the Apache License, Version
2.0 (the
"License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-
2.0
15 local fs = require
"luci.fs"
16 local utl = require
"luci.util"
21 local services_file_empty = true
22 local has_services = false
23 local uci = require
"luci.model.uci".cursor()
24 local ip = require
"luci.ip"
26 uci:foreach(
"olsrd",
"LoadPlugin", function(s)
27 if s.library ==
"olsrd_nameservice.so.0.3" then
28 local services_file=s.services_file
29 if services_file and fs.access(services_file) then
31 rawdata = fs.readfile(s.services_file)
33 services_file=
"/var/run/services_olsr"
34 if fs.access(services_file) then
36 rawdata = fs.readfile(services_file)
39 services_file=services_file..
".ipv6"
40 if services_file and fs.access(services_file) then
42 rawdata6 = fs.readfile(services_file)
44 services_file=
"/var/run/services_olsr.ipv6"
45 if fs.access(services_file) then
47 rawdata6 = fs.readfile(services_file)
50 if rawdata and #rawdata ~=
0 then
51 services_file_empty = nil
53 if rawdata6 and #rawdata6 ~=
0 then
54 services_file_empty = nil
60 if not has_services or services_file_empty then
64 <%:No services can be shown, because olsrd is not running or the olsrd-nameservice Plugin is not loaded.%
>
70 function fetch_services()
72 if rawdata and #rawdata ~=
0 then
73 tables = utl.split(utl.trim(rawdata),
"\n", nil, true)
74 -- remove first
3 lines
76 table.remove(tables,
1)
80 if rawdata6 and #rawdata6 ~=
0 then
81 tables6 = utl.split(utl.trim(rawdata6),
"\n", nil, true)
82 -- remove first
3 lines
84 table.remove(tables6,
1)
88 -- store last line in last_update and remove it, then remove another empty line at the end
89 last_update=table.remove(tables)
91 last_update=table.remove(tables6)
93 for k, v in ipairs(tables6) do
94 table.insert(tables, v)
98 local services = fetch_services()
100 if luci.http.formvalue(
"status") ==
"1" then
102 for k, line in ipairs(services) do
103 local field = utl.split(line,
"[#|]", split, true)
104 local origin_lnk = ip.IPv6(pcdata(field[
4])) or
""
105 local origin_link =
""
106 if #origin_lnk ~=
0 and origin_lnk:is6() then
107 origin_link =
"["..origin_lnk:string()..
"]"
109 origin_link = pcdata(field[
4])
111 local url, proto, descr, origin = pcdata(field[
1]), pcdata(field[
2]), utl.trim(pcdata(field[
3])), pcdata(field[
4])
116 origin_link = origin_link,
120 luci.http.prepare_content(
"application/json")
121 luci.http.write_json(rv)
129 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
130 <script type=
"text/javascript">//<![CDATA[
132 XHR.poll(
10 , '<%=REQUEST_URI%
>', { status:
1 },
135 var tbody = document.getElementById('olsr_services');
139 for (var idx =
0; idx < info.length; idx++)
141 var service = info[idx];
143 '
<tr class=
"cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+'">' +
144 '
<td class=
"cbi-section-table-titles"><a href=
"%s">%s
</a></td>' +
145 '
<td class=
"cbi-section-table-titles">%s
</td>' +
146 '
<td class=
"cbi-section-table-titles"><a href=
"http://%s/cgi-bin-status.html">%s
</a></td>' +
148 service.url, service.descr, service.proto, service.origin_link, service.origin || '?'
160 <h2><a id=
"content" name=
"content"><%:Services%
></a></h2>
162 <fieldset class=
"cbi-section">
163 <legend><%:Internal services%
></legend>
164 <table class=
"cbi-section-table">
166 <tr class=
"cbi-section-table-titles">
167 <th class=
"cbi-section-table-cell"><%:Url%
></th>
168 <th class=
"cbi-section-table-cell"><%:Protocol%
></th>
169 <th class=
"cbi-section-table-cell"><%:Source%
></th>
173 <tbody id=
"olsr_services">
175 for k, line in ipairs(services) do
177 -- split line at # and |,
1=url,
2=proto,
3=description,
4=source
178 local field = utl.split(line,
"[#|]", split, true)
179 local origin_lnk = ip.IPv6(pcdata(field[
4])) or
""
181 if #origin_lnk ~=
0 and origin_lnk:is6() then
182 origin_link =
"["..origin_lnk:string()..
"]"
184 origin_link = pcdata(field[
4])
186 local url, proto, descr, origin = pcdata(field[
1]), pcdata(field[
2]), utl.trim(pcdata(field[
3])), pcdata(field[
4])
189 <tr class=
"cbi-section-table-row cbi-rowstyle-<%=i%>">
190 <td class=
"cbi-section-table-titles"><a href=
"<%=url%>"><%=descr%
></a></td>
191 <td class=
"cbi-section-table-titles"><%=proto%
></td>
192 <td class=
"cbi-section-table-titles"><a href=
"http://<%=origin_link%>/cgi-bin-status.html"><%=origin%
></a></td>