2 -- Only populate textarea through XHR.poll
3 --
"refresh" is present in the URL (.../log?refresh=
1)
4 if luci.http.formvalue(
"refresh") then
6 -- Force HTTP Contents to be
"text/plain"
7 luci.http.prepare_content(
"text/plain")
9 local sys = require(
"luci.sys")
10 local uci = require
"luci.model.uci".cursor()
12 -- Get Log File from Bird's configuration or leave it empty.
13 local log_file = uci:get(
"bird4",
"global",
"log_file") or
""
16 log_size = sys.exec(
"du -h " .. log_file ..
" | awk '{print $1}'")
17 -- Gathering last
30 lines of the Log File.
18 lf = sys.exec(
"tail -n30 " .. log_file):gsub(
"\r\n?",
"\n")
21 -- Write File used and its contents.
22 luci.http.write(
"Using Log File: " .. log_file ..
" - File Size: " .. log_size ..
"\n" .. lf)
24 -- Avoid printing the rest of the page (return only text log data)
30 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
31 <script type=
"text/javascript">//<![CDATA[
32 // Refresh page each second. Use
"refresh=1" as trigger.
33 XHR.poll(
1, '<%=url('admin/network/bird4/log')%
>', { refresh:
1 }, function(xhrInstance) {
34 var area = document.getElementById('log')
35 area.value = xhrInstance.responseText;
40 <textarea readonly=
"readonly" style=
"width: 100%" wrap=
"on" rows=
"32" id=
"log"><%=lf:pcdata()%
></textarea>