mirror of
https://github.com/techgarage-ir/MTWireGuard.git
synced 2025-08-04 10:14:52 +02:00
Upgrade to SerilogUi v3
This commit is contained in:
parent
0f1b5106d8
commit
af5de0a5fd
8 changed files with 36 additions and 101 deletions
|
@ -4,8 +4,9 @@ using MTWireGuard.Application.Mapper;
|
|||
using MTWireGuard.Application.Repositories;
|
||||
using MTWireGuard.Application.Services;
|
||||
using Serilog;
|
||||
using Serilog.Ui.SqliteDataProvider;
|
||||
using Serilog.Ui.Web;
|
||||
using Serilog.Ui.Core.Extensions;
|
||||
using Serilog.Ui.SqliteDataProvider.Extensions;
|
||||
using Serilog.Ui.Web.Extensions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MTWireGuard.Application
|
||||
|
@ -94,7 +95,13 @@ namespace MTWireGuard.Application
|
|||
// Add SerilogUI
|
||||
services.AddSerilogUi(options =>
|
||||
{
|
||||
options.UseSqliteServer($"Data Source={Helper.GetLogPath("logs.db")}", "Logs");
|
||||
options.UseSqliteServer(setupOptions =>
|
||||
{
|
||||
setupOptions.WithConnectionString($"Data Source={Helper.GetLogPath("logs.db")}");
|
||||
setupOptions.WithTable("Logs");
|
||||
});
|
||||
|
||||
options.AddScopedSyncAuthFilter<SerilogUiAuthorizeFilter>();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,29 +13,29 @@
|
|||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="IPAddressRange" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||
<PackageReference Include="Newtonsoft.Json.Schema" Version="4.0.1" />
|
||||
<PackageReference Include="QRCoder" Version="1.6.0" />
|
||||
<PackageReference Include="Serilog" Version="4.0.1" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2" />
|
||||
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
|
||||
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
|
||||
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Seq" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.SQLite" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.UI" Version="2.6.0" />
|
||||
<PackageReference Include="Serilog.UI" Version="3.1.0" />
|
||||
<PackageReference Include="Serilog.UI.SqliteProvider" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MikrotikAPI\MikrotikAPI.csproj" />
|
||||
<ProjectReference Include="..\Serilog.Ui.SqliteProvider\Serilog.Ui.SqliteProvider.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,18 +1,13 @@
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Serilog.Ui.Web.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog.Ui.Core.Interfaces;
|
||||
|
||||
namespace MTWireGuard.Application
|
||||
{
|
||||
public class SerilogUiAuthorizeFilter : IUiAuthorizationFilter
|
||||
public class SerilogUiAuthorizeFilter(IHttpContextAccessor httpContextAccessor) : IUiAuthorizationFilter
|
||||
{
|
||||
public bool Authorize(HttpContext httpContext)
|
||||
public bool Authorize()
|
||||
{
|
||||
return httpContext.User.Identity is { IsAuthenticated: true };
|
||||
return httpContextAccessor.HttpContext?.User.Identity is { IsAuthenticated: true };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MTWireGuard.Application", "
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MikrotikAPI", "MikrotikAPI\MikrotikAPI.csproj", "{357EE40B-AA30-482C-94CF-34854BE24D61}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Ui.SqliteProvider", "Serilog.Ui.SqliteProvider\Serilog.Ui.SqliteProvider.csproj", "{4D0ED34E-E84B-4861-82DC-C2149DCD6E14}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -34,10 +32,6 @@ Global
|
|||
{357EE40B-AA30-482C-94CF-34854BE24D61}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{357EE40B-AA30-482C-94CF-34854BE24D61}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{357EE40B-AA30-482C-94CF-34854BE24D61}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4D0ED34E-E84B-4861-82DC-C2149DCD6E14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4D0ED34E-E84B-4861-82DC-C2149DCD6E14}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4D0ED34E-E84B-4861-82DC-C2149DCD6E14}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4D0ED34E-E84B-4861-82DC-C2149DCD6E14}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -13,22 +13,22 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.5" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.6" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NuGet.Protocol" Version="6.11.0" />
|
||||
<PackageReference Include="Razor.Templating.Core" Version="2.0.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2" />
|
||||
<PackageReference Include="NuGet.Protocol" Version="6.11.1" />
|
||||
<PackageReference Include="Razor.Templating.Core" Version="2.1.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
|
||||
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
|
||||
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Seq" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.SQLite" Version="6.0.0" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.8" />
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using MTWireGuard.Middlewares;
|
||||
using MTWireGuard.Application;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using MTWireGuard.Application.MinimalAPI;
|
||||
using MTWireGuard.Middlewares;
|
||||
using Serilog;
|
||||
using Serilog.Exceptions.Core;
|
||||
using Serilog.Exceptions;
|
||||
using System.Configuration;
|
||||
using Serilog.Ui.Web;
|
||||
using Serilog.Ui.Web.Authorization;
|
||||
using Serilog.Ui.Web.Extensions;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
|
@ -77,15 +71,11 @@ internal class Program
|
|||
|
||||
app.UseSerilogUi(options =>
|
||||
{
|
||||
options.RoutePrefix = "Debug";
|
||||
options.InjectStylesheet("/assets/lib/boxicons/css/boxicons.min.css");
|
||||
options.InjectStylesheet("/assets/css/serilogui.css");
|
||||
options.HideSerilogUiBrand();
|
||||
options.InjectJavascript("/assets/js/serilogui.js");
|
||||
options.Authorization.AuthenticationType = AuthenticationType.Jwt;
|
||||
options.Authorization.Filters =
|
||||
[
|
||||
new SerilogUiAuthorizeFilter()
|
||||
];
|
||||
options.WithRoutePrefix("Debug");
|
||||
options.WithAuthenticationType(Serilog.Ui.Web.Models.AuthenticationType.Custom);
|
||||
options.EnableAuthorizationOnAppRoutes();
|
||||
});
|
||||
|
||||
app.Run();
|
||||
|
|
46
UI/wwwroot/assets/css/serilogui.css
vendored
46
UI/wwwroot/assets/css/serilogui.css
vendored
|
@ -1,46 +0,0 @@
|
|||
#sidebar {
|
||||
background: #343a40;
|
||||
}
|
||||
|
||||
#sidebar .logo {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
#sidebar ul li a {
|
||||
padding: 0;
|
||||
border-radius: .5rem;
|
||||
border-bottom: 3px solid;
|
||||
outline: 0;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
margin: .5rem;
|
||||
}
|
||||
|
||||
#sidebar ul li a span {
|
||||
margin-right: 15px;
|
||||
width: 50px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 40px;
|
||||
font-size: 1.25rem;
|
||||
margin-right: .25rem;
|
||||
}
|
||||
|
||||
#sidebar ul.components li a {
|
||||
--bs-primary: #4582ec;
|
||||
padding: 10px 0;
|
||||
color: var(--bs-primary);
|
||||
background-color: rgba(105,108,255,.16) !important;
|
||||
border-color: var(--bs-primary);
|
||||
}
|
||||
|
||||
#sidebar.active ul.components li a {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
#logTable .log-level {
|
||||
border-radius: 5px;
|
||||
user-select: none;
|
||||
}
|
7
UI/wwwroot/assets/js/serilogui.js
vendored
7
UI/wwwroot/assets/js/serilogui.js
vendored
|
@ -1,6 +1 @@
|
|||
let favicon = document.createElement('link');
|
||||
favicon.href = 'img/favicon.ico';
|
||||
favicon.rel = 'icon';
|
||||
document.getElementsByTagName('head')[0].appendChild(favicon);
|
||||
document.querySelector('#sidebar.active .logo:first-child').innerHTML = 'MW';
|
||||
document.querySelector('#sidebar.active .logo:last-child').innerHTML = 'MTWireguard';
|
||||
document.querySelector('link[rel="icon"').setAttribute('href', '/img/favicon.ico');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue