Procházet zdrojové kódy

😎1、增加IP黑名单访问限制 2、调整代码生成模板 3、升级依赖

zuohuaijun před 1 rokem
rodič
revize
0af5d7814f

+ 23 - 37
Admin.NET/Admin.NET.Application/Configuration/Limit.json

@@ -21,7 +21,7 @@
     // 客户端白名单
     "ClientWhitelist": [],
     "QuotaExceededResponse": {
-      "Content": "{{\"code\":429,\"type\":\"error\",\"message\":\"访问过于频繁,请稍后重试!\",\"result\":null,\"extras\":null}}",
+      "Content": "{{\"code\":429,\"type\":\"error\",\"message\":\"访问过于频繁,请稍后重试!禁止违法行为否则110 👮\",\"result\":null,\"extras\":null}}",
       "ContentType": "application/json",
       "StatusCode": 429
     },
@@ -29,46 +29,42 @@
     "HttpStatusCode": 429,
     // API规则,结尾一定要带*
     "GeneralRules": [
-      // 1秒钟只能调用10次
+      // 1秒钟只能调用1000
       {
         "Endpoint": "*",
         "Period": "1s",
-        "Limit": 10
+        "Limit": 1000
       },
-      // 1分钟只能调用600次
+      // 1分钟只能调用60000
       {
         "Endpoint": "*",
         "Period": "1m",
-        "Limit": 600
-      },
-      // 1小时只能调用3600
-      {
-        "Endpoint": "*",
-        "Period": "1h",
-        "Limit": 3600
-      },
-      // 1天只能调用86400次
-      {
-        "Endpoint": "*",
-        "Period": "1d",
-        "Limit": 86400
+        "Limit": 60000
       }
+      //// 1小时只能调用3600000次
+      //{
+      //  "Endpoint": "*",
+      //  "Period": "1h",
+      //  "Limit": 3600000
+      //},
+      //// 1天只能调用86400000次
+      //{
+      //  "Endpoint": "*",
+      //  "Period": "1d",
+      //  "Limit": 86400000
+      //}
     ]
   },
+  // IP 黑名单
   "IpRateLimitPolicies": {
     "IpRules": [
       {
-        "Ip": "XXX.XXX.XXX.XXX",
+        "Ip": "0.0.0.0", // IP可用:"::1/10" 
         "Rules": [
           {
             "Endpoint": "*",
             "Period": "1s",
-            "Limit": 10
-          },
-          {
-            "Endpoint": "*",
-            "Period": "1m",
-            "Limit": 600
+            "Limit": 0 // 设置为0就是1次都不能请求,完全屏蔽
           }
         ]
       }
@@ -90,29 +86,19 @@
       {
         "Endpoint": "*",
         "Period": "1s",
-        "Limit": 10
-      },
-      {
-        "Endpoint": "*",
-        "Period": "1m",
-        "Limit": 600
+        "Limit": 2000
       }
     ]
   },
   "ClientRateLimitPolicies": {
     "ClientRules": [
       {
-        "ClientId": "xxx-xxx",
+        "ClientId": "",
         "Rules": [
           {
             "Endpoint": "*",
             "Period": "1s",
-            "Limit": 10
-          },
-          {
-            "Endpoint": "*",
-            "Period": "1m",
-            "Limit": 600
+            "Limit": 2000
           }
         ]
       }

+ 2 - 2
Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj

@@ -17,7 +17,7 @@
     <PackageReference Include="AngleSharp" Version="1.1.2" />
     <PackageReference Include="AspectCore.Extensions.Reflection" Version="2.4.0" />
     <PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
-    <PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.15.3" />
+    <PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.15.4" />
     <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.9.5.5" />
     <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.5.5" />
     <PackageReference Include="Furion.Pure" Version="4.9.5.5" />
@@ -39,7 +39,7 @@
     <PackageReference Include="SqlSugarCore" Version="5.1.4.167" />
     <PackageReference Include="SSH.NET" Version="2024.1.0" />
     <PackageReference Include="System.Linq.Dynamic.Core" Version="1.4.5" />
-    <PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1078" />
+    <PackageReference Include="TencentCloudSDK.Sms" Version="3.0.1079" />
     <PackageReference Include="UAParser" Version="3.1.47" />
     <PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
   </ItemGroup>

+ 26 - 0
Admin.NET/Admin.NET.Core/Extension/UseApplicationBuilder.cs

@@ -0,0 +1,26 @@
+// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
+//
+// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
+//
+// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
+
+using AspNetCoreRateLimit;
+using Microsoft.AspNetCore.Builder;
+
+namespace Admin.NET.Core;
+
+/// <summary>
+/// 配置中间件扩展
+/// </summary>
+public static class UseApplicationBuilder
+{
+    // 配置限流中间件策略
+    public static void UsePolicyRateLimit(this IApplicationBuilder app)
+    {
+        var ipPolicyStore = app.ApplicationServices.GetRequiredService<IIpPolicyStore>();
+        ipPolicyStore.SeedAsync().GetAwaiter().GetResult();
+
+        var clientPolicyStore = app.ApplicationServices.GetRequiredService<IClientPolicyStore>();
+        clientPolicyStore.SeedAsync().GetAwaiter().GetResult();
+    }
+}

+ 1 - 0
Admin.NET/Admin.NET.Web.Core/Startup.cs

@@ -259,6 +259,7 @@ public class Startup : AppStartup
         // 限流组件(在跨域之后)
         app.UseIpRateLimiting();
         app.UseClientRateLimiting();
+        app.UsePolicyRateLimit();
 
         // 任务调度看板
         app.UseScheduleUI(options =>

+ 1 - 1
Admin.NET/Admin.NET.Web.Entry/wwwroot/template/Service.cs.vm

@@ -109,7 +109,7 @@ if (@column.QueryWhether == "Y"){
 } else {
             @:.Select<@(@Model.ClassName)Output>();
 }
-		return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
+		return await query.OrderBuilder(input, "u.").ToPagedListAsync(input.Page, input.PageSize);
     }
 
     /// <summary>

+ 3 - 3
Web/package.json

@@ -2,7 +2,7 @@
 	"name": "admin.net",
 	"type": "module",
 	"version": "2.4.33",
-	"lastBuildTime": "2024.08.28",
+	"lastBuildTime": "2024.08.30",
 	"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",
 	"author": "zuohuaijun",
 	"license": "MIT",
@@ -39,7 +39,7 @@
 		"js-table2excel": "^1.1.2",
 		"jsplumb": "^2.15.6",
 		"lodash-es": "^4.17.21",
-		"md-editor-v3": "^4.19.1",
+		"md-editor-v3": "^4.19.2",
 		"mitt": "^3.0.1",
 		"monaco-editor": "^0.51.0",
 		"mqtt": "^4.3.8",
@@ -77,7 +77,7 @@
 		"@types/sortablejs": "^1.15.8",
 		"@typescript-eslint/eslint-plugin": "^8.3.0",
 		"@typescript-eslint/parser": "^8.3.0",
-		"@vitejs/plugin-vue": "^5.1.2",
+		"@vitejs/plugin-vue": "^5.1.3",
 		"@vitejs/plugin-vue-jsx": "^4.0.1",
 		"@vue/compiler-sfc": "^3.4.38",
 		"code-inspector-plugin": "^0.16.0",