Implemented console. Fixed streaming bugs. Added server command sending. Added reset and router back
This commit is contained in:
20
Moonlight/Core/UI/Components/Partials/Route.razor
Normal file
20
Moonlight/Core/UI/Components/Partials/Route.razor
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
@{
|
||||||
|
var route = "/" + (Router.Route ?? "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (route == Path)
|
||||||
|
{
|
||||||
|
@ChildContent
|
||||||
|
}
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
[CascadingParameter]
|
||||||
|
public SmartRouter Router { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public RenderFragment ChildContent { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public string Path { get; set; }
|
||||||
|
}
|
||||||
12
Moonlight/Core/UI/Components/Partials/SmartRouter.razor
Normal file
12
Moonlight/Core/UI/Components/Partials/SmartRouter.razor
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<CascadingValue TValue="SmartRouter" Value="@this">
|
||||||
|
@ChildContent
|
||||||
|
</CascadingValue>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
[Parameter]
|
||||||
|
public string? Route { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public RenderFragment ChildContent { get; set; }
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Moonlight.Features.Servers.UI.Layouts;
|
using Moonlight.Features.Servers.UI.Layouts;
|
||||||
|
using Moonlight.Features.Servers.UI.UserViews;
|
||||||
using Moonlight.Features.ServiceManagement.Models.Abstractions;
|
using Moonlight.Features.ServiceManagement.Models.Abstractions;
|
||||||
using Console = Moonlight.Features.Servers.UI.UserViews.Console;
|
using Console = Moonlight.Features.Servers.UI.UserViews.Console;
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ public class ServerServiceDefinition : ServiceDefinition
|
|||||||
context.Layout = typeof(UserLayout);
|
context.Layout = typeof(UserLayout);
|
||||||
|
|
||||||
await context.AddPage<Console>("Console", "/console", "bx bx-sm bxs-terminal");
|
await context.AddPage<Console>("Console", "/console", "bx bx-sm bxs-terminal");
|
||||||
|
await context.AddPage<Reset>("Reset", "/reset", "bx bx-sm bx-revision");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task BuildAdminView(ServiceViewContext context)
|
public override Task BuildAdminView(ServiceViewContext context)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Moonlight.Features.Servers.Models.Packets;
|
namespace Moonlight.Features.Servers.Api.Packets;
|
||||||
|
|
||||||
public class ServerOutputMessage
|
public class ServerOutputMessage
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using Moonlight.Features.Servers.Models.Enums;
|
using Moonlight.Features.Servers.Models.Enums;
|
||||||
|
|
||||||
namespace Moonlight.Features.Servers.Models.Packets;
|
namespace Moonlight.Features.Servers.Api.Packets;
|
||||||
|
|
||||||
public class ServerStateUpdate
|
public class ServerStateUpdate
|
||||||
{
|
{
|
||||||
6
Moonlight/Features/Servers/Api/Requests/EnterCommand.cs
Normal file
6
Moonlight/Features/Servers/Api/Requests/EnterCommand.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Moonlight.Features.Servers.Api.Requests;
|
||||||
|
|
||||||
|
public class EnterCommand
|
||||||
|
{
|
||||||
|
public string Command { get; set; }
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using MoonCore.Helpers;
|
using MoonCore.Helpers;
|
||||||
|
using Moonlight.Features.Servers.Api.Packets;
|
||||||
using Moonlight.Features.Servers.Entities;
|
using Moonlight.Features.Servers.Entities;
|
||||||
using Moonlight.Features.Servers.Extensions.Attributes;
|
using Moonlight.Features.Servers.Extensions.Attributes;
|
||||||
using Moonlight.Features.Servers.Models.Packets;
|
|
||||||
using Moonlight.Features.Servers.Services;
|
using Moonlight.Features.Servers.Services;
|
||||||
|
|
||||||
namespace Moonlight.Features.Servers.Http.Controllers;
|
namespace Moonlight.Features.Servers.Http.Controllers;
|
||||||
@@ -82,8 +82,6 @@ public class NodeController : Controller
|
|||||||
{
|
{
|
||||||
lock (meta.ConsoleMessages)
|
lock (meta.ConsoleMessages)
|
||||||
meta.ConsoleMessages.Add(serverOutputMessage.Message);
|
meta.ConsoleMessages.Add(serverOutputMessage.Message);
|
||||||
|
|
||||||
meta.LastChangeTimestamp = DateTime.UtcNow;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await (await ServerService.Meta.Get(serverOutputMessage.Id)).OnConsoleMessage.Invoke(serverOutputMessage
|
await (await ServerService.Meta.Get(serverOutputMessage.Id)).OnConsoleMessage.Invoke(serverOutputMessage
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using MoonCore.Abstractions;
|
using MoonCore.Abstractions;
|
||||||
using MoonCore.Attributes;
|
using MoonCore.Attributes;
|
||||||
using MoonCore.Helpers;
|
using MoonCore.Helpers;
|
||||||
|
using Moonlight.Features.Servers.Api.Requests;
|
||||||
|
|
||||||
using Moonlight.Features.Servers.Entities;
|
using Moonlight.Features.Servers.Entities;
|
||||||
using Moonlight.Features.Servers.Exceptions;
|
using Moonlight.Features.Servers.Exceptions;
|
||||||
using Moonlight.Features.Servers.Helpers;
|
using Moonlight.Features.Servers.Helpers;
|
||||||
@@ -47,6 +46,16 @@ public class ServerService
|
|||||||
await httpClient.Post($"servers/{server.Id}/subscribe");
|
await httpClient.Post($"servers/{server.Id}/subscribe");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task SendCommand(Server server, string command)
|
||||||
|
{
|
||||||
|
using var httpClient = CreateHttpClient(server);
|
||||||
|
|
||||||
|
await httpClient.Post($"servers/{server.Id}/command", new EnterCommand()
|
||||||
|
{
|
||||||
|
Command = command
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private HttpApiClient<NodeException> CreateHttpClient(Server server)
|
private HttpApiClient<NodeException> CreateHttpClient(Server server)
|
||||||
{
|
{
|
||||||
using var scope = ServiceProvider.CreateScope();
|
using var scope = ServiceProvider.CreateScope();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
@inject ClipboardService ClipboardService
|
@inject ClipboardService ClipboardService
|
||||||
@inject ToastService ToastService
|
@inject ToastService ToastService
|
||||||
|
|
||||||
<Xterm @ref="Term" Options="Options" AddonIds="AddonIds" OnFirstRender="OnFirstRender" />
|
<Xterm @ref="Term" Options="Options" OnFirstRender="OnFirstRender" />
|
||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
@@ -25,13 +25,6 @@
|
|||||||
FontFamily = "monospace"
|
FontFamily = "monospace"
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly string[] AddonIds = new[]
|
|
||||||
{
|
|
||||||
"xterm-addon-fit",
|
|
||||||
"xterm-addon-web-links",
|
|
||||||
"xterm-addon-search"
|
|
||||||
};
|
|
||||||
|
|
||||||
private bool HasBeenRendered = false;
|
private bool HasBeenRendered = false;
|
||||||
private readonly List<string> UnRenderedMessageCache = new();
|
private readonly List<string> UnRenderedMessageCache = new();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
@using Moonlight.Features.Servers.Models.Abstractions
|
@using Moonlight.Features.Servers.Models.Abstractions
|
||||||
|
@using Moonlight.Features.Servers.Services
|
||||||
@using Moonlight.Features.Servers.UI.Components
|
@using Moonlight.Features.Servers.UI.Components
|
||||||
|
@using Moonlight.Features.Servers.Entities
|
||||||
|
|
||||||
|
@inject ServerService ServerService
|
||||||
|
|
||||||
@implements IDisposable
|
@implements IDisposable
|
||||||
|
|
||||||
@@ -7,8 +11,8 @@
|
|||||||
<Terminal @ref="Terminal" />
|
<Terminal @ref="Terminal" />
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input class="form-control form-control-transparent text-white" placeholder="Enter command"/>
|
<input @bind="CommandInput" class="form-control form-control-transparent text-white" placeholder="Enter command"/>
|
||||||
<button class="btn btn-secondary rounded-start">Execute</button>
|
<WButton CssClasses="btn btn-secondary rounded-start" Text="Execute" OnClick="SendCommand" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -18,7 +22,11 @@
|
|||||||
[CascadingParameter]
|
[CascadingParameter]
|
||||||
public ServerMeta Meta { get; set; }
|
public ServerMeta Meta { get; set; }
|
||||||
|
|
||||||
|
[CascadingParameter]
|
||||||
|
public Server Server { get; set; }
|
||||||
|
|
||||||
private Terminal Terminal;
|
private Terminal Terminal;
|
||||||
|
private string CommandInput = "";
|
||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
@@ -41,9 +49,18 @@
|
|||||||
await Terminal.WriteLine(message);
|
await Terminal.WriteLine(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task SendCommand()
|
||||||
|
{
|
||||||
|
await ServerService.SendCommand(Server, CommandInput);
|
||||||
|
CommandInput = "";
|
||||||
|
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if(Meta != null)
|
if(Meta != null)
|
||||||
Meta.OnConsoleMessage -= OnConsoleMessage;
|
Meta.OnConsoleMessage -= OnConsoleMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
53
Moonlight/Features/Servers/UI/UserViews/Reset.razor
Normal file
53
Moonlight/Features/Servers/UI/UserViews/Reset.razor
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
@using Moonlight.Features.Servers.Entities
|
||||||
|
@using Moonlight.Features.Servers.Models.Abstractions
|
||||||
|
@using Moonlight.Features.Servers.Models.Enums
|
||||||
|
@using Moonlight.Features.Servers.Services
|
||||||
|
|
||||||
|
@implements IDisposable
|
||||||
|
|
||||||
|
@inject ServerService ServerService
|
||||||
|
|
||||||
|
<div class="card card-body">
|
||||||
|
@if (Meta.State == ServerState.Offline)
|
||||||
|
{
|
||||||
|
<ConfirmButton OnClick="ResetServer" CssClasses="btn btn-danger" Text="Reset server" />
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<button class="btn btn-danger disabled" disabled="">Reset server</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
[CascadingParameter]
|
||||||
|
public Server Server { get; set; }
|
||||||
|
|
||||||
|
[CascadingParameter]
|
||||||
|
public ServerMeta Meta { get; set; }
|
||||||
|
|
||||||
|
protected override Task OnAfterRenderAsync(bool firstRender)
|
||||||
|
{
|
||||||
|
if (firstRender)
|
||||||
|
{
|
||||||
|
Meta.OnStateChanged += OnStateChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ResetServer()
|
||||||
|
{
|
||||||
|
await ServerService.SendPowerAction(Server, PowerAction.Install);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task OnStateChanged()
|
||||||
|
{
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Meta.OnStateChanged -= OnStateChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@
|
|||||||
<Folder Include="Features\Dummy\Services\" />
|
<Folder Include="Features\Dummy\Services\" />
|
||||||
<Folder Include="Features\Dummy\UI\Components\" />
|
<Folder Include="Features\Dummy\UI\Components\" />
|
||||||
<Folder Include="Features\Dummy\UI\Views\" />
|
<Folder Include="Features\Dummy\UI\Views\" />
|
||||||
|
<Folder Include="Features\Servers\Api\Resources\" />
|
||||||
<Folder Include="Features\Servers\Configuration\" />
|
<Folder Include="Features\Servers\Configuration\" />
|
||||||
<Folder Include="Features\Servers\Http\Requests\" />
|
<Folder Include="Features\Servers\Http\Requests\" />
|
||||||
<Folder Include="Features\Servers\Http\Resources\" />
|
<Folder Include="Features\Servers\Http\Resources\" />
|
||||||
@@ -56,7 +57,7 @@
|
|||||||
<PackageReference Include="MoonCoreUI" Version="1.0.1" />
|
<PackageReference Include="MoonCoreUI" Version="1.0.1" />
|
||||||
<PackageReference Include="Otp.NET" Version="1.3.0" />
|
<PackageReference Include="Otp.NET" Version="1.3.0" />
|
||||||
<PackageReference Include="QRCoder" Version="1.4.3" />
|
<PackageReference Include="QRCoder" Version="1.4.3" />
|
||||||
<PackageReference Include="XtermBlazor" Version="1.10.0" />
|
<PackageReference Include="XtermBlazor" Version="1.10.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -60,9 +60,6 @@
|
|||||||
<script src="/js/ckeditor.js"></script>
|
<script src="/js/ckeditor.js"></script>
|
||||||
|
|
||||||
<script src="/_content/XtermBlazor/XtermBlazor.min.js"></script>
|
<script src="/_content/XtermBlazor/XtermBlazor.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/xterm-addon-fit@0.8.0/lib/xterm-addon-fit.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/xterm-addon-web-links@0.9.0/lib/xterm-addon-web-links.min.js"></script>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/xterm-addon-search@0.13.0/lib/xterm-addon-search.min.js"></script>
|
|
||||||
|
|
||||||
@foreach (var theme in themes)
|
@foreach (var theme in themes)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user