浏览代码

发件箱记录

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

+ 3 - 1
src/Masuit.MyBlogs.Core/Common/CommonHelper.cs

@@ -201,7 +201,7 @@ namespace Masuit.MyBlogs.Core.Common
         /// <param name="content">内容</param>
         /// <param name="tos">收件人</param>
         [AutomaticRetry(Attempts = 1, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
-        public static void SendMail(string title, string content, string tos)
+        public static void SendMail(string title, string content, string tos, string clientip)
         {
 #if !DEBUG
             new Email()
@@ -216,6 +216,8 @@ namespace Masuit.MyBlogs.Core.Common
                 Tos = tos
             }.Send();
 #endif
+            RedisHelper.SAdd($"Email:{DateTime.Now:yyyyMMdd}", new { title, content, tos, time = DateTime.Now, clientip });
+            RedisHelper.Expire($"Email:{DateTime.Now:yyyyMMdd}", 86400);
         }
 
         /// <summary>

+ 4 - 8
src/Masuit.MyBlogs.Core/Controllers/CommentController.cs

@@ -117,7 +117,6 @@ namespace Masuit.MyBlogs.Core.Controllers
                         Link = Url.Action("Details", "Post", new { id = comment.PostId, cid = comment.Id }, Request.Scheme) + "#comment"
                     });
                 }
-#if !DEBUG
                 if (comment.ParentId == 0)
                 {
                     emails.Add(post.Email);
@@ -125,7 +124,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                     //新评论,只通知博主和楼主
                     foreach (var s in emails)
                     {
-                        BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "|博客文章新评论:", content.Set("link", Url.Action("Details", "Post", new { id = comment.PostId, cid = comment.Id }, Request.Scheme) + "#comment").Render(false), s));
+                        BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "|博客文章新评论:", content.Set("link", Url.Action("Details", "Post", new { id = comment.PostId, cid = comment.Id }, Request.Scheme) + "#comment").Render(false), s, ClientIP));
                     }
                 }
                 else
@@ -138,16 +137,15 @@ namespace Masuit.MyBlogs.Core.Controllers
                     string link = Url.Action("Details", "Post", new { id = comment.PostId, cid = comment.Id }, Request.Scheme) + "#comment";
                     foreach (var s in emails)
                     {
-                        BackgroundJob.Enqueue(() => CommonHelper.SendMail($"{Request.Host}{CommonHelper.SystemSettings["Title"]}文章评论回复:", content.Set("link", link).Render(false), s));
+                        BackgroundJob.Enqueue(() => CommonHelper.SendMail($"{Request.Host}{CommonHelper.SystemSettings["Title"]}文章评论回复:", content.Set("link", link).Render(false), s, ClientIP));
                     }
                 }
-#endif
                 return ResultData(null, true, "评论发表成功,服务器正在后台处理中,这会有一定的延迟,稍后将显示到评论列表中");
             }
 
             foreach (var s in emails)
             {
-                BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "|博客文章新评论(待审核):", content.Set("link", Url.Action("Details", "Post", new { id = comment.PostId, cid = comment.Id }, Request.Scheme) + "#comment").Render(false) + "<p style='color:red;'>(待审核)</p>", s));
+                BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "|博客文章新评论(待审核):", content.Set("link", Url.Action("Details", "Post", new { id = comment.PostId, cid = comment.Id }, Request.Scheme) + "#comment").Render(false) + "<p style='color:red;'>(待审核)</p>", s, ClientIP));
             }
 
             return ResultData(null, true, "评论成功,待站长审核通过以后将显示");
@@ -250,7 +248,6 @@ namespace Masuit.MyBlogs.Core.Controllers
             if (b)
             {
                 var pid = comment.ParentId == 0 ? comment.Id : CommentService.GetParentCommentIdByChildId(id);
-#if !DEBUG
                 var content = new Template(await System.IO.File.ReadAllTextAsync(Path.Combine(HostEnvironment.WebRootPath, "template", "notify.html")))
                     .Set("title", post.Title)
                     .Set("time", DateTime.Now.ToTimeZoneF(HttpContext.Session.Get<string>(SessionKey.TimeZone)))
@@ -264,9 +261,8 @@ namespace Masuit.MyBlogs.Core.Controllers
                 }, Request.Scheme) + "#comment";
                 foreach (var email in emails)
                 {
-                    BackgroundJob.Enqueue(() => CommonHelper.SendMail($"{Request.Host}{CommonHelper.SystemSettings["Title"]}文章评论回复:", content.Set("link", link).Render(false), email));
+                    BackgroundJob.Enqueue(() => CommonHelper.SendMail($"{Request.Host}{CommonHelper.SystemSettings["Title"]}文章评论回复:", content.Set("link", link).Render(false), email, ClientIP));
                 }
-#endif
                 return ResultData(null, true, "审核通过!");
             }
 

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/ErrorController.cs

@@ -183,7 +183,7 @@ namespace Masuit.MyBlogs.Core.Controllers
 
             var token = SnowFlake.GetInstance().GetUniqueShortId(6);
             RedisHelper.Set("token:" + email, token, 86400);
-            BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "博客访问验证码", $"{Request.Host}本次验证码是:<span style='color:red'>{token}</span>,有效期为24h,请按时使用!", email));
+            BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "博客访问验证码", $"{Request.Host}本次验证码是:<span style='color:red'>{token}</span>,有效期为24h,请按时使用!", email, HttpContext.Connection.RemoteIpAddress.ToString()));
             RedisHelper.Set("get:" + email, token, 120);
             return ResultData(null);
 

+ 2 - 2
src/Masuit.MyBlogs.Core/Controllers/MergeController.cs

@@ -111,7 +111,7 @@ namespace Masuit.MyBlogs.Core.Controllers
 
             string link = Request.Scheme + "://" + Request.Host + "/" + merge.Post.Id;
             string content = new Template(await System.IO.File.ReadAllTextAsync(HostEnvironment.WebRootPath + "/template/merge-pass.html")).Set("link", link).Set("title", merge.Post.Title).Render();
-            BackgroundJob.Enqueue(() => CommonHelper.SendMail(CommonHelper.SystemSettings["Title"] + "博客你提交的修改已通过", content, merge.ModifierEmail));
+            BackgroundJob.Enqueue(() => CommonHelper.SendMail(CommonHelper.SystemSettings["Title"] + "博客你提交的修改已通过", content, merge.ModifierEmail, "127.0.0.1"));
             return ResultData(null, true, "文章合并完成!");
         }
 
@@ -148,7 +148,7 @@ namespace Masuit.MyBlogs.Core.Controllers
 
             var link = Request.Scheme + "://" + Request.Host + "/" + merge.Post.Id + "/merge/" + id;
             var content = new Template(await System.IO.File.ReadAllTextAsync(HostEnvironment.WebRootPath + "/template/merge-reject.html")).Set("link", link).Set("title", merge.Post.Title).Set("reason", reason).Render();
-            BackgroundJob.Enqueue(() => CommonHelper.SendMail(CommonHelper.SystemSettings["Title"] + "博客你提交的修改已被拒绝", content, merge.ModifierEmail));
+            BackgroundJob.Enqueue(() => CommonHelper.SendMail(CommonHelper.SystemSettings["Title"] + "博客你提交的修改已被拒绝", content, merge.ModifierEmail, "127.0.0.1"));
             return ResultData(null, true, "合并已拒绝!");
         }
 

+ 5 - 8
src/Masuit.MyBlogs.Core/Controllers/MsgController.cs

@@ -181,11 +181,10 @@ namespace Masuit.MyBlogs.Core.Controllers
                         Link = Url.Action("Index", "Msg", new { cid = msg.Id }, Request.Scheme)
                     });
                 }
-#if !DEBUG
                 if (msg.ParentId == 0)
                 {
                     //新评论,只通知博主
-                    BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "|博客新留言:", content.Set("link", Url.Action("Index", "Msg", new { cid = msg.Id }, Request.Scheme)).Render(false), email));
+                    BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "|博客新留言:", content.Set("link", Url.Action("Index", "Msg", new { cid = msg.Id }, Request.Scheme)).Render(false), email, ClientIP));
                 }
                 else
                 {
@@ -195,17 +194,16 @@ namespace Masuit.MyBlogs.Core.Controllers
                     string link = Url.Action("Index", "Msg", new { cid = msg.Id }, Request.Scheme);
                     foreach (var s in emails)
                     {
-                        BackgroundJob.Enqueue(() => CommonHelper.SendMail($"{Request.Host}{CommonHelper.SystemSettings["Title"]} 留言回复:", content.Set("link", link).Render(false), s));
+                        BackgroundJob.Enqueue(() => CommonHelper.SendMail($"{Request.Host}{CommonHelper.SystemSettings["Title"]} 留言回复:", content.Set("link", link).Render(false), s, ClientIP));
                     }
                 }
-#endif
                 return ResultData(null, true, "留言发表成功,服务器正在后台处理中,这会有一定的延迟,稍后将会显示到列表中!");
             }
 
             BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "|博客新留言(待审核):", content.Set("link", Url.Action("Index", "Msg", new
             {
                 cid = msg.Id
-            }, Request.Scheme)).Render(false) + "<p style='color:red;'>(待审核)</p>", email));
+            }, Request.Scheme)).Render(false) + "<p style='color:red;'>(待审核)</p>", email, ClientIP));
             return ResultData(null, true, "留言发表成功,待站长审核通过以后将显示到列表中!");
         }
 
@@ -220,16 +218,15 @@ namespace Masuit.MyBlogs.Core.Controllers
             var msg = await LeaveMessageService.GetByIdAsync(id);
             msg.Status = Status.Published;
             bool b = await LeaveMessageService.SaveChangesAsync() > 0;
-#if !DEBUG
             var pid = msg.ParentId == 0 ? msg.Id : LeaveMessageService.GetParentMessageIdByChildId(id);
             var content = new Template(await System.IO.File.ReadAllTextAsync(Path.Combine(HostEnvironment.WebRootPath, "template", "notify.html"))).Set("time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Set("nickname", msg.NickName).Set("content", msg.Content);
             var emails = LeaveMessageService.GetSelfAndAllChildrenMessagesByParentId(pid).Select(c => c.Email).Except(new List<string> { msg.Email, CurrentUser.Email }).ToHashSet();
             var link = Url.Action("Index", "Msg", new { cid = pid }, Request.Scheme);
             foreach (var s in emails)
             {
-                BackgroundJob.Enqueue(() => CommonHelper.SendMail($"{Request.Host}{CommonHelper.SystemSettings["Title"]} 留言回复:", content.Set("link", link).Render(false), s));
+                BackgroundJob.Enqueue(() => CommonHelper.SendMail($"{Request.Host}{CommonHelper.SystemSettings["Title"]} 留言回复:", content.Set("link", link).Render(false), s, ClientIP));
             }
-#endif
+
             return ResultData(null, b, b ? "审核通过!" : "审核失败!");
         }
 

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

@@ -257,6 +257,11 @@ namespace Masuit.MyBlogs.Core.Controllers
                 return ResultData(null, false, "验证码错误!");
             }
 
+            if (PostService.Any(p => p.Status == Status.Forbidden && p.Email == post.Email))
+            {
+                return ResultData(null, false, "由于您曾经恶意投稿,该邮箱已经被标记为黑名单,无法进行投稿,如有疑问,请联系网站管理员进行处理。");
+            }
+
             var match = Regex.Match(post.Title + post.Author + post.Content, CommonHelper.BanRegex);
             if (match.Success)
             {
@@ -288,7 +293,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 .Set("link", Url.Action("Details", "Post", new { id = p.Id }, Request.Scheme))
                 .Set("time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
                 .Set("title", p.Title).Render();
-            BackgroundJob.Enqueue(() => CommonHelper.SendMail(CommonHelper.SystemSettings["Title"] + "有访客投稿:", content, CommonHelper.SystemSettings["ReceiveEmail"]));
+            BackgroundJob.Enqueue(() => CommonHelper.SendMail(CommonHelper.SystemSettings["Title"] + "有访客投稿:", content, CommonHelper.SystemSettings["ReceiveEmail"], ClientIP));
             return ResultData(p.Mapper<PostDto>(), message: "文章发表成功,待站长审核通过以后将显示到列表中!");
         }
 
@@ -387,7 +392,7 @@ namespace Masuit.MyBlogs.Core.Controllers
 
             var token = SnowFlake.GetInstance().GetUniqueShortId(6);
             RedisHelper.Set("token:" + email, token, 86400);
-            BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "博客访问验证码", $"{Request.Host}本次验证码是:<span style='color:red'>{token}</span>,有效期为24h,请按时使用!", email));
+            BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "博客访问验证码", $"{Request.Host}本次验证码是:<span style='color:red'>{token}</span>,有效期为24h,请按时使用!", email, ClientIP));
             RedisHelper.Set("get:" + email, token, 120);
             return ResultData(null);
 
@@ -493,7 +498,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 Link = "#/merge/compare?id=" + merge.Id
             });
             var content = new Template(await System.IO.File.ReadAllTextAsync(HostEnvironment.WebRootPath + "/template/merge-request.html")).Set("title", post.Title).Set("link", Url.Action("Index", "Dashboard", new { }, Request.Scheme) + "#/merge/compare?id=" + merge.Id).Render();
-            BackgroundJob.Enqueue(() => CommonHelper.SendMail("博客文章修改请求:", content, CommonHelper.SystemSettings["ReceiveEmail"]));
+            BackgroundJob.Enqueue(() => CommonHelper.SendMail("博客文章修改请求:", content, CommonHelper.SystemSettings["ReceiveEmail"], ClientIP));
             return ResultData(null, true, "您的修改请求已提交,已进入审核状态,感谢您的参与!");
         }
 
@@ -954,6 +959,20 @@ namespace Masuit.MyBlogs.Core.Controllers
             return RedirectToAction("Details", new { id });
         }
 
+        /// <summary>
+        /// 标记为恶意修改
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        [MyAuthorize]
+        [HttpPost("post/block/{id}")]
+        public async Task<ActionResult> Block(int id)
+        {
+            var merge = await PostService.GetByIdAsync(id) ?? throw new NotFoundException("文章未找到");
+            merge.Status = Status.Forbidden;
+            var b = await PostService.SaveChangesAsync() > 0;
+            return b ? ResultData(null, true, "操作成功!") : ResultData(null, false, "操作失败!");
+        }
         #endregion
     }
 }

+ 10 - 0
src/Masuit.MyBlogs.Core/Controllers/SystemController.cs

@@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.EntityFrameworkCore.Internal;
 using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
 using System;
 using System.Collections.Generic;
 using System.IO;
@@ -247,6 +248,15 @@ namespace Masuit.MyBlogs.Core.Controllers
             return Ok();
         }
 
+        /// <summary>
+        /// 发件箱记录
+        /// </summary>
+        /// <returns></returns>
+        public ActionResult<List<JObject>> SendBox()
+        {
+            return RedisHelper.Keys("Email:*").SelectMany(key => RedisHelper.SMembers(key).Select(JObject.Parse)).ToList();
+        }
+
         #region 网站防火墙
 
         /// <summary>

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/ValidateController.cs

@@ -30,7 +30,7 @@ namespace Masuit.MyBlogs.Core.Controllers
 
             string code = SnowFlake.GetInstance().GetUniqueShortId(6);
             await RedisHelper.SetAsync("code:" + email, code, 86400);
-            BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "博客验证码", $"{Request.Host}本次验证码是:<span style='color:red'>{code}</span>,有效期为24h,请按时使用!", email));
+            BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "博客验证码", $"{Request.Host}本次验证码是:<span style='color:red'>{code}</span>,有效期为24h,请按时使用!", email, ClientIP));
             await RedisHelper.SetAsync("get:" + email, code, 120);
 #if !DEBUG
             return ResultData(null, true, "验证码发送成功!");

+ 1 - 1
src/Masuit.MyBlogs.Core/Extensions/Hangfire/HangfireBackJob.cs

@@ -88,7 +88,7 @@ namespace Masuit.MyBlogs.Core.Extensions.Hangfire
                 .Set("time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
                 .Set("ip", record.IP)
                 .Set("address", record.PhysicAddress).Render();
-            CommonHelper.SendMail(_settingService.Get(s => s.Name.Equals("Title")).Value + "账号登录通知", content, _settingService.Get(s => s.Name.Equals("ReceiveEmail")).Value);
+            CommonHelper.SendMail(_settingService.Get(s => s.Name.Equals("Title")).Value + "账号登录通知", content, _settingService.Get(s => s.Name.Equals("ReceiveEmail")).Value, "127.0.0.1");
         }
 
         /// <summary>

+ 10 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/app/route.config.js

@@ -321,6 +321,16 @@ myApp.config([
                     }
                 ]
             }
+        }).state("sendbox", {
+            url: "/system/sendbox",
+            templateUrl: vpath + "/system/sendbox.html",
+            controller: "sendbox as list",
+            resolve: {
+                deps: ["$ocLazyLoad", function($ocLazyLoad) {
+                        return $ocLazyLoad.load([cpath + "/system.js"]);
+                    }
+                ]
+            }
         }).state("search", {
             url: "/search",
             templateUrl: vpath + "/analysis/search.html",

文件差异内容过多而无法显示
+ 0 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/app/route.config.min.js


+ 28 - 1
src/Masuit.MyBlogs.Core/wwwroot/ng-views/controllers/post.js

@@ -874,7 +874,34 @@ myApp.controller("postpending", ["$scope", "$http", "NgTableParams", "$timeout",
 		}, 500);
 	}
 	
-
+	$scope.addToBlock= function(row) {
+		swal({
+			title: "确认添加恶意名单吗?",
+			text: "将"+row.Email+"添加到恶意名单",
+			showCancelButton: true,
+			confirmButtonColor: "#DD6B55",
+			confirmButtonText: "确定",
+			cancelButtonText: "取消",
+			animation: true,
+			allowOutsideClick: false,
+			showLoaderOnConfirm: true,
+			preConfirm: function () {
+				return new Promise(function (resolve, reject) {
+					$http.post("/post/block/"+row.Id).then(function(res) {
+						resolve(res.data);
+					}, function() {
+						reject("请求服务器失败!");
+					});
+				});
+			}
+		}).then(function (data) {
+			if (data.Success) {
+				swal("添加成功",'','success');
+			} else {
+				swal("添加失败",'','error');
+			}
+		}).catch(swal.noop);
+	}
 }]);
 
 myApp.controller("share", ["$scope", "$http", "NgTableParams", function ($scope, $http, NgTableParams) {

文件差异内容过多而无法显示
+ 0 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/controllers/post.min.js


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

@@ -537,4 +537,41 @@ myApp.controller("firewall", ["$scope", "$http","NgTableParams","$timeout", func
 				}
 			}).catch(swal.noop);
 		}
+}]);
+
+myApp.controller("sendbox", ["$scope", "$http", function ($scope, $http) {
+	window.hub.stop();
+	$http.post("/system/sendbox").then(function (res) {
+		$scope.Mails = res.data;
+	});
+	$scope.addToBlackList = function(ip) {
+			swal({
+				title: "确认添加黑名单吗?",
+				text: "将"+ip+"添加到黑名单",
+				showCancelButton: true,
+				confirmButtonColor: "#DD6B55",
+				confirmButtonText: "确定",
+				cancelButtonText: "取消",
+				animation: true,
+				allowOutsideClick: false,
+				showLoaderOnConfirm: true,
+				preConfirm: function () {
+					return new Promise(function (resolve, reject) {
+						$http.post("/system/AddToBlackList", {ip}, {
+							'Content-Type': 'application/x-www-form-urlencoded'
+						}).then(function(res) {
+							resolve(res.data);
+						}, function() {
+							reject("请求服务器失败!");
+						});
+					});
+				}
+			}).then(function (data) {
+				if (data.Success) {
+					swal("添加成功",'','success');
+				} else {
+					swal("添加失败",'','error');
+				}
+			}).catch(swal.noop);
+		}
 }]);

文件差异内容过多而无法显示
+ 0 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/controllers/system.min.js


+ 1 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/template/sidebar-left.html

@@ -87,6 +87,7 @@
                 <li><a data-ui-sref-active="active" data-ui-sref="system-firewall" data-ng-click="mactrl.sidebarStat($event)">网站防火墙</a></li>
                 <li><a data-ui-sref-active="active" data-ui-sref="links" data-ng-click="mactrl.sidebarStat($event)">友情链接管理</a></li>
                 <li><a data-ui-sref-active="active" data-ui-sref="email" data-ng-click="mactrl.sidebarStat($event)">邮件模版</a></li>
+                <li><a data-ui-sref-active="active" data-ui-sref="sendbox" data-ng-click="mactrl.sidebarStat($event)">邮件发送记录</a></li>
             </ul>
         </li>
         <li data-ui-sref-active="active">

+ 1 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/views/post/pending.html

@@ -26,6 +26,7 @@
             </td>
             <td title="'作者邮箱'">
                 {{row.Email}}
+                <button class="badge btn btn-primary" ng-click="addToBlock(row)">标记为恶意提交</button>
             </td>
             <td title="'标签'">
                 {{row.Label}}

+ 25 - 0
src/Masuit.MyBlogs.Core/wwwroot/ng-views/views/system/sendbox.html

@@ -0,0 +1,25 @@
+<div class="row">
+    <div class="card">
+        <div class="listview lv-bordered lv-lg">
+            <div class="lv-header-alt clearfix">
+                <h2 class="lvh-label hidden-xs" style="font-size: 20px">发件箱</h2>
+            </div>
+
+            <div class="lv-body">
+                <div class="lv-item media" ng-repeat="m in Mails">
+                    <div class="media-body">
+                            <h2 class="lv-title">{{m.title}}</h2>
+                            <small class="lv-small" ng-bind-html="m.content|htmlString"></small>
+                        <ul class="lv-attrs">
+                            <li>收件人:{{m.tos}}</li>
+                            <li>发送日期:{{m.time|date:'yyyy-MM-dd HH:mm:ss'}}</li>
+                            <li>
+                                <a ng-click="addToBlackList(m.clientip)">请求IP:{{m.clientip}}</a>
+                            </li>
+                        </ul>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>

部分文件因为文件数量过多而无法显示