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