summaryrefslogtreecommitdiffstats
path: root/applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_monitor_admin.js
blob: 51864eecf78be5055145b958e649145ed1120461 (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
'use strict';
'require form';
'require fs';
'require view';

const ups_ssl_backend_file = '/usr/share/nut/ssl_backend';
const upsmon_daemon = '/usr/sbin/upsmon';

return view.extend({
	load: function() {
		return Promise.all([
			fs.trimmed(ups_ssl_backend_file).then(function(backend) {
				if (backend)
					return backend;
				// nut older than 2.8.5-5 does not ship ssl_backend, so probe the binary instead
				return L.resolveDefault(fs.exec_direct('/usr/bin/ldd', [upsmon_daemon]), '').then(function(stdout) {
					return stdout.includes('libssl.so') ? 'old_nut_openssl' : 'none';
				});
			}),
		])
	},

	render: function(loaded_promises) {
		let m, s, o;

		const ssl_support_type = loaded_promises[0];

		m = new form.Map('nut_monitor', _('NUT Monitor'),
			_('Network UPS Tools Monitoring Configuration'));

		s = m.section(form.NamedSection, 'upsmon', 'upsmon', _('Global Settings'));
		s.addremove = true;
		s.optional = true;

		o = s.option(form.Value, 'runas', _('RunAs User'), _('upsmon drops privileges to this user'));
		o.placeholder = 'nutmon'

		o = s.option(form.Value, 'notifycmd', _('Notify command'));
		o.optional = true;

		o = s.option(form.Value, 'shutdowncmd', _('Shutdown command'));
		o.optional = true;
		o.placeholder = '/usr/sbin/nutshutdown'

		if (ssl_support_type == 'openssl') {
			o = s.option(form.FileUpload, 'certfile', _('Client certificate chain and private key'), _('PEM file containing client certificate chain and private key (OpenSSL)'));
			o.rmempty = true;
			o.optional = true;
		}

		if (ssl_support_type == 'openssl' || ssl_support_type == 'old_nut_openssl') {
			// For OpenSSL, certpath is a PEM file, not a database directory as with NSS
			o = s.option(form.FileUpload, 'certpath', _('CA certificate(s)'), _('PEM file containing the CA certificate(s) (OpenSSL)'));
			o.rmempty = true;
			o.optional = true;
		}

		if (ssl_support_type == 'nss') {
			// For NSS, certpath is a database directory, not a PEM file as with OpenSSL.
			// We do not fill this field by default as the default database has no certificates,
			// and must be filled to be useful. Doing this through the UI is a future task.
			o = s.option(form.Value, 'certpath', _('Path to NSS certificate and key databases'), _('An empty database was created in /etc/nut/cert_db at package install. To use it, SSH in, fill it using certutil, and put /etc/nut/cert_db in this field.'));
			o.optional = true;
		}

		if (ssl_support_type == 'openssl' || ssl_support_type == 'nss') {
			o = s.option(form.Value, 'certident', _('Certificate name and password'), _('"Certificate name" and "certificate password" need to be entered in double-quotes (") if the value has a space in it. An empty password must be entered as an empty pair of double-quotes ("")'));
			o.placeholder = '"certificate name" "certificate password"';
			o.password = true;
		}

		if (ssl_support_type == 'openssl' || ssl_support_type == 'old_nut_openssl' || ssl_support_type == 'nss') {
			o = s.option(form.Flag, 'certverify', _('Verify all connections with SSL'), _('Require SSL and verify host certificate'));
			o.optional = true;
			o.default = false;
			o.rmempty = false

			o = s.option(form.Flag, 'forcessl', _('Require SSL to connect'), _('Require SSL even if not verifying host certificates'));
			o.optional = true;
			o.default = false;
			o.rmempty = false;
		}

		if (ssl_support_type == 'openssl' || ssl_support_type == 'nss') {
			o = s.option(form.DynamicList, 'certhost', _('Per-host override for certident, certverify, and forcessl'), _('hostname "certificate name" certverify (as 0 or 1) forcessl (as 0 or 1)'));
			o.optional = true;
			o.placeholder = 'hostname "certificate name" certverify forcessl';
		}

		return m.render();
	}
});