mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-21 11:08:13 +08:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b64ac0539e | ||
![]() |
541c60b363 | ||
![]() |
824e95f7cb | ||
![]() |
38f7850196 | ||
![]() |
bef9de88e2 |
@@ -0,0 +1,21 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
|
||||
// 此代码版权(除特别声明外的代码)归作者本人Diego所有
|
||||
// 源代码使用协议遵循本仓库的开源协议及附加协议
|
||||
// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
|
||||
// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
|
||||
// 使用文档:https://thingsgateway.cn/
|
||||
// QQ群:605534569
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public sealed class LoginLogAttribute : Attribute
|
||||
{
|
||||
}
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public sealed class LogoutLogAttribute : Attribute
|
||||
{
|
||||
}
|
@@ -28,6 +28,7 @@ public class AuthController : ControllerBase
|
||||
|
||||
[HttpPost("login")]
|
||||
[AllowAnonymous]
|
||||
[LoginLog]
|
||||
public Task<LoginOutput> LoginAsync([FromBody] LoginInput input)
|
||||
{
|
||||
|
||||
@@ -37,6 +38,7 @@ public class AuthController : ControllerBase
|
||||
|
||||
[HttpGet("oauth-login")]
|
||||
[AllowAnonymous]
|
||||
[SuppressRequestAudit]
|
||||
public IActionResult OAuthLogin(string scheme = "Gitee", string returnUrl = "/")
|
||||
{
|
||||
var props = new AuthenticationProperties
|
||||
@@ -50,6 +52,7 @@ public class AuthController : ControllerBase
|
||||
[HttpPost("logout")]
|
||||
[Authorize]
|
||||
[IgnoreRolePermission]
|
||||
[LogoutLog]
|
||||
public Task LogoutAsync()
|
||||
{
|
||||
return _authService.LoginOutAsync();
|
||||
|
@@ -8,6 +8,8 @@
|
||||
// QQ群:605534569
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System.Reflection;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
public class RequestAuditData
|
||||
@@ -94,5 +96,6 @@ public class RequestAuditData
|
||||
/// 验证错误信息
|
||||
/// </summary>
|
||||
public Validation Validation { get; set; }
|
||||
public MethodInfo MethodInfo { get; set; }
|
||||
}
|
||||
|
||||
|
@@ -123,12 +123,12 @@ public class RequestAuditFilter : IAsyncActionFilter, IOrderedFilter
|
||||
var desc = App.CreateLocalizerByType(controllerActionDescriptor.ControllerTypeInfo.AsType())[actionMethod.Name];
|
||||
//获取特性
|
||||
|
||||
|
||||
logData.CateGory = desc.Value;//传操作名称
|
||||
logData.Operation = desc.Value;//传操作名称
|
||||
logData.Client = client;
|
||||
logData.Path = httpContext.Request.Path.Value;//请求地址
|
||||
logData.Method = httpContext.Request.Method;//请求方法
|
||||
logData.MethodInfo = actionMethod;//请求方法
|
||||
|
||||
logData.ControllerName = controllerActionDescriptor.ControllerName;
|
||||
logData.ActionName = controllerActionDescriptor.ActionName;
|
||||
|
@@ -1,15 +1,21 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.OAuth;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
|
||||
using ThingsGateway.Extension;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
/// <summary>
|
||||
@@ -22,6 +28,7 @@ public class AdminOAuthHandler<TOptions>(
|
||||
ISysDictService configService,
|
||||
IOptionsMonitor<TOptions> options,
|
||||
ILoggerFactory logger,
|
||||
IUserAgentService userAgentService,
|
||||
UrlEncoder encoder
|
||||
) : OAuthHandler<TOptions>(options, logger, encoder)
|
||||
where TOptions : AdminOAuthOptions, new()
|
||||
@@ -104,6 +111,48 @@ public class AdminOAuthHandler<TOptions>(
|
||||
App.CacheService.HashAdd(CacheConst.Cache_SysUser, sysUser.Id.ToString(), sysUser);//更新Cache信息
|
||||
}
|
||||
|
||||
|
||||
static AdminOAuthHandler()
|
||||
{
|
||||
Task.Factory.StartNew(Insertable, TaskCreationOptions.LongRunning);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 日志消息队列(线程安全)
|
||||
/// </summary>
|
||||
protected static readonly ConcurrentQueue<SysOperateLog> _operateLogMessageQueue = new();
|
||||
|
||||
/// <summary>
|
||||
/// 创建访问日志
|
||||
/// </summary>
|
||||
private static async Task Insertable()
|
||||
{
|
||||
var db = DbContext.Db.GetConnectionScopeWithAttr<SysOperateLog>().CopyNew();
|
||||
var appLifetime = App.RootServices!.GetService<IHostApplicationLifetime>()!;
|
||||
while (!appLifetime.ApplicationStopping.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = _operateLogMessageQueue.ToListWithDequeue(); // 从日志队列中获取数据
|
||||
if (data.Count > 0)
|
||||
{
|
||||
await db.InsertableWithAttr(data).ExecuteCommandAsync(appLifetime.ApplicationStopping).ConfigureAwait(false);//入库
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NewLife.Log.XTrace.WriteException(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await Task.Delay(3000, appLifetime.ApplicationStopping).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected override async Task<AuthenticationTicket> CreateTicketAsync(
|
||||
ClaimsIdentity identity,
|
||||
AuthenticationProperties properties,
|
||||
@@ -118,9 +167,9 @@ public class AdminOAuthHandler<TOptions>(
|
||||
}
|
||||
var user = await HandleUserInfoAsync(tokens).ConfigureAwait(false);
|
||||
|
||||
var sysUser = await GetLogin().ConfigureAwait(false);
|
||||
await UpdateUser(sysUser).ConfigureAwait(false);
|
||||
identity.AddClaim(new Claim(ClaimConst.VerificatId, sysUser.VerificatId.ToString()));
|
||||
var loginEvent = await GetLogin().ConfigureAwait(false);
|
||||
await UpdateUser(loginEvent).ConfigureAwait(false);
|
||||
identity.AddClaim(new Claim(ClaimConst.VerificatId, loginEvent.VerificatId.ToString()));
|
||||
identity.AddClaim(new Claim(ClaimConst.UserId, RoleConst.SuperAdminId.ToString()));
|
||||
|
||||
identity.AddClaim(new Claim(ClaimConst.SuperAdmin, "true"));
|
||||
@@ -142,6 +191,34 @@ public class AdminOAuthHandler<TOptions>(
|
||||
context.RunClaimActions();
|
||||
await Events.CreatingTicket(context).ConfigureAwait(false);
|
||||
|
||||
var httpContext = context.HttpContext;
|
||||
UserAgent? userAgent = null;
|
||||
var str = httpContext?.Request?.Headers?.UserAgent;
|
||||
if (!string.IsNullOrEmpty(str))
|
||||
{
|
||||
userAgent = userAgentService.Parse(str);
|
||||
}
|
||||
|
||||
var sysOperateLog = new SysOperateLog()
|
||||
{
|
||||
Name = this.Scheme.Name,
|
||||
Category = LogCateGoryEnum.Login,
|
||||
ExeStatus = true,
|
||||
OpIp = httpContext.GetRemoteIpAddressToIPv4(),
|
||||
OpBrowser = userAgent?.Browser,
|
||||
OpOs = userAgent?.Platform,
|
||||
OpTime = DateTime.Now,
|
||||
VerificatId = loginEvent.VerificatId,
|
||||
OpAccount = Options.GetName(user),
|
||||
|
||||
ReqMethod = "OAuth",
|
||||
ReqUrl = string.Empty,
|
||||
ResultJson = string.Empty,
|
||||
ClassName = nameof(AdminOAuthHandler<TOptions>),
|
||||
MethodName = string.Empty,
|
||||
ParamJson = string.Empty,
|
||||
};
|
||||
_operateLogMessageQueue.Enqueue(sysOperateLog);
|
||||
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Authentication.OAuth;
|
||||
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
/// <summary>OAuthOptions 配置类</summary>
|
||||
@@ -9,7 +11,6 @@ public abstract class AdminOAuthOptions : OAuthOptions
|
||||
protected AdminOAuthOptions()
|
||||
{
|
||||
ConfigureClaims();
|
||||
|
||||
this.Events.OnRemoteFailure = context =>
|
||||
{
|
||||
var redirectUri = string.IsNullOrEmpty(HomePath) ? "/" : HomePath;
|
||||
@@ -27,6 +28,12 @@ public abstract class AdminOAuthOptions : OAuthOptions
|
||||
|
||||
}
|
||||
|
||||
public virtual string GetName(JsonElement element)
|
||||
{
|
||||
JsonElement.ObjectEnumerator target = element.EnumerateObject();
|
||||
return target.TryGetValue("name");
|
||||
}
|
||||
|
||||
/// <summary>获得/设置 登陆后首页</summary>
|
||||
public string HomePath { get; set; } = "/";
|
||||
|
||||
|
@@ -3,11 +3,13 @@ using Microsoft.AspNetCore.Authentication.OAuth;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
public class GiteeOAuthOptions : AdminOAuthOptions
|
||||
{
|
||||
|
||||
public GiteeOAuthOptions() : base()
|
||||
{
|
||||
this.SignInScheme = ClaimConst.Scheme;
|
||||
@@ -16,6 +18,8 @@ public class GiteeOAuthOptions : AdminOAuthOptions
|
||||
this.UserInformationEndpoint = "https://gitee.com/api/v5/user";
|
||||
this.HomePath = "/";
|
||||
this.CallbackPath = "/signin-gitee";
|
||||
Scope.Add("user_info");
|
||||
Scope.Add("projects");
|
||||
|
||||
Events.OnCreatingTicket = async context =>
|
||||
{
|
||||
@@ -29,6 +33,13 @@ public class GiteeOAuthOptions : AdminOAuthOptions
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
}
|
||||
|
||||
public override string GetName(JsonElement element)
|
||||
{
|
||||
JsonElement.ObjectEnumerator target = element.EnumerateObject();
|
||||
return target.TryGetValue("name");
|
||||
}
|
||||
|
||||
private static async Task HandlerGiteeStarredUrl(OAuthCreatingTicketContext context, string repoFullName = "ThingsGateway/ThingsGateway")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(context.AccessToken))
|
||||
@@ -53,6 +64,8 @@ public class GiteeOAuthOptions : AdminOAuthOptions
|
||||
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
throw new Exception($"Failed to star repository: {response.StatusCode}, {content}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
protected override void ConfigureClaims()
|
||||
{
|
||||
|
@@ -11,11 +11,13 @@
|
||||
using SqlSugar;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Reflection;
|
||||
|
||||
using ThingsGateway.Extension;
|
||||
using ThingsGateway.FriendlyException;
|
||||
using ThingsGateway.Logging;
|
||||
using ThingsGateway.NewLife.Json.Extension;
|
||||
using ThingsGateway.Razor;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
@@ -51,13 +53,18 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
|
||||
var client = requestAuditData.Client;//获取客户端信息
|
||||
var path = requestAuditData.Path;//获取操作名称
|
||||
var method = requestAuditData.Method;//获取方法
|
||||
var methodInfo = requestAuditData.MethodInfo;
|
||||
var login = methodInfo.GetCustomAttribute(typeof(LoginLogAttribute));
|
||||
var logout = methodInfo.GetCustomAttribute(typeof(LogoutLogAttribute));
|
||||
|
||||
//表示访问日志
|
||||
if (path == "/api/auth/login" || path == "/api/auth/logout")
|
||||
if (login != null || logout != null)
|
||||
{
|
||||
//如果没有异常信息
|
||||
if (requestAuditData.Exception == null)
|
||||
{
|
||||
save = await CreateVisitLog(operation, path, requestAuditData, client, flush).ConfigureAwait(false);//添加到访问日志
|
||||
LogCateGoryEnum logCateGoryEnum = login != null ? LogCateGoryEnum.Login : LogCateGoryEnum.Logout;
|
||||
save = await CreateVisitLog(operation, path, requestAuditData, client, logCateGoryEnum, flush).ConfigureAwait(false);//添加到访问日志
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -151,17 +158,20 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
|
||||
/// <param name="path"></param>
|
||||
/// <param name="requestAuditData">requestAuditData</param>
|
||||
/// <param name="userAgent">客户端信息</param>
|
||||
/// <param name="logCateGoryEnum">logCateGory</param>
|
||||
/// <param name="flush"></param>
|
||||
private async Task<bool> CreateVisitLog(string operation, string path, RequestAuditData requestAuditData, UserAgent userAgent, bool flush)
|
||||
private async Task<bool> CreateVisitLog(string operation, string path, RequestAuditData requestAuditData, UserAgent userAgent, LogCateGoryEnum logCateGoryEnum, bool flush)
|
||||
{
|
||||
long verificatId = 0;//验证Id
|
||||
var opAccount = "";//用户账号
|
||||
if (path == "/api/auth/login")
|
||||
if (logCateGoryEnum == LogCateGoryEnum.Login)
|
||||
{
|
||||
//如果是登录,用户信息就从返回值里拿
|
||||
dynamic userInfo = requestAuditData.ReturnInformation;
|
||||
opAccount = userInfo.Data.Account;//赋值账号
|
||||
verificatId = userInfo.Data.VerificatId;
|
||||
if (requestAuditData.ReturnInformation is UnifyResult<LoginOutput> userInfo)
|
||||
{
|
||||
opAccount = userInfo.Data.Account;//赋值账号
|
||||
verificatId = userInfo.Data.VerificatId;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -173,7 +183,7 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
|
||||
var sysLogVisit = new SysOperateLog
|
||||
{
|
||||
Name = operation,
|
||||
Category = path == "/api/auth/login" ? LogCateGoryEnum.Login : LogCateGoryEnum.Logout,
|
||||
Category = logCateGoryEnum,
|
||||
ExeStatus = true,
|
||||
OpIp = requestAuditData.RemoteIPv4,
|
||||
OpBrowser = userAgent?.Browser,
|
||||
|
12
src/Admin/ThingsGateway.AdminServer/GlobalUsings.cs
Normal file
12
src/Admin/ThingsGateway.AdminServer/GlobalUsings.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// 版权信息
|
||||
// 版权归百小僧及百签科技(广东)有限公司所有。
|
||||
// 所有权利保留。
|
||||
// 官方网站:https://baiqian.com
|
||||
//
|
||||
// 许可证信息
|
||||
// 项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。
|
||||
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
global using ThingsGateway.Admin.Application;
|
@@ -12,11 +12,14 @@
|
||||
|
||||
#pragma warning disable CA2007 // 考虑对等待的任务调用 ConfigureAwait
|
||||
|
||||
using BootstrapBlazor.Components;
|
||||
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
using ThingsGateway.Admin.Razor;
|
||||
using ThingsGateway.Extension;
|
||||
|
||||
namespace ThingsGateway.AdminServer;
|
||||
|
||||
|
@@ -9,6 +9,10 @@
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#pragma warning disable CA2007 // 考虑对等待的任务调用 ConfigureAwait
|
||||
using BootstrapBlazor.Components;
|
||||
|
||||
using Mapster;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Microsoft.Extensions.Localization;
|
||||
@@ -16,6 +20,11 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
using ThingsGateway.DataEncryption;
|
||||
using ThingsGateway.NewLife.Extension;
|
||||
using ThingsGateway.Razor;
|
||||
|
||||
|
||||
namespace ThingsGateway.AdminServer;
|
||||
|
||||
public partial class Login
|
||||
|
@@ -9,6 +9,8 @@
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#pragma warning disable CA2007 // 考虑对等待的任务调用 ConfigureAwait
|
||||
using BootstrapBlazor.Components;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -16,6 +18,7 @@ using Microsoft.Extensions.Options;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
using ThingsGateway.Admin.Razor;
|
||||
using ThingsGateway.Razor;
|
||||
|
||||
namespace ThingsGateway.AdminServer;
|
||||
|
||||
|
@@ -13,6 +13,8 @@ using Microsoft.AspNetCore.ResponseCompression;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
using ThingsGateway.NewLife.Log;
|
||||
|
||||
namespace ThingsGateway.AdminServer;
|
||||
|
||||
public class Program
|
||||
|
@@ -18,12 +18,16 @@ using Microsoft.AspNetCore.StaticFiles;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Unicode;
|
||||
|
||||
using ThingsGateway.Admin.Razor;
|
||||
using ThingsGateway.Extension;
|
||||
using ThingsGateway.NewLife.Caching;
|
||||
|
||||
namespace ThingsGateway.AdminServer;
|
||||
|
||||
|
@@ -39,7 +39,7 @@
|
||||
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
|
||||
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.5.4" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.2" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
|
||||
|
@@ -11,7 +11,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.193" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.195" />
|
||||
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.2.5" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@@ -1,9 +1,9 @@
|
||||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<PluginVersion>10.7.14</PluginVersion>
|
||||
<ProPluginVersion>10.7.14</ProPluginVersion>
|
||||
<AuthenticationVersion>2.2.0</AuthenticationVersion>
|
||||
<PluginVersion>10.7.20</PluginVersion>
|
||||
<ProPluginVersion>10.7.20</ProPluginVersion>
|
||||
<AuthenticationVersion>2.4.0</AuthenticationVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
@@ -10,8 +10,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="9.0.5" />
|
||||
<PackageReference Include="TouchSocket" Version="3.1.5" />
|
||||
<PackageReference Include="TouchSocket.SerialPorts" Version="3.1.5" />
|
||||
<PackageReference Include="TouchSocket" Version="3.1.6" />
|
||||
<PackageReference Include="TouchSocket.SerialPorts" Version="3.1.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@@ -12,6 +12,8 @@ using BootstrapBlazor.Components;
|
||||
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
using System.Text;
|
||||
|
||||
using ThingsGateway.NewLife;
|
||||
using ThingsGateway.NewLife.Threading;
|
||||
using ThingsGateway.Razor;
|
||||
@@ -345,8 +347,9 @@ public abstract class DriverBase : DisposableObject, IDriver
|
||||
|
||||
#region 插件重写
|
||||
|
||||
public virtual bool Authentication()
|
||||
public virtual bool GetAuthentication(out DateTime? expireTime)
|
||||
{
|
||||
expireTime = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -354,8 +357,24 @@ public abstract class DriverBase : DisposableObject, IDriver
|
||||
{
|
||||
if (PluginServiceUtil.IsEducation(GetType()))
|
||||
{
|
||||
ThingsGateway.Authentication.ProAuthentication.TryGetAuthorizeInfo(out var authorizeInfo);
|
||||
return authorizeInfo.Auth ? Localizer["Authorized"] : Localizer["Unauthorized"];
|
||||
StringBuilder stringBuilder = new();
|
||||
var ret = GetAuthentication(out var expireTime);
|
||||
if (ret)
|
||||
{
|
||||
stringBuilder.Append(Localizer["Authorized"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder.Append(Localizer["Unauthorized"]);
|
||||
}
|
||||
|
||||
stringBuilder.Append(" ");
|
||||
if (expireTime.HasValue && (DateTime.Now - expireTime.Value).TotalHours > -72)
|
||||
{
|
||||
stringBuilder.Append(Localizer["ExpireTime", expireTime.Value.ToString("yyyy-MM-dd HH")]);
|
||||
}
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
@@ -43,6 +43,6 @@ namespace ThingsGateway.Gateway.Application
|
||||
Task SetLogAsync(LogLevel? logLevel = null, bool upDataBase = true);
|
||||
Task AfterVariablesChangedAsync(CancellationToken cancellationToken);
|
||||
string GetAuthString();
|
||||
bool Authentication();
|
||||
bool GetAuthentication(out DateTime? expireTime);
|
||||
}
|
||||
}
|
@@ -234,6 +234,7 @@
|
||||
"ThingsGateway.Gateway.Application.DriverBase": {
|
||||
"Authorized": "Authorized",
|
||||
"Unauthorized": "Unauthorized",
|
||||
"ExpireTime": "ExpireTime",
|
||||
"DeviceTaskStart": "Device {0} thread started",
|
||||
"DeviceTaskStartTimeout": "Device {0} thread start timeout {1} s",
|
||||
"DeviceTaskStop": "Device {0} thread stopped",
|
||||
|
@@ -240,6 +240,7 @@
|
||||
"ThingsGateway.Gateway.Application.DriverBase": {
|
||||
"Authorized": "已授权",
|
||||
"Unauthorized": "未授权",
|
||||
"ExpireTime": "过期时间",
|
||||
"DeviceTaskStart": "设备 {0} 线程开始",
|
||||
"DeviceTaskStartTimeout": "设备 {0} 线程启动超时 {1} s",
|
||||
"DeviceTaskStop": "设备 {0} 线程停止",
|
||||
|
@@ -8,9 +8,10 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
|
||||
<PackageReference Include="Rougamo.Fody" Version="5.0.0" />
|
||||
<PackageReference Include="TouchSocket.Dmtp" Version="3.1.5" />
|
||||
<PackageReference Include="TouchSocket.WebApi.Swagger" Version="3.1.5" />
|
||||
<PackageReference Include="TouchSocket.Dmtp" Version="3.1.6" />
|
||||
<PackageReference Include="TouchSocket.WebApi.Swagger" Version="3.1.6" />
|
||||
<PackageReference Include="ThingsGateway.Authentication" Version="$(AuthenticationVersion)" />
|
||||
<!--<ProjectReference Include="..\..\PluginPro\ThingsGateway.Authentication\ThingsGateway.Authentication.csproj" />-->
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
|
@@ -19,7 +19,7 @@
|
||||
<Tag Color="Color.Primary" >PRO</Tag>
|
||||
}
|
||||
<span class="ms-2 text-truncate" title=@Name>@(Name)</span>
|
||||
<span class=@(DeviceRuntime?.Driver?.Authentication()==true?"green--text ms-3":"red--text ms-3")>@(DeviceRuntime?.Driver?.GetAuthString())</span>
|
||||
<span class=@(DeviceRuntime?.Driver?.GetAuthentication(out _)==true?"green--text ms-3":"red--text ms-3")>@(DeviceRuntime?.Driver?.GetAuthString())</span>
|
||||
</span>
|
||||
|
||||
<div style="flex-grow: 1;"></div>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
@@ -19,7 +19,7 @@
|
||||
|
||||
|
||||
|
||||
<PackageReference Include="SqlSugar.TDengineCore" Version="4.18.33" GeneratePathProperty="true">
|
||||
<PackageReference Include="SqlSugar.TDengineCore" Version="4.18.36" GeneratePathProperty="true">
|
||||
<PrivateAssets>contentFiles;compile;build;buildMultitargeting;buildTransitive;analyzers;</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TouchSocket.Dmtp" Version="3.1.5" />
|
||||
<PackageReference Include="TouchSocket.Dmtp" Version="3.1.6" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
16
src/Upgrade/ThingsGateway.UpgradeServer/GlobalUsings.cs
Normal file
16
src/Upgrade/ThingsGateway.UpgradeServer/GlobalUsings.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// 版权信息
|
||||
// 版权归百小僧及百签科技(广东)有限公司所有。
|
||||
// 所有权利保留。
|
||||
// 官方网站:https://baiqian.com
|
||||
//
|
||||
// 许可证信息
|
||||
// 项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。
|
||||
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
global using Mapster;
|
||||
|
||||
global using ThingsGateway.Admin.Application;
|
||||
global using ThingsGateway.Admin.Razor;
|
||||
global using ThingsGateway.Razor;
|
@@ -12,10 +12,14 @@
|
||||
|
||||
#pragma warning disable CA2007 // 考虑对等待的任务调用 ConfigureAwait
|
||||
|
||||
using BootstrapBlazor.Components;
|
||||
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
using ThingsGateway.Extension;
|
||||
|
||||
namespace ThingsGateway.UpgradeServer;
|
||||
|
||||
|
||||
|
@@ -9,6 +9,8 @@
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#pragma warning disable CA2007 // 考虑对等待的任务调用 ConfigureAwait
|
||||
using BootstrapBlazor.Components;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Microsoft.Extensions.Localization;
|
||||
@@ -16,6 +18,10 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
using ThingsGateway.DataEncryption;
|
||||
|
||||
using TouchSocket.Core;
|
||||
|
||||
namespace ThingsGateway.UpgradeServer;
|
||||
|
||||
public partial class Login
|
||||
|
@@ -9,6 +9,8 @@
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#pragma warning disable CA2007 // 考虑对等待的任务调用 ConfigureAwait
|
||||
using BootstrapBlazor.Components;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
@@ -13,6 +13,8 @@ using Microsoft.AspNetCore.ResponseCompression;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
using ThingsGateway.NewLife.Log;
|
||||
|
||||
|
||||
namespace ThingsGateway.UpgradeServer;
|
||||
|
||||
|
@@ -18,11 +18,15 @@ using Microsoft.AspNetCore.StaticFiles;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Unicode;
|
||||
|
||||
using ThingsGateway.Extension;
|
||||
|
||||
namespace ThingsGateway.UpgradeServer;
|
||||
|
||||
[AppStartup(-99999)]
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>10.7.14</Version>
|
||||
<Version>10.7.20</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user