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