fix(#IVYHA): UserAgent字符串引发解析OS/Browser异常

升级Longbow.Web组件到2.2.11,数据库增加UserAgent字段保存相关UserAgent
comment #IVYHA

close https://gitee.com/LongbowEnterprise/dashboard/issues?id=IVYHA
This commit is contained in:
Argo Zhang 2019-04-27 20:39:24 +08:00
parent 05374f7794
commit 9fc8e53fc5
16 changed files with 47 additions and 22 deletions

View File

@ -13,7 +13,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.4" /> <PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.5" />
<PackageReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.2" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" PrivateAssets="All" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" PrivateAssets="All" />

Binary file not shown.

View File

@ -69,11 +69,12 @@ namespace Bootstrap.Admin.Controllers
/// <param name="loginUser"></param> /// <param name="loginUser"></param>
internal static void CreateLoginUser(IOnlineUsers onlineUserSvr, IIPLocatorProvider ipLocator, HttpContext context, LoginUser loginUser) internal static void CreateLoginUser(IOnlineUsers onlineUserSvr, IIPLocatorProvider ipLocator, HttpContext context, LoginUser loginUser)
{ {
var agent = new UserAgent(context.Request.Headers["User-Agent"]); loginUser.UserAgent = context.Request.Headers["User-Agent"];
var agent = new UserAgent(loginUser.UserAgent);
loginUser.Ip = (context.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString(); loginUser.Ip = (context.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString();
loginUser.City = ipLocator.Locate(loginUser.Ip); loginUser.City = ipLocator.Locate(loginUser.Ip);
loginUser.Browser = $"{agent.Browser.Name} {agent.Browser.Version}"; loginUser.Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}";
loginUser.OS = $"{agent.OS.Name} {agent.OS.Version}"; loginUser.OS = $"{agent.OS?.Name} {agent.OS?.Version}";
} }
/// <summary> /// <summary>

View File

@ -35,10 +35,11 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpPost] [HttpPost]
public bool Post([FromServices]IOnlineUsers onlineUserSvr, [FromServices]IIPLocatorProvider ipLocator, [FromBody]Log value) public bool Post([FromServices]IOnlineUsers onlineUserSvr, [FromServices]IIPLocatorProvider ipLocator, [FromBody]Log value)
{ {
var agent = new UserAgent(Request.Headers["User-Agent"]); value.UserAgent = Request.Headers["User-Agent"];
var agent = new UserAgent(value.UserAgent);
value.Ip = (HttpContext.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString(); value.Ip = (HttpContext.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString();
value.Browser = $"{agent.Browser.Name} {agent.Browser.Version}"; value.Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}";
value.OS = $"{agent.OS.Name} {agent.OS.Version}"; value.OS = $"{agent.OS?.Name} {agent.OS?.Version}";
value.City = ipLocator.Locate(value.Ip); value.City = ipLocator.Locate(value.Ip);
value.UserName = User.Identity.Name; value.UserName = User.Identity.Name;
return LogHelper.Save(value); return LogHelper.Save(value);

View File

@ -14,7 +14,7 @@
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.1.0" /> <PackageReference Include="Bootstrap.Security.DataAccess" Version="2.1.0" />
<PackageReference Include="Longbow.Cache" Version="2.2.7" /> <PackageReference Include="Longbow.Cache" Version="2.2.7" />
<PackageReference Include="Longbow.Data" Version="2.2.8" /> <PackageReference Include="Longbow.Data" Version="2.2.8" />
<PackageReference Include="Longbow.Web" Version="2.2.10" /> <PackageReference Include="Longbow.Web" Version="2.2.11" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" /> <PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" />
</ItemGroup> </ItemGroup>

View File

@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.4" /> <PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.5" />
<PackageReference Include="Longbow.Logging" Version="2.2.6" /> <PackageReference Include="Longbow.Logging" Version="2.2.6" />
<PackageReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup> </ItemGroup>

View File

@ -15,7 +15,7 @@
<PackageReference Include="Longbow.Data" Version="2.2.8" /> <PackageReference Include="Longbow.Data" Version="2.2.8" />
<PackageReference Include="Longbow.Logging" Version="2.2.6" /> <PackageReference Include="Longbow.Logging" Version="2.2.6" />
<PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" /> <PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" />
<PackageReference Include="Longbow.Web" Version="2.2.10" /> <PackageReference Include="Longbow.Web" Version="2.2.11" />
<PackageReference Include="Longbow.Cache" Version="2.2.7" /> <PackageReference Include="Longbow.Cache" Version="2.2.7" />
<PackageReference Include="Longbow" Version="2.2.9" /> <PackageReference Include="Longbow" Version="2.2.9" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" /> <PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" />

View File

@ -30,7 +30,8 @@ namespace Bootstrap.DataAccess
City = v.Location, City = v.Location,
Browser = v.Browser, Browser = v.Browser,
OS = v.OS, OS = v.OS,
UserName = v.UserName UserName = v.UserName,
UserAgent = v.UserAgent
}); });
} }
} }

View File

@ -50,6 +50,11 @@ namespace Bootstrap.DataAccess
/// </summary> /// </summary>
public string Result { get; set; } public string Result { get; set; }
/// <summary>
///
/// </summary>
public string UserAgent { get; set; }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>

View File

@ -49,6 +49,11 @@ namespace Bootstrap.DataAccess
/// </summary> /// </summary>
public string RequestUrl { get; set; } public string RequestUrl { get; set; }
/// <summary>
///
/// </summary>
public string UserAgent { get; set; }
/// <summary> /// <summary>
/// 保存访问历史记录 /// 保存访问历史记录
/// </summary> /// </summary>

View File

@ -273,6 +273,7 @@ CREATE TABLE [dbo].[Logs](
[City] [nvarchar](50) NULL, [City] [nvarchar](50) NULL,
[RequestUrl] [nvarchar](500) NOT NULL, [RequestUrl] [nvarchar](500) NOT NULL,
[RequestData] [nvarchar](500) NULL, [RequestData] [nvarchar](500) NULL,
[UserAgent] [varchar](2000) NULL,
CONSTRAINT [PK_Logs] PRIMARY KEY CLUSTERED CONSTRAINT [PK_Logs] PRIMARY KEY CLUSTERED
( (
[ID] ASC [ID] ASC
@ -499,6 +500,7 @@ CREATE TABLE [dbo].[LoginLogs](
[Browser] [varchar](50) NULL, [Browser] [varchar](50) NULL,
[City] [nvarchar](50) NULL, [City] [nvarchar](50) NULL,
[Result] [nvarchar](50) NOT NULL, [Result] [nvarchar](50) NOT NULL,
[UserAgent] [varchar](2000) NULL,
CONSTRAINT [PK_LoginLogs] PRIMARY KEY CLUSTERED CONSTRAINT [PK_LoginLogs] PRIMARY KEY CLUSTERED
( (
[ID] ASC [ID] ASC
@ -556,6 +558,7 @@ CREATE TABLE [dbo].[Traces](
[OS] [varchar](50) NULL, [OS] [varchar](50) NULL,
[City] [nvarchar](50) NULL, [City] [nvarchar](50) NULL,
[RequestUrl] [nvarchar](500) NOT NULL, [RequestUrl] [nvarchar](500) NOT NULL,
[UserAgent] [varchar](2000) NULL,
CONSTRAINT [PK_Traces] PRIMARY KEY CLUSTERED CONSTRAINT [PK_Traces] PRIMARY KEY CLUSTERED
( (
[ID] ASC [ID] ASC

View File

@ -87,7 +87,8 @@ CREATE TABLE Logs(
OS VARCHAR (50) NULL, OS VARCHAR (50) NULL,
City VARCHAR (50) NULL, City VARCHAR (50) NULL,
RequestUrl VARCHAR (500) NOT NULL, RequestUrl VARCHAR (500) NOT NULL,
RequestData VARCHAR (500) NULL RequestData VARCHAR (500) NULL,
UserAgent VARCHAR (2000) NULL
); );
CREATE TABLE `Groups`( CREATE TABLE `Groups`(
@ -158,7 +159,8 @@ CREATE TABLE LoginLogs(
OS VARCHAR (50) NULL, OS VARCHAR (50) NULL,
Browser VARCHAR (50) NULL, Browser VARCHAR (50) NULL,
City VARCHAR (50) NULL, City VARCHAR (50) NULL,
Result VARCHAR (50) NOT NULL Result VARCHAR (50) NOT NULL,
UserAgent VARCHAR (2000) NULL
); );
CREATE TABLE ResetUsers( CREATE TABLE ResetUsers(
@ -177,5 +179,6 @@ CREATE TABLE Traces(
Browser VARCHAR (50), Browser VARCHAR (50),
OS VARCHAR (50), OS VARCHAR (50),
City VARCHAR (50), City VARCHAR (50),
RequestUrl VARCHAR (500) NOT NULL RequestUrl VARCHAR (500) NOT NULL,
UserAgent VARCHAR (2000) NULL
); );

View File

@ -87,7 +87,8 @@ CREATE TABLE Logs(
OS VARCHAR (50) NULL, OS VARCHAR (50) NULL,
City VARCHAR (50) NULL, City VARCHAR (50) NULL,
RequestUrl VARCHAR (500) NOT NULL, RequestUrl VARCHAR (500) NOT NULL,
RequestData VARCHAR (500) NULL RequestData VARCHAR (500) NULL,
UserAgent VARCHAR (2000) NULL
); );
CREATE TABLE Groups( CREATE TABLE Groups(
@ -158,7 +159,8 @@ CREATE TABLE RejectUsers(
OS VARCHAR (50) NULL, OS VARCHAR (50) NULL,
Browser VARCHAR (50) NULL, Browser VARCHAR (50) NULL,
City VARCHAR (50) NULL, City VARCHAR (50) NULL,
Result VARCHAR (50) NOT NULL Result VARCHAR (50) NOT NULL,
UserAgent VARCHAR (2000) NULL
); );
CREATE TABLE ResetUsers( CREATE TABLE ResetUsers(
@ -177,5 +179,6 @@ CREATE TABLE Traces(
Browser VARCHAR (50), Browser VARCHAR (50),
OS VARCHAR (50), OS VARCHAR (50),
City VARCHAR (50), City VARCHAR (50),
RequestUrl VARCHAR (500) NOT NULL RequestUrl VARCHAR (500) NOT NULL,
UserAgent VARCHAR (2000) NULL
); );

View File

@ -87,7 +87,8 @@ CREATE TABLE Logs(
OS VARCHAR (50) NULL, OS VARCHAR (50) NULL,
City VARCHAR (50) NULL, City VARCHAR (50) NULL,
RequestUrl VARCHAR (500) NOT NULL, RequestUrl VARCHAR (500) NOT NULL,
RequestData VARCHAR (500) NULL RequestData VARCHAR (500) NULL,
UserAgent VARCHAR (2000) NULL
); );
CREATE TABLE Groups( CREATE TABLE Groups(
@ -158,7 +159,8 @@ CREATE TABLE LoginLogs(
OS VARCHAR (50) NULL, OS VARCHAR (50) NULL,
Browser VARCHAR (50) NULL, Browser VARCHAR (50) NULL,
City VARCHAR (50) NULL, City VARCHAR (50) NULL,
Result VARCHAR (50) NOT NULL Result VARCHAR (50) NOT NULL,
UserAgent VARCHAR (2000) NULL
); );
CREATE TABLE ResetUsers( CREATE TABLE ResetUsers(
@ -177,5 +179,6 @@ CREATE TABLE Traces(
Browser VARCHAR (50), Browser VARCHAR (50),
OS VARCHAR (50), OS VARCHAR (50),
City VARCHAR (50), City VARCHAR (50),
RequestUrl VARCHAR (500) NOT NULL RequestUrl VARCHAR (500) NOT NULL,
UserAgent VARCHAR (2000)
); );

Binary file not shown.