vrrp_instance.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. 'use strict';
  2. 'require view';
  3. 'require form';
  4. 'require uci';
  5. 'require network';
  6. 'require tools.widgets as widgets';
  7. return view.extend({
  8. load: function() {
  9. return Promise.all([
  10. network.getDevices(),
  11. uci.load('keepalived'),
  12. ]);
  13. },
  14. renderGeneralTab: function(s) {
  15. var o, ipaddress;
  16. o = s.taboption('general',form.Value, 'name', _('Name'));
  17. o.rmempty = false;
  18. o.optional = false;
  19. o = s.taboption('general', form.ListValue, 'state', _('State'),
  20. _('Initial State. As soon as the other machine(s) come up,') +
  21. _('an election will be held and the machine with the highest "priority" will become MASTER.'));
  22. o.value('MASTER', _('Master'));
  23. o.value('BACKUP', _('Backup'));
  24. o.optional = false;
  25. o.rmempty = false;
  26. o = s.taboption('general', widgets.DeviceSelect, 'interface', _('Interface'),
  27. _('Interface for inside_network, bound by VRRP'));
  28. o.noaliases = true;
  29. o.noinactive = true;
  30. o.optional = false;
  31. o.rmempty = false;
  32. o = s.taboption('general', form.Value, 'virtual_router_id', _('Virtual Router Id'),
  33. _('Differentiate multiple instances of vrrpd, running on the same NIC'));
  34. o.datatype = 'range(1-255)';
  35. o.optional = false;
  36. o.rmempty = false;
  37. o = s.taboption('general', form.Value, 'priority', _('Priority'),
  38. _('A server with a higher priority becomes a MASTER'));
  39. o.datatype = 'uinteger';
  40. o.optional = false;
  41. o.rmempty = false;
  42. o = s.taboption('general', form.ListValue, 'advert_int', _('Interval'),
  43. _('VRRP Advert interval in seconds'));
  44. o.datatype = 'float';
  45. o.default = '1';
  46. o.rmempty = false;
  47. o.optional = false;
  48. o.value('1');
  49. o.value('3');
  50. o.value('5');
  51. o.value('10');
  52. o.value('30');
  53. o.value('60');
  54. o = s.taboption('general', form.Flag, 'nopreempt', _('Disable Preempt'),
  55. _('Allows the lower priority machine to maintain the master role,') +
  56. _('even when a higher priority machine comes back online.') + ' ' +
  57. _('For this to work, the initial state of this entry must be BACKUP.'));
  58. o.optional = true;
  59. o.default = false;
  60. ipaddress = uci.sections('keepalived', 'ipaddress');
  61. o = s.taboption('general', form.DynamicList, 'virtual_ipaddress', _('Virtual IP Address'),
  62. _('Addresses add|del on change to MASTER, to BACKUP.') + ' ' +
  63. _('With the same entries on other machines, the opposite transition will be occurring.'));
  64. if (ipaddress != '') {
  65. for (var i = 0; i < ipaddress.length; i++) {
  66. o.value(ipaddress[i]['name']);
  67. }
  68. }
  69. o.rmempty = false;
  70. o.optional = false;
  71. },
  72. renderPeerTab: function(s, netDevs) {
  73. var o;
  74. o = s.taboption('peer', form.ListValue, 'unicast_src_ip', _('Unicast Source IP'),
  75. _('Default IP for binding vrrpd is the primary IP on interface'));
  76. o.datatype = 'ipaddr';
  77. o.optional = true;
  78. o.modalonly = true;
  79. for (var i = 0; i < netDevs.length; i++) {
  80. var addrs = netDevs[i].getIPAddrs();
  81. for (var j = 0; j < addrs.length; j++) {
  82. o.value(addrs[j].split('/')[0]);
  83. }
  84. }
  85. var peers = uci.sections('keepalived', 'peer');
  86. o = s.taboption('peer', form.DynamicList, 'unicast_peer', _('Peer'),
  87. _('Do not send VRRP adverts over VRRP multicast group.') + ' ' +
  88. _('Instead it sends adverts to the following list of ip addresses using unicast design fashion'));
  89. if (peers != '') {
  90. for (var i = 0; i < peers.length; i++) {
  91. o.value(peers[i]['name']);
  92. }
  93. }
  94. o = s.taboption('peer', form.Value, 'mcast_src_ip', _('Multicast Source IP'),
  95. _('If you want to hide location of vrrpd, use this IP for multicast vrrp packets'));
  96. o.datatype = 'ipaddr';
  97. o.optional = true;
  98. o.modalonly = true;
  99. o.depends({ 'unicast_peer' : '' });
  100. o = s.taboption('peer', form.ListValue, 'auth_type', _('HA Authentication Type'));
  101. o.value('PASS', _('Simple Password'));
  102. o.value('AH', _('IPSec'));
  103. o = s.taboption('peer', form.Value, 'auth_pass', _('Password'),
  104. _('Password for accessing vrrpd, should be the same on all machines'));
  105. o.datatype = 'maxlength(8)';
  106. o.password = true;
  107. o.modalonly = true;
  108. o.depends({ 'auth_type' : 'PASS' });
  109. },
  110. renderGARPTab: function(s) {
  111. var o;
  112. o = s.taboption('garp', form.ListValue, 'garp_master_delay', _('GARP Delay'),
  113. _('Gratuitous Master Delay in seconds'));
  114. o.datatype = 'uinteger';
  115. o.modalonly = true;
  116. o.value('1');
  117. o.value('3');
  118. o.value('5');
  119. o.value('10');
  120. o.value('30');
  121. o.value('60');
  122. o = s.taboption('garp', form.ListValue, 'garp_master_repeat', _('GARP Repeat'),
  123. _('Gratuitous Master Repeat in seconds'));
  124. o.datatype = 'uinteger';
  125. o.modalonly = true;
  126. o.value('1');
  127. o.value('3');
  128. o.value('5');
  129. o.value('10');
  130. o.value('30');
  131. o.value('60');
  132. o = s.taboption('garp', form.ListValue, 'garp_master_refresh', _('GARP Refresh'),
  133. _('Gratuitous Master Refresh in seconds'));
  134. o.datatype = 'uinteger';
  135. o.modalonly = true;
  136. o.value('1');
  137. o.value('3');
  138. o.value('5');
  139. o.value('10');
  140. o.value('30');
  141. o.value('60');
  142. o = s.taboption('garp', form.ListValue, 'garp_master_refresh_repeat', _('GARP Refresh Repeat'),
  143. _('Gratuitous Master Refresh Repeat in seconds'));
  144. o.datatype = 'uinteger';
  145. o.modalonly = true;
  146. o.value('1');
  147. o.value('3');
  148. o.value('5');
  149. o.value('10');
  150. o.value('30');
  151. o.value('60');
  152. },
  153. renderAdvancedTab: function(s) {
  154. var o;
  155. o = s.taboption('advanced', form.Value, 'use_vmac', _('Use VMAC'),
  156. _('Use VRRP Virtual MAC'));
  157. o.optional = true;
  158. o.placeholder = '[<VMAC_INTERFACE_NAME>] [MAC_ADDRESS]';
  159. o.modalonly = true;
  160. o = s.taboption('advanced', form.Flag, 'vmac_xmit_base', _('Use VMAC Base'),
  161. _('Send/Recv VRRP messages from base interface instead of VMAC interfac'));
  162. o.default = false;
  163. o.optional = true;
  164. o.modalonly = true;
  165. o = s.taboption('advanced', form.Flag, 'native_ipv6', _('Use IPV6'),
  166. _('Force instance to use IPv6'));
  167. o.default = false;
  168. o.optional = true;
  169. o.modalonly = true;
  170. o = s.taboption('advanced', form.Flag, 'dont_track_primary', _('Disable Primary Tracking'),
  171. _('Ignore VRRP interface faults'));
  172. o.default = false;
  173. o.optional = true;
  174. o.modalonly = true;
  175. o = s.taboption('advanced', form.ListValue, 'version', _('Version'),
  176. _('VRRP version to run on interface'));
  177. o.value('', _('None'));
  178. o.value('2', _('2'));
  179. o.value('3', _('3'));
  180. o.default = '';
  181. o.modalonly = true;
  182. o = s.taboption('advanced', form.Flag, 'accept', _('Accept'),
  183. _('Accept packets to non address-owner'));
  184. o.default = false;
  185. o.optional = true;
  186. o = s.taboption('advanced', form.Value, 'preempt_delay', _('Preempt Delay'),
  187. _('Time in seconds to delay preempting compared'));
  188. o.datatype = 'float';
  189. o.placeholder = '300';
  190. o.modalonly = true;
  191. o = s.taboption('advanced', form.ListValue, 'debug', _('Debug'),
  192. _('Debug Level'));
  193. o.default = '0';
  194. o.value('0');
  195. o.value('1');
  196. o.value('2');
  197. o.value('3');
  198. o.value('4');
  199. o.modalonly = true;
  200. o = s.taboption('advanced', form.Flag, 'smtp_alert', _('Email Alert'),
  201. _('Send SMTP alerts'));
  202. o.default = false;
  203. o.modalonly = true;
  204. },
  205. renderTrackingTab: function(s) {
  206. var o;
  207. var ipaddress, routes, interfaces, scripts;
  208. ipaddress = uci.sections('keepalived', 'ipaddress');
  209. routes = uci.sections('keepalived', 'route');
  210. interfaces = uci.sections('keepalived', 'track_interface');
  211. scripts = uci.sections('keepalived', 'track_script');
  212. o = s.taboption('tracking', form.DynamicList, 'virtual_ipaddress_excluded', _('Exclude Virtual IP Address'),
  213. _('VRRP IP excluded from VRRP. For cases with large numbers (eg 200) of IPs on the same interface.') + ' ' +
  214. _('To decrease the number of packets sent in adverts, you can exclude most IPs from adverts.'));
  215. o.modalonly = true;
  216. if (ipaddress != '') {
  217. for (var i = 0; i < ipaddress.length; i++) {
  218. o.value(ipaddress[i]['name']);
  219. }
  220. }
  221. o = s.taboption('tracking', form.DynamicList, 'virtual_routes', _('Virtual Routes'),
  222. _('Routes add|del when changing to MASTER, to BACKUP'));
  223. o.modalonly = true;
  224. if (routes != '') {
  225. for (var i = 0; i < routes.length; i++) {
  226. o.value(routes[i]['name']);
  227. }
  228. }
  229. o = s.taboption('tracking', form.DynamicList, 'track_interface', _('Track Interfaces'),
  230. _('Go to FAULT state if any of these go down'));
  231. o.modalonly = true;
  232. if (interfaces != '') {
  233. for (var i = 0; i < interfaces.length; i++) {
  234. o.value(interfaces[i]['name']);
  235. }
  236. }
  237. o = s.taboption('tracking', form.DynamicList, 'track_script', _('Track Script'),
  238. _('Go to FAULT state if any of these go down, if unweighted'));
  239. o.modalonly = true;
  240. if (scripts != '') {
  241. for (var i = 0; i < scripts.length; i++) {
  242. o.value(scripts[i]['name']);
  243. }
  244. }
  245. },
  246. render: function(data) {
  247. var netDevs = data[0];
  248. let m, s, o;
  249. m = new form.Map('keepalived');
  250. s = m.section(form.GridSection, 'vrrp_instance', _('VRRP Instance'),
  251. _('Define an individual instance of the VRRP protocol running on an interface'));
  252. s.anonymous = true;
  253. s.addremove = true;
  254. s.nodescriptions = true;
  255. o = s.tab('general', _('General'));
  256. o = s.tab('peer', _('Peer'));
  257. o = s.tab('tracking', _('Tracking'));
  258. o = s.tab('garp', _('GARP'));
  259. o = s.tab('advanced', _('Advanced'));
  260. this.renderGeneralTab(s);
  261. this.renderPeerTab(s, netDevs);
  262. this.renderTrackingTab(s);
  263. this.renderGARPTab(s);
  264. this.renderAdvancedTab(s);
  265. return m.render();
  266. }
  267. });