Freifunk: Add page to show services announced by olsrd
[project/luci.git] / modules / freifunk / luasrc / view / freifunk-services / services.htm
1 <%+header%>
2
3 <%
4 require("luci.fs")
5 require("luci.util")
6
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
13 has_services = true
14 services_file = s.services_file
15 else
16 has_services = true
17 services_file = "/var/run/services_olsr"
18 end
19 end
20 end)
21
22
23 function fetch_services()
24 local rawdata = luci.fs.readfile(services_file)
25
26 if #rawdata == 0 then
27 return nil
28 end
29
30 local data = {}
31
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)
37
38 -- store last line in last_update and remove it, then remove another empty line at the end
39 last_update=table.remove(tables)
40 table.remove(tables)
41
42 for i, tbl in ipairs(tables) do
43 local lines = luci.util.split(tbl, "\n", nil, true)
44 end
45
46 return tables
47 end
48
49 %>
50
51 <% if has_services then %>
52 <h2><a id="content" name="content"><%:Services%></a></h2>
53 <br />
54
55 <table class="smalltext" cellspacing="0" cellpadding="6">
56 <tr>
57 <th><%:Url%></th>
58 <th><%:Source%></th>
59 </tr>
60
61 <%
62 table=fetch_services()
63 for k, line in ipairs(table) do
64 local field = {}
65 -- split line at # and |, 1=url, 2=proto, 3=description, 4=source
66 local field = luci.util.split(line, "[#|]", split, true)
67 %>
68 <tr><td>
69 <a href="<%=field[1]%>"><%=field[3]%></a>
70 </td>
71 <td>
72 <%=field[4]%>
73 </td>
74 </tr>
75 <%end%>
76
77 </table>
78 <br />
79 <%=last_update%>
80
81 <%else%>
82 <%:No services can be shown, because olsrd is not running or the olsrd-nameservice Plugin is not loaded.%>
83 <%end%>
84
85 <%+footer%>