浏览代码

防火墙统计优化,文章历史版本优化

懒得勤快 5 年之前
父节点
当前提交
83adc42529

+ 3 - 3
src/Masuit.MyBlogs.Core/Controllers/PostController.cs

@@ -5,6 +5,7 @@ using Masuit.LuceneEFCore.SearchEngine.Linq;
 using Masuit.MyBlogs.Core.Common;
 using Masuit.MyBlogs.Core.Configs;
 using Masuit.MyBlogs.Core.Extensions;
+using Masuit.MyBlogs.Core.Extensions.Firewall;
 using Masuit.MyBlogs.Core.Extensions.Hangfire;
 using Masuit.MyBlogs.Core.Infrastructure;
 using Masuit.MyBlogs.Core.Infrastructure.Repository;
@@ -33,7 +34,6 @@ using System.Linq.Dynamic.Core;
 using System.Linq.Expressions;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
-using Masuit.MyBlogs.Core.Extensions.Firewall;
 
 namespace Masuit.MyBlogs.Core.Controllers
 {
@@ -705,7 +705,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 post.Label = post.Label.Replace(",", ",");
             }
 
-            if (string.IsNullOrEmpty(post.ProtectContent) || post.ProtectContent.Equals("null", StringComparison.InvariantCultureIgnoreCase))
+            if (string.IsNullOrEmpty(post.ProtectContent?.RemoveHtmlTag()) || post.ProtectContent.Equals("null"))
             {
                 post.ProtectContent = null;
             }
@@ -782,7 +782,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 post.Label = post.Label.Replace(",", ",");
             }
 
-            if (string.IsNullOrEmpty(post.ProtectContent) || post.ProtectContent.Equals("null", StringComparison.InvariantCultureIgnoreCase))
+            if (string.IsNullOrEmpty(post.ProtectContent?.RemoveHtmlTag()) || post.ProtectContent.Equals("null"))
             {
                 post.ProtectContent = null;
             }

+ 16 - 4
src/Masuit.MyBlogs.Core/Controllers/SystemController.cs

@@ -1,11 +1,11 @@
 using Masuit.MyBlogs.Core.Common;
-using Masuit.MyBlogs.Core.Extensions;
-using Masuit.MyBlogs.Core.Extensions.Hangfire;
+using Masuit.MyBlogs.Core.Extensions.Firewall;
 using Masuit.MyBlogs.Core.Hubs;
 using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
 using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.Tools;
+using Masuit.Tools.DateTimeExt;
 using Masuit.Tools.Hardware;
 using Masuit.Tools.Logging;
 using Masuit.Tools.Models;
@@ -24,7 +24,6 @@ using System.Net;
 using System.Net.Sockets;
 using System.Text;
 using System.Threading.Tasks;
-using Masuit.MyBlogs.Core.Extensions.Firewall;
 
 namespace Masuit.MyBlogs.Core.Controllers
 {
@@ -350,7 +349,20 @@ namespace Masuit.MyBlogs.Core.Controllers
             {
                 interceptCount = RedisHelper.Get("interceptCount"),
                 list,
-                ranking = list.GroupBy(i => i.IP).Select(g => new { g.Key, Count = g.Count() }).OrderByDescending(a => a.Count).Take(30)
+                ranking = list.GroupBy(i => i.IP).Where(g => g.Count() > 1).Select(g =>
+                {
+                    var start = g.Min(t => t.Time);
+                    var end = g.Max(t => t.Time);
+                    return new
+                    {
+                        g.Key,
+                        g.First().Address,
+                        Start = start,
+                        End = end,
+                        Continue = start.GetDiffTime(end),
+                        Count = g.Count()
+                    };
+                }).OrderByDescending(a => a.Count).Take(30)
             });
         }
 

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Post/HistoryVersion.cshtml

@@ -86,7 +86,7 @@
                             @if (!string.IsNullOrEmpty(Model.ProtectContent))
                             {
                                 <div class="row protected">
-                                    @if (string.IsNullOrEmpty(Context.Session.Get<string>("AccessViewToken")))
+                                    @if (string.IsNullOrEmpty(Context.Session.Get<string>("AccessViewToken")) && !string.IsNullOrEmpty(Model.Post.ProtectContent))
                                     {
                                         <p class="text-red text-center size24 margin-bot10">↓↓↓恭喜你发现镇站之宝,请注意,前方高能!非战斗人员请及时撤离,这不是演习!↓↓↓</p>
                                         <div class="col-md-6">

+ 8 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/views/system/firewall.html

@@ -127,6 +127,10 @@
                 <th>序号</th>
                 <th>IP</th>
                 <th>次数</th>
+                <th>地理位置</th>
+                <th>拦截开始时间</th>
+                <th>拦截截止时间</th>
+                <th>持续时长</th>
             </tr>
         </thead>
         <tbody>
@@ -137,6 +141,10 @@
                     <button class="badge btn btn-primary pull-right" ng-click="addToBlackList(item.Key)">添加到黑名单</button>
                 </td>
                 <td>{{item.Count}}</td>
+                <td>{{item.Address}}</td>
+                <td>{{item.Start|date:'yyyy-MM-dd HH:mm:ss'}}</td>
+                <td>{{item.End|date:'yyyy-MM-dd HH:mm:ss'}}</td>
+                <td>{{item.Continue}}</td>
             </tr>
         </tbody>
     </table>