Skip to content

Commit b59e51a

Browse files
committed
luci-mod-status: update syslog viewer to use the remodeled CBILogreadBox
Signed-off-by: Paul Donald <newtwen+github@gmail.com>
1 parent 0a6180d commit b59e51a

File tree

2 files changed

+4
-229
lines changed

2 files changed

+4
-229
lines changed
Lines changed: 2 additions & 226 deletions
Original file line numberDiff line numberDiff line change
@@ -1,228 +1,4 @@
11
'use strict';
2-
'require view';
3-
'require fs';
4-
'require poll';
5-
'require ui';
2+
'require tools.views as views';
63

7-
return view.extend({
8-
logFacilityFilter: 'any',
9-
invertLogFacilitySearch: false,
10-
logSeverityFilter: 'any',
11-
invertLogSeveritySearch: false,
12-
logTextFilter: '',
13-
invertLogTextSearch: false,
14-
15-
facilities: [
16-
['any', 'any', _('Any')],
17-
['0', 'kern', _('Kernel')],
18-
['1', 'user', _('User')],
19-
['2', 'mail', _('Mail')],
20-
['3', 'daemon', _('Daemon')],
21-
['4', 'auth', _('Auth')],
22-
['5', 'syslog', _('Syslog')],
23-
['6', 'lpr', _('LPR')],
24-
['7', 'news', _('News')],
25-
['8', 'uucp', _('UUCP')],
26-
['9', 'cron', _('Cron')],
27-
['10', 'authpriv', _('Auth Priv')],
28-
['11', 'ftp', _('FTP')],
29-
['12', 'ntp', _('NTP')],
30-
['13', 'security', _('Log audit')],
31-
['14', 'console', _('Log alert')],
32-
['15', 'cron', _('Scheduling daemon')],
33-
['16', 'local0', _('Local 0')],
34-
['17', 'local1', _('Local 1')],
35-
['18', 'local2', _('Local 2')],
36-
['19', 'local3', _('Local 3')],
37-
['20', 'local4', _('Local 4')],
38-
['21', 'local5', _('Local 5')],
39-
['22', 'local6', _('Local 6')],
40-
['23', 'local7', _('Local 7')]
41-
],
42-
43-
severity: [
44-
['any','any', _('Any')],
45-
['0', 'emerg', _('Emergency')],
46-
['1', 'alert', _('Alert')],
47-
['2', 'crit', _('Critical')],
48-
['3', 'err', _('Error')],
49-
['4', 'warn', _('Warning')],
50-
['5', 'notice', _('Notice')],
51-
['6', 'info', _('Info')],
52-
['7', 'debug', _('Debug')]
53-
],
54-
55-
56-
retrieveLog: async function() {
57-
58-
return Promise.all([
59-
L.resolveDefault(fs.stat('/usr/libexec/syslog-wrapper'), null),
60-
]).then((stat) => {
61-
const logger = stat[0]?.path;
62-
63-
return fs.exec_direct(logger).then(logdata => {
64-
let loglines = logdata.trim().split(/\n/);
65-
66-
loglines = loglines.filter(line => {
67-
const sevMatch = this.logSeverityFilter === 'any' || line.includes(`.${this.logSeverityFilter}`);
68-
const facMatch = this.logFacilityFilter === 'any' || line.includes(`${this.logFacilityFilter}.`);
69-
70-
return (this.invertLogSeveritySearch != sevMatch)
71-
&& (this.invertLogFacilitySearch != facMatch);
72-
});
73-
74-
loglines = loglines.filter(line => {
75-
const match = line.includes(this.logTextFilter);
76-
return this.invertLogTextSearch ? !match : match;
77-
});
78-
79-
return {
80-
value: loglines.join('\n'),
81-
rows: loglines.length + 1
82-
};
83-
}).catch(function(err) {
84-
ui.addNotification(null, E('p', {}, _('Unable to load log data: ' + err.message)));
85-
return {
86-
value: '',
87-
rows: 0
88-
};
89-
});
90-
});
91-
},
92-
93-
pollLog: async function() {
94-
const element = document.getElementById('syslog');
95-
if (element) {
96-
const log = await this.retrieveLog();
97-
element.value = log.value;
98-
element.rows = log.rows;
99-
}
100-
},
101-
102-
load: async function() {
103-
poll.add(this.pollLog.bind(this));
104-
return await this.retrieveLog();
105-
},
106-
107-
render: function(loglines) {
108-
const scrollDownButton = E('button', {
109-
'id': 'scrollDownButton',
110-
'class': 'cbi-button cbi-button-neutral'
111-
}, _('Scroll to tail', 'scroll to bottom (the tail) of the log file')
112-
);
113-
scrollDownButton.addEventListener('click', () => {
114-
scrollUpButton.scrollIntoView();
115-
scrollDownButton.blur();
116-
});
117-
118-
const scrollUpButton = E('button', {
119-
'id' : 'scrollUpButton',
120-
'class': 'cbi-button cbi-button-neutral'
121-
}, _('Scroll to head', 'scroll to top (the head) of the log file')
122-
);
123-
scrollUpButton.addEventListener('click', () => {
124-
scrollDownButton.scrollIntoView();
125-
scrollUpButton.blur();
126-
});
127-
128-
const self = this;
129-
130-
// Create facility invert checkbox
131-
const facilityInvert = E('input', {
132-
'id': 'invertLogFacilitySearch',
133-
'type': 'checkbox',
134-
'class': 'cbi-input-checkbox',
135-
});
136-
137-
// Create facility select-dropdown from facilities map
138-
const facilitySelect = E('select', {
139-
'id': 'logFacilitySelect',
140-
'class': 'cbi-input-select',
141-
'style': 'margin-bottom:10px',
142-
},
143-
this.facilities.map(([_, val, label]) =>
144-
E('option', { value: val }, label)
145-
));
146-
147-
// Create severity invert checkbox
148-
const severityInvert = E('input', {
149-
'id': 'invertLogSeveritySearch',
150-
'type': 'checkbox',
151-
'class': 'cbi-input-checkbox',
152-
});
153-
154-
// Create severity select-dropdown from facilities map
155-
const severitySelect = E('select', {
156-
'id': 'logSeveritySelect',
157-
'class': 'cbi-input-select',
158-
},
159-
this.severity.map(([_, val, label]) =>
160-
E('option', { value: val }, label)
161-
));
162-
163-
// Create raw text search invert checkbox
164-
const filterTextInvert = E('input', {
165-
'id': 'invertLogTextSearch',
166-
'type': 'checkbox',
167-
'class': 'cbi-input-checkbox',
168-
});
169-
170-
// Create raw text search text input
171-
const filterTextInput = E('input', {
172-
'id': 'logTextFilter',
173-
'class': 'cbi-input-text',
174-
});
175-
176-
function handleLogFilterChange() {
177-
self.logFacilityFilter = facilitySelect.value;
178-
self.invertLogFacilitySearch = facilityInvert.checked;
179-
self.logSeverityFilter = severitySelect.value;
180-
self.invertLogSeveritySearch = severityInvert.checked;
181-
self.logTextFilter = filterTextInput.value;
182-
self.invertLogTextSearch = filterTextInvert.checked;
183-
self.pollLog();
184-
}
185-
186-
facilitySelect.addEventListener('change', handleLogFilterChange);
187-
facilityInvert.addEventListener('change', handleLogFilterChange);
188-
severitySelect.addEventListener('change', handleLogFilterChange);
189-
severityInvert.addEventListener('change', handleLogFilterChange);
190-
filterTextInput.addEventListener('input', handleLogFilterChange);
191-
filterTextInvert.addEventListener('change', handleLogFilterChange);
192-
193-
return E([], [
194-
E('h2', {}, [ _('System Log') ]),
195-
E('div', { 'id': 'content_syslog' }, [
196-
E('div', { 'style': 'margin-bottom:10px' }, [
197-
E('label', { 'for': 'invertLogFacilitySearch', 'style': 'margin-right:5px' }, _('Not')),
198-
facilityInvert,
199-
E('label', { 'for': 'logFacilitySelect', 'style': 'margin: 0 5px' }, _('facility:')),
200-
facilitySelect,
201-
E('label', { 'for': 'invertLogSeveritySearch', 'style': 'margin: 0 5px' }, _('Not')),
202-
severityInvert,
203-
E('label', { 'for': 'logSeveritySelect', 'style': 'margin: 0 5px' }, _('severity:')),
204-
severitySelect,
205-
]),
206-
E('div', { 'style': 'margin-bottom:10px' }, [
207-
E('label', { 'for': 'invertLogTextSearch', 'style': 'margin-right:5px' }, _('Not')),
208-
filterTextInvert,
209-
E('label', { 'for': 'logTextFilter', 'style': 'margin: 0 5px' }, _('including:')),
210-
filterTextInput,
211-
]),
212-
E('div', {'style': 'padding-bottom: 20px'}, [scrollDownButton]),
213-
E('textarea', {
214-
'id': 'syslog',
215-
'style': 'font-size:12px',
216-
'readonly': 'readonly',
217-
'wrap': 'off',
218-
'rows': loglines.rows,
219-
}, [ loglines.value ]),
220-
E('div', {'style': 'padding-bottom: 20px'}, [scrollUpButton])
221-
])
222-
]);
223-
},
224-
225-
handleSaveApply: null,
226-
handleSave: null,
227-
handleReset: null
228-
});
4+
return views.LogreadBox(null, _('System'));

modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@
3131
"read": {
3232
"cgi-io": [ "exec" ],
3333
"file": {
34-
"/bin/dmesg -r": [ "exec" ],
35-
"/usr/libexec/syslog-wrapper": [ "exec" ]
34+
"/bin/dmesg -r": [ "exec" ]
3635
},
3736
"ubus": {
38-
"file": [ "stat" ]
37+
"log": [ "read" ]
3938
}
4039
}
4140
},

0 commit comments

Comments
 (0)