1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2024-11-25 16:42:54 +01:00

Compare commits

..

No commits in common. "1ded0e50b2cd527550ae79b21b4cfcaf513193bb" and "2471dc04f12d5465a0ab757552be4cb0d3ff0458" have entirely different histories.

42 changed files with 364 additions and 431 deletions

View File

@ -4,7 +4,7 @@ using System.Diagnostics.CodeAnalysis;
namespace Phantom.Utils.Collections;
public sealed class TableData<TRow, TKey> : IReadOnlyList<TRow>, IReadOnlyDictionary<TKey, TRow> where TRow : notnull where TKey : notnull {
public sealed class Table<TRow, TKey> : IReadOnlyList<TRow>, IReadOnlyDictionary<TKey, TRow> where TRow : notnull where TKey : notnull {
private readonly List<TRow> rowList = new();
private readonly Dictionary<TKey, TRow> rowDictionary = new ();

View File

@ -4,6 +4,6 @@ namespace Phantom.Utils.Runtime;
public static class AssemblyAttributes {
public static string GetFullVersion(Assembly assembly) {
return assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion.Replace('+', '-') ?? string.Empty;
return assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion.Replace('+', '/') ?? string.Empty;
}
}

View File

@ -39,10 +39,8 @@ $dropdown-link-active-bg: mix($gray-200, $gray-300, 75%);
@import "./components";
.spinner-border {
--bs-spinner-width: 1em;
--bs-spinner-height: 1em;
--bs-spinner-border-width: 0.15rem;
.spinner-border-sm {
--bs-spinner-border-width: 0.15em;
}
.progress {

View File

@ -1,9 +1,9 @@
.progress {
height: 4px;
margin: 0.15rem 0;
}
.progress-label {
width: 100%;
margin-bottom: 0.15rem;
font-size: 0.9rem;
}

View File

@ -1,14 +0,0 @@
@using System.Globalization
<p>
<time datetime="@Time.ToString("o", CultureInfo.InvariantCulture)" data-time-type="relative">
@Time.ToString("dd MMM yyyy, HH:mm:ss", CultureInfo.InvariantCulture)
</time>
</p>
<small>@Time.ToString("zzz", CultureInfo.InvariantCulture)</small>
@code {
[Parameter, EditorRequired]
public DateTimeOffset Time { get; set; }
}

View File

@ -13,8 +13,4 @@
<PackageReference Include="Microsoft.AspNetCore.Components.Web" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Phantom.Web.Services\Phantom.Web.Services.csproj" />
</ItemGroup>
</Project>

View File

@ -1,4 +1,4 @@
<th style="@style" class="@Class">
<th style="min-width: @minWidth; width: @preferredWidth;" class="@Class">
@ChildContent
</th>
@ -7,29 +7,32 @@
[Parameter]
public string Class { get; set; } = string.Empty;
[Parameter]
public string? MinWidth { get; set; }
[Parameter]
public string? Width { get; set; }
[Parameter]
public RenderFragment? ChildContent { get; set; }
private string style = string.Empty;
private string minWidth = string.Empty;
private string preferredWidth = string.Empty;
protected override void OnParametersSet() {
List<string> styles = new (2);
if (MinWidth != null) {
styles.Add("min-width: " + MinWidth);
if (string.IsNullOrEmpty(Width)) {
minWidth = string.Empty;
preferredWidth = string.Empty;
return;
}
if (Width != null) {
styles.Add("width: " + Width);
int separator = Width.IndexOf(';');
if (separator == -1) {
minWidth = Width;
preferredWidth = Width;
return;
}
style = string.Join(';', styles);
var span = Width.AsSpan();
minWidth = span[..separator].Trim().ToString();
preferredWidth = span[(separator + 1)..].Trim().ToString();
}
}

View File

@ -1,58 +0,0 @@
@typeparam TItem
<div class="horizontal-scroll">
<table class="table align-middle@(Class.Length == 0 ? "" : " " + Class)">
<thead>
<tr>
@HeaderRow
</tr>
</thead>
@if (Items is null) {
<tbody>
<tr>
<td colspan="1000" class="fw-semibold">
Loading...
</td>
</tr>
</tbody>
}
else if (Items.Count > 0) {
<tbody>
@foreach (var item in Items) {
<tr>
@ItemRow(item)
</tr>
}
</tbody>
}
else if (NoItemsRow != null) {
<tfoot>
<tr>
<td colspan="1000">@NoItemsRow</td>
</tr>
</tfoot>
}
</table>
</div>
@code {
[Parameter]
public string Class { get; set; } = string.Empty;
[Parameter, EditorRequired]
public RenderFragment HeaderRow { get; set; } = null!;
[Parameter, EditorRequired]
public RenderFragment<TItem> ItemRow { get; set; } = null!;
[Parameter]
public RenderFragment? NoItemsRow { get; set; } = null!;
[Parameter, EditorRequired]
public IReadOnlyList<TItem>? Items { get; set; }
}

View File

@ -1,6 +1,5 @@
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Web
@using Phantom.Web.Components
@using Phantom.Web.Components.Forms
@using Phantom.Web.Components.Forms.Base
@using Phantom.Web.Components.Forms.Fields

View File

@ -1,6 +0,0 @@
namespace Phantom.Web.Services;
public sealed record ApplicationProperties(
string Version,
byte[] AdministratorToken
);

View File

@ -9,13 +9,13 @@ namespace Phantom.Web.Services.Authentication;
public sealed class UserLoginManager {
private static readonly ILogger Logger = PhantomLogger.Create<UserLoginManager>();
private readonly Navigation navigation;
private readonly INavigation navigation;
private readonly UserSessionManager sessionManager;
private readonly UserSessionBrowserStorage sessionBrowserStorage;
private readonly CustomAuthenticationStateProvider authenticationStateProvider;
private readonly ControllerConnection controllerConnection;
public UserLoginManager(Navigation navigation, UserSessionManager sessionManager, UserSessionBrowserStorage sessionBrowserStorage, CustomAuthenticationStateProvider authenticationStateProvider, ControllerConnection controllerConnection) {
public UserLoginManager(INavigation navigation, UserSessionManager sessionManager, UserSessionBrowserStorage sessionBrowserStorage, CustomAuthenticationStateProvider authenticationStateProvider, ControllerConnection controllerConnection) {
this.navigation = navigation;
this.sessionManager = sessionManager;
this.sessionBrowserStorage = sessionBrowserStorage;

View File

@ -0,0 +1,9 @@
using System.Diagnostics.CodeAnalysis;
namespace Phantom.Web.Services;
public interface INavigation {
string BasePath { get; }
bool GetQueryParameter(string key, [MaybeNullWhen(false)] out string value);
Task NavigateTo(string url, bool forceLoad = false);
}

View File

@ -1,5 +1,6 @@
@using Phantom.Web.Services
@inject Navigation Navigation
@inject INavigation Nav
@inject NavigationManager NavigationManager
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
@ -11,7 +12,8 @@
<p role="alert">You do not have permission to visit this page.</p>
}
else {
Navigation.NavigateTo("login" + QueryString.Create("return", Navigation.CreateReturnUrl()), forceLoad: true);
var returnUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).TrimEnd('/');
Nav.NavigateTo("login" + QueryString.Create("return", returnUrl), forceLoad: true);
}
</NotAuthorized>
</AuthorizeRouteView>

View File

@ -2,10 +2,11 @@
using System.Web;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Routing;
using Phantom.Web.Services;
namespace Phantom.Web.Services;
namespace Phantom.Web.Base;
public sealed class Navigation {
sealed class Navigation : INavigation {
public static Func<IServiceProvider, Navigation> Create(string basePath) {
return provider => new Navigation(basePath, provider.GetRequiredService<NavigationManager>());
}
@ -27,10 +28,6 @@ public sealed class Navigation {
return value != null;
}
public string CreateReturnUrl() {
return navigationManager.ToBaseRelativePath(navigationManager.Uri).TrimEnd('/');
}
public async Task NavigateTo(string url, bool forceLoad = false) {
var newPath = BasePath + url;

View File

@ -6,7 +6,7 @@ using Phantom.Web.Services.Authorization;
using ILogger = Serilog.ILogger;
using UserInfo = Phantom.Web.Services.Authentication.UserInfo;
namespace Phantom.Web.Components;
namespace Phantom.Web.Base;
public abstract class PhantomComponent : ComponentBase, IDisposable {
private static readonly ILogger Logger = PhantomLogger.Create<PhantomComponent>();

View File

@ -0,0 +1,7 @@
using ILogger = Serilog.ILogger;
namespace Phantom.Web;
sealed record Configuration(ILogger Logger, string Host, ushort Port, string BasePath, string DataProtectionKeyFolderPath, CancellationToken CancellationToken) {
public string HttpUrl => "http://" + Host + ":" + Port;
}

View File

@ -1,15 +1,11 @@
@using Phantom.Web.Services
@using Phantom.Web.Services.Authorization
@using Phantom.Web.Services.Authorization
@using Phantom.Common.Data.Web.Users
@inject ApplicationProperties ApplicationProperties
@inject ServiceConfiguration Configuration
@inject PermissionManager PermissionManager
<div class="navbar navbar-dark">
<div class="container-fluid">
<div class="pt-1 pb-2">
<a class="navbar-brand" href="">Phantom Panel</a>
<small class="navbar-text">Version&nbsp;@ApplicationProperties.Version</small>
</div>
<a class="navbar-brand" href="">Phantom Panel</a>
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
@ -48,6 +44,9 @@
</Authorized>
</AuthorizeView>
</nav>
<footer>
Build @Configuration.Version
</footer>
</div>
@code {

View File

@ -1,7 +1,7 @@
@page
@using Phantom.Web.Services
@model Phantom.Web.Layout.ErrorModel
@inject Navigation Navigation
@inject INavigation Navigation
<!DOCTYPE html>
<html lang="en">

View File

@ -1,7 +1,7 @@
@using Phantom.Web.Services
@namespace Phantom.Web.Layout
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@inject Navigation Navigation
@inject INavigation Navigation
<!DOCTYPE html>
<html lang="en">

View File

@ -2,68 +2,80 @@
@using Phantom.Common.Data.Web.Agent
@using Phantom.Utils.Collections
@using Phantom.Web.Services.Agents
@inherits Phantom.Web.Components.PhantomComponent
@inherits PhantomComponent
@inject AgentManager AgentManager
<h1>Agents</h1>
<Table Items="agentTable">
<HeaderRow>
<Column Width="50%">Name</Column>
<Column Class="text-end" Width="24%" MinWidth="90px">Instances</Column>
<Column Class="text-end" Width="26%" MinWidth="145px">Memory</Column>
<Column>Version</Column>
<Column Class="text-center">Status</Column>
<Column Class="text-end" MinWidth="200px">Last Ping</Column>
</HeaderRow>
<ItemRow Context="agent">
@{
var usedInstances = agent.Stats?.RunningInstanceCount;
var usedMemory = agent.Stats?.RunningInstanceMemory.InMegabytes;
}
<td>
<p class="fw-semibold">@agent.Name</p>
<small class="font-monospace text-uppercase">@agent.Guid.ToString()</small>
</td>
<td class="text-end">
<ProgressBar Value="@(usedInstances ?? 0)" Maximum="@agent.MaxInstances">
@(usedInstances?.ToString() ?? "?") / @agent.MaxInstances.ToString()
</ProgressBar>
</td>
<td class="text-end">
<ProgressBar Value="@(usedMemory ?? 0)" Maximum="@agent.MaxMemory.InMegabytes">
@(usedMemory?.ToString() ?? "?") / @agent.MaxMemory.InMegabytes.ToString() MB
</ProgressBar>
</td>
<td class="text-condensed">
Build: <span class="font-monospace">@agent.BuildVersion</span>
<br>
Protocol: <span class="font-monospace">v@(agent.ProtocolVersion.ToString())</span>
</td>
@if (agent.IsOnline) {
<td class="fw-semibold text-center text-success">Online</td>
<td class="text-end">-</td>
}
else {
<td class="fw-semibold text-center">Offline</td>
<td class="text-end">
@if (agent.LastPing is {} lastPing) {
<TimeWithOffset Time="lastPing" />
<table class="table align-middle">
<thead>
<tr>
<Column Width="200px; 44%">Name</Column>
<Column Width=" 90px; 19%" Class="text-end">Instances</Column>
<Column Width="145px; 21%" Class="text-end">Memory</Column>
<Column Width="180px; 8%">Version</Column>
<Column Width="320px">Identifier</Column>
<Column Width="100px; 8%" Class="text-center">Status</Column>
<Column Width="215px" Class="text-end">Last Ping</Column>
</tr>
</thead>
@if (!agentTable.IsEmpty) {
<tbody>
@foreach (var agent in agentTable) {
var usedInstances = agent.Stats?.RunningInstanceCount;
var usedMemory = agent.Stats?.RunningInstanceMemory.InMegabytes;
<tr>
<td>@agent.Name</td>
<td class="text-end">
<ProgressBar Value="@(usedInstances ?? 0)" Maximum="@agent.MaxInstances">
@(usedInstances?.ToString() ?? "?") / @agent.MaxInstances
</ProgressBar>
</td>
<td class="text-end">
<ProgressBar Value="@(usedMemory ?? 0)" Maximum="@agent.MaxMemory.InMegabytes">
@(usedMemory?.ToString() ?? "?") / @agent.MaxMemory.InMegabytes MB
</ProgressBar>
</td>
<td class="text-condensed">
Build: <code>@agent.BuildVersion</code>
<br>
Protocol: <code>v@(agent.ProtocolVersion)</code>
</td>
<td>
<code class="text-uppercase">@agent.Guid.ToString()</code>
</td>
@if (agent.IsOnline) {
<td class="text-center text-success">Online</td>
<td class="text-end"></td>
}
else {
<td class="text-center text-danger">Offline</td>
@if (agent.LastPing is {} lastPing) {
<td class="text-end">
<time datetime="@lastPing.ToString("o")" data-time-type="relative">@lastPing.ToString()</time>
</td>
}
else {
<td class="text-end">-</td>
}
}
</tr>
}
else {
<text>N/A</text>
}
</td>
}
</ItemRow>
<NoItemsRow>
No agents registered.
</NoItemsRow>
</Table>
</tbody>
}
else {
<tfoot>
<tr>
<td colspan="7">No agents registered.</td>
</tr>
</tfoot>
}
</table>
@code {
private readonly TableData<AgentWithStats, Guid> agentTable = new();
private readonly Table<AgentWithStats, Guid> agentTable = new();
protected override void OnInitialized() {
AgentManager.AgentsChanged.Subscribe(this, agents => {

View File

@ -5,49 +5,55 @@
@using Phantom.Common.Data.Web.Users
@using Phantom.Web.Services.Users
@using Phantom.Web.Services.Instances
@inherits Phantom.Web.Components.PhantomComponent
@inherits PhantomComponent
@inject AuditLogManager AuditLogManager
@inject InstanceManager InstanceManager
@inject UserManager UserManager
<h1>Audit Log</h1>
<Table TItem="AuditLogItem" Items="logItems">
<HeaderRow>
<Column Class="text-end" MinWidth="200px">Time</Column>
<Column>User</Column>
<Column>Event Type</Column>
<Column>Subject</Column>
<Column Width="100%">Data</Column>
</HeaderRow>
<ItemRow Context="logItem">
<td class="text-end">
<TimeWithOffset Time="logItem.UtcTime.ToLocalTime()" />
</td>
<td>
<p class="fw-semibold">@(logItem.UserName ?? "-")</p>
<small class="font-monospace text-uppercase">@logItem.UserGuid.ToString()</small>
</td>
<td>
<p>@logItem.EventType.ToNiceString()</p>
</td>
<td>
<p class="fw-semibold">@(logItem.SubjectId is {} subjectId && GetSubjectName(logItem.SubjectType, subjectId) is {} subjectName ? subjectName : "-")</p>
<small class="font-monospace text-uppercase">@(logItem.SubjectId ?? "-")</small>
</td>
<td>
<code>@logItem.JsonData</code>
</td>
</ItemRow>
<NoItemsRow>
No audit log entries found.
</NoItemsRow>
</Table>
<table class="table">
<thead>
<tr>
<Column Width="165px" Class="text-end">Time</Column>
<Column Width="320px; 20%">User</Column>
<Column Width="160px">Event Type</Column>
<Column Width="320px; 20%">Subject</Column>
<Column Width="100px; 60%">Data</Column>
</tr>
</thead>
<tbody>
@foreach (var logItem in logItems) {
DateTimeOffset time = logItem.UtcTime.ToLocalTime();
<tr>
<td class="text-end">
<time datetime="@time.ToString("o")">@time.ToString()</time>
</td>
<td>
@(logItem.UserName ?? "-")
<br>
<code class="text-uppercase">@logItem.UserGuid</code>
</td>
<td>@logItem.EventType.ToNiceString()</td>
<td>
@if (logItem.SubjectId is {} subjectId && GetSubjectName(logItem.SubjectType, subjectId) is {} subjectName) {
@subjectName
<br>
}
<code class="text-uppercase">@(logItem.SubjectId ?? "-")</code>
</td>
<td>
<code>@logItem.JsonData</code>
</td>
</tr>
}
</tbody>
</table>
@code {
private CancellationTokenSource? initializationCancellationTokenSource;
private ImmutableArray<AuditLogItem>? logItems;
private ImmutableArray<AuditLogItem> logItems = ImmutableArray<AuditLogItem>.Empty;
private ImmutableDictionary<Guid, string>? userNamesByGuid;
private ImmutableDictionary<Guid, string> instanceNamesByGuid = ImmutableDictionary<Guid, string>.Empty;
@ -66,9 +72,9 @@
private string? GetSubjectName(AuditLogSubjectType type, string id) {
return type switch {
AuditLogSubjectType.Instance => instanceNamesByGuid.TryGetValue(Guid.Parse(id), out var name) ? name : null,
AuditLogSubjectType.User => userNamesByGuid != null && userNamesByGuid.TryGetValue(Guid.Parse(id), out var name) ? name : null,
_ => null
AuditLogSubjectType.Instance => instanceNamesByGuid.TryGetValue(Guid.Parse(id), out var name) ? name : null,
AuditLogSubjectType.User => userNamesByGuid != null && userNamesByGuid.TryGetValue(Guid.Parse(id), out var name) ? name : null,
_ => null
};
}

View File

@ -6,52 +6,60 @@
@using Phantom.Web.Services.Agents
@using Phantom.Web.Services.Events
@using Phantom.Web.Services.Instances
@inherits Phantom.Web.Components.PhantomComponent
@inherits PhantomComponent
@inject AgentManager AgentManager
@inject EventLogManager EventLogManager
@inject InstanceManager InstanceManager
<h1>Event Log</h1>
<Table TItem="EventLogItem" Items="logItems">
<HeaderRow>
<Column Class="text-end" MinWidth="200px">Time</Column>
<Column>Agent</Column>
<Column>Event Type</Column>
<Column>Subject</Column>
<Column Width="100%">Data</Column>
</HeaderRow>
<ItemRow Context="logItem">
<td class="text-end">
<TimeWithOffset Time="logItem.UtcTime.ToLocalTime()" />
</td>
<td>
@if (logItem.AgentGuid is {} agentGuid) {
<p class="fw-semibold">@(GetAgentName(agentGuid))</p>
<small class="font-monospace text-uppercase">@agentGuid.ToString()</small>
}
else {
<text>-</text>
}
</td>
<td>@logItem.EventType.ToNiceString()</td>
<td>
<p class="fw-semibold">@(GetSubjectName(logItem.SubjectType, logItem.SubjectId) ?? "-")</p>
<small class="font-monospace text-uppercase">@(logItem.SubjectId)</small>
</td>
<td>
<code>@logItem.JsonData</code>
</td>
</ItemRow>
<NoItemsRow>
No event log entries found.
</NoItemsRow>
</Table>
<table class="table">
<thead>
<tr>
<Column Width="165px" Class="text-end">Time</Column>
<Column Width="320px; 20%">Agent</Column>
<Column Width="160px">Event Type</Column>
<Column Width="320px; 20%">Subject</Column>
<Column Width="100px; 60%">Data</Column>
</tr>
</thead>
<tbody>
@foreach (var logItem in logItems) {
DateTimeOffset time = logItem.UtcTime.ToLocalTime();
<tr>
<td class="text-end">
<time datetime="@time.ToString("o")">@time.ToString()</time>
</td>
<td>
@if (logItem.AgentGuid is {} agentGuid) {
@(GetAgentName(agentGuid))
<br>
<code class="text-uppercase">@agentGuid</code>
}
else {
<text>-</text>
}
</td>
<td>@logItem.EventType.ToNiceString()</td>
<td>
@if (GetSubjectName(logItem.SubjectType, logItem.SubjectId) is {} subjectName) {
@subjectName
<br>
}
<code class="text-uppercase">@logItem.SubjectId</code>
</td>
<td>
<code>@logItem.JsonData</code>
</td>
</tr>
}
</tbody>
</table>
@code {
private CancellationTokenSource? initializationCancellationTokenSource;
private ImmutableArray<EventLogItem>? logItems;
private ImmutableArray<EventLogItem> logItems = ImmutableArray<EventLogItem>.Empty;
private ImmutableDictionary<Guid, string> agentNamesByGuid = ImmutableDictionary<Guid, string>.Empty;
private ImmutableDictionary<Guid, string> instanceNamesByGuid = ImmutableDictionary<Guid, string>.Empty;
@ -74,8 +82,8 @@
private string? GetSubjectName(EventLogSubjectType type, string id) {
return type switch {
EventLogSubjectType.Instance => instanceNamesByGuid.TryGetValue(Guid.Parse(id), out var name) ? name : null,
_ => null
EventLogSubjectType.Instance => instanceNamesByGuid.TryGetValue(Guid.Parse(id), out var name) ? name : null,
_ => null
};
}

View File

@ -6,7 +6,7 @@
@using Phantom.Common.Data.Web.Users
@using Phantom.Web.Services.Instances
@using Phantom.Web.Services.Authorization
@inherits Phantom.Web.Components.PhantomComponent
@inherits PhantomComponent
@inject InstanceManager InstanceManager
@if (Instance == null) {
@ -14,19 +14,14 @@
<p>Return to <a href="instances">all instances</a>.</p>
}
else {
<div class="d-flex flex-row align-items-center gap-3 mb-3">
<h1 class="mb-0">Instance: @Instance.Configuration.InstanceName</h1>
<span class="fs-4 text-muted">//</span>
<div class="mt-2">
<InstanceStatusText Status="Instance.Status" />
</div>
</div>
<h1>Instance: @Instance.Configuration.InstanceName</h1>
<div class="d-flex flex-row align-items-center gap-2">
<PermissionView Permission="Permission.ControlInstances">
<button type="button" class="btn btn-success" @onclick="LaunchInstance" disabled="@(isLaunchingInstance || !Instance.Status.CanLaunch())">Launch</button>
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#stop-instance" disabled="@(!Instance.Status.CanStop())">Stop...</button>
<span><!-- extra spacing --></span>
</PermissionView>
<InstanceStatusText Status="Instance.Status" />
<PermissionView Permission="Permission.CreateInstances">
<a href="instances/@InstanceGuid/edit" class="btn btn-warning ms-auto">Edit Configuration</a>
</PermissionView>

View File

@ -3,7 +3,7 @@
@using Phantom.Common.Data.Instance
@using Phantom.Common.Data.Web.Users
@using Phantom.Web.Services.Instances
@inherits Phantom.Web.Components.PhantomComponent
@inherits PhantomComponent
@inject InstanceManager InstanceManager
@if (InstanceConfiguration == null) {

View File

@ -16,56 +16,66 @@
<a href="instances/create" class="btn btn-primary" role="button">New Instance</a>
</PermissionView>
<Table TItem="Instance" Items="instances">
<HeaderRow>
<Column Width="40%">Agent</Column>
<Column Width="40%">Name</Column>
<Column MinWidth="215px">Status</Column>
<Column Width="20%">Version</Column>
<Column Class="text-center" MinWidth="110px">Server Port</Column>
<Column Class="text-center" MinWidth="110px">Rcon Port</Column>
<Column Class="text-end" MinWidth="90px">Memory</Column>
<Column MinWidth="75px">Actions</Column>
</HeaderRow>
<ItemRow Context="instance">
@{
var configuration = instance.Configuration;
var agentName = agentNamesByGuid.TryGetValue(configuration.AgentGuid, out var name) ? name : string.Empty;
}
<td>
<p class="fw-semibold">@agentName</p>
<small class="font-monospace text-uppercase">@configuration.AgentGuid.ToString()</small>
</td>
<td>
<p class="fw-semibold">@configuration.InstanceName</p>
<small class="font-monospace text-uppercase">@configuration.InstanceGuid.ToString()</small>
</td>
<td>
<InstanceStatusText Status="instance.Status" />
</td>
<td>@configuration.MinecraftServerKind @configuration.MinecraftVersion</td>
<td class="text-center">
<p class="font-monospace">@configuration.ServerPort.ToString()</p>
</td>
<td class="text-center">
<p class="font-monospace">@configuration.RconPort.ToString()</p>
</td>
<td class="text-end">
<p class="font-monospace">@configuration.MemoryAllocation.InMegabytes.ToString() MB</p>
</td>
<td>
<a href="instances/@configuration.InstanceGuid.ToString()" class="btn btn-info btn-sm">Detail</a>
</td>
</ItemRow>
<NoItemsRow>
No instances found.
</NoItemsRow>
</Table>
<table class="table align-middle">
<thead>
<tr>
<Column Width="200px; 28%">Agent</Column>
<Column Width="200px; 28%">Name</Column>
<Column Width="130px; 11%">Version</Column>
<Column Width="110px; 8%" Class="text-center">Server Port</Column>
<Column Width="110px; 8%" Class="text-center">Rcon Port</Column>
<Column Width=" 90px; 8%" Class="text-end">Memory</Column>
<Column Width="320px">Identifier</Column>
<Column Width="200px; 9%">Status</Column>
<Column Width=" 75px">Actions</Column>
</tr>
</thead>
@if (!instances.IsEmpty) {
<tbody>
@foreach (var (configuration, status, _) in instances) {
var agentName = agentNamesByGuid.TryGetValue(configuration.AgentGuid, out var name) ? name : string.Empty;
var instanceGuid = configuration.InstanceGuid.ToString();
<tr>
<td>@agentName</td>
<td>@configuration.InstanceName</td>
<td>@configuration.MinecraftServerKind @configuration.MinecraftVersion</td>
<td class="text-center">
<code>@configuration.ServerPort</code>
</td>
<td class="text-center">
<code>@configuration.RconPort</code>
</td>
<td class="text-end">
<code>@configuration.MemoryAllocation.InMegabytes MB</code>
</td>
<td>
<code class="text-uppercase">@instanceGuid</code>
</td>
<td>
<InstanceStatusText Status="status" />
</td>
<td>
<a href="instances/@instanceGuid" class="btn btn-info btn-sm">Detail</a>
</td>
</tr>
}
</tbody>
}
@if (instances.IsEmpty) {
<tfoot>
<tr>
<td colspan="9">
No instances.
</td>
</tr>
</tfoot>
}
</table>
@code {
private ImmutableDictionary<Guid, string> agentNamesByGuid = ImmutableDictionary<Guid, string>.Empty;
private ImmutableArray<Instance>? instances;
private ImmutableArray<Instance> instances = ImmutableArray<Instance>.Empty;
protected override void OnInitialized() {
AgentManager.AgentsChanged.Subscribe(this, agents => {

View File

@ -3,7 +3,7 @@
@using Phantom.Web.Services.Authentication
@using System.ComponentModel.DataAnnotations
@attribute [AllowAnonymous]
@inject Navigation Navigation
@inject INavigation Navigation
@inject UserLoginManager LoginManager
<h1>Login</h1>

View File

@ -1,6 +1,5 @@
@page "/setup"
@using Phantom.Utils.Tasks
@using Phantom.Web.Services
@using Phantom.Web.Services.Authentication
@using Phantom.Web.Services.Rpc
@using System.ComponentModel.DataAnnotations
@ -10,7 +9,7 @@
@using Phantom.Common.Data.Web.Users
@using Phantom.Common.Data.Web.Users.CreateOrUpdateAdministratorUserResults
@attribute [AllowAnonymous]
@inject ApplicationProperties ApplicationProperties
@inject ServiceConfiguration ServiceConfiguration
@inject UserLoginManager LoginManager
@inject ControllerConnection ControllerConnection
@ -84,7 +83,7 @@
return false;
}
return CryptographicOperations.FixedTimeEquals(formTokenBytes, ApplicationProperties.AdministratorToken);
return CryptographicOperations.FixedTimeEquals(formTokenBytes, ServiceConfiguration.AdministratorToken);
}
private async Task<Result<string>> CreateOrUpdateAdministrator() {

View File

@ -4,7 +4,7 @@
@using Phantom.Common.Data.Web.Users
@using Phantom.Web.Services.Users
@using Phantom.Web.Services.Authorization
@inherits Phantom.Web.Components.PhantomComponent
@inherits PhantomComponent
@inject UserManager UserManager
@inject RoleManager RoleManager
@inject UserRoleManager UserRoleManager
@ -18,36 +18,43 @@
<AuthorizeView>
<Authorized>
@{ var canEdit = PermissionManager.CheckPermission(context.User, Permission.EditUsers); }
<Table TItem="UserInfo" Items="allUsers">
<HeaderRow>
<Column>Username</Column>
<Column Width="100%">Roles</Column>
@if (canEdit) {
<Column MinWidth="175px">Actions</Column>
}
</HeaderRow>
<ItemRow Context="user">
@{ var isMe = me == user.Guid; }
<td>
<p class="fw-semibold">@user.Name</p>
<small class="font-monospace text-uppercase">@user.Guid.ToString()</small>
</td>
<td>
@(userGuidToRoleDescription.TryGetValue(user.Guid, out var roles) ? roles : "?")
</td>
@if (canEdit) {
<td>
@if (!isMe) {
<button class="btn btn-primary btn-sm" @onclick="() => userRolesDialog.Show(user)">Edit Roles</button>
<button class="btn btn-danger btn-sm" @onclick="() => userDeleteDialog.Show(user)">Delete...</button>
<table class="table align-middle">
<thead>
<tr>
<Column Width="320px">Identifier</Column>
<Column Width="125px; 40%">Username</Column>
<Column Width="125px; 60%">Roles</Column>
@if (canEdit) {
<Column Width="175px">Actions</Column>
}
</tr>
</thead>
<tbody>
@foreach (var user in allUsers) {
var isMe = me == user.Guid;
<tr>
<td>
<code class="text-uppercase">@user.Guid</code>
</td>
@if (isMe) {
<td class="fw-semibold">@user.Name</td>
}
</td>
else {
<td>@user.Name</td>
}
<td>@(userGuidToRoleDescription.TryGetValue(user.Guid, out var roles) ? roles : "?")</td>
@if (canEdit) {
<td>
@if (!isMe) {
<button class="btn btn-primary btn-sm" @onclick="() => userRolesDialog.Show(user)">Edit Roles</button>
<button class="btn btn-danger btn-sm" @onclick="() => userDeleteDialog.Show(user)">Delete...</button>
}
</td>
}
</tr>
}
</ItemRow>
<NoItemsRow>
No users found.
</NoItemsRow>
</Table>
</tbody>
</table>
</Authorized>
</AuthorizeView>
@ -60,11 +67,9 @@
@code {
private Guid? me = Guid.Empty;
private ImmutableArray<UserInfo>? allUsers;
private ImmutableArray<UserInfo> allUsers = ImmutableArray<UserInfo>.Empty;
private ImmutableDictionary<Guid, RoleInfo> allRolesByGuid = ImmutableDictionary<Guid, RoleInfo>.Empty;
private readonly Dictionary<Guid, string> userGuidToRoleDescription = new ();
private ImmutableArray<UserInfo> AllUsers => allUsers.GetValueOrDefault(ImmutableArray<UserInfo>.Empty);
private readonly Dictionary<Guid, string> userGuidToRoleDescription = new();
private UserRolesDialog userRolesDialog = null!;
private UserDeleteDialog userDeleteDialog = null!;
@ -76,9 +81,8 @@
allRolesByGuid = (await RoleManager.GetAll(CancellationToken)).ToImmutableDictionary(static role => role.Guid, static role => role);
var allUserGuids = allUsers
.Value
.Select(static user => user.Guid)
.ToImmutableHashSet();
.Select(static user => user.Guid)
.ToImmutableHashSet();
foreach (var (userGuid, roleGuids) in await UserRoleManager.GetUserRoles(allUserGuids, CancellationToken)) {
userGuidToRoleDescription[userGuid] = StringifyRoles(roleGuids);
@ -98,7 +102,7 @@
}
private Task OnUserAdded(UserInfo user) {
allUsers = AllUsers.Add(user);
allUsers = allUsers.Add(user);
return RefreshUserRoles(user);
}
@ -107,7 +111,7 @@
}
private void OnUserDeleted(UserInfo user) {
allUsers = AllUsers.Remove(user);
allUsers = allUsers.Remove(user);
userGuidToRoleDescription.Remove(user.Guid);
}

View File

@ -10,7 +10,6 @@ using Phantom.Utils.Rpc.Sockets;
using Phantom.Utils.Runtime;
using Phantom.Utils.Tasks;
using Phantom.Web;
using Phantom.Web.Services;
using Phantom.Web.Services.Rpc;
var shutdownCancellationTokenSource = new CancellationTokenSource();
@ -49,15 +48,15 @@ try {
var (controllerCertificate, webToken) = webKey.Value;
var administratorToken = TokenGenerator.Create(60);
var applicationProperties = new ApplicationProperties(fullVersion, TokenGenerator.GetBytesOrThrow(administratorToken));
var rpcConfiguration = new RpcConfiguration("Rpc", controllerHost, controllerPort, controllerCertificate);
var rpcSocket = RpcClientSocket.Connect(rpcConfiguration, WebMessageRegistries.Definitions, new RegisterWebMessage(webToken));
var webConfiguration = new WebLauncher.Configuration(PhantomLogger.Create("Web"), webServerHost, webServerPort, webBasePath, dataProtectionKeysPath, shutdownCancellationToken);
var configuration = new Configuration(PhantomLogger.Create("Web"), webServerHost, webServerPort, webBasePath, dataProtectionKeysPath, shutdownCancellationToken);
var administratorToken = TokenGenerator.Create(60);
var taskManager = new TaskManager(PhantomLogger.Create<TaskManager>("Web"));
var webApplication = WebLauncher.CreateApplication(webConfiguration, taskManager, applicationProperties, rpcSocket.Connection);
var serviceConfiguration = new ServiceConfiguration(fullVersion, TokenGenerator.GetBytesOrThrow(administratorToken), shutdownCancellationToken);
var webApplication = WebLauncher.CreateApplication(configuration, taskManager, serviceConfiguration, rpcSocket.Connection);
MessageListener messageListener;
await using (var scope = webApplication.Services.CreateAsyncScope()) {
@ -78,9 +77,9 @@ try {
PhantomLogger.Root.InformationHeading("Launching Phantom Panel web...");
PhantomLogger.Root.Information("Your administrator token is: {AdministratorToken}", administratorToken);
PhantomLogger.Root.Information("For administrator setup, visit: {HttpUrl}{SetupPath}", webConfiguration.HttpUrl, webConfiguration.BasePath + "setup");
PhantomLogger.Root.Information("For administrator setup, visit: {HttpUrl}{SetupPath}", configuration.HttpUrl, configuration.BasePath + "setup");
await WebLauncher.Launch(webConfiguration, webApplication);
await WebLauncher.Launch(configuration, webApplication);
} finally {
shutdownCancellationTokenSource.Cancel();
await taskManager.Stop();

View File

@ -0,0 +1,7 @@
namespace Phantom.Web;
public sealed record ServiceConfiguration(
string Version,
byte[] AdministratorToken,
CancellationToken CancellationToken
);

View File

@ -15,8 +15,8 @@
@using Phantom.Web.Services.Agents
@using Phantom.Web.Services.Instances
@using Phantom.Web.Services.Rpc
@inherits Phantom.Web.Components.PhantomComponent
@inject Navigation Navigation
@inherits PhantomComponent
@inject INavigation Nav
@inject ControllerConnection ControllerConnection
@inject AgentManager AgentManager
@inject InstanceManager InstanceManager
@ -342,7 +342,7 @@
var result = await InstanceManager.CreateOrUpdateInstance(loggedInUserGuid.Value, instance, CancellationToken);
if (result.Is(CreateOrUpdateInstanceResult.Success)) {
await Navigation.NavigateTo("instances/" + instance.InstanceGuid);
await Nav.NavigateTo("instances/" + instance.InstanceGuid);
}
else {
form.SubmitModel.StopSubmitting(result.ToSentence(CreateOrUpdateInstanceResultExtensions.ToSentence));

View File

@ -1,7 +1,7 @@
@using Phantom.Web.Services.Instances
@using Phantom.Common.Data.Web.Users
@using Phantom.Common.Data.Replies
@inherits Phantom.Web.Components.PhantomComponent
@inherits PhantomComponent
@inject InstanceManager InstanceManager
<Form Model="form" OnSubmit="ExecuteCommand">

View File

@ -3,7 +3,7 @@
@using System.Diagnostics
@using Phantom.Web.Services.Instances
@using Phantom.Common.Data.Web.Users
@inherits Phantom.Web.Components.PhantomComponent
@inherits PhantomComponent
@inject IJSRuntime Js;
@inject InstanceLogManager InstanceLogManager;

View File

@ -1,48 +1,46 @@
@using Phantom.Common.Data.Instance
<nobr>
@switch (Status) {
case InstanceIsOffline:
<span class="fw-semibold">Offline</span>
<text>Offline</text>
break;
case InstanceIsInvalid invalid:
<span class="fw-semibold text-danger">Invalid <sup title="@invalid.Reason">[?]</sup></span>
<text>Invalid <sup title="@invalid.Reason">[?]</sup></text>
break;
case InstanceIsNotRunning:
<span class="fw-semibold">Not Running</span>
<text>Not Running</text>
break;
case InstanceIsDownloading downloading:
<ProgressBar Value="@downloading.Progress" Maximum="100">
<span class="fw-semibold">Downloading Server</span> (@downloading.Progress%)
Downloading Server (@downloading.Progress%)
</ProgressBar>
break;
case InstanceIsLaunching:
<div class="spinner-border" role="status"></div>
<span class="fw-semibold">&nbsp;Launching</span>
<div class="spinner-border spinner-border-sm" role="status"></div>
<text>&nbsp;Launching</text>
break;
case InstanceIsRunning:
<span class="fw-semibold text-success">Running</span>
<text>Running</text>
break;
case InstanceIsRestarting:
<div class="spinner-border" role="status"></div>
<span class="fw-semibold">&nbsp;Restarting</span>
<div class="spinner-border spinner-border-sm" role="status"></div>
<text>&nbsp;Restarting</text>
break;
case InstanceIsStopping:
<div class="spinner-border" role="status"></div>
<span class="fw-semibold">&nbsp;Stopping</span>
<div class="spinner-border spinner-border-sm" role="status"></div>
<text>&nbsp;Stopping</text>
break;
case InstanceIsFailed failed:
<span class="fw-semibold text-danger">Failed <sup title="@failed.Reason.ToSentence()">[?]</sup></span>
<text>Failed <sup title="@failed.Reason.ToSentence()">[?]</sup></text>
break;
}
</nobr>
@code {

View File

@ -3,7 +3,7 @@
@using Phantom.Common.Data.Web.Users
@using Phantom.Common.Data.Minecraft
@using Phantom.Common.Data.Replies
@inherits Phantom.Web.Components.PhantomComponent
@inherits PhantomComponent
@inject IJSRuntime Js;
@inject InstanceManager InstanceManager;

View File

@ -2,7 +2,7 @@
@using Phantom.Common.Data.Web.Users.CreateUserResults
@using Phantom.Web.Services.Users
@using System.ComponentModel.DataAnnotations
@inherits Phantom.Web.Components.PhantomComponent
@inherits PhantomComponent
@inject IJSRuntime Js;
@inject UserManager UserManager;

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using Phantom.Common.Data.Web.Users;
using Phantom.Web.Components;
using Phantom.Web.Base;
using Phantom.Web.Components.Forms;
namespace Phantom.Web.Shared;

View File

@ -2,18 +2,14 @@
using Phantom.Common.Messages.Web;
using Phantom.Utils.Rpc.Runtime;
using Phantom.Utils.Tasks;
using Phantom.Web.Base;
using Phantom.Web.Services;
using Serilog;
using ILogger = Serilog.ILogger;
namespace Phantom.Web;
static class WebLauncher {
internal sealed record Configuration(ILogger Logger, string Host, ushort Port, string BasePath, string DataProtectionKeyFolderPath, CancellationToken CancellationToken) {
public string HttpUrl => "http://" + Host + ":" + Port;
}
internal static WebApplication CreateApplication(Configuration config, TaskManager taskManager, ApplicationProperties applicationProperties, RpcConnectionToServer<IMessageToControllerListener> controllerConnection) {
public static WebApplication CreateApplication(Configuration config, TaskManager taskManager, ServiceConfiguration serviceConfiguration, RpcConnectionToServer<IMessageToControllerListener> controllerConnection) {
var assembly = typeof(WebLauncher).Assembly;
var builder = WebApplication.CreateBuilder(new WebApplicationOptions {
ApplicationName = assembly.GetName().Name,
@ -30,12 +26,12 @@ static class WebLauncher {
}
builder.Services.AddSingleton(taskManager);
builder.Services.AddSingleton(applicationProperties);
builder.Services.AddSingleton(serviceConfiguration);
builder.Services.AddSingleton(controllerConnection);
builder.Services.AddPhantomServices();
builder.Services.AddSingleton<IHostLifetime>(new NullLifetime());
builder.Services.AddScoped(Navigation.Create(config.BasePath));
builder.Services.AddScoped<INavigation>(Navigation.Create(config.BasePath));
builder.Services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(config.DataProtectionKeyFolderPath));
@ -45,7 +41,7 @@ static class WebLauncher {
return builder.Build();
}
internal static Task Launch(Configuration config, WebApplication application) {
public static Task Launch(Configuration config, WebApplication application) {
var logger = config.Logger;
application.UseSerilogRequestLogging();

View File

@ -6,7 +6,8 @@
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using Phantom.Web.Components
@using Phantom.Web
@using Phantom.Web.Base
@using Phantom.Web.Components.Dialogs
@using Phantom.Web.Components.Forms
@using Phantom.Web.Components.Graphics

View File

@ -14,8 +14,6 @@
.sidebar {
background-image: linear-gradient(180deg, #0f6477 200px, #1b3d59 1000px);
border-right: 1px solid rgba(2, 39, 47, 0.5);
box-shadow: 0 0 2px #093c47;
}
@media (min-width: 960px) {
@ -28,22 +26,16 @@
flex-direction: column;
position: sticky;
top: 0;
width: 230px;
height: 100vh;
width: 250px;
min-height: 100vh;
}
}
main {
flex: 1;
min-width: 0;
padding: 1.1rem 1.5rem 0;
}
h1 {
font-size: 2rem;
font-weight: 600;
}
h1:focus {
outline: none;
}
@ -59,30 +51,14 @@ code {
.table {
margin-top: 0.5rem;
white-space: nowrap;
}
.table > :not(:first-child) {
border-top: 2px solid #a6a6a6;
}
.table th, .table td {
padding: 0.5rem 1.25rem;
}
.table p {
margin: 0;
}
.table small {
display: block;
font-weight: normal;
font-size: 0.825rem;
color: #666;
}
.table small.font-monospace {
font-size: 0.875rem;
.table > :not(caption) > * > * {
padding: 0.5rem 0.75rem;
}
.form-range {
@ -115,19 +91,9 @@ code {
.text-condensed {
font-size: 0.9rem;
line-height: 1.15rem;
line-height: 1.05rem;
}
.text-condensed code {
font-size: 0.9rem;
}
.horizontal-scroll {
overflow-x: auto;
scrollbar-width: thin;
margin-bottom: 1rem;
}
.horizontal-scroll > .table {
margin-bottom: 0;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long