small-package/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/log.js

130 lines
3.1 KiB
JavaScript
Raw Normal View History

2024-10-26 10:27:23 +08:00
/* Thanks to homeproxy */
'use strict';
'require dom';
'require form';
'require fs';
'require poll';
'require rpc';
'require ui';
'require view';
/* Thanks to luci-app-aria2 */
2025-01-15 16:25:40 +08:00
const css = ' \
2024-10-26 10:27:23 +08:00
#log_textarea { \
padding: 10px; \
text-align: left; \
} \
#log_textarea pre { \
padding: .5rem; \
word-break: break-all; \
margin: 0; \
} \
.description { \
background-color: #33ccff; \
}';
2025-01-15 16:25:40 +08:00
const hm_dir = '/var/run/fchomo';
2024-10-26 10:27:23 +08:00
function getRuntimeLog(name, filename) {
2024-12-10 16:28:20 +08:00
const callLogClean = rpc.declare({
2024-10-26 10:27:23 +08:00
object: 'luci.fchomo',
method: 'log_clean',
params: ['type'],
expect: { '': {} }
});
2025-01-15 16:25:40 +08:00
let log_textarea = E('div', { 'id': 'log_textarea' },
2024-10-26 10:27:23 +08:00
E('pre', {
'class': 'spinning'
}, _('Collecting data...'))
);
2025-01-15 16:25:40 +08:00
let log;
2024-10-26 10:27:23 +08:00
poll.add(L.bind(function() {
return fs.read_direct(String.format('%s/%s.log', hm_dir, filename), 'text')
2025-01-18 00:23:28 +08:00
.then((res) => {
2024-10-26 10:27:23 +08:00
log = E('pre', { 'wrap': 'pre' }, [
res.trim() || _('Log is empty.')
]);
dom.content(log_textarea, log);
2025-01-18 00:23:28 +08:00
}).catch((err) => {
2024-10-26 10:27:23 +08:00
if (err.toString().includes('NotFoundError'))
log = E('pre', { 'wrap': 'pre' }, [
_('Log file does not exist.')
]);
else
log = E('pre', { 'wrap': 'pre' }, [
_('Unknown error: %s').format(err)
]);
dom.content(log_textarea, log);
});
}));
return E([
E('style', [ css ]),
E('div', {'class': 'cbi-map'}, [
E('h3', {'name': 'content'}, [
_('%s log').format(name),
' ',
E('button', {
'class': 'btn cbi-button cbi-button-action',
'click': ui.createHandlerFn(this, function() {
return L.resolveDefault(callLogClean(filename), {});
})
}, [ _('Clean log') ])
]),
E('div', {'class': 'cbi-section'}, [
log_textarea,
E('div', {'style': 'text-align:right'},
E('small', {}, _('Refresh every %s seconds.').format(L.env.pollinterval))
)
])
])
]);
}
return view.extend({
2025-01-15 16:25:40 +08:00
render(data) {
2024-12-22 14:14:14 +08:00
let m, s, o, ss, so;
2024-10-26 10:27:23 +08:00
m = new form.Map('fchomo');
s = m.section(form.NamedSection, 'config', 'fchomo');
2025-02-10 00:21:15 +08:00
/* FullCombo Shark! START */
s.tab('fchomo', _('FullCombo Shark!'));
2024-12-22 14:14:14 +08:00
o = s.taboption('fchomo', form.SectionValue, '_fchomo', form.NamedSection, 'config', null);
ss = o.subsection;
2024-10-26 10:27:23 +08:00
2024-12-22 14:14:14 +08:00
so = ss.option(form.DummyValue, '_fchomo_logview');
2025-02-10 00:21:15 +08:00
so.render = L.bind(getRuntimeLog, so, _('FullCombo Shark!'), 'fchomo');
/* FullCombo Shark! END */
2024-10-26 10:27:23 +08:00
2024-12-22 14:14:14 +08:00
/* Mihomo client START */
s.tab('mihomo_c', _('Mihomo client'));
o = s.taboption('mihomo_c', form.SectionValue, '_mihomo_c', form.NamedSection, 'config', null);
ss = o.subsection;
so = ss.option(form.DummyValue, '_mihomo-c_logview');
so.render = L.bind(getRuntimeLog, so, _('Mihomo client'), 'mihomo-c');
/* Mihomo client END */
/* Mihomo server START */
s.tab('mihomo_s', _('Mihomo server'));
o = s.taboption('mihomo_s', form.SectionValue, '_mihomo_s', form.NamedSection, 'config', null);
ss = o.subsection;
so = ss.option(form.DummyValue, '_mihomo-s_logview');
so.render = L.bind(getRuntimeLog, so, _('Mihomo server'), 'mihomo-s');
/* Mihomo server END */
2024-10-26 10:27:23 +08:00
return m.render();
},
handleSaveApply: null,
handleSave: null,
handleReset: null
});