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)
51 <% if has_services then %
>
52 <h2><a id=
"content" name=
"content"><%:Services%
></a></h2>
55 <table class=
"smalltext" cellspacing=
"0" cellpadding=
"6">
62 table=fetch_services()
63 for k, line in ipairs(table) do
65 -- split line at # and |,
1=url,
2=proto,
3=description,
4=source
66 local field = luci.util.split(line,
"[#|]", split, true)
69 <a href=
"<%=field[1]%>"><%=field[
3]%
></a>
82 <%:No services can be shown, because olsrd is not running or the olsrd-nameservice Plugin is not loaded.%
>