7 -- check if nameservice plugin is enabled and where to find the services file
8 local has_services = false
9 local uci = require
"luci.model.uci".cursor()
10 uci:foreach(
"olsrd",
"LoadPlugin", function(s)
11 if s.library ==
"olsrd_nameservice.so.0.3" then
12 if s.services_file then
14 services_file = s.services_file
17 services_file =
"/var/run/services_olsr"
23 function fetch_services()
24 local rawdata = luci.fs.readfile(services_file)
32 local tables = luci.util.split(luci.util.trim(rawdata),
"\n", nil, true)
33 -- remove the first
3 lines
34 table.remove(tables,
1)
35 table.remove(tables,
1)
36 table.remove(tables,
1)
38 -- store last line in last_update and remove it, then remove another empty line at the end
39 last_update=table.remove(tables)
42 for i, tbl in ipairs(tables) do
43 local lines = luci.util.split(tbl,
"\n", nil, true)
50 <% if has_services then %
>
52 <h2><a id=
"content" name=
"content"><%:Services%
></a></h2>
53 <div class=
"cbi-map-descr"/>
54 <div class=
"cbi-section">
55 <div class=
"cbi-section-node">
56 <table class=
"cbi-section-table">
57 <tr class=
"cbi-section-table-titles">
58 <th class=
"cbi-section-table-cell"><%:Url%
></th>
59 <th class=
"cbi-section-table-cell"><%:Source%
></th>
62 <% table=fetch_services()
64 for k, line in ipairs(table) do
66 -- split line at # and |,
1=url,
2=proto,
3=description,
4=source
67 local field = luci.util.split(line,
"[#|]", split, true)
68 local url,descr,origin = pcdata(field[
1]),pcdata(field[
3]),pcdata(field[
4])
70 <tr class=
"cbi-section-table-row cbi-rowstyle-<%=i%>">
71 <td class=
"cbi-section-table-cell"><a href=
"<%=url%>"><%=descr%
></a></td>
72 <td class=
"cbi-section-table-cell"><%=origin%
></td>
74 <% if i ==
1 then i =
0 elseif i ==
0 then i =
1 end %
>
84 <%:No services can be shown, because olsrd is not running or the olsrd-nameservice Plugin is not loaded.%
>