增加功能:操作日志增加登录主机、客户端浏览器、操作系统等信息 #IS7RI

This commit is contained in:
Argo-MacBookPro 2019-03-04 16:29:35 +08:00
parent 9e1941edf1
commit 5730180fd6
6 changed files with 39 additions and 16 deletions

View File

@ -1,5 +1,6 @@
using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
using Longbow.Web;
using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Mvc;
using System.Net;
@ -27,14 +28,19 @@ namespace Bootstrap.Admin.Controllers.Api
/// <summary>
///
/// </summary>
/// <param name="onlineUserSvr"></param>
/// <param name="value"></param>
/// <returns></returns>
[HttpPost]
public bool Post([FromBody]Log value)
public bool Post([FromServices]IOnlineUsers onlineUserSvr, [FromBody]Log value)
{
value.ClientAgent = Request.Headers["User-Agent"];
value.ClientIp = (HttpContext.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString();
var agent = new UserAgent(Request.Headers["User-Agent"]);
value.Ip = HttpContext.Connection.RemoteIpAddress?.ToString();
value.Browser = $"{agent.Browser.Name} {agent.Browser.Version}";
value.OS = $"{agent.OS.Name} {agent.OS.Version}";
value.City = onlineUserSvr.RetrieveLocaleByIp(value.Ip);
value.UserName = User.Identity.Name;
if (string.IsNullOrEmpty(value.Ip)) value.Ip = IPAddress.IPv6Loopback.ToString();
return LogHelper.Save(value);
}
}

View File

@ -57,7 +57,7 @@ namespace Bootstrap.Admin.Query
data = Order == "asc" ? data.OrderBy(t => t.LogTime) : data.OrderByDescending(t => t.LogTime);
break;
case "ClientIp":
data = Order == "asc" ? data.OrderBy(t => t.ClientIp) : data.OrderByDescending(t => t.ClientIp);
data = Order == "asc" ? data.OrderBy(t => t.Ip) : data.OrderByDescending(t => t.Ip);
break;
case "RequestUrl":
data = Order == "asc" ? data.OrderBy(t => t.RequestUrl) : data.OrderByDescending(t => t.RequestUrl);

View File

@ -10,9 +10,11 @@
{ title: "操作类型", field: "CRUD", sortable: true },
{ title: "用户名称", field: "UserName", sortable: true },
{ title: "操作时间", field: "LogTime", sortable: true },
{ title: "操作IP", field: "ClientIp", sortable: true },
{ title: "Url", field: "RequestUrl", sortable: true },
{ title: "备注", field: "ClientAgent", sortable: false }
{ title: "登录主机", field: "Ip", sortable: true },
{ title: "操作地点", field: "City", sortable: true },
{ title: "浏览器", field: "Browser", sortable: true },
{ title: "操作系统", field: "OS", sortable: true },
{ title: "Url", field: "RequestUrl", sortable: true }
]
});
});

View File

@ -33,12 +33,22 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 获得/设置 客户端IP
/// </summary>
public string ClientIp { get; set; }
public string Ip { get; set; }
/// <summary>
/// 获取/设置 客户端信息
///
/// </summary>
public string ClientAgent { get; set; }
public string City { get; set; }
/// <summary>
///
/// </summary>
public string Browser { get; set; }
/// <summary>
///
/// </summary>
public string OS { get; set; }
/// <summary>
/// 获取/设置 请求网址

View File

@ -1,5 +1,6 @@
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using System;
using Xunit;
namespace Bootstrap.Admin.Api
@ -11,7 +12,7 @@ namespace Bootstrap.Admin.Api
[Fact]
public async void Get_Ok()
{
var log = new Log() { CRUD = "UnitTest", ClientAgent = "UnitTest", ClientIp = "::1", RequestUrl = "~/UnitTest", UserName = "UnitTest" };
var log = new Log() { CRUD = "UnitTest", Browser = "UnitTest", OS = "UnitTest", City = "本地连接", Ip = "::1", RequestUrl = "~/UnitTest", UserName = "UnitTest", LogTime = DateTime.Now };
log.Save(log);
// 菜单 系统菜单 系统使用条件

View File

@ -11,8 +11,10 @@ namespace Bootstrap.DataAccess
var log = new Log()
{
UserName = "UnitTest",
ClientAgent = "UnitTest-Agent",
ClientIp = "::",
Browser = "UnitTest",
City = "本地连接",
OS = "UnitTest",
Ip = "::",
CRUD = "UnitTest",
RequestUrl = "~/Home/Index"
};
@ -25,8 +27,10 @@ namespace Bootstrap.DataAccess
var log = new Log()
{
UserName = "UnitTest",
ClientAgent = "UnitTest-Agent",
ClientIp = "::",
Browser = "UnitTest",
City = "本地连接",
OS = "UnitTest",
Ip = "::",
CRUD = "UnitTest",
RequestUrl = "~/Home/Index"
};