summaryrefslogtreecommitdiffstats
path: root/applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_server.js
blob: eb9df2e9719694307e593db4bd5c4ec472666171 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
'use strict';
'require form';
'require fs';
'require view';

const driver_path = '/usr/libexec/nut/';
const old_driver_path = '/lib/nut/';

function resolveDriverList(path) {
	return Promise.resolve(L.resolveDefault(fs.list(path), []).then(function(entries) {
		var files = [];
		if (entries && entries.length > 0) {
			entries.forEach(object => {
				if (object.type == 'file') {
					files.push(object.name);
				}
			});
		}
		return files;
	}));
}

return view.extend({
	load: function() {
		return Promise.all([
			resolveDriverList(driver_path),
			resolveDriverList(old_driver_path),
		])
	},

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

		const driver_list = (loaded_promises[0].length > 0) ? loaded_promises[0] : loaded_promises[1];

		m = new form.Map('nut_server', _('NUT Server'),
			_('Network UPS Tools Server Configuration'));

		// User settings
		s = m.section(form.TypedSection, 'user', _('NUT Users'));
		s.addremove = true;
		s.anonymous = true;

		o = s.option(form.Value, 'username', _('Username'));
		o.optional = false;

		o = s.option(form.Value, 'password', _('Password'));
		o.password = true;
		o.optional = false;

		o = s.option(form.MultiValue, 'actions', _('Allowed actions'));
		// o.widget = 'select'
		o.value('set', _('Set variables'));
		o.value('fsd', _('Forced Shutdown'));
		o.optional = true;

		o = s.option(form.DynamicList, 'instcmd', _('Instant commands'), _('Use %s to see full list of commands your UPS supports (requires %s package)'.format('<code>upscmd -l</code>', '<code>upscmd</code>')));
		o.optional = true;

		o = s.option(form.ListValue, 'upsmon', _('Role'));
		o.value('secondary', _('Auxiliary'));
		o.value('primary', _('Primary'));
		o.value('slave', _('Auxiliary (Deprecated)'));
		o.value('master', _('Primary (Deprecated)'));
		o.optional = false;

		// Listen settings
		s = m.section(form.TypedSection, 'listen_address', _('Addresses on which to listen'));
		s.addremove = true;
		s.anonymous = true;

		o = s.option(form.Value, 'address', _('IP Address'));
		o.optional = false;
		o.datatype = 'ipaddr';
		o.placeholder = '127.0.0.1';

		o = s.option(form.Value, 'port', _('Port'));
		o.optional = true;
		o.datatype = 'port';
		o.placeholder = '3493';

		// Server global settings
		s = m.section(form.NamedSection, 'upsd', 'upsd', _('UPS Server Global Settings'));
		s.addremove = true;

		o = s.option(form.Value, 'maxage', _('Maximum Age of Data'), _('Period after which data is considered stale'));
		o.datatype = 'uinteger'
		o.optional = true;
		o.placeholder = 15;

		o = s.option(form.Value, 'maxconn', _('Maximum connections'));
		o.optional = true;
		o.datatype = 'uinteger'
		o.placeholder = 24;

		// Drivers global settings
		s = m.section(form.NamedSection, 'driver_global', 'driver_global', _('Driver Global Settings'));
		s.addremove = true;

		o = s.option(form.Value, 'chroot', _('chroot'), _('Run drivers in a chroot(2) environment'));
		o.optional = true;

		o = s.option(form.Value, 'maxstartdelay', _('Maximum Start Delay'), _('Default for UPSes without this field.'));
		o.optional = true;
		o.datatype = 'uinteger';

		o = s.option(form.Value, 'maxretry', _('Maximum Retries'), _('Maximum number of times to try starting a driver.'));
		o.optional = true;
		o.placeholder = 1
		o.datatype = 'uinteger';

		o = s.option(form.Value, 'retrydelay', _('Retry Delay'), _('Time in seconds between driver start retry attempts.'));
		o.optional = true;
		o.placeholder = 5
		o.datatype = 'uinteger';

		o = s.option(form.Value, 'pollinterval', _('Poll Interval'), _('Maximum time in seconds between refresh of UPS status'));
		o.optional = true;
		o.placeholder = 2
		o.datatype = 'uinteger';

		o = s.option(form.Flag, 'synchronous', _('Synchronous Communication'), _('Driver waits for data to be consumed by upsd before publishing more.'));
		o.optional = true;
		o.default = false;

		// Drivers
		s = m.section(form.TypedSection, 'driver', _('Driver Configuration'),
			_('The name of this section will be used as UPS name elsewhere'));
		s.addremove = true;
		s.anonymous = false;

		o = s.option(form.ListValue, 'driver', _('Driver'),
			_('If this list is empty you need to %s'.format('<a href="/cgi-bin/luci/admin/system/package-manager?query=nut-driver-">%s</a>'.format(_('install drivers')))));
		driver_list.forEach(driver => {
			o.value(driver);
		});
		o.optional = false;

		o = s.option(form.Value, 'productid', _('USB Product Id'), _('For USB HID based UPSes, USB Product Id is required for NUT to set permissions so the driver can access the UPS'));
		o.optional = true;

		o = s.option(form.Value, 'vendorid', _('USB Vendor Id'), _('For USB HID based UPSes, USB Vendor Id is required for NUT to set permissions so the driver can access the UPS'));
		o.optional = true;

		o = s.option(form.Value, 'serial', _('Serial Number'), _('For USB HID based UPSes, allows use of multiple USB devices of the same type (USB product and USB vendor are identical). Other UPSes may also use this value.'));
		o.optional = true;

		o = s.option(form.Flag, 'enable_usb_serial', _('Set USB serial port permissions'),
			_('Enables a hotplug script that makes all ttyUSB devices (e.g. serial USB) group read-write as user %s'.format('<code>nut</code>')));
		o.optional = true;
		o.default = false;

		o = s.option(form.Value, 'bus', _('USB Bus(es) (regex)'));
		o.optional = true;
		o.datatype = 'uinteger';

		o = s.option(form.Value, 'community', _('SNMP Community'));
		o.optional = true;
		o.placeholder = 'private';

		o = s.option(form.Value, 'desc', _('Description (Display)'), _('This is passed through to the driver, so make sure your driver supports this option'));
		o.optional = true;

		o = s.option(form.Flag, 'ignorelb', _('Ignore Low Battery'));
		o.optional = true;
		o.default = false;

		o = s.option(form.Flag, 'interruptonly', _('Interrupt Only'));
		o.optional = true;
		o.default = false;

		o = s.option(form.Value, 'interruptsize', _('Interrupt Size'), _('Bytes to read from interrupt pipe'));
		o.optional = true;
		o.datatype = 'uinteger';

		o = s.option(form.Value, 'maxreport', _('Max USB HID Length Reported'), _('Workaround for buggy firmware'));
		o.optional = true;
		o.datatype = 'uinteger';

		o = s.option(form.Value, 'maxstartdelay', _('Maximum Start Delay'), _('Time in seconds that upsdrvctl will wait for driver to finish starting'));
		o.optional = true;
		o.datatype = 'uinteger';
		o.placeholder = 45;

		o = s.option(form.Value, 'mfr', _('Manufacturer (Display)'), _('This is passed through to the driver, so make sure your driver supports this option'));
		o.optional = true;

		o = s.option(form.Value, 'model', _('Model (Display)'), _('This is passed through to the driver, so make sure your driver supports this option'));
		o.optional = true;

		o = s.option(form.Flag, 'nolock', _('No Lock'), _('Do not lock port when starting driver'));
		o.optional = true;
		o.default = false;

		o = s.option(form.Flag, 'notransferoids', _('No low/high voltage transfer OIDs'));
		o.optional = true;
		o.default = false;

		o = s.option(form.Value, 'offdelay', _('Off Delay(s)'), _('Delay for kill power command'));
		o.optional = true;
		o.placeholder = 20;
		// function o.validate(self, cfg, value);
		//    if n:cfgvalue(cfg) <= value then
		// 	return nil
		//    end
		// end

		o = s.option(form.Value, 'ondelay', _('On Delay(s)'), _('Delay to power on UPS if power returns after kill power'));
		o.optional = true;
		o.placeholder = 30;
		// function o.validate(self, cfg, value);
		//    if o.cfgvalue(cfg) >= value then
		// 	return nil
		//    end
		// end

		o = s.option(form.Value, 'pollfreq', _('Polling Frequency(s)'));
		o.optional = true;
		o.datatype = 'integer';
		o.placeholder = 30;

		o = s.option(form.Value, 'port', _('Port'));
		o.optional = false;
		o.default = 'auto';

		o = s.option(form.Value, 'product', _('Product (regex)'));
		o.optional = true;

		o = s.option(form.Value, 'sdorder', _('Driver Shutdown Order'));
		o.optional = true;
		o.datatype = 'uinteger';

		o = s.option(form.Value, 'sdtime', _('Additional Shutdown Time(s)'));
		o.optional = true;

		o = s.option(form.Value, 'snmp_retries', _('SNMP retries'));
		o.optional = true;
		o.datatype = 'uinteger';

		o = s.option(form.Value, 'snmp_timeout', _('SNMP timeout(s)'));
		o.optional = true;
		o.datatype = 'uinteger';

		o = s.option(form.ListValue, 'snmp_version', _('SNMP version'));
		o.optional = true;
		o.value('v1', _('SNMPv1'));
		o.value('v2c', _('SNMPv2c'));
		o.value('v3', _('SNMPv3'));
		o.value('', '');
		o.placeholder = ''

		o = s.option(form.Value, 'vendor', _('Vendor (regex)'));
		o.optional = true;

		o = s.option(form.Flag, 'synchronous', _('Synchronous Communication'), _('Driver waits for data to be consumed by upsd before publishing more.'));
		o.optional = true;
		o.default = false;

		return m.render();
	}
});