1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
'use strict';
'require dom';
'require fs';
'require poll';
'require view';
var css = ' \
#log_textarea { \
padding: 10px; \
text-align: left; \
} \
#log_textarea pre { \
padding: .5rem; \
word-break: break-all; \
margin: 0; \
} \
.description { \
background-color: #33ccff; \
}';
function pollLog(e) {
return Promise.all([
fs.exec_direct('/usr/libexec/aria2-call', [ 'tail' ]).then(function(res) {
return res.trim().split(/\n/).reverse().join('\n')
}),
fs.exec_direct('/sbin/logread', [ '-e', 'aria2' ]).then(function(res) {
return res.trim().split(/\n/).reverse().slice(0, 50).join('\n')
})
]).then(function(data) {
var t = E('pre', { 'wrap': 'pre' }, [
E('div', { 'class': 'description' }, _('Last 50 lines of log file:')),
E('br'),
data[0] || _('No log data.'),
E('br'),
E('br'),
E('div', { 'class': 'description' }, _('Last 50 lines of syslog:')),
E('br'),
data[1] || _('No log data.')
]);
dom.content(e, t);
});
};
return view.extend({
render: function() {
var log_textarea = E('div', { 'id': 'log_textarea' },
E('img', {
'src': L.resource(['icons/loading.gif']),
'alt': _('Loading'),
'style': 'vertical-align:middle'
}, _('Collecting data...'))
);
poll.add(pollLog.bind(this, log_textarea));
return E([
E('style', [ css ]),
E('div', {'class': 'cbi-map'}, [
E('h2', {'name': 'content'}, '%s - %s'.format(_('Aria2'), _('Log Data'))),
E('div', {'class': 'cbi-section'}, [
log_textarea,
E('div', {'style': 'text-align:right'},
E('small', {}, _('Refresh every %s seconds.').format(L.env.pollinterval))
)
])
])
]);
},
handleSave: null,
handleSaveApply: null,
handleReset: null
});
|