summaryrefslogtreecommitdiffstats
path: root/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/logtemplate.js
blob: 2026fffe8ffefd0f04accd3d04748fccb2cb40bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
'require rpc';

const callLogRead = rpc.declare({
	object: 'log',
	method: 'read',
	params: ['lines', 'stream', 'oneshot'],
	expect: {}
});

function Logview(logtag, name) {
	return L.view.extend({
		load: () => Promise.resolve(),

		render: function () {
			const pollFn = () => {
				return callLogRead(1000, false, true).then(res => {
					const logEl = document.getElementById('logfile');
					if (!logEl) return;
					const filtered = (res?.log ?? [])
						.filter(entry => !logtag || entry.msg.includes(logtag))
						.map(entry => {
							const d = new Date(entry.time);
							const pad = n => String(n).padStart(2, '0');
							const date = `${pad(d.getDate())}/${pad(d.getMonth() + 1)}/${d.getFullYear()}`;
							const time = `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
							return `[${date}-${time}] ${entry.msg}`;
						});
					logEl.value = filtered.length > 0
						? filtered.join('\n')
						: _('No %s related logs yet!').format(name);
					logEl.scrollTop = logEl.scrollHeight;
				});
			};

			this._pollFn = pollFn;
			L.Poll.add(pollFn);

			return E('div', { class: 'cbi-map' }, [
				E('div', { class: 'cbi-section' }, [
					E('div', { class: 'cbi-section-descr' },
						_('The syslog output, pre-filtered for messages related to: %s').format(name)),
					E('textarea', {
						id: 'logfile',
						style: 'min-height: 500px; max-height: 90vh; width: 100%; padding: 5px; font-family: monospace; resize: vertical;',
						readonly: 'readonly',
						wrap: 'off'
					})
				])
			]);
		},

		unload: function () {
			if (this._pollFn) {
				L.Poll.remove(this._pollFn);
				this._pollFn = null;
			}
		},

		handleSaveApply: null,
		handleSave: null,
		handleReset: null
	});
}

return L.Class.extend({ Logview });