summaryrefslogtreecommitdiffstats
path: root/applications/luci-app-unbound/htdocs/luci-static/resources/view/unbound/status.js
blob: 1d7fa0071985691e527a0faa3f261daf52f4c5af (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
'use strict';
'require dom';
'require fs';
'require poll';
'require view';

const FILENAME = '/usr/sbin/unbound-control';

return view.extend({
	load() {
		return L.resolveDefault(fs.stat(FILENAME), "")
			.then(stat => {
			if (!stat) {
				return Promise.all([
					L.resolveDefault(fs.stat('/sbin/logread'), {path: ''}),
					Promise.resolve({ path: '' }),
					Promise.resolve(null),
					Promise.resolve(null),
					Promise.resolve(null),
					Promise.resolve(null),
				]);
			} else {
				return Promise.all([
					L.resolveDefault(fs.stat('/sbin/logread'), {path: ''}),
					L.resolveDefault(fs.stat(FILENAME), {path: false}),
					L.resolveDefault(fs.exec_direct(FILENAME, ['-c', '/var/lib/unbound/unbound.conf', 'stats_noreset']).then(data => {return data}), {}),
					L.resolveDefault(fs.exec_direct(FILENAME, ['-c', '/var/lib/unbound/unbound.conf', 'list_local_data']).then(data => {return data}), {}),
					L.resolveDefault(fs.exec_direct(FILENAME, ['-c', '/var/lib/unbound/unbound.conf', 'list_local_zones']).then(data => {return data}), {}),
					L.resolveDefault(fs.exec_direct(FILENAME, ['-c', '/var/lib/unbound/unbound.conf', 'dump_cache']).then(data => {return data}), {}),
				]);
			}
		});
	},

	render([logread, uc, stats, data, zones, cache]) {

		L.Poll.add(() => {
			return L.resolveDefault(fs.exec_direct(logread.path, ['-e', 'unbound:'])).then(function(res) {
				const log = document.getElementById("logfile");
				log.value = res ? res.trim() : _('No related logs yet!');
				log.scrollTop = log.scrollHeight;
			});
		});

		if (uc.path) {
			// Stats
			L.Poll.add(() => {
				return L.resolveDefault(fs.exec_direct('/usr/sbin/unbound-control', ['-c', '/var/lib/unbound/unbound.conf', 'stats_noreset'])).then(function(res) {
					const stats = document.getElementById("stats");
					stats.value = res ? res.trim() : _('No stats yet!');
				});
			});
			// Local Data
			L.Poll.add(() => {
				return L.resolveDefault(fs.exec_direct('/usr/sbin/unbound-control', ['-c', '/var/lib/unbound/unbound.conf', 'list_local_data'])).then(function(res) {
					const ld = document.getElementById("local_data");
					ld.value = res ? res.trim() : _('No local data yet!');
					ld.scrollTop = ld.scrollHeight;
				});
			});
			// Zones Data
			L.Poll.add(() => {
				return L.resolveDefault(fs.exec_direct('/usr/sbin/unbound-control', ['-c', '/var/lib/unbound/unbound.conf', 'list_local_zones'])).then(function(res) {
					const zd = document.getElementById("zones_data");
					zd.value = res ? res.trim() :_('No zones data yet!');
					zd.scrollTop = zd.scrollHeight;
				});
			});
			// Cache Dump
			L.Poll.add(() => {
				return L.resolveDefault(fs.exec_direct('/usr/sbin/unbound-control', ['-c', '/var/lib/unbound/unbound.conf', 'dump_cache'])).then(function(res) {
					const dc = document.getElementById("cache_dump");
					dc.value = res ? (res.length > 262144 ? _('Unbound cache is too large to display in LuCI.') : res.trim()) : _('No cache dump yet!');
					dc.scrollTop = dc.scrollHeight;
				});
			});
		}

		return E('div', [
				(!uc.path) ?
				E('div', { class: 'cbi-section' }, [
					E('div', { class: 'cbi-section-descr' }, _('This could display more statistics with the unbound-control package.')),
				]) : '',
				(uc.path) ?
				E('div', { class: 'cbi-section' }, [
					E('div', { class: 'cbi-section-descr' }, _('This shows Unbound self reported performance statistics.')),
					E('textarea', {
						'id': 'stats',
						'style': 'width: 100% !important; padding: 5px; font-family: monospace',
						'readonly': 'readonly',
						'wrap': 'off',
						'rows': 10,
						'value': stats,
						'placeholder': _('Statistics'),
				})]) : '',
				(uc.path) ?
				E('div', { class: 'cbi-section' }, [
					E('div', { class: 'cbi-section-descr' }, _("This shows Unbound 'local-data:' entries from default, .conf, or control.")),
					E('textarea', {
						'id': 'local_data',
						'style': 'width: 100% !important; padding: 5px; font-family: monospace',
						'readonly': 'readonly',
						'wrap': 'off',
						'rows': 10,
						'value': data,
						'placeholder': _('Local Data'),
				})]) : '',
				(uc.path) ?
				E('div', { class: 'cbi-section' }, [
					E('div', { class: 'cbi-section-descr' }, _("This shows Unbound 'local-zone:' entries from default, .conf, or control.")),
					E('textarea', {
						'id': 'zones_data',
						'style': 'width: 100% !important; padding: 5px; font-family: monospace',
						'readonly': 'readonly',
						'wrap': 'off',
						'rows': 10,
						'value': zones,
						'placeholder': _('Local Zones'),
				})]) : '',
				(uc.path) ?
				E('div', { class: 'cbi-section' }, [
					E('div', { class: 'cbi-section-descr' }, _("This shows 'ubound-control dump_cache' for auditing records including DNSSEC.")),
					E('textarea', {
						'id': 'cache_dump',
						'style': 'width: 100% !important; padding: 5px; font-family: monospace',
						'readonly': 'readonly',
						'wrap': 'off',
						'rows': 10,
						'value': cache,
						'placeholder': _('DNS Cache'),
				})]) : '',
				E('div', { class: 'cbi-map' },
					E('div', { class: 'cbi-section' }, [
					E('div', { class: 'cbi-section-descr' }, _('This shows syslog filtered for events involving Unbound.')),
					E('textarea', {
						'id': 'logfile',
						'style': 'width: 100% !important; padding: 5px; font-family: monospace',
						'readonly': 'readonly',
						'wrap': 'off',
						'rows': 25,
						'placeholder': _('Log'),
					}),
				])),
			]);
	},

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