summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-nut/htdocs/luci-static/resources
diff options
context:
space:
mode:
authorPaul Donald <newtwen+github@gmail.com>2024-10-09 15:27:46 +0200
committerPaul Donald <newtwen+github@gmail.com>2024-10-10 00:42:40 +0200
commit84c04c3707b992ba8aa1c66ee876d46eaeeb47ef (patch)
tree9688a1a8aab6dbb486720b2ac9eca2513ad3416c /applications/luci-app-nut/htdocs/luci-static/resources
parentf6e6b055d514595941db4a4cc11c3d9902eabefb (diff)
luci-app-nut: Convert to JS
Tested on 23.05.5 Signed-off-by: Paul Donald <newtwen+github@gmail.com>
Diffstat (limited to 'applications/luci-app-nut/htdocs/luci-static/resources')
-rw-r--r--applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_cgi.js47
-rw-r--r--applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_monitor.js212
-rw-r--r--applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_server.js278
3 files changed, 537 insertions, 0 deletions
diff --git a/applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_cgi.js b/applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_cgi.js
new file mode 100644
index 0000000000..f7067990a1
--- /dev/null
+++ b/applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_cgi.js
@@ -0,0 +1,47 @@
+'use strict';
+'require form';
+'require view';
+
+return view.extend({
+ load: function() {
+
+ },
+
+ render: function() {
+ var m, s, o;
+
+ m = new form.Map('nut_cgi', _('NUT CGI'),
+ _('Network UPS Tools CGI Configuration') + '<br />' +
+ '%s'.format('<a href="/nut">%s</a>'.format(_('Go to NUT CGI'))));
+
+ s = m.section(form.TypedSection, 'host', _('Host'));
+ s.addremove = true;
+ s.anonymous = true;
+
+ o = s.option(form.Value, 'upsname', _('UPS name'), _('As configured by NUT'));
+ o.optional = false;
+
+ o = s.option(form.Value, 'hostname', _('Hostname or IP address'));
+ o.optional = false;
+ o.datatype = 'or(host,ipaddr)';
+
+ o = s.option(form.Value, 'port', _('Port'));
+ o.datatype = 'port';
+ o.optional = true;
+ o.placeholder = 3493;
+
+ o = s.option(form.Value, 'displayname', _('Display name'));
+ o.optional = false;
+
+ s = m.section(form.TypedSection, 'upsset', _('Control UPS via CGI'));
+ s.addremove = false;
+ s.anonymous = true;
+ s.optional = false;
+
+ o = s.option(form.Flag, 'enable', _('Enable'));
+ o.optional = false;
+ o.default = false;
+
+ return m.render();
+ }
+});
diff --git a/applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_monitor.js b/applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_monitor.js
new file mode 100644
index 0000000000..16b951a6d6
--- /dev/null
+++ b/applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_monitor.js
@@ -0,0 +1,212 @@
+'use strict';
+'require form';
+'require fs';
+'require view';
+
+const upsmon_tool = '/usr/sbin/upsmon';
+
+function ESIFlags(o) {
+ o.value('EXEC', _('Execute notify command'));
+ o.value('SYSLOG', _('Write to syslog'));
+ o.value('IGNORE', _('Ignore'));
+ o.optional = true;
+ o.validate = function(section, v) {
+ if (!v) return true;
+ if(v.includes(' ') && v.includes('IGNORE'))
+ return _('%s is mutually exclusive to other choices'.format(_('Ignore')));
+ return true;
+ }
+ return o;
+}
+
+return view.extend({
+ load: function() {
+ return Promise.all([
+ L.resolveDefault(fs.exec_direct('/usr/bin/ldd', [upsmon_tool]), []).catch(function(err) {
+ throw new Error(_('Unable to run ldd: %s').format(err.message));
+ }).then(function(stdout) {
+ return stdout.includes('libssl.so');
+ }),
+ ])
+ },
+
+ render: function(loaded_promises) {
+ var m, s, o;
+ const have_ssl_support = 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, 'minsupplies', _('Minimum required number or power supplies'));
+ o.datatype = 'uinteger'
+ o.placeholder = 1;
+ o.optional = true;
+
+ o = s.option(form.Value, 'shutdowncmd', _('Shutdown command'));
+ o.optional = true;
+ o.placeholder = '/sbin/halt'
+
+ o = s.option(form.Value, 'notifycmd', _('Notify command'));
+ o.optional = true;
+
+ o = s.option(form.Value, 'pollfreq', _('Poll frequency'));
+ o.datatype = 'uinteger'
+ o.placeholder = 5;
+ o.optional = true;
+
+ o = s.option(form.Value, 'pollfreqalert', _('Poll frequency alert'));
+ o.datatype = 'uinteger'
+ o.optional = true;
+ o.placeholder = 5;
+
+ o = s.option(form.Value, 'hotsync', _('Hot Sync'));
+ o.optional = true;
+ o.placeholder = 15;
+
+ o = s.option(form.Value, 'deadtime', _('Deadtime'));
+ o.datatype = 'uinteger'
+ o.optional = true;
+ o.placeholder = 15;
+
+ o = s.option(form.Value, 'onlinemsg', _('Online message'));
+ o.optional = true;
+
+ o = s.option(form.Value, 'onbattmsg', _('On battery message'));
+ o.optional = true;
+
+ o = s.option(form.Value, 'lowbattmsg', _('Low battery message'));
+ o.optional = true;
+
+ o = s.option(form.Value, 'fsdmsg', _('Forced shutdown message'));
+ o.optional = true;
+
+ o = s.option(form.Value, 'comokmsg', _('Communications restored message'));
+ o.optional = true;
+
+ o = s.option(form.Value, 'combadmsg', _('Communications lost message'));
+ o.optional = true;
+
+ o = s.option(form.Value, 'shutdownmsg', _('Shutdown message'));
+ o.optional = true;
+
+ o = s.option(form.Value, 'replbattmsg', _('Replace battery message'));
+ o.optional = true;
+
+ o = s.option(form.Value, 'nocommsg', _('No communications message'));
+ o.optional = true;
+
+ o = s.option(form.Value, 'noparentmsg', _('No parent message'));
+ o.optional = true;
+
+ o = s.option(form.MultiValue, 'defaultnotify', _('Notification defaults'));
+ ESIFlags(o);
+
+ o = s.option(form.MultiValue, 'onlinenotify', _('Notify when back online'));
+ ESIFlags(o);
+
+ o = s.option(form.MultiValue, 'onbattnotify', _('Notify when on battery'));
+ ESIFlags(o);
+
+ o = s.option(form.MultiValue, 'lowbattnotify', _('Notify when low battery'));
+ ESIFlags(o);
+
+ o = s.option(form.MultiValue, 'fsdnotify', _('Notify when force shutdown'));
+ ESIFlags(o);
+
+ o = s.option(form.MultiValue, 'comoknotify', _('Notify when communications restored'));
+ ESIFlags(o);
+
+ o = s.option(form.MultiValue, 'combadnotify', _('Notify when communications lost'));
+ ESIFlags(o);
+
+ o = s.option(form.MultiValue, 'shutdownotify', _('Notify when shutting down'));
+ ESIFlags(o);
+
+ o = s.option(form.MultiValue, 'replbattnotify', _('Notify when battery needs replacing'));
+ ESIFlags(o);
+
+ o = s.option(form.MultiValue, 'nocommnotify', _('Notify when no communications'));
+ ESIFlags(o);
+
+ o = s.option(form.MultiValue, 'noparentnotify', _('Notify when no parent process'));
+ ESIFlags(o);
+
+ if (have_ssl_support) {
+ o = s.option(form.Value, 'certpath', _('CA Certificate path'), _('Path containing ca certificates to match against host certificate'));
+ o.optional = true;
+ o.placeholder = '/etc/ssl/certs'
+
+ o = s.option(form.Flag, 'certverify', _('Verify all connection with SSL'), _('Require SSL and make sure server CN matches hostname'));
+ o.optional = true;
+ o.default = false;
+ }
+
+ s = m.section(form.TypedSection, 'master', _('UPS Primary'));
+ s.optional = true;
+ s.addremove = true;
+ s.anonymous = true;
+
+ o = s.option(form.Value, 'upsname', _('Name of UPS'), _('As configured by NUT'));
+ o.optional = false;
+
+ o = s.option(form.Value, 'hostname', _('Hostname or address of UPS'));
+ o.optional = false;
+ o.datatype = 'or(host,ipaddr)';
+
+ o = s.option(form.Value, 'port', _('Port'));
+ o.optional = true;
+ o.placeholder = 3493;
+ o.datatype = 'port';
+
+ o = s.option(form.Value, 'powervalue', _('Power value'));
+ o.optional = false;
+ o.datatype = 'uinteger';
+ o.default = 1;
+
+ o = s.option(form.Value, 'username', _('Username'));
+ o.optional = false;
+
+ o = s.option(form.Value, 'password', _('Password'));
+ o.optional = false;
+ o.password = true;
+
+ s = m.section(form.TypedSection, 'slave', _('UPS Auxiliary'));
+ s.optional = true;
+ s.addremove = true;
+ s.anonymous = true;
+
+ o = s.option(form.Value, 'upsname', _('Name of UPS'), _('As configured by NUT'));
+ o.optional = false;
+
+ o = s.option(form.Value, 'hostname', _('Hostname or address of UPS'));
+ o.optional = false;
+ o.datatype = 'or(host,ipaddr)';
+
+ o = s.option(form.Value, 'port', _('Port'));
+ o.optional = true;
+ o.placeholder = 3493;
+ o.datatype = 'port';
+
+ o = s.option(form.Value, 'powervalue', _('Power value'));
+ o.optional = false;
+ o.datatype = 'uinteger';
+ o.default = 1;
+
+ o = s.option(form.Value, 'username', _('Username'));
+ o.optional = false;
+
+ o = s.option(form.Value, 'password', _('Password'));
+ o.optional = false;
+ o.password = true;
+
+
+ return m.render();
+ }
+});
diff --git a/applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_server.js b/applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_server.js
new file mode 100644
index 0000000000..9de4d52b42
--- /dev/null
+++ b/applications/luci-app-nut/htdocs/luci-static/resources/view/nut/nut_server.js
@@ -0,0 +1,278 @@
+'use strict';
+'require form';
+'require fs';
+'require view';
+
+const driver_path = '/lib/nut/';
+const ups_daemon = '/usr/sbin/upsd';
+
+return view.extend({
+ load: function() {
+ return Promise.all([
+ L.resolveDefault(fs.exec_direct('/usr/bin/ldd', [ups_daemon]), []).catch(function(err) {
+ throw new Error(_('Unable to run ldd: %s').format(err.message));
+ }).then(function(stdout) {
+ return stdout.includes('libssl.so');
+ }),
+ L.resolveDefault(fs.list(driver_path), []).then(function(entries) {
+ var files = [];
+ entries.forEach(object => {
+ if (object.type == 'file') {
+ files.push(object.name);
+ }
+ });
+ return files;
+ }),
+ ])
+ },
+
+ render: function(loaded_promises) {
+ var m, s, o;
+ const have_ssl_support = loaded_promises[0];
+ const driver_list = 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('slave', _('Auxiliary'));
+ o.value('master', _('Primary'));
+ 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, 'runas', _('RunAs User'), _('Drop privileges to this user'));
+ o.optional = true;
+ o.placeholder = 'nut'
+
+ o = s.option(form.Value, 'statepath', _('Path to state file'));
+ o.optional = true;
+ o.placeholder = '/var/run/nut'
+
+ o = s.option(form.Value, 'maxconn', _('Maximum connections'));
+ o.optional = true;
+ o.datatype = 'uinteger'
+ o.placeholder = 24;
+
+ if (have_ssl_support) {
+ o = s.option(form.Value, 'certfile', _('Certificate file (SSL)'));
+ o.optional = true;
+ }
+
+ // 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, 'driverpath', _('Driver Path'), _('Path to drivers (instead of default)'));
+ o.optional = true;
+ o.placeholder = '/lib/lnut';
+
+ 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;
+
+ o = s.option(form.Value, 'user', _('RunAs User'), _('User as which to execute driver; requires device file accessed by driver to be read-write for that user.'));
+ o.optional = true;
+ o.placeholder = 'nut';
+
+ // 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.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)'));
+ o.optional = true;
+
+ o = s.option(form.ListValue, 'driver', _('Driver'),
+ _('If this list is empty you need to %s'.format('<a href="/cgi-bin/luci/admin/system/opkg?query=nut-driver-">%s</a>'.format(_('install drivers')))));
+ driver_list.forEach(driver => {
+ o.value(driver_path + driver);
+ });
+ o.optional = false;
+
+ 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.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)'));
+ o.optional = true;
+
+ o = s.option(form.Value, 'model', _('Model (Display)'));
+ 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, 'productid', _('USB Product Id'));
+ 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, 'serial', _('Serial Number'));
+ 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.Value, 'vendorid', _('USB Vendor Id'));
+ 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();
+ }
+});