Browse Source

防火墙全局开关

懒得勤快 6 years ago
parent
commit
2fda2f40f7

+ 1 - 1
src/Masuit.MyBlogs.Core/Extensions/FirewallAttribute.cs

@@ -25,7 +25,7 @@ namespace Masuit.MyBlogs.Core.Extensions
         public override void OnActionExecuting(ActionExecutingContext context)
         {
             var request = context.HttpContext.Request;
-            if (context.Filters.Any(m => m.ToString().Contains(nameof(AllowAccessFirewallAttribute))) || request.Cookies["Email"].MDString3(AppConfig.BaiduAK).Equals(request.Cookies["FullAccessToken"]))
+            if (!bool.Parse(CommonHelper.SystemSettings.GetOrAdd("FirewallEnabled", "true")) || context.Filters.Any(m => m.ToString().Contains(nameof(AllowAccessFirewallAttribute))) || request.Cookies["Email"].MDString3(AppConfig.BaiduAK).Equals(request.Cookies["FullAccessToken"]))
             {
                 return;
             }

+ 29 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/controllers/system.js

@@ -282,6 +282,7 @@ myApp.controller("firewall", ["$scope", "$http","NgTableParams","$timeout", func
 			$scope.interceptCount=res.Data.interceptCount;
 		});
 	}
+
 	self.load();
 	this.clear= function() {
 		swal({
@@ -305,6 +306,7 @@ myApp.controller("firewall", ["$scope", "$http","NgTableParams","$timeout", func
 			self.load();
 		}).catch(swal.noop);
 	}
+
 	$scope.EnableDenyAreaPolicy= function() {
 		if($scope.Settings.EnableDenyArea=="true") {
 			$scope.Settings.EnableDenyArea="false";
@@ -312,6 +314,29 @@ myApp.controller("firewall", ["$scope", "$http","NgTableParams","$timeout", func
 			$scope.Settings.EnableDenyArea="true";
 		}
 	}
+
+	$scope.EnableFirewall= function() {
+		if($scope.Settings.FirewallEnabled=="true") {
+            swal({
+				title: '确定要关闭网站防火墙么?',
+				text: "一旦关闭,网站将面临可能会被流量攻击的风险!",
+				type: 'warning',
+				showCancelButton: true,
+				confirmButtonColor: '#3085d6',
+				cancelButtonColor: '#d33',
+				confirmButtonText: '确定',
+				cancelButtonText: '取消',
+			}).then(function(isConfirm) {
+				if (isConfirm) {
+			        $scope.Settings.FirewallEnabled="false";
+					$scope.$apply();
+				}
+			});
+		} else {
+			$scope.Settings.FirewallEnabled="true";
+		}
+	}
+
 	$scope.getIPBlackList= function() {
 		$scope.request("/system/IpBlackList",null, function (data) {
 			swal({
@@ -338,6 +363,7 @@ myApp.controller("firewall", ["$scope", "$http","NgTableParams","$timeout", func
 			}).catch(swal.noop);
 		});
 	}
+
 	$scope.getIPWhiteList= function() {
 		$scope.request("/system/IpWhiteList",null, function (data) {
 			swal({
@@ -364,6 +390,7 @@ myApp.controller("firewall", ["$scope", "$http","NgTableParams","$timeout", func
 			}).catch(swal.noop);
 		});
 	}
+
 	$scope.getIPRangeBlackList= function() {
 		$scope.request("/system/GetIPRangeBlackList",null, function (data) {
 			swal({
@@ -390,6 +417,7 @@ myApp.controller("firewall", ["$scope", "$http","NgTableParams","$timeout", func
 			}).catch(swal.noop);
 		});
 	}
+
 	$scope.save = function() {
 		swal({
 			title: '确认保存吗?',
@@ -430,6 +458,7 @@ myApp.controller("firewall", ["$scope", "$http","NgTableParams","$timeout", func
 			});
 		}).catch(swal.noop);
 	}
+
 	$scope.addToWhiteList= function(ip) {
 		swal({
 			title: "确认添加白名单吗?",

+ 17 - 14
src/Masuit.MyBlogs.Core/wwwroot/ng-views/views/system/firewall.html

@@ -25,26 +25,21 @@
     <div class="card-body p-t-0">
         <div class="card-body card-padding">
             <div class="row">
-                <div class="col-lg-2 col-md-4 col-sm-6">
+                <div class="col-md-12 form-inline">
                     <div class="input-group">
-                        <span class="input-group-addon">启用地区限制访问策略:</span>
+                        <span class="input-group-addon">防火墙状态:</span>
+                        <span class="el-switch">
+                            <input name="switch" ng-checked="Settings.FirewallEnabled=='true'" type="checkbox">
+                            <span class="el-switch-style" ng-click="EnableFirewall()"></span>
+                        </span>
+                    </div>
+                    <div class="input-group">
+                        <span class="input-group-addon">地区限制:</span>
                         <span class="el-switch">
                             <input name="switch" ng-checked="Settings.EnableDenyArea=='true'" type="checkbox">
                             <span class="el-switch-style" ng-click="EnableDenyAreaPolicy()"></span>
                         </span>
                     </div>
-                </div>
-                <div class="col-lg-10 col-md-8 col-sm-6">
-                    <div class="input-group">
-                        <span class="input-group-addon">受限制的地区:</span>
-                        <div class="fg-line">
-                            <input class="form-control" ng-model="Settings.DenyArea" ng-readonly="Settings.EnableDenyArea=='false'" placeholder="禁止访问的地区,逗号分隔" type="text" />
-                        </div>
-                    </div>
-                </div>
-            </div>
-            <div class="row">
-                <div class="col-md-5 col-sm-6">
                     <div class="input-group">
                         <span class="input-group-addon">单IP访问频次:每</span>
                         <div class="fg-line">
@@ -61,6 +56,14 @@
                         <span class="input-group-addon">分钟</span>
                     </div>
                 </div>
+                <div class="col-md-12">
+                    <div class="input-group">
+                        <span class="input-group-addon">受限制的地区:</span>
+                        <div class="fg-line">
+                            <input class="form-control" ng-model="Settings.DenyArea" ng-readonly="Settings.EnableDenyArea=='false'" placeholder="禁止访问的地区,逗号分隔" type="text" />
+                        </div>
+                    </div>
+                </div>
             </div>
         </div>
     </div>