modules/freifunk: show warning when libiwinfo is not installed.
[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 <% if has_services then %>
51 <div class="cbi-map">
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>
60                                         </tr>
61
62         <% table=fetch_services()
63         local i = 1
64         for k, line in ipairs(table) do
65                 local field = {}
66                 -- split line at # and |, 1=url, 2=proto, 3=description, 4=source
67                 local field = luci.util.split(line, "[#|]", split, true) %>
68                                         <tr class="cbi-section-table-row cbi-rowstyle-<%=i%>">
69                                                 <td class="cbi-section-table-cell"><a href="<%=field[1]%>"><%=field[3]%></a></td>
70                                                 <td class="cbi-section-table-cell"><%=field[4]%></td>
71                                         </tr>
72         <% if i == 1 then i = 0 elseif i == 0 then i = 1 end %>
73         <%end%>
74                                 </table>
75                         </div>
76                 </div>
77         </div>
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%>