mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2024-11-25 16:42:54 +01:00
Compare commits
2 Commits
1ce0c4cfa9
...
0a29b6f21e
Author | SHA1 | Date | |
---|---|---|---|
0a29b6f21e | |||
8bee9bc763 |
@ -4,7 +4,7 @@ using Phantom.Controller.Database.Entities;
|
|||||||
|
|
||||||
namespace Phantom.Controller.Services.Users;
|
namespace Phantom.Controller.Services.Users;
|
||||||
|
|
||||||
internal static class UserPasswords {
|
static class UserPasswords {
|
||||||
private static PasswordHasher<UserEntity> Hasher { get; } = new ();
|
private static PasswordHasher<UserEntity> Hasher { get; } = new ();
|
||||||
|
|
||||||
private const int MinimumLength = 16;
|
private const int MinimumLength = 16;
|
||||||
|
@ -17,6 +17,34 @@ public static class Files {
|
|||||||
await stream.WriteAsync(bytes);
|
await stream.WriteAsync(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task ReadExactlyBytesAsync(string path, Memory<byte> bytes) {
|
||||||
|
var options = new FileStreamOptions {
|
||||||
|
Mode = FileMode.Open,
|
||||||
|
Access = FileAccess.Read,
|
||||||
|
Options = FileOptions.Asynchronous,
|
||||||
|
Share = FileShare.Read
|
||||||
|
};
|
||||||
|
|
||||||
|
await using var stream = new FileStream(path, options);
|
||||||
|
|
||||||
|
bool wrongLength = false;
|
||||||
|
|
||||||
|
if (stream.Length == bytes.Length) {
|
||||||
|
try {
|
||||||
|
await stream.ReadExactlyAsync(bytes);
|
||||||
|
} catch (EndOfStreamException) {
|
||||||
|
wrongLength = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wrongLength = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wrongLength) {
|
||||||
|
throw new IOException("Expected file size to be exactly " + bytes.Length + " B, actual size is " + stream.Length + " B.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void RequireMaximumFileSize(string path, long maximumBytes) {
|
public static void RequireMaximumFileSize(string path, long maximumBytes) {
|
||||||
var actualBytes = new FileInfo(path).Length;
|
var actualBytes = new FileInfo(path).Length;
|
||||||
if (actualBytes > maximumBytes) {
|
if (actualBytes > maximumBytes) {
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
using Phantom.Common.Logging;
|
using Phantom.Common.Logging;
|
||||||
using Phantom.Controller.Services.Users;
|
|
||||||
using Phantom.Utils.Cryptography;
|
using Phantom.Utils.Cryptography;
|
||||||
using Phantom.Web.Identity.Interfaces;
|
using Phantom.Web.Identity.Interfaces;
|
||||||
using ILogger = Serilog.ILogger;
|
using ILogger = Serilog.ILogger;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Phantom.Web.Identity.Data;
|
|
||||||
|
|
||||||
namespace Phantom.Web.Identity.Authorization;
|
namespace Phantom.Web.Identity.Authorization;
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using Phantom.Controller.Database.Entities;
|
namespace Phantom.Web.Identity.Interfaces;
|
||||||
|
|
||||||
namespace Phantom.Web.Identity.Interfaces;
|
|
||||||
|
|
||||||
public interface ILoginEvents {
|
public interface ILoginEvents {
|
||||||
void UserLoggedIn(UserEntity user);
|
void UserLoggedIn(UserEntity user);
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using Phantom.Controller.Database.Entities;
|
using Phantom.Web.Identity.Interfaces;
|
||||||
using Phantom.Controller.Services.Audit;
|
|
||||||
using Phantom.Web.Identity.Interfaces;
|
|
||||||
|
|
||||||
namespace Phantom.Web.Base;
|
namespace Phantom.Web.Base;
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components.Authorization;
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
using Phantom.Common.Logging;
|
using Phantom.Common.Logging;
|
||||||
using Phantom.Web.Identity.Authorization;
|
|
||||||
using Phantom.Web.Identity.Data;
|
|
||||||
using ILogger = Serilog.ILogger;
|
using ILogger = Serilog.ILogger;
|
||||||
|
|
||||||
namespace Phantom.Web.Base;
|
namespace Phantom.Web.Base;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using Microsoft.AspNetCore.DataProtection;
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
using Phantom.Controller.Services;
|
|
||||||
using Phantom.Utils.Tasks;
|
using Phantom.Utils.Tasks;
|
||||||
using Phantom.Web.Base;
|
using Phantom.Web.Base;
|
||||||
using Phantom.Web.Identity;
|
using Phantom.Web.Identity;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
@using Phantom.Controller.Services
|
@inject ServiceConfiguration Configuration
|
||||||
@inject ServiceConfiguration Configuration
|
|
||||||
@inject PermissionManager PermissionManager
|
@inject PermissionManager PermissionManager
|
||||||
|
|
||||||
<div class="navbar navbar-dark">
|
<div class="navbar navbar-dark">
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
@page "/agents"
|
@page "/agents"
|
||||||
@using Phantom.Controller.Services.Agents
|
|
||||||
@using Phantom.Utils.Collections
|
@using Phantom.Utils.Collections
|
||||||
@implements IDisposable
|
@implements IDisposable
|
||||||
@inject AgentManager AgentManager
|
@inject AgentManager AgentManager
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
@page "/audit"
|
@page "/audit"
|
||||||
@attribute [Authorize(Permission.ViewAuditPolicy)]
|
@attribute [Authorize(Permission.ViewAuditPolicy)]
|
||||||
@using Phantom.Controller.Services.Audit
|
|
||||||
@using Phantom.Controller.Services.Instances
|
|
||||||
@using Phantom.Controller.Services.Users
|
|
||||||
@using System.Collections.Immutable
|
@using System.Collections.Immutable
|
||||||
@using Phantom.Controller.Database.Enums
|
|
||||||
@implements IDisposable
|
@implements IDisposable
|
||||||
@inject AuditLog AuditLog
|
@inject AuditLog AuditLog
|
||||||
@inject InstanceManager InstanceManager
|
@inject InstanceManager InstanceManager
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
@page "/events"
|
@page "/events"
|
||||||
@attribute [Authorize(Permission.ViewEventsPolicy)]
|
@attribute [Authorize(Permission.ViewEventsPolicy)]
|
||||||
@using System.Collections.Immutable
|
@using System.Collections.Immutable
|
||||||
@using Phantom.Controller.Services.Events
|
|
||||||
@using Phantom.Controller.Services.Instances
|
|
||||||
@using Phantom.Controller.Database.Enums
|
|
||||||
@using Phantom.Controller.Services.Agents
|
|
||||||
@implements IDisposable
|
@implements IDisposable
|
||||||
@inject AgentManager AgentManager
|
@inject AgentManager AgentManager
|
||||||
@inject EventLog EventLog
|
@inject EventLog EventLog
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
@page "/instances/{InstanceGuid:guid}"
|
@page "/instances/{InstanceGuid:guid}"
|
||||||
@attribute [Authorize(Permission.ViewInstancesPolicy)]
|
@attribute [Authorize(Permission.ViewInstancesPolicy)]
|
||||||
@inherits PhantomComponent
|
@inherits PhantomComponent
|
||||||
@using Phantom.Common.Data.Instance
|
|
||||||
@using Phantom.Common.Data.Replies
|
|
||||||
@using Phantom.Controller.Services.Audit
|
|
||||||
@using Phantom.Controller.Services.Instances
|
|
||||||
@implements IDisposable
|
@implements IDisposable
|
||||||
@inject InstanceManager InstanceManager
|
@inject InstanceManager InstanceManager
|
||||||
@inject AuditLog AuditLog
|
@inject AuditLog AuditLog
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
@page "/instances/{InstanceGuid:guid}/edit"
|
@page "/instances/{InstanceGuid:guid}/edit"
|
||||||
@attribute [Authorize(Permission.CreateInstancesPolicy)]
|
@attribute [Authorize(Permission.CreateInstancesPolicy)]
|
||||||
@using Phantom.Common.Data.Instance
|
|
||||||
@using Phantom.Controller.Services.Instances
|
|
||||||
@inherits PhantomComponent
|
@inherits PhantomComponent
|
||||||
@inject InstanceManager InstanceManager
|
@inject InstanceManager InstanceManager
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
@page "/instances"
|
@page "/instances"
|
||||||
@attribute [Authorize(Permission.ViewInstancesPolicy)]
|
@attribute [Authorize(Permission.ViewInstancesPolicy)]
|
||||||
@using System.Collections.Immutable
|
@using System.Collections.Immutable
|
||||||
@using Phantom.Controller.Services.Instances
|
|
||||||
@using Phantom.Controller.Services.Agents
|
|
||||||
@implements IDisposable
|
@implements IDisposable
|
||||||
@inject AgentManager AgentManager
|
@inject AgentManager AgentManager
|
||||||
@inject InstanceManager InstanceManager
|
@inject InstanceManager InstanceManager
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
@page "/setup"
|
@page "/setup"
|
||||||
@using Phantom.Controller.Services.Users
|
|
||||||
@using Phantom.Utils.Cryptography
|
|
||||||
@using Phantom.Utils.Tasks
|
@using Phantom.Utils.Tasks
|
||||||
@using Phantom.Controller.Database.Entities
|
|
||||||
@using Phantom.Controller.Services
|
|
||||||
@using Phantom.Controller.Services.Audit
|
|
||||||
@using Phantom.Web.Identity.Authentication
|
@using Phantom.Web.Identity.Authentication
|
||||||
@using System.ComponentModel.DataAnnotations
|
@using System.ComponentModel.DataAnnotations
|
||||||
|
@using Phantom.Utils.Cryptography
|
||||||
@using System.Security.Cryptography
|
@using System.Security.Cryptography
|
||||||
@attribute [AllowAnonymous]
|
@attribute [AllowAnonymous]
|
||||||
@inject ServiceConfiguration ServiceConfiguration
|
@inject ServiceConfiguration ServiceConfiguration
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
@page "/users"
|
@page "/users"
|
||||||
@using Phantom.Controller.Database.Entities
|
|
||||||
@using Phantom.Controller.Services.Users
|
|
||||||
@using System.Collections.Immutable
|
@using System.Collections.Immutable
|
||||||
@attribute [Authorize(Permission.ViewUsersPolicy)]
|
@attribute [Authorize(Permission.ViewUsersPolicy)]
|
||||||
@inject UserManager UserManager
|
@inject UserManager UserManager
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Phantom.Common.Logging;
|
using Phantom.Common.Logging;
|
||||||
using Phantom.Controller.Services;
|
|
||||||
using Phantom.Utils.Cryptography;
|
using Phantom.Utils.Cryptography;
|
||||||
using Phantom.Utils.IO;
|
using Phantom.Utils.IO;
|
||||||
using Phantom.Utils.Runtime;
|
using Phantom.Utils.Runtime;
|
||||||
@ -30,7 +29,7 @@ try {
|
|||||||
PhantomLogger.Root.InformationHeading("Initializing Phantom Panel web...");
|
PhantomLogger.Root.InformationHeading("Initializing Phantom Panel web...");
|
||||||
PhantomLogger.Root.Information("Web version: {Version}", fullVersion);
|
PhantomLogger.Root.Information("Web version: {Version}", fullVersion);
|
||||||
|
|
||||||
var (webServerHost, webServerPort, webBasePath) = Variables.LoadOrStop();
|
var (controllerHost, controllerPort, webKeyToken, webKeyFilePath, webServerHost, webServerPort, webBasePath) = Variables.LoadOrStop();
|
||||||
|
|
||||||
string webKeysPath = Path.GetFullPath("./keys");
|
string webKeysPath = Path.GetFullPath("./keys");
|
||||||
CreateFolderOrStop(webKeysPath, Chmod.URWX);
|
CreateFolderOrStop(webKeysPath, Chmod.URWX);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
namespace Phantom.Controller.Services;
|
namespace Phantom.Web;
|
||||||
|
|
||||||
public sealed record ServiceConfiguration(
|
public sealed record ServiceConfiguration(
|
||||||
string Version,
|
string Version,
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.JSInterop;
|
using Microsoft.JSInterop;
|
||||||
using Phantom.Controller.Database.Entities;
|
|
||||||
using Phantom.Web.Base;
|
using Phantom.Web.Base;
|
||||||
using Phantom.Web.Components.Forms;
|
using Phantom.Web.Components.Forms;
|
||||||
using Phantom.Web.Identity.Data;
|
|
||||||
|
|
||||||
namespace Phantom.Web.Shared;
|
namespace Phantom.Web.Shared;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user