Files
ruantiblock_openwrt/luci-app-ruantiblock/htdocs/luci-static/resources/view/ruantiblock/log.js
T

62 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-06-19 20:43:08 +03:00
'require fs';
'require ui';
2021-03-11 18:24:24 +03:00
'require view.ruantiblock.baselog as baselog';
2020-06-19 20:43:08 +03:00
'require view.ruantiblock.tools as tools';
2021-03-11 18:24:24 +03:00
return baselog.view.extend({
viewName: 'ruantiblock-log',
2020-06-19 20:43:08 +03:00
2021-03-11 18:24:24 +03:00
title: _('Ruantiblock') + ' - ' + _('Log'),
2020-06-19 20:43:08 +03:00
2021-03-11 18:24:24 +03:00
getLogData: function(tail) {
return Promise.all([
L.resolveDefault(fs.stat('/sbin/logread'), null),
L.resolveDefault(fs.stat('/usr/sbin/logread'), null),
]).then(stat => {
let logger = (stat[0]) ? stat[0].path : (stat[1]) ? stat[1].path : null;
2020-06-19 20:43:08 +03:00
2021-03-11 18:24:24 +03:00
if(logger) {
return fs.exec_direct(logger, [ '-e', '^' + tools.app_name ]).catch(err => {
ui.addNotification(null, E('p', _('Unable to execute or read contents')
+ ': %s<br />[ %s ]'.format(err.message, logger)
2020-06-19 20:43:08 +03:00
));
2021-03-11 18:24:24 +03:00
return '';
});
};
});
},
parseLogData: function(logdata, tail) {
if(!logdata) {
return [];
};
let strings = logdata.trim().split(/\n/);
if(tail && tail > 0 && strings) {
strings = strings.slice(-tail);
};
this.totalLogLines = strings.length;
let entriesArray = strings.map((e, i) => {
let strArray = e.split(/\s+/);
let logLevel = strArray[5].split('.');
return [
i + 1, // # (Number)
strArray.slice(0, 5).join(' '), // Timestamp (String)
logLevel[1], // Level (String)
logLevel[0], // Facility (String)
this.htmlEntities(strArray.slice(6).join(' ')), // Message (String)
];
});
if(this.logSortingValue === 'desc') {
entriesArray.reverse();
};
return entriesArray;
},
2020-06-19 20:43:08 +03:00
});