mirror of
https://github.com/remittor/zapret-openwrt.git
synced 2025-12-06 03:26:49 +03:00
luci: Add human readable messages (dmnlog)
This commit is contained in:
@@ -12,6 +12,7 @@ return view.extend({
|
|||||||
return Promise.all([
|
return Promise.all([
|
||||||
L.resolveDefault(fs.stat('/bin/cat'), null),
|
L.resolveDefault(fs.stat('/bin/cat'), null),
|
||||||
fs.exec('/usr/bin/find', [ '/tmp', '-maxdepth', '1', '-type', 'f', '-name', 'zapret+*.log' ]),
|
fs.exec('/usr/bin/find', [ '/tmp', '-maxdepth', '1', '-type', 'f', '-name', 'zapret+*.log' ]),
|
||||||
|
uci.load(tools.appName),
|
||||||
]).then(function(status_array) {
|
]).then(function(status_array) {
|
||||||
var filereader = status_array[0] ? status_array[0].path : null;
|
var filereader = status_array[0] ? status_array[0].path : null;
|
||||||
var log_data = status_array[1]; // stdout: multiline text
|
var log_data = status_array[1]; // stdout: multiline text
|
||||||
@@ -19,14 +20,20 @@ return view.extend({
|
|||||||
ui.addNotification(null, E('p', _('Unable to get log files') + '(code = ' + log_data.code + ') : retrieveLog()'));
|
ui.addNotification(null, E('p', _('Unable to get log files') + '(code = ' + log_data.code + ') : retrieveLog()'));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
var reason = '';
|
||||||
|
var uci_cfg = uci.get(tools.appName, 'config');
|
||||||
|
if (uci_cfg !== null && typeof(uci_cfg) === 'object') {
|
||||||
|
let flag = uci_cfg.DAEMON_LOG_ENABLE;
|
||||||
|
if (flag != '1') {
|
||||||
|
reason = ' (Reason: option DAEMON_LOG_ENABLE = ' + flag + ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
if (typeof(log_data.stdout) !== 'string') {
|
if (typeof(log_data.stdout) !== 'string') {
|
||||||
ui.addNotification(null, E('p', _('Unable to get log files') + '(undefined stdout) : retrieveLog()'));
|
return 'Log files not found.' + reason;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
var log_list = log_data.stdout.trim().split('\n');
|
var log_list = log_data.stdout.trim().split('\n');
|
||||||
if (log_list.length <= 0) {
|
if (log_list.length <= 0) {
|
||||||
ui.addNotification(null, E('p', _('Unable to get log files') + '(not found) : retrieveLog()'));
|
return 'Log files not found!' + reason;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
for (let i = 0; i < log_list.length; i++) {
|
for (let i = 0; i < log_list.length; i++) {
|
||||||
let logfn = log_list[i].trim();
|
let logfn = log_list[i].trim();
|
||||||
@@ -56,15 +63,16 @@ return view.extend({
|
|||||||
return logdata;
|
return logdata;
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
ui.addNotification(null, E('p', _('Unable to execute or read contents')
|
ui.addNotification(null, E('p', _('Unable to execute or read contents')
|
||||||
+ ': %s [ %s | %s | %s | %s ]'.format(
|
+ ': %s [ %s | %s | %s ]'.format(
|
||||||
e.message, tools.execPath, 'retrieveLogData', 'uci.zapret'
|
e.message, 'retrieveLogData', 'uci.zapret'
|
||||||
)));
|
)));
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
|
const [, lineno, colno] = e.stack.match(/(\d+):(\d+)/);
|
||||||
ui.addNotification(null, E('p', _('Unable to execute or read contents')
|
ui.addNotification(null, E('p', _('Unable to execute or read contents')
|
||||||
+ ': %s [ %s | %s | %s | %s ]'.format(
|
+ ': %s [ lineno: %s | %s | %s | %s ]'.format(
|
||||||
e.message, tools.execPath, 'retrieveLog', 'uci.zapret'
|
e.message, lineno, 'retrieveLog', 'uci.zapret'
|
||||||
)));
|
)));
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@@ -79,7 +87,7 @@ return view.extend({
|
|||||||
break;
|
break;
|
||||||
if (logdate_len == -2) {
|
if (logdate_len == -2) {
|
||||||
logdata = await this.retrieveLog();
|
logdata = await this.retrieveLog();
|
||||||
logdate_len = (logdata) ? logdata.length : -1;
|
logdate_len = (Array.isArray(logdata)) ? logdata.length : -1;
|
||||||
}
|
}
|
||||||
let elem_name = elem.getAttribute("name");
|
let elem_name = elem.getAttribute("name");
|
||||||
let founded = false;
|
let founded = false;
|
||||||
@@ -112,6 +120,15 @@ return view.extend({
|
|||||||
if (!logdata) {
|
if (!logdata) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (typeof(logdata) === 'string') {
|
||||||
|
return E('div', {}, [
|
||||||
|
E('p', {'class': 'cbi-title-field'}, [ logdata ]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if (!Array.isArray(logdata)) {
|
||||||
|
ui.addNotification(null, E('p', _('Unable to get log files') + ' : render()'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
var h2 = E('div', {'class' : 'cbi-title-section'}, [
|
var h2 = E('div', {'class' : 'cbi-title-section'}, [
|
||||||
E('h2', {'class': 'cbi-title-field'}, [ _('Zapret') + ' - ' + _('Log Viewer') ]),
|
E('h2', {'class': 'cbi-title-field'}, [ _('Zapret') + ' - ' + _('Log Viewer') ]),
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user