From 584f15d39f97b7212fa416fd42f8aa1b595d12e4 Mon Sep 17 00:00:00 2001 From: JianWeie Date: Sun, 25 Jul 2021 00:22:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9F=9F=E5=90=8D=E8=BD=AC?= =?UTF-8?q?=E5=8F=91=E8=8E=B7=E5=8F=96ip=E5=9C=B0=E5=9D=80=E9=95=BF?= =?UTF-8?q?=E5=BA=A6=E8=BF=87=E9=95=BF=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CoreCms.Net.Middlewares/IPLogMildd.cs | 5 ++++- .../Bill/CoreCmsBillPaymentsServices.cs | 3 ++- .../IntelligentForms/CoreCmsFormServices.cs | 2 +- CoreCms.Net.Services/Message/CoreCmsSmsServices.cs | 5 +++-- CoreCms.Net.Services/Order/CoreCmsOrderServices.cs | 2 +- CoreCms.Net.Services/User/CoreCmsUserServices.cs | 3 ++- .../Controllers/Com/LoginController.cs | 10 ++++++++-- CoreCms.Net.Web.WebApi/Controllers/UserController.cs | 8 +++++--- 8 files changed, 26 insertions(+), 12 deletions(-) diff --git a/CoreCms.Net.Middlewares/IPLogMildd.cs b/CoreCms.Net.Middlewares/IPLogMildd.cs index 7025ea0..1bf81cd 100644 --- a/CoreCms.Net.Middlewares/IPLogMildd.cs +++ b/CoreCms.Net.Middlewares/IPLogMildd.cs @@ -95,7 +95,10 @@ namespace CoreCms.Net.Middlewares var ip = context.Request.Headers["X-Forwarded-For"].ObjectToString(); if (string.IsNullOrEmpty(ip)) { - ip = context.Connection.RemoteIpAddress.ObjectToString(); + if (context.Connection.RemoteIpAddress != null) + { + ip = context.Connection.RemoteIpAddress.MapToIPv4().ObjectToString(); + } } return ip; } diff --git a/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs b/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs index d56a01e..2778385 100644 --- a/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs +++ b/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs @@ -409,7 +409,8 @@ namespace CoreCms.Net.Services billPayments.type = type; billPayments.status = (int)GlobalEnumVars.BillPaymentsStatus.NoPay; billPayments.paymentCode = paymentCode; - billPayments.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + billPayments.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; + billPayments.parameters = @params != null ? JsonConvert.SerializeObject(@params) : ""; billPayments.createTime = DateTime.Now; diff --git a/CoreCms.Net.Services/IntelligentForms/CoreCmsFormServices.cs b/CoreCms.Net.Services/IntelligentForms/CoreCmsFormServices.cs index 1585c03..b282d86 100644 --- a/CoreCms.Net.Services/IntelligentForms/CoreCmsFormServices.cs +++ b/CoreCms.Net.Services/IntelligentForms/CoreCmsFormServices.cs @@ -385,7 +385,7 @@ namespace CoreCms.Net.Services formSubmitModel.payStatus = false; formSubmitModel.status = false; formSubmitModel.createTime = DateTime.Now; - formSubmitModel.ip = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(); + formSubmitModel.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; var formSubmitId = await _formSubmitServices.InsertReturnIdentityAsync(formSubmitModel); diff --git a/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs b/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs index 40d51bc..f24fa93 100644 --- a/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs +++ b/CoreCms.Net.Services/Message/CoreCmsSmsServices.cs @@ -87,7 +87,7 @@ namespace CoreCms.Net.Services oldLog.code = type; oldLog.createTime = DateTime.Now; oldLog.mobile = mobile; - oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; oldLog.isUsed = false; var obj = new { @@ -238,7 +238,8 @@ namespace CoreCms.Net.Services oldLog.parameters = JsonConvert.SerializeObject(parameters); oldLog.contentBody = str; oldLog.createTime = DateTime.Now; - oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; oldLog.isUsed = isUsed; await _dal.InsertAsync(oldLog); diff --git a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs index d854a6d..1d2becb 100644 --- a/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs +++ b/CoreCms.Net.Services/Order/CoreCmsOrderServices.cs @@ -532,7 +532,7 @@ namespace CoreCms.Net.Services order.orderDiscountAmount = cartDto.orderPromotionMoney > 0 ? cartDto.orderPromotionMoney : 0; order.goodsDiscountAmount = cartDto.goodsPromotionMoney > 0 ? cartDto.goodsPromotionMoney : 0; order.couponDiscountAmount = cartDto.couponPromotionMoney; - order.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + order.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; //以上保存了订单主体表信息,以下生成订单明细表 var items = FormatOrderItems(cartDto.list, order.orderId); if (!items.Any()) diff --git a/CoreCms.Net.Services/User/CoreCmsUserServices.cs b/CoreCms.Net.Services/User/CoreCmsUserServices.cs index 7d6dc48..dc0e0b9 100644 --- a/CoreCms.Net.Services/User/CoreCmsUserServices.cs +++ b/CoreCms.Net.Services/User/CoreCmsUserServices.cs @@ -630,7 +630,8 @@ namespace CoreCms.Net.Services var log = new CoreCmsUserLog(); log.userId = userInfo.id; log.state = isReg ? (int)GlobalEnumVars.UserLogTypes.注册 : (int)GlobalEnumVars.UserLogTypes.登录; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; log.createTime = DateTime.Now; log.parameters = isReg ? GlobalEnumVars.UserLogTypes.注册.ToString() : GlobalEnumVars.UserLogTypes.登录.ToString(); await _userLogServices.InsertAsync(log); diff --git a/CoreCms.Net.Web.Admin/Controllers/Com/LoginController.cs b/CoreCms.Net.Web.Admin/Controllers/Com/LoginController.cs index ec9e7d6..9474772 100644 --- a/CoreCms.Net.Web.Admin/Controllers/Com/LoginController.cs +++ b/CoreCms.Net.Web.Admin/Controllers/Com/LoginController.cs @@ -137,7 +137,9 @@ namespace CoreCms.Net.Web.Admin.Controllers //插入登录日志 var log = new SysLoginRecord(); log.username = model.userName; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; + log.os = RuntimeInformation.OSDescription; if (_httpContextAccessor.HttpContext != null) log.browser = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent]; @@ -152,7 +154,9 @@ namespace CoreCms.Net.Web.Admin.Controllers //插入登录日志 var log = new SysLoginRecord(); log.username = model.userName; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; + log.os = RuntimeInformation.OSDescription; if (_httpContextAccessor.HttpContext != null) log.browser = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent]; @@ -212,7 +216,9 @@ namespace CoreCms.Net.Web.Admin.Controllers if (_httpContextAccessor.HttpContext != null) { if (_httpContextAccessor.HttpContext.Connection.RemoteIpAddress != null) + { log.ip = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(); + } log.os = RuntimeInformation.OSDescription; log.browser = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent]; } diff --git a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs index 890b86f..a19a88a 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs @@ -208,7 +208,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers var log = new CoreCmsUserLog(); log.userId = user.id; log.state = (int)GlobalEnumVars.UserLogTypes.登录; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; log.createTime = DateTime.Now; log.parameters = GlobalEnumVars.UserLogTypes.登录.ToString(); await _userLogServices.InsertAsync(log); @@ -316,7 +316,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers var log = new CoreCmsUserLog(); log.userId = user.id; log.state = (int)GlobalEnumVars.UserLogTypes.登录; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; log.createTime = DateTime.Now; log.parameters = GlobalEnumVars.UserLogTypes.登录.ToString(); await _userLogServices.InsertAsync(log); @@ -522,7 +522,9 @@ namespace CoreCms.Net.Web.WebApi.Controllers var log = new CoreCmsUserLog(); log.userId = id; log.state = (int)GlobalEnumVars.UserLogTypes.注册; - log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1"; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; + log.createTime = DateTime.Now; log.parameters = GlobalEnumVars.UserLogTypes.注册.ToString(); await _userLogServices.InsertAsync(log);