2019-11-07 15:26:18 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/* global angular */
|
2023-07-08 19:48:12 +05:30
|
|
|
/* global $, TASK_TYPES */
|
2019-11-07 15:26:18 +01:00
|
|
|
|
2023-07-08 19:48:12 +05:30
|
|
|
angular.module('Application').controller('NetworkController', ['$scope', '$location', '$timeout', 'Client', function ($scope, $location, $timeout, Client) {
|
2020-02-24 12:56:13 +01:00
|
|
|
Client.onReady(function () { if (!Client.getUserInfo().isAtLeastAdmin) $location.path('/'); });
|
2019-11-07 15:26:18 +01:00
|
|
|
|
2020-08-31 22:55:30 -07:00
|
|
|
$scope.user = Client.getUserInfo();
|
2019-11-07 15:26:18 +01:00
|
|
|
$scope.config = Client.getConfig();
|
|
|
|
|
|
|
|
|
|
// keep in sync with sysinfo.js
|
|
|
|
|
$scope.sysinfoProvider = [
|
2024-04-25 14:48:17 +02:00
|
|
|
{ name: 'Disabled', value: 'noop' },
|
2019-11-07 10:20:34 -08:00
|
|
|
{ name: 'Public IP', value: 'generic' },
|
2019-11-07 15:26:18 +01:00
|
|
|
{ name: 'Static IP Address', value: 'fixed' },
|
|
|
|
|
{ name: 'Network Interface', value: 'network-interface' }
|
|
|
|
|
];
|
|
|
|
|
|
2022-02-15 12:54:02 -08:00
|
|
|
$scope.ipv6ConfigureProvider = [
|
|
|
|
|
{ name: 'Disabled', value: 'noop' },
|
|
|
|
|
{ name: 'Public IP', value: 'generic' },
|
|
|
|
|
{ name: 'Static IP Address', value: 'fixed' },
|
|
|
|
|
{ name: 'Network Interface', value: 'network-interface' }
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$scope.prettyIpProviderName = function (provider) {
|
2019-11-07 15:26:18 +01:00
|
|
|
switch (provider) {
|
2022-02-15 12:54:02 -08:00
|
|
|
case 'noop': return 'Disabled';
|
2019-11-07 10:20:34 -08:00
|
|
|
case 'generic': return 'Public IP';
|
|
|
|
|
case 'fixed': return 'Static IP Address';
|
|
|
|
|
case 'network-interface': return 'Network Interface';
|
|
|
|
|
default: return 'Unknown';
|
2019-11-07 15:26:18 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.dyndnsConfigure = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: '',
|
2022-02-09 16:55:36 +01:00
|
|
|
isEnabled: false,
|
2023-07-08 19:48:12 +05:30
|
|
|
tasks: [],
|
|
|
|
|
|
|
|
|
|
refreshTasks: function () {
|
|
|
|
|
Client.getTasksByType(TASK_TYPES.TASK_SYNC_DYNDNS, function (error, tasks) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
$scope.dyndnsConfigure.tasks = tasks.slice(0, 10);
|
|
|
|
|
if ($scope.dyndnsConfigure.tasks.length && $scope.dyndnsConfigure.tasks[0].active) {
|
|
|
|
|
$timeout($scope.renewCerts.refreshTasks, 5000);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2019-11-07 15:26:18 +01:00
|
|
|
|
|
|
|
|
refresh: function () {
|
|
|
|
|
Client.getDynamicDnsConfig(function (error, enabled) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
2022-02-09 16:55:36 +01:00
|
|
|
$scope.dyndnsConfigure.isEnabled = enabled;
|
2023-07-08 19:48:12 +05:30
|
|
|
|
|
|
|
|
$scope.dyndnsConfigure.refreshTasks();
|
2019-11-07 15:26:18 +01:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2022-02-09 16:55:36 +01:00
|
|
|
setEnabled: function (enabled) {
|
2019-11-07 15:26:18 +01:00
|
|
|
$scope.dyndnsConfigure.busy = true;
|
|
|
|
|
$scope.dyndnsConfigure.error = '';
|
|
|
|
|
|
2022-02-09 16:55:36 +01:00
|
|
|
Client.setDynamicDnsConfig(enabled, function (error) {
|
2019-11-07 15:26:18 +01:00
|
|
|
$scope.dyndnsConfigure.busy = false;
|
2022-02-09 16:55:36 +01:00
|
|
|
|
|
|
|
|
if (error) $scope.dyndnsConfigure.error = error.message;
|
|
|
|
|
else $scope.dyndnsConfigure.isEnabled = enabled;
|
2019-11-07 15:26:18 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-06 21:50:23 -08:00
|
|
|
$scope.ipv6Configure = {
|
|
|
|
|
busy: false,
|
2022-02-15 12:54:02 -08:00
|
|
|
error: {},
|
2022-04-27 14:09:07 +02:00
|
|
|
displayError: '',
|
2022-02-15 12:54:02 -08:00
|
|
|
|
|
|
|
|
serverIPv6: '',
|
|
|
|
|
|
|
|
|
|
provider: '',
|
|
|
|
|
ipv6: '',
|
|
|
|
|
ifname: '',
|
|
|
|
|
|
|
|
|
|
// configure dialog
|
|
|
|
|
newProvider: '',
|
|
|
|
|
newIPv6: '',
|
|
|
|
|
newIfname: '',
|
2022-01-06 21:50:23 -08:00
|
|
|
|
|
|
|
|
refresh: function () {
|
2022-02-15 12:54:02 -08:00
|
|
|
Client.getIPv6Config(function (error, result) {
|
2022-02-17 18:11:22 +01:00
|
|
|
if (error) {
|
|
|
|
|
$scope.ipv6Configure.displayError = error.message;
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
2022-01-06 21:50:23 -08:00
|
|
|
|
2022-02-15 12:54:02 -08:00
|
|
|
$scope.ipv6Configure.provider = result.provider;
|
2023-09-12 20:13:27 +05:30
|
|
|
$scope.ipv6Configure.ipv6 = result.ip || '';
|
2022-02-15 12:54:02 -08:00
|
|
|
$scope.ipv6Configure.ifname = result.ifname || '';
|
|
|
|
|
if (result.provider === 'noop') return;
|
|
|
|
|
|
|
|
|
|
Client.getServerIpv6(function (error, result) {
|
2022-02-17 18:11:22 +01:00
|
|
|
if (error) {
|
|
|
|
|
$scope.ipv6Configure.displayError = error.message;
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
2022-02-15 12:54:02 -08:00
|
|
|
|
2023-09-12 20:13:27 +05:30
|
|
|
$scope.ipv6Configure.serverIPv6 = result.ip;
|
2022-02-15 12:54:02 -08:00
|
|
|
});
|
2022-01-06 21:50:23 -08:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2022-02-15 12:54:02 -08:00
|
|
|
show: function () {
|
|
|
|
|
$scope.ipv6Configure.error = {};
|
|
|
|
|
$scope.ipv6Configure.newProvider = $scope.ipv6Configure.provider;
|
|
|
|
|
$scope.ipv6Configure.newIPv6 = $scope.ipv6Configure.ipv6;
|
|
|
|
|
$scope.ipv6Configure.newIfname = $scope.ipv6Configure.ifname;
|
|
|
|
|
|
|
|
|
|
$('#ipv6ConfigureModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.ipv6Configure.error = {};
|
2022-01-06 21:50:23 -08:00
|
|
|
$scope.ipv6Configure.busy = true;
|
|
|
|
|
|
2022-02-15 12:54:02 -08:00
|
|
|
var config = {
|
|
|
|
|
provider: $scope.ipv6Configure.newProvider
|
|
|
|
|
};
|
2022-02-04 11:16:04 -08:00
|
|
|
|
2022-02-15 12:54:02 -08:00
|
|
|
if (config.provider === 'fixed') {
|
2023-09-12 20:13:27 +05:30
|
|
|
config.ip = $scope.ipv6Configure.newIPv6;
|
2022-02-15 12:54:02 -08:00
|
|
|
} else if (config.provider === 'network-interface') {
|
|
|
|
|
config.ifname = $scope.ipv6Configure.newIfname;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Client.setIPv6Config(config, function (error) {
|
|
|
|
|
$scope.ipv6Configure.busy = false;
|
|
|
|
|
if (error && error.message.indexOf('ipv') !== -1) {
|
|
|
|
|
$scope.ipv6Configure.error.ipv6 = error.message;
|
|
|
|
|
$scope.ipv6ConfigureForm.$setPristine();
|
|
|
|
|
$scope.ipv6ConfigureForm.$setUntouched();
|
|
|
|
|
return;
|
|
|
|
|
} else if (error && (error.message.indexOf('interface') !== -1 || error.message.indexOf('IPv6') !== -1)) {
|
|
|
|
|
$scope.ipv6Configure.error.ifname = error.message;
|
|
|
|
|
$scope.ipv6ConfigureForm.$setPristine();
|
|
|
|
|
$scope.ipv6ConfigureForm.$setUntouched();
|
|
|
|
|
return;
|
|
|
|
|
} else if (error) {
|
2022-04-27 14:09:07 +02:00
|
|
|
$scope.ipv6Configure.error.generic = error.message;
|
|
|
|
|
$scope.ipv6ConfigureForm.$setPristine();
|
|
|
|
|
$scope.ipv6ConfigureForm.$setUntouched();
|
2022-02-15 12:54:02 -08:00
|
|
|
console.error(error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.ipv6Configure.refresh();
|
|
|
|
|
|
|
|
|
|
$('#ipv6ConfigureModal').modal('hide');
|
2022-01-06 21:50:23 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-31 21:45:56 -07:00
|
|
|
$scope.blocklist = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
blocklist: '',
|
2020-09-14 10:34:04 -07:00
|
|
|
currentBlocklist: '',
|
2020-09-14 12:12:39 -07:00
|
|
|
currentBlocklistLength: 0,
|
2020-08-31 21:45:56 -07:00
|
|
|
|
|
|
|
|
refresh: function () {
|
|
|
|
|
Client.getBlocklist(function (error, result) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.blocklist.currentBlocklist = result;
|
2020-09-14 12:12:39 -07:00
|
|
|
$scope.blocklist.currentBlocklistLength = result.split('\n').filter(function (l) { return l.length !== 0 && l[0] !== '#'; }).length;
|
2020-08-31 21:45:56 -07:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
show: function () {
|
|
|
|
|
$scope.blocklist.error = {};
|
2020-09-14 10:34:04 -07:00
|
|
|
$scope.blocklist.blocklist = $scope.blocklist.currentBlocklist;
|
2020-08-31 21:45:56 -07:00
|
|
|
|
|
|
|
|
$('#blocklistModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.blocklist.error = {};
|
|
|
|
|
$scope.blocklist.busy = true;
|
|
|
|
|
|
2020-09-14 10:34:04 -07:00
|
|
|
Client.setBlocklist($scope.blocklist.blocklist, function (error) {
|
2020-08-31 21:45:56 -07:00
|
|
|
$scope.blocklist.busy = false;
|
|
|
|
|
if (error) {
|
|
|
|
|
$scope.blocklist.error.blocklist = error.message;
|
|
|
|
|
$scope.blocklist.error.ip = error.message;
|
2020-09-12 19:13:10 +02:00
|
|
|
$scope.blocklistChangeForm.$setPristine();
|
|
|
|
|
$scope.blocklistChangeForm.$setUntouched();
|
2020-08-31 21:45:56 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.blocklist.refresh();
|
|
|
|
|
|
|
|
|
|
$('#blocklistModal').modal('hide');
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-02-09 16:49:53 +01:00
|
|
|
};
|
2020-08-31 21:45:56 -07:00
|
|
|
|
2023-05-13 14:59:57 +02:00
|
|
|
$scope.trustedIps = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
trustedIps: '',
|
|
|
|
|
currentTrustedIps: '',
|
|
|
|
|
currentTrustedIpsLength: 0,
|
|
|
|
|
|
|
|
|
|
refresh: function () {
|
|
|
|
|
Client.getTrustedIps(function (error, result) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.trustedIps.currentTrustedIps = result;
|
|
|
|
|
$scope.trustedIps.currentTrustedIpsLength = result.split('\n').filter(function (l) { return l.length !== 0 && l[0] !== '#'; }).length;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
show: function () {
|
|
|
|
|
$scope.trustedIps.error = {};
|
|
|
|
|
$scope.trustedIps.trustedIps = $scope.trustedIps.currentTrustedIps;
|
|
|
|
|
|
|
|
|
|
$('#trustedIpsModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.trustedIps.error = {};
|
|
|
|
|
$scope.trustedIps.busy = true;
|
|
|
|
|
|
|
|
|
|
Client.setTrustedIps($scope.trustedIps.trustedIps, function (error) {
|
|
|
|
|
$scope.trustedIps.busy = false;
|
|
|
|
|
if (error) {
|
|
|
|
|
$scope.trustedIps.error.trustedIps = error.message;
|
|
|
|
|
$scope.trustedIps.error.ip = error.message;
|
|
|
|
|
$scope.trustedIpsChangeForm.$setPristine();
|
|
|
|
|
$scope.trustedIpsChangeForm.$setUntouched();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.trustedIps.refresh();
|
|
|
|
|
|
|
|
|
|
$('#trustedIpsModal').modal('hide');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-07 15:26:18 +01:00
|
|
|
$scope.sysinfo = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
|
2022-01-06 17:56:56 -08:00
|
|
|
serverIPv4: '',
|
2019-11-07 10:41:24 -08:00
|
|
|
|
2019-11-07 15:26:18 +01:00
|
|
|
provider: '',
|
2022-01-06 17:56:56 -08:00
|
|
|
ipv4: '',
|
2019-11-07 15:26:18 +01:00
|
|
|
ifname: '',
|
|
|
|
|
|
|
|
|
|
// configure dialog
|
|
|
|
|
newProvider: '',
|
2022-01-06 17:56:56 -08:00
|
|
|
newIPv4: '',
|
2019-11-07 15:26:18 +01:00
|
|
|
newIfname: '',
|
|
|
|
|
|
|
|
|
|
refresh: function () {
|
2023-08-03 06:05:29 +05:30
|
|
|
Client.getIPv4Config(function (error, result) {
|
2019-11-07 15:26:18 +01:00
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.sysinfo.provider = result.provider;
|
2023-09-12 20:13:27 +05:30
|
|
|
$scope.sysinfo.ipv4 = result.ip || '';
|
2019-11-07 15:26:18 +01:00
|
|
|
$scope.sysinfo.ifname = result.ifname || '';
|
2019-11-07 10:41:24 -08:00
|
|
|
|
2022-02-15 12:51:06 -08:00
|
|
|
Client.getServerIpv4(function (error, result) {
|
2019-11-07 10:41:24 -08:00
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
2023-09-12 20:13:27 +05:30
|
|
|
$scope.sysinfo.serverIPv4 = result.ip;
|
2019-11-07 10:41:24 -08:00
|
|
|
});
|
2019-11-07 15:26:18 +01:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
show: function () {
|
|
|
|
|
$scope.sysinfo.error = {};
|
|
|
|
|
$scope.sysinfo.newProvider = $scope.sysinfo.provider;
|
2022-01-06 17:56:56 -08:00
|
|
|
$scope.sysinfo.newIPv4 = $scope.sysinfo.ipv4;
|
2019-11-07 15:26:18 +01:00
|
|
|
$scope.sysinfo.newIfname = $scope.sysinfo.ifname;
|
|
|
|
|
|
|
|
|
|
$('#sysinfoModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.sysinfo.error = {};
|
|
|
|
|
$scope.sysinfo.busy = true;
|
|
|
|
|
|
|
|
|
|
var config = {
|
|
|
|
|
provider: $scope.sysinfo.newProvider
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (config.provider === 'fixed') {
|
2023-09-12 20:13:27 +05:30
|
|
|
config.ip = $scope.sysinfo.newIPv4;
|
2019-11-07 15:26:18 +01:00
|
|
|
} else if (config.provider === 'network-interface') {
|
|
|
|
|
config.ifname = $scope.sysinfo.newIfname;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 06:05:29 +05:30
|
|
|
Client.setIPv4Config(config, function (error) {
|
2019-11-07 15:26:18 +01:00
|
|
|
$scope.sysinfo.busy = false;
|
2022-01-06 17:56:56 -08:00
|
|
|
if (error && error.message.indexOf('ipv') !== -1) {
|
2022-02-15 12:51:06 -08:00
|
|
|
$scope.sysinfo.error.ipv4 = error.message;
|
2019-11-07 15:26:18 +01:00
|
|
|
$scope.sysinfoForm.$setPristine();
|
|
|
|
|
$scope.sysinfoForm.$setUntouched();
|
|
|
|
|
return;
|
|
|
|
|
} else if (error && (error.message.indexOf('interface') !== -1 || error.message.indexOf('IPv4') !== -1)) {
|
|
|
|
|
$scope.sysinfo.error.ifname = error.message;
|
|
|
|
|
$scope.sysinfoForm.$setPristine();
|
|
|
|
|
$scope.sysinfoForm.$setUntouched();
|
|
|
|
|
return;
|
|
|
|
|
} else if (error) {
|
2022-04-27 14:09:07 +02:00
|
|
|
$scope.sysinfo.error.generic = error.message;
|
2019-11-07 15:26:18 +01:00
|
|
|
console.error(error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.sysinfo.refresh();
|
|
|
|
|
|
|
|
|
|
$('#sysinfoModal').modal('hide');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Client.onReady(function () {
|
|
|
|
|
$scope.sysinfo.refresh();
|
|
|
|
|
|
2020-02-04 12:55:51 -08:00
|
|
|
$scope.dyndnsConfigure.refresh();
|
2022-01-06 21:50:23 -08:00
|
|
|
$scope.ipv6Configure.refresh();
|
2023-05-13 14:59:57 +02:00
|
|
|
$scope.trustedIps.refresh();
|
2021-12-02 12:21:59 -08:00
|
|
|
if ($scope.user.isAtLeastOwner) $scope.blocklist.refresh();
|
2019-11-07 15:26:18 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.modal-backdrop').remove();
|
|
|
|
|
}]);
|