diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index 9d25b0b8..9888019a 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -13,7 +13,7 @@ - + diff --git a/Bootstrap.Admin/BootstrapAdmin.db b/Bootstrap.Admin/BootstrapAdmin.db index c76dddca..852930a0 100644 Binary files a/Bootstrap.Admin/BootstrapAdmin.db and b/Bootstrap.Admin/BootstrapAdmin.db differ diff --git a/Bootstrap.Admin/Controllers/AccountController.cs b/Bootstrap.Admin/Controllers/AccountController.cs index f267a050..bea7827a 100644 --- a/Bootstrap.Admin/Controllers/AccountController.cs +++ b/Bootstrap.Admin/Controllers/AccountController.cs @@ -69,11 +69,12 @@ namespace Bootstrap.Admin.Controllers /// 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.City = ipLocator.Locate(loginUser.Ip); - loginUser.Browser = $"{agent.Browser.Name} {agent.Browser.Version}"; - loginUser.OS = $"{agent.OS.Name} {agent.OS.Version}"; + loginUser.Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}"; + loginUser.OS = $"{agent.OS?.Name} {agent.OS?.Version}"; } /// diff --git a/Bootstrap.Admin/Controllers/Api/LogsController.cs b/Bootstrap.Admin/Controllers/Api/LogsController.cs index d96b8ab2..dc654858 100644 --- a/Bootstrap.Admin/Controllers/Api/LogsController.cs +++ b/Bootstrap.Admin/Controllers/Api/LogsController.cs @@ -35,10 +35,11 @@ namespace Bootstrap.Admin.Controllers.Api [HttpPost] 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.Browser = $"{agent.Browser.Name} {agent.Browser.Version}"; - value.OS = $"{agent.OS.Name} {agent.OS.Version}"; + value.Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}"; + value.OS = $"{agent.OS?.Name} {agent.OS?.Version}"; value.City = ipLocator.Locate(value.Ip); value.UserName = User.Identity.Name; return LogHelper.Save(value); diff --git a/Bootstrap.Admin/Views/Account/Login.cshtml b/Bootstrap.Admin/Views/Account/Login.cshtml index 170de7f6..6829268e 100644 --- a/Bootstrap.Admin/Views/Account/Login.cshtml +++ b/Bootstrap.Admin/Views/Account/Login.cshtml @@ -45,15 +45,8 @@ public string CRUD { get; set; } - /// - /// 获得/设置 请求数据 + /// + /// 获得/设置 请求数据 /// public string RequestData { get; set; } diff --git a/Bootstrap.DataAccess/LoginUser.cs b/Bootstrap.DataAccess/LoginUser.cs index ef1cd124..ae2f4b65 100644 --- a/Bootstrap.DataAccess/LoginUser.cs +++ b/Bootstrap.DataAccess/LoginUser.cs @@ -50,6 +50,11 @@ namespace Bootstrap.DataAccess /// public string Result { get; set; } + /// + /// + /// + public string UserAgent { get; set; } + /// /// /// diff --git a/Bootstrap.DataAccess/Trace.cs b/Bootstrap.DataAccess/Trace.cs index 003197bc..7bd2190a 100644 --- a/Bootstrap.DataAccess/Trace.cs +++ b/Bootstrap.DataAccess/Trace.cs @@ -49,6 +49,11 @@ namespace Bootstrap.DataAccess /// public string RequestUrl { get; set; } + /// + /// + /// + public string UserAgent { get; set; } + /// /// 保存访问历史记录 /// diff --git a/DatabaseScripts/Install.sql b/DatabaseScripts/Install.sql index 14789910..b8399279 100644 --- a/DatabaseScripts/Install.sql +++ b/DatabaseScripts/Install.sql @@ -273,6 +273,7 @@ CREATE TABLE [dbo].[Logs]( [City] [nvarchar](50) NULL, [RequestUrl] [nvarchar](500) NOT NULL, [RequestData] [nvarchar](500) NULL, + [UserAgent] [varchar](2000) NULL, CONSTRAINT [PK_Logs] PRIMARY KEY CLUSTERED ( [ID] ASC @@ -342,7 +343,7 @@ CREATE TABLE [dbo].[Dicts]( [ID] [int] IDENTITY(1,1) NOT NULL, [Category] [nvarchar](50) NOT NULL, [Name] [nvarchar](50) NOT NULL, - [Code] [nvarchar](500) NOT NULL, + [Code] [nvarchar](2000) NOT NULL, [Define] [int] NOT NULL, CONSTRAINT [PK_dbo.Dict] PRIMARY KEY CLUSTERED ( @@ -499,6 +500,7 @@ CREATE TABLE [dbo].[LoginLogs]( [Browser] [varchar](50) NULL, [City] [nvarchar](50) NULL, [Result] [nvarchar](50) NOT NULL, + [UserAgent] [varchar](2000) NULL, CONSTRAINT [PK_LoginLogs] PRIMARY KEY CLUSTERED ( [ID] ASC @@ -556,6 +558,7 @@ CREATE TABLE [dbo].[Traces]( [OS] [varchar](50) NULL, [City] [nvarchar](50) NULL, [RequestUrl] [nvarchar](500) NOT NULL, + [UserAgent] [varchar](2000) NULL, CONSTRAINT [PK_Traces] PRIMARY KEY CLUSTERED ( [ID] ASC diff --git a/DatabaseScripts/MySQL/install.sql b/DatabaseScripts/MySQL/install.sql index 2423ed3d..1ba142f8 100644 --- a/DatabaseScripts/MySQL/install.sql +++ b/DatabaseScripts/MySQL/install.sql @@ -87,7 +87,8 @@ CREATE TABLE Logs( OS VARCHAR (50) NULL, City VARCHAR (50) NULL, RequestUrl VARCHAR (500) NOT NULL, - RequestData VARCHAR (500) NULL + RequestData VARCHAR (500) NULL, + UserAgent VARCHAR (2000) NULL ); CREATE TABLE `Groups`( @@ -113,7 +114,7 @@ CREATE TABLE Dicts( ID INTEGER PRIMARY KEY Auto_increment, Category VARCHAR (50) NOT NULL, Name VARCHAR (50) NOT NULL, - Code VARCHAR (500) NOT NULL, + Code VARCHAR (2000) NOT NULL, Define INT NOT NULL DEFAULT 1 ); @@ -158,7 +159,8 @@ CREATE TABLE LoginLogs( OS VARCHAR (50) NULL, Browser VARCHAR (50) NULL, City VARCHAR (50) NULL, - Result VARCHAR (50) NOT NULL + Result VARCHAR (50) NOT NULL, + UserAgent VARCHAR (2000) NULL ); CREATE TABLE ResetUsers( @@ -177,5 +179,6 @@ CREATE TABLE Traces( Browser VARCHAR (50), OS VARCHAR (50), City VARCHAR (50), - RequestUrl VARCHAR (500) NOT NULL + RequestUrl VARCHAR (500) NOT NULL, + UserAgent VARCHAR (2000) NULL ); \ No newline at end of file diff --git a/DatabaseScripts/Postgresql/install.sql b/DatabaseScripts/Postgresql/install.sql index 34276d44..0a877dad 100644 --- a/DatabaseScripts/Postgresql/install.sql +++ b/DatabaseScripts/Postgresql/install.sql @@ -87,7 +87,8 @@ CREATE TABLE Logs( OS VARCHAR (50) NULL, City VARCHAR (50) NULL, RequestUrl VARCHAR (500) NOT NULL, - RequestData VARCHAR (500) NULL + RequestData VARCHAR (500) NULL, + UserAgent VARCHAR (2000) NULL ); CREATE TABLE Groups( @@ -113,7 +114,7 @@ CREATE TABLE Dicts( ID SERIAL PRIMARY KEY, Category VARCHAR (50) NOT NULL, Name VARCHAR (50) NOT NULL, - Code VARCHAR (500) NOT NULL, + Code VARCHAR (2000) NOT NULL, Define INT NOT NULL DEFAULT 1 ); @@ -158,7 +159,8 @@ CREATE TABLE RejectUsers( OS VARCHAR (50) NULL, Browser VARCHAR (50) NULL, City VARCHAR (50) NULL, - Result VARCHAR (50) NOT NULL + Result VARCHAR (50) NOT NULL, + UserAgent VARCHAR (2000) NULL ); CREATE TABLE ResetUsers( @@ -177,5 +179,6 @@ CREATE TABLE Traces( Browser VARCHAR (50), OS VARCHAR (50), City VARCHAR (50), - RequestUrl VARCHAR (500) NOT NULL + RequestUrl VARCHAR (500) NOT NULL, + UserAgent VARCHAR (2000) NULL ); \ No newline at end of file diff --git a/DatabaseScripts/SQLite/Install.sql b/DatabaseScripts/SQLite/Install.sql index d90a7b21..cc11e308 100644 --- a/DatabaseScripts/SQLite/Install.sql +++ b/DatabaseScripts/SQLite/Install.sql @@ -87,7 +87,8 @@ CREATE TABLE Logs( OS VARCHAR (50) NULL, City VARCHAR (50) NULL, RequestUrl VARCHAR (500) NOT NULL, - RequestData VARCHAR (500) NULL + RequestData VARCHAR (500) NULL, + UserAgent VARCHAR (2000) NULL ); CREATE TABLE Groups( @@ -113,7 +114,7 @@ CREATE TABLE Dicts( ID INTEGER PRIMARY KEY, Category VARCHAR (50) NOT NULL, Name VARCHAR (50) NOT NULL, - Code VARCHAR (500) NOT NULL, + Code VARCHAR (2000) NOT NULL, Define INT NOT NULL DEFAULT (1) ); @@ -158,7 +159,8 @@ CREATE TABLE LoginLogs( OS VARCHAR (50) NULL, Browser VARCHAR (50) NULL, City VARCHAR (50) NULL, - Result VARCHAR (50) NOT NULL + Result VARCHAR (50) NOT NULL, + UserAgent VARCHAR (2000) NULL ); CREATE TABLE ResetUsers( @@ -177,5 +179,6 @@ CREATE TABLE Traces( Browser VARCHAR (50), OS VARCHAR (50), City VARCHAR (50), - RequestUrl VARCHAR (500) NOT NULL + RequestUrl VARCHAR (500) NOT NULL, + UserAgent VARCHAR (2000) ); \ No newline at end of file diff --git a/UnitTest/DB/UnitTest.db b/UnitTest/DB/UnitTest.db index 10e6d098..b259bfe5 100644 Binary files a/UnitTest/DB/UnitTest.db and b/UnitTest/DB/UnitTest.db differ