2 LuCI - Lua Configuration Interface
4 Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
15 local fs = require "luci.fs"
16 local utl = require "luci.util"
19 -- check if nameservice plugin is enabled and where to find the services file
20 local has_services = false
22 local uci = require "luci.model.uci".cursor()
23 uci:foreach("olsrd", "LoadPlugin", function(s)
24 if s.library == "olsrd_nameservice.so.0.3" then
25 if s.services_file and fs.access(s.services_file) then
27 services_file = s.services_file
29 if fs.access("/var/run/services_olsr") then
31 services_file = "/var/run/services_olsr"
37 function fetch_services()
38 local rawdata = fs.readfile(services_file)
46 local tables = utl.split(utl.trim(rawdata), "\n", nil, true)
47 -- remove the first 3 lines
48 table.remove(tables,1)
49 table.remove(tables,1)
50 table.remove(tables,1)
52 -- store last line in last_update and remove it, then remove another empty line at the end
53 last_update=table.remove(tables)
56 for i, tbl in ipairs(tables) do
57 local lines = utl.split(tbl, "\n", nil, true)
62 local table = fetch_services()
64 if luci.http.formvalue("status") == "1" then
66 for k, line in ipairs(table) do
67 local field = utl.split(line, "[#|]", split, true)
68 local url,descr,origin = pcdata(field[1]),pcdata(field[3]),pcdata(field[4])
76 if i == 1 then i = 0 elseif i == 0 then i = 1 end
78 luci.http.prepare_content("application/json")
79 luci.http.write_json(rv)
85 <% if has_services then %>
89 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
90 <script type="text/javascript">//<![CDATA[
92 XHR.poll(10 , '<%=REQUEST_URI%>', { status: 1 },
95 var tbody = document.getElementById('olsr_services');
99 for (var idx = 0; idx < info.length; idx++)
101 var service = info[idx];
103 '<tr class="cbi-section-table-row cbi-rowstyle-%s">' +
104 '<td class="cbi-section-table-cell"><a href="%s">%s</a></td>' +
105 '<td class="cbi-section-table-cell">%s</td>' +
107 service.rs, service.url, service.descr, service.origin || '?'
119 <h2><a id="content" name="content"><%:Services%></a></h2>
121 <fieldset class="cbi-section">
122 <legend><%:Internal services%></legend>
123 <table class="cbi-section-table">
124 <tr class="cbi-section-table-titles">
125 <th class="cbi-section-table-cell"><%:Url%></th>
126 <th class="cbi-section-table-cell"><%:Source%></th>
129 <tbody id="olsr_services">
131 for k, line in ipairs(table) do
133 -- split line at # and |, 1=url, 2=proto, 3=description, 4=source
134 local field = utl.split(line, "[#|]", split, true)
135 local url,descr,origin = pcdata(field[1]),pcdata(field[3]),pcdata(field[4])
138 <tr class="cbi-section-table-row cbi-rowstyle-<%=i%>">
139 <td class="cbi-section-table-cell"><a href="<%=url%>"><%=descr%></a></td>
140 <td class="cbi-section-table-cell"><%=origin%></td>
142 <% if i == 1 then i = 0 elseif i == 0 then i = 1 end
151 <%:No services can be shown, because olsrd is not running or the olsrd-nameservice Plugin is not loaded.%>