nut_server.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. 'use strict';
  2. 'require form';
  3. 'require fs';
  4. 'require view';
  5. const driver_path = '/lib/nut/';
  6. const ups_daemon = '/usr/sbin/upsd';
  7. return view.extend({
  8. load: function() {
  9. return Promise.all([
  10. L.resolveDefault(fs.exec_direct('/usr/bin/ldd', [ups_daemon]), []).catch(function(err) {
  11. throw new Error(_('Unable to run ldd: %s').format(err.message));
  12. }).then(function(stdout) {
  13. return stdout.includes('libssl.so');
  14. }),
  15. L.resolveDefault(fs.list(driver_path), []).then(function(entries) {
  16. var files = [];
  17. entries.forEach(object => {
  18. if (object.type == 'file') {
  19. files.push(object.name);
  20. }
  21. });
  22. return files;
  23. }),
  24. ])
  25. },
  26. render: function(loaded_promises) {
  27. var m, s, o;
  28. const have_ssl_support = loaded_promises[0];
  29. const driver_list = loaded_promises[1];
  30. m = new form.Map('nut_server', _('NUT Server'),
  31. _('Network UPS Tools Server Configuration'));
  32. // User settings
  33. s = m.section(form.TypedSection, 'user', _('NUT Users'));
  34. s.addremove = true;
  35. s.anonymous = true;
  36. o = s.option(form.Value, 'username', _('Username'));
  37. o.optional = false;
  38. o = s.option(form.Value, 'password', _('Password'));
  39. o.password = true;
  40. o.optional = false;
  41. o = s.option(form.MultiValue, 'actions', _('Allowed actions'));
  42. // o.widget = 'select'
  43. o.value('set', _('Set variables'));
  44. o.value('fsd', _('Forced Shutdown'));
  45. o.optional = true;
  46. 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>')));
  47. o.optional = true;
  48. o = s.option(form.ListValue, 'upsmon', _('Role'));
  49. o.value('slave', _('Auxiliary'));
  50. o.value('master', _('Primary'));
  51. o.optional = false;
  52. // Listen settings
  53. s = m.section(form.TypedSection, 'listen_address', _('Addresses on which to listen'));
  54. s.addremove = true;
  55. s.anonymous = true;
  56. o = s.option(form.Value, 'address', _('IP Address'));
  57. o.optional = false;
  58. o.datatype = 'ipaddr';
  59. o.placeholder = '127.0.0.1';
  60. o = s.option(form.Value, 'port', _('Port'));
  61. o.optional = true;
  62. o.datatype = 'port';
  63. o.placeholder = '3493';
  64. // Server global settings
  65. s = m.section(form.NamedSection, 'upsd', 'upsd', _('UPS Server Global Settings'));
  66. s.addremove = true;
  67. o = s.option(form.Value, 'maxage', _('Maximum Age of Data'), _('Period after which data is considered stale'));
  68. o.datatype = 'uinteger'
  69. o.optional = true;
  70. o.placeholder = 15;
  71. o = s.option(form.Value, 'runas', _('RunAs User'), _('Drop privileges to this user'));
  72. o.optional = true;
  73. o.placeholder = 'nut'
  74. o = s.option(form.Value, 'statepath', _('Path to state file'));
  75. o.optional = true;
  76. o.placeholder = '/var/run/nut'
  77. o = s.option(form.Value, 'maxconn', _('Maximum connections'));
  78. o.optional = true;
  79. o.datatype = 'uinteger'
  80. o.placeholder = 24;
  81. if (have_ssl_support) {
  82. o = s.option(form.Value, 'certfile', _('Certificate file (SSL)'));
  83. o.optional = true;
  84. }
  85. // Drivers global settings
  86. s = m.section(form.NamedSection, 'driver_global', 'driver_global', _('Driver Global Settings'));
  87. s.addremove = true;
  88. o = s.option(form.Value, 'chroot', _('chroot'), _('Run drivers in a chroot(2) environment'));
  89. o.optional = true;
  90. o = s.option(form.Value, 'driverpath', _('Driver Path'), _('Path to drivers (instead of default)'));
  91. o.optional = true;
  92. o.placeholder = '/lib/lnut';
  93. o = s.option(form.Value, 'maxstartdelay', _('Maximum Start Delay'), _('Default for UPSes without this field.'));
  94. o.optional = true;
  95. o.datatype = 'uinteger';
  96. o = s.option(form.Value, 'maxretry', _('Maximum Retries'), _('Maximum number of times to try starting a driver.'));
  97. o.optional = true;
  98. o.placeholder = 1
  99. o.datatype = 'uinteger';
  100. o = s.option(form.Value, 'retrydelay', _('Retry Delay'), _('Time in seconds between driver start retry attempts.'));
  101. o.optional = true;
  102. o.placeholder = 5
  103. o.datatype = 'uinteger';
  104. o = s.option(form.Value, 'pollinterval', _('Poll Interval'), _('Maximum time in seconds between refresh of UPS status'));
  105. o.optional = true;
  106. o.placeholder = 2
  107. o.datatype = 'uinteger';
  108. o = s.option(form.Flag, 'synchronous', _('Synchronous Communication'), _('Driver waits for data to be consumed by upsd before publishing more.'));
  109. o.optional = true;
  110. o.default = false;
  111. 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.'));
  112. o.optional = true;
  113. o.placeholder = 'nut';
  114. // Drivers
  115. s = m.section(form.TypedSection, 'driver', _('Driver Configuration'),
  116. _('The name of this section will be used as UPS name elsewhere'));
  117. s.addremove = true;
  118. s.anonymous = false;
  119. o = s.option(form.Value, 'bus', _('USB Bus(es) (regex)'));
  120. o.optional = true;
  121. o.datatype = 'uinteger';
  122. o = s.option(form.Value, 'community', _('SNMP Community'));
  123. o.optional = true;
  124. o.placeholder = 'private';
  125. o = s.option(form.Value, 'desc', _('Description (Display)'));
  126. o.optional = true;
  127. o = s.option(form.ListValue, 'driver', _('Driver'),
  128. _('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')))));
  129. driver_list.forEach(driver => {
  130. o.value(driver_path + driver);
  131. });
  132. o.optional = false;
  133. o = s.option(form.Flag, 'enable_usb_serial', _('Set USB serial port permissions'),
  134. _('Enables a hotplug script that makes all ttyUSB devices (e.g. serial USB) group read-write as user %s'.format('<code>nut</code>')));
  135. o.optional = true;
  136. o.default = false;
  137. o = s.option(form.Flag, 'ignorelb', _('Ignore Low Battery'));
  138. o.optional = true;
  139. o.default = false;
  140. o = s.option(form.Flag, 'interruptonly', _('Interrupt Only'));
  141. o.optional = true;
  142. o.default = false;
  143. o = s.option(form.Value, 'interruptsize', _('Interrupt Size'), _('Bytes to read from interrupt pipe'));
  144. o.optional = true;
  145. o.datatype = 'uinteger';
  146. o = s.option(form.Value, 'maxreport', _('Max USB HID Length Reported'), _('Workaround for buggy firmware'));
  147. o.optional = true;
  148. o.datatype = 'uinteger';
  149. o = s.option(form.Value, 'maxstartdelay', _('Maximum Start Delay'), _('Time in seconds that upsdrvctl will wait for driver to finish starting'));
  150. o.optional = true;
  151. o.datatype = 'uinteger';
  152. o.placeholder = 45;
  153. o = s.option(form.Value, 'mfr', _('Manufacturer (Display)'));
  154. o.optional = true;
  155. o = s.option(form.Value, 'model', _('Model (Display)'));
  156. o.optional = true;
  157. o = s.option(form.Flag, 'nolock', _('No Lock'), _('Do not lock port when starting driver'));
  158. o.optional = true;
  159. o.default = false;
  160. o = s.option(form.Flag, 'notransferoids', _('No low/high voltage transfer OIDs'));
  161. o.optional = true;
  162. o.default = false;
  163. o = s.option(form.Value, 'offdelay', _('Off Delay(s)'), _('Delay for kill power command'));
  164. o.optional = true;
  165. o.placeholder = 20;
  166. // function o.validate(self, cfg, value);
  167. // if n:cfgvalue(cfg) <= value then
  168. // return nil
  169. // end
  170. // end
  171. o = s.option(form.Value, 'ondelay', _('On Delay(s)'), _('Delay to power on UPS if power returns after kill power'));
  172. o.optional = true;
  173. o.placeholder = 30;
  174. // function o.validate(self, cfg, value);
  175. // if o.cfgvalue(cfg) >= value then
  176. // return nil
  177. // end
  178. // end
  179. o = s.option(form.Value, 'pollfreq', _('Polling Frequency(s)'));
  180. o.optional = true;
  181. o.datatype = 'integer';
  182. o.placeholder = 30;
  183. o = s.option(form.Value, 'port', _('Port'));
  184. o.optional = false;
  185. o.default = 'auto';
  186. o = s.option(form.Value, 'product', _('Product (regex)'));
  187. o.optional = true;
  188. o = s.option(form.Value, 'productid', _('USB Product Id'));
  189. o.optional = true;
  190. o = s.option(form.Value, 'sdorder', _('Driver Shutdown Order'));
  191. o.optional = true;
  192. o.datatype = 'uinteger';
  193. o = s.option(form.Value, 'sdtime', _('Additional Shutdown Time(s)'));
  194. o.optional = true;
  195. o = s.option(form.Value, 'serial', _('Serial Number'));
  196. o.optional = true;
  197. o = s.option(form.Value, 'snmp_retries', _('SNMP retries'));
  198. o.optional = true;
  199. o.datatype = 'uinteger';
  200. o = s.option(form.Value, 'snmp_timeout', _('SNMP timeout(s)'));
  201. o.optional = true;
  202. o.datatype = 'uinteger';
  203. o = s.option(form.ListValue, 'snmp_version', _('SNMP version'));
  204. o.optional = true;
  205. o.value('v1', _('SNMPv1'));
  206. o.value('v2c', _('SNMPv2c'));
  207. o.value('v3', _('SNMPv3'));
  208. o.value('', '');
  209. o.placeholder = ''
  210. o = s.option(form.Value, 'vendor', _('Vendor (regex)'));
  211. o.optional = true;
  212. o = s.option(form.Value, 'vendorid', _('USB Vendor Id'));
  213. o.optional = true;
  214. o = s.option(form.Flag, 'synchronous', _('Synchronous Communication'), _('Driver waits for data to be consumed by upsd before publishing more.'));
  215. o.optional = true;
  216. o.default = false;
  217. return m.render();
  218. }
  219. });