'require tools.widgets as widgets';
function calculateNetwork(addr, mask) {
- addr = validation.parseIPv4(String(addr));
-
- if (!isNaN(mask))
- mask = validation.parseIPv4(network.prefixToMask(+mask));
- else
- mask = validation.parseIPv4(String(mask));
-
- if (addr == null || mask == null)
- return null;
-
- return [
- addr[0] & (mask[0] >>> 0 & 255),
- addr[1] & (mask[1] >>> 0 & 255),
- addr[2] & (mask[2] >>> 0 & 255),
- addr[3] & (mask[3] >>> 0 & 255)
- ].join('.') + '/' +
- network.maskToPrefix(mask.join('.'));
+ const parsedAddr = validation.parseIPv4(String(addr));
+ if (parsedAddr == null) return null;
+
+ const parsedMask = !isNaN(mask)
+ ? validation.parseIPv4(network.prefixToMask(+mask))
+ : validation.parseIPv4(String(mask));
+ if (parsedMask == null) return null;
+
+ const networkAddr = parsedAddr.map((byte, i) => byte & (parsedMask[i] >>> 0 & 255));
+
+ return `${networkAddr.join('.')}/${network.maskToPrefix(parsedMask.join('.'))}`;
}
return view.extend({
o = s.taboption('general', form.Value, 'left', _('Left IP/Device'));
o.datatype = 'or(string, ipaddr)';
- for (var i = 0; i < netDevs.length; i++) {
- var addrs = netDevs[i].getIPAddrs();
- for (var j = 0; j < addrs.length; j++) {
- o.value(addrs[j].split('/')[0]);
- }
- }
- for (var i = 0; i < netDevs.length; i++) {
- o.value('%' + netDevs[i].device);
- }
+ netDevs.forEach(netDev => {
+ netDev.getIPAddrs().forEach(addr => {
+ o.value(addr.split('/')[0]);
+ });
+ });
+ netDevs.forEach(netDev => {
+ o.value(`%${netDev.device}`);
+ });
o.value('%defaultroute');
o.optional = false;
o.depends({ 'left_interface' : '' });
o = s.taboption('general', form.Value, 'leftsourceip', _('Local Source IP'));
o.datatype = 'ipaddr';
- for (var i = 0; i < netDevs.length; i++) {
- var addrs = netDevs[i].getIPAddrs();
- for (var j = 0; j < addrs.length; j++) {
- o.value(addrs[j].split('/')[0]);
- }
- }
+ netDevs.forEach(netDev => {
+ netDev.getIPAddrs().forEach(addr => {
+ o.value(addr.split('/')[0]);
+ });
+ });
o.optional = false;
o.modalonly = true;
}
o.modalonly = true;
+ function timevalidate(section_id, value) {
+ if (!/^[0-9]{1,3}[smhd]$/.test(value)) {
+ return _('Acceptable values are an integer followed by m, h, d');
+ }
+ return true;
+ }
+
o = s.taboption('advanced', form.Value, 'ikelifetime', _('IKE Life Time'), _('Acceptable values are an integer followed by m, h, d'));
o.default = '8h';
o.value('1h', '1h');
o.value('24h', '24h');
o.modalonly = false;
o.modalonly = true;
- o.validate = function(section_id, value) {
- if (!/^[0-9]{1,3}[smhd]$/.test(value)) {
- return _('Acceptable values are an integer followed by m, h, d');
- }
- return true;
- }
+ o.validate = timevalidate;
o = s.taboption('advanced', form.Flag, 'rekey', _('Rekey'));
o.default = false;
o.value('60m', '60m');
o.modalonly = false;
o.modalonly = true;
- o.validate = function(section_id, value) {
- if (!/^[0-9]{1,3}[smhd]$/.test(value)) {
- return _('Acceptable values are an integer followed by m, h, d');
- }
- return true;
- }
+ o.validate = timevalidate;
o = s.taboption('advanced', form.ListValue, 'dpdaction', _('DPD Action'));
o.default = 'restart';
o.rmempty = true;
o.modalonly = true;
o.value('');
- for (var i = 0; i < interfaces.length; i++) {
- if ((interfaces[i]['proto'] == "vti") && interfaces[i]['ikey'] && interfaces[i]['okey']) {
- o.value(interfaces[i]['.name'], 'VTI - ' + interfaces[i]['.name']);
+ interfaces.forEach(iface => {
+ const { proto, ikey, okey, ifid, ['.name']: name } = iface;
+
+ if (proto === "vti" && ikey && okey) {
+ o.value(name, `VTI - ${name}`);
}
- if ((interfaces[i]['proto'] == "xfrm")
- && interfaces[i]['ifid']
- && interfaces[i]['.name'].match('ipsec' + interfaces[i]['ifid'])) {
- o.value(interfaces[i]['.name'], 'XFRM - ' + interfaces[i]['.name']);
+ if (proto === "xfrm" && ifid && name.match(`ipsec${ifid}`)) {
+ o.value(name, `XFRM - ${name}`);
}
- }
+ });
o = s.taboption('advanced', form.Flag, 'update_peeraddr', _('Update Peer Address'),
_('Auto Update Peer Address of VTI interface'));