diff --git a/src/js/client.js b/src/js/client.js index b5b226f8a..85d451226 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -750,6 +750,7 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; + // network Client.prototype.setSysinfoConfig = function (config, callback) { post('/api/v1/settings/sysinfo_config', config, null, function (error, data, status) { if (error) return callback(error); @@ -777,6 +778,25 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; + Client.prototype.getBlocklist = function (callback) { + var config = {}; + + get('/api/v1/network/blocklist', config, function (error, data, status) { + if (error) return callback(error); + if (status !== 200) return callback(new ClientError(status, data)); + callback(null, data.blocklist); + }); + }; + + Client.prototype.setBlocklist = function (blocklist, callback) { + post('/api/v1/network/blocklist', { blocklist: blocklist }, null, function (error, data, status) { + if (error) return callback(error); + if (status !== 200) return callback(new ClientError(status, data)); + + callback(null); + }); + }; + Client.prototype.setDynamicDnsConfig = function (enabled, callback) { post('/api/v1/settings/dynamic_dns', { enabled: enabled }, null, function (error, data, status) { if (error) return callback(error); @@ -794,6 +814,7 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; + // branding Client.prototype.setFooter = function (footer, callback) { post('/api/v1/branding/footer', { footer: footer }, null, function (error, data, status) { if (error) return callback(error); diff --git a/src/views/network.html b/src/views/network.html index 86e5e3699..e8c96b9a4 100644 --- a/src/views/network.html +++ b/src/views/network.html @@ -44,6 +44,32 @@ + + +

Network

@@ -98,6 +124,21 @@
+
+

Firewall

+
+ +
+
+
+ Blocked IPs & Ranges +
+
+ {{ blocklist.currentBlocklist.length }} IP(s) blocked +
+
+
+

Dynamic DNS

diff --git a/src/views/network.js b/src/views/network.js index 7c654ea7a..d14d508f3 100644 --- a/src/views/network.js +++ b/src/views/network.js @@ -55,6 +55,51 @@ angular.module('Application').controller('NetworkController', ['$scope', '$locat } }; + $scope.blocklist = { + busy: false, + error: {}, + blocklist: '', + currentBlocklist: [], + + refresh: function () { + Client.getBlocklist(function (error, result) { + if (error) return console.error(error); + + $scope.blocklist.currentBlocklist = result; + }); + }, + + + show: function () { + $scope.blocklist.error = {}; + $scope.blocklist.blocklist = $scope.blocklist.currentBlocklist.join('\n'); + + $('#blocklistModal').modal('show'); + }, + + submit: function () { + $scope.blocklist.error = {}; + $scope.blocklist.busy = true; + + var blocklist = $scope.blocklist.blocklist.split('\n').filter(function (x) { return x !== ''; }); + + Client.setBlocklist(blocklist, function (error) { + $scope.blocklist.busy = false; + if (error) { + $scope.blocklist.error.blocklist = error.message; + $scope.blocklist.error.ip = error.message; + $scope.blocklistForm.$setPristine(); + $scope.blocklistForm.$setUntouched(); + return; + } + + $scope.blocklist.refresh(); + + $('#blocklistModal').modal('hide'); + }); + } + }, + $scope.sysinfo = { busy: false, error: {}, @@ -137,6 +182,7 @@ angular.module('Application').controller('NetworkController', ['$scope', '$locat $scope.sysinfo.refresh(); $scope.dyndnsConfigure.refresh(); + $scope.blocklist.refresh(); }); $('.modal-backdrop').remove();