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"
20 local services_file_empty
21 local has_services = false
22 local uci = require "luci.model.uci".cursor()
24 uci:foreach("olsrd", "LoadPlugin", function(s)
25 if s.library == "olsrd_nameservice.so.0.3" then
26 if s.services_file and fs.access(s.services_file) then
28 rawdata = fs.readfile(s.services_file)
31 if fs.access("/var/run/services_olsr") then
33 rawdata = fs.readfile("/var/run/services_olsr")
36 if rawdata and #rawdata == 0 then
37 services_file_empty = true
43 if not has_services or services_file_empty then
47 <%:No services can be shown, because olsrd is not running or the olsrd-nameservice Plugin is not loaded.%>
53 function fetch_services()
54 local tables = utl.split(utl.trim(rawdata), "\n", nil, true)
55 -- remove first 3 lines
57 table.remove(tables,1)
60 -- store last line in last_update and remove it, then remove another empty line at the end
61 last_update=table.remove(tables)
65 local services = fetch_services()
67 if luci.http.formvalue("status") == "1" then
69 for k, line in ipairs(services) do
70 local field = utl.split(line, "[#|]", split, true)
71 local url, proto, descr, origin = pcdata(field[1]), pcdata(field[2]), utl.trim(pcdata(field[3])), pcdata(field[4])
79 luci.http.prepare_content("application/json")
80 luci.http.write_json(rv)
88 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
89 <script type="text/javascript">//<![CDATA[
91 XHR.poll(10 , '<%=REQUEST_URI%>', { status: 1 },
94 var tbody = document.getElementById('olsr_services');
98 for (var idx = 0; idx < info.length; idx++)
100 var service = info[idx];
102 '<tr class="cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+'">' +
103 '<td class="cbi-section-table-cell"><a href="%s">%s</a></td>' +
104 '<td class="cbi-section-table-cell">%s</td>' +
105 '<td class="cbi-section-table-cell"><a href="http://%s/cgi-bin-status.html">%s</a></td>' +
107 service.url, service.descr, service.proto, service.origin, 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">
125 <tr class="cbi-section-table-titles">
126 <th class="cbi-section-table-cell"><%:Url%></th>
127 <th class="cbi-section-table-cell"><%:Protocol%></th>
128 <th class="cbi-section-table-cell"><%:Source%></th>
132 <tbody id="olsr_services">
134 for k, line in ipairs(services) do
136 -- split line at # and |, 1=url, 2=proto, 3=description, 4=source
137 local field = utl.split(line, "[#|]", split, true)
138 local url, proto, descr, origin = pcdata(field[1]), pcdata(field[2]), utl.trim(pcdata(field[3])), pcdata(field[4])
141 <tr class="cbi-section-table-row cbi-rowstyle-<%=i%>">
142 <td class="cbi-section-table-cell"><a href="<%=url%>"><%=descr%></a></td>
143 <td class="cbi-section-table-cell"><%=proto%></td>
144 <td class="cbi-section-table-cell"><a href="http://<%=origin%>/cgi-bin-status.html"><%=origin%></a></td>