Add option DAEMON_LOG_SIZE_MAX

This commit is contained in:
remittor
2026-01-28 16:31:21 +03:00
parent 16d28be806
commit 7e3fc6f435
7 changed files with 93 additions and 35 deletions

View File

@@ -8,15 +8,17 @@
'require view.zapret.tools as tools';
return view.extend({
retrieveLog: async function() {
return Promise.all([
L.resolveDefault(fs.stat('/bin/cat'), null),
fs.exec('/usr/bin/find', [ '/tmp', '-maxdepth', '1', '-type', 'f', '-name', tools.appName+'+*.log' ]),
uci.load(tools.appName),
]).then(function(status_array) {
var filereader = status_array[0] ? status_array[0].path : null;
var log_data = status_array[1]; // stdout: multiline text
if (log_data.code != 0) {
POLL: new tools.POLLER( { } ),
retrieveLog: async function()
{
return tools.promiseAllDict({
filereader : L.resolveDefault(fs.stat('/bin/cat'), null),
log_data : fs.exec('/usr/bin/find', [ '/tmp', '-maxdepth', '1', '-type', 'f', '-name', tools.appName+'+*.log' ]),
}).then( (data) => {
var filereader = data.filereader ? data.filereader.path : null;
var log_data = data.log_data; // stdout: multiline text
if (log_data?.code === undefined || log_data.code != 0) {
ui.addNotification(null, E('p', _('Unable to get log files') + '(code = ' + log_data.code + ') : retrieveLog()'));
return null;
}
@@ -68,17 +70,20 @@ return view.extend({
)));
return null;
});
}).catch(function(e) {
}).catch( (e) => {
const [, lineno, colno] = e.stack.match(/(\d+):(\d+)/);
ui.addNotification(null, E('p', _('Unable to execute or read contents')
+ ': %s [ lineno: %s | %s | %s | %s ]'.format(
e.message, lineno, 'retrieveLog', 'uci.'+tools.appName
)));
return null;
}).finally( () => {
this.POLL.running = false;
});
},
pollLog: async function() {
pollLog: async function()
{
let logdate_len = -2;
let logdata;
for (let txt_id = 0; txt_id < 10; txt_id++) {
@@ -111,26 +116,28 @@ return view.extend({
}
},
load: async function() {
poll.add(this.pollLog.bind(this));
return await this.retrieveLog();
load: function()
{
return tools.baseLoad(this, (data) => {
tools.load_feat_env();
this.svc_info = data.svc_info;
return this.retrieveLog();
});
},
render: function(logdata) {
if (!logdata) {
return;
}
render: function(logdata)
{
if (typeof(logdata) === 'string') {
return E('div', {}, [
E('p', {'class': 'cbi-title-field'}, [ logdata ]),
]);
}
if (!Array.isArray(logdata)) {
if (!logdata || !Array.isArray(logdata)) {
ui.addNotification(null, E('p', _('Unable to get log files') + ' : render()'));
return;
}
var h2 = E('div', {'class' : 'cbi-title-section'}, [
E('h2', {'class': 'cbi-title-field'}, [ tools.AppName + ' - ' + _('Log Viewer') ]),
E('h2', {'class': 'cbi-title-field'}, [ ]),
]);
var tabs = E('div', {}, E('div'));
@@ -193,8 +200,11 @@ return view.extend({
tabs.firstElementChild.appendChild(tab);
}
ui.tabs.initTabGroup(tabs.firstElementChild.childNodes);
//this.pollFn = L.bind(this.handleScanRefresh, this);
//poll.add(this.pollFn);
this.POLL.mode = 1;
this.POLL.init( this.pollLog.bind(this), 1000 ); // interval 1000 ms
this.POLL.start();
return E('div', { }, [ h2, tabs ]);
},

View File

@@ -90,6 +90,43 @@ return view.extend({
o.rmempty = false;
o.default = 0;
let current_size = uci.get(tools.appName, 'config', 'DAEMON_LOG_SIZE_MAX') || '0';
let has_valid_value = false;
let size_list = [ 500, 1000, 1500, 2000, 2500, 3000, 4000, 5000, 7000 ];
if (current_size && current_size != '0') {
try {
current_size = parseInt(current_size, 10);
if (!isNaN(current_size) && current_size > 0) {
has_valid_value = true;
if (!size_list.includes(current_size)) {
size_list.push(current_size);
size_list.sort((a, b) => a - b);
}
}
} catch(e) {
has_valid_value = false;
}
}
o = s.taboption(tabname, form.ListValue, 'DAEMON_LOG_SIZE_MAX', _('DAEMON_LOG_SIZE_MAX'));
o.rmempty = false;
if (!has_valid_value) {
o.value('', '');
o.default = '';
}
for (let idx = 0; idx < size_list.length; idx++) {
let fsize = size_list[idx];
o.value('' + fsize, fsize + ' KB');
if (has_valid_value && fsize === current_size) {
o.default = '' + fsize;
}
}
o.validate = function(section_id, value) {
if (!value || value === '') {
return _('Please select maximum log size');
}
return true;
};
/* NFQWS_OPT_DESYNC tab */
tabname = 'nfqws_params';