From 50e21b9d4496bd9280e87381a57553fcba9fc277 Mon Sep 17 00:00:00 2001 From: Kim Date: Sun, 6 Oct 2024 18:37:19 +0200 Subject: [PATCH] V0.3: HTTPS with LetsEncrypt and ReadMe changes --- MinecraftBlazorSuite/Manager/Utils.cs | 32 +++++++- .../MinecraftBlazorSuite.csproj | 6 ++ .../MinecraftBlazorSuiteSettings.json | 5 +- .../Models/ServerWrapperConfig.cs | 11 ++- MinecraftBlazorSuite/Program.cs | 40 +++++++-- .../Services/SettingsService.cs | 26 ++---- .../appsettings.Development.json | 8 +- MinecraftBlazorSuite/appsettings.json | 9 +- README.md | 82 +++++++++++++------ 9 files changed, 162 insertions(+), 57 deletions(-) diff --git a/MinecraftBlazorSuite/Manager/Utils.cs b/MinecraftBlazorSuite/Manager/Utils.cs index 993b56a..81163dc 100644 --- a/MinecraftBlazorSuite/Manager/Utils.cs +++ b/MinecraftBlazorSuite/Manager/Utils.cs @@ -1,9 +1,21 @@ -using MinecraftBlazorSuite.Models.Enums; +using MinecraftBlazorSuite.Models; +using MinecraftBlazorSuite.Models.Enums; +using Newtonsoft.Json; namespace MinecraftBlazorSuite.Manager; public class Utils { + public static string AppSettingsFile { get; } = "MinecraftBlazorSuiteSettings.json"; + + /// + /// Uses mc-heads.net to get the heads of minecraft skins + /// + /// + /// + /// + /// + /// URL with selected type public static string GetUserSkin(string uuid, string username, SkinSelectionType userSelection, int size) { if (string.IsNullOrEmpty(uuid)) @@ -27,4 +39,22 @@ public static string GetUserSkin(string uuid, string username, SkinSelectionType _ => $"https://mc-heads.net/avatar/{uuid}/{size}" }; } + + /// + /// Central method to get settings as a ServerWrapperConfig object + /// + /// ServerWrapperConfig + public static ServerWrapperConfig? ReadFile() + { + if (File.Exists(AppSettingsFile)) + { + string settingsFileContent = File.ReadAllText(AppSettingsFile); + ServerWrapperConfig? configObj = JsonConvert.DeserializeObject(settingsFileContent); + + return configObj; + } + + Environment.Exit(1); + return null; + } } \ No newline at end of file diff --git a/MinecraftBlazorSuite/MinecraftBlazorSuite.csproj b/MinecraftBlazorSuite/MinecraftBlazorSuite.csproj index bce0ff6..7c16060 100644 --- a/MinecraftBlazorSuite/MinecraftBlazorSuite.csproj +++ b/MinecraftBlazorSuite/MinecraftBlazorSuite.csproj @@ -6,7 +6,10 @@ liebki https://github.com/liebki/MinecraftBlazorSuite https://github.com/liebki/MinecraftBlazorSuite + 0.3 + 0.3 + Always @@ -14,10 +17,13 @@ + + + \ No newline at end of file diff --git a/MinecraftBlazorSuite/MinecraftBlazorSuiteSettings.json b/MinecraftBlazorSuite/MinecraftBlazorSuiteSettings.json index a71e7a5..d687fcc 100644 --- a/MinecraftBlazorSuite/MinecraftBlazorSuiteSettings.json +++ b/MinecraftBlazorSuite/MinecraftBlazorSuiteSettings.json @@ -1,6 +1,7 @@ { "MaxConsoleMessages": 100, - "ServerJarPath": "/your/path/to/minecraft/server.jar", + "ServerJarPath": "/path/to/server.jar", "JavaArguments": "-Xms1G -Xmx1G -XX:+UnlockExperimentalVMOptions", - "PanelAccess": "$2a$14$NXRKFP8VW6SF7rCM3rEiQOx1T8Y/pMq9sxLNYgsRrxB7yL6LMt5qC" + "PanelAccess": "$2a$14$NXRKFP8VW6SF7rCM3rEiQOx1T8Y/pMq9sxLNYgsRrxB7yL6LMt5qC", + "UseLetsEncrypt": false } \ No newline at end of file diff --git a/MinecraftBlazorSuite/Models/ServerWrapperConfig.cs b/MinecraftBlazorSuite/Models/ServerWrapperConfig.cs index 16d4e65..401f25f 100644 --- a/MinecraftBlazorSuite/Models/ServerWrapperConfig.cs +++ b/MinecraftBlazorSuite/Models/ServerWrapperConfig.cs @@ -1,4 +1,6 @@ -namespace MinecraftBlazorSuite.Models; +using Newtonsoft.Json; + +namespace MinecraftBlazorSuite.Models; public class ServerWrapperConfig { @@ -9,4 +11,11 @@ public class ServerWrapperConfig public string JavaArguments { get; set; } public string PanelAccess { get; set; } + + public bool UseLetsEncrypt { get; set; } + + public override string ToString() + { + return JsonConvert.SerializeObject(this); + } } \ No newline at end of file diff --git a/MinecraftBlazorSuite/Program.cs b/MinecraftBlazorSuite/Program.cs index bd15e06..ff241fc 100644 --- a/MinecraftBlazorSuite/Program.cs +++ b/MinecraftBlazorSuite/Program.cs @@ -1,6 +1,6 @@ /* - Copyright (C) <2024> + Copyright (C) <2024> This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as @@ -16,7 +16,9 @@ You should have received a copy of the GNU Affero General Public License along with this program (License.txt). If not, see . */ +using System.Net; using MinecraftBlazorSuite.Manager; +using MinecraftBlazorSuite.Models; using MinecraftBlazorSuite.Services; using MudBlazor.Services; @@ -26,6 +28,7 @@ public class Program { public static void Main(string[] args) { + ServerWrapperConfig? config = Utils.ReadFile(); Console.WriteLine( "This software is licensed under the 'GNU AFFERO GENERAL PUBLIC LICENSE' V3.0 all details can be found under License.txt found in the same directory."); @@ -46,22 +49,47 @@ public static void Main(string[] args) builder.Services.AddSingleton(); builder.Services.AddScoped(); + + if (config?.UseLetsEncrypt == true) + { + builder.Services.AddLettuceEncrypt(); + } + + builder.WebHost.UseKestrel(k => + { + if (config?.UseLetsEncrypt == true) + { + IServiceProvider appServices = k.ApplicationServices; + k.Listen(IPAddress.Any, 443, o => o.UseHttps(h => + { + h.UseLettuceEncrypt(appServices); + })); + } + else + { + k.Listen(IPAddress.Any, 5000); + } + }); WebApplication app = builder.Build(); - if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); app.UseHsts(); + app.UseDeveloperExceptionPage(); } - - app.UseHttpsRedirection(); + + if (config?.UseLetsEncrypt == true) + { + app.UseHttpsRedirection(); + } + app.UseStaticFiles(); - app.UseRouting(); + app.MapBlazorHub(); - app.MapFallbackToPage("/_Host"); + app.Run(); } } \ No newline at end of file diff --git a/MinecraftBlazorSuite/Services/SettingsService.cs b/MinecraftBlazorSuite/Services/SettingsService.cs index f958733..961ced3 100644 --- a/MinecraftBlazorSuite/Services/SettingsService.cs +++ b/MinecraftBlazorSuite/Services/SettingsService.cs @@ -1,3 +1,4 @@ +using MinecraftBlazorSuite.Manager; using MinecraftBlazorSuite.Models; using Newtonsoft.Json; @@ -5,40 +6,23 @@ namespace MinecraftBlazorSuite.Services; public class SettingsService { - private const string AppSettingsFile = "MinecraftBlazorSuiteSettings.json"; private const string ErrorFile = "error-no-config-found.txt"; - private const string ErrorFileMessage = $"An error occurred: Configuration '{AppSettingsFile}' file not found!"; - + private static readonly string ErrorFileMessage = $"An error occurred: Configuration '{Utils.AppSettingsFile}' file not found!"; + private ServerWrapperConfig? Settings { get; set; } public void SetSettings(ServerWrapperConfig settings) { string settingsJson = JsonConvert.SerializeObject(settings, Formatting.Indented); - File.WriteAllText(AppSettingsFile, settingsJson); + File.WriteAllText(Utils.AppSettingsFile, settingsJson); } public ServerWrapperConfig? GetSettings() { - Settings = ReadFile(); + Settings = Utils.ReadFile(); return Settings; } - private static ServerWrapperConfig? ReadFile() - { - if (File.Exists(AppSettingsFile)) - { - string settingsFileContent = File.ReadAllText(AppSettingsFile); - ServerWrapperConfig? configObj = JsonConvert.DeserializeObject(settingsFileContent); - - return configObj; - } - - CreateErrorFile(); - Environment.Exit(1); - - return null; - } - private static void CreateErrorFile() { using FileStream fileStream = new(ErrorFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); diff --git a/MinecraftBlazorSuite/appsettings.Development.json b/MinecraftBlazorSuite/appsettings.Development.json index 770d3e9..254b77e 100644 --- a/MinecraftBlazorSuite/appsettings.Development.json +++ b/MinecraftBlazorSuite/appsettings.Development.json @@ -5,5 +5,11 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } + }, + "AllowedHosts": "*", + "LettuceEncrypt": { + "AcceptTermsOfService": true, + "DomainNames": [ "yourdomain.com", "www.yourdomain.de" ], + "EmailAddress": "your-email@server.com" } -} +} \ No newline at end of file diff --git a/MinecraftBlazorSuite/appsettings.json b/MinecraftBlazorSuite/appsettings.json index 10f68b8..8121077 100644 --- a/MinecraftBlazorSuite/appsettings.json +++ b/MinecraftBlazorSuite/appsettings.json @@ -5,5 +5,10 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" -} + "AllowedHosts": "*", + "LettuceEncrypt": { + "AcceptTermsOfService": true, + "DomainNames": [ "yourdomain.com", "www.yourdomain.de" ], + "EmailAddress": "your-email@server.com" + } +} \ No newline at end of file diff --git a/README.md b/README.md index 0ef283e..5ca7c5f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This is a simple web-based dashboard, created to make administration of a Minecr - **Customizable Display:** Limit the number of console messages displayed on the console page. -- **Server Control:** Quick-controls for things like time, status, weather etc. +- **Server Control:** Quick-controls for things like time, status, weather, etc. - **Server Environment Compatibility:** Please note that some functions depend on specific server environments and Minecraft versions like Forge, CraftBukkit, etc. @@ -32,11 +32,11 @@ For more information about forks, environments, and versions see here: [spigotmc - **Actions:** Perform actions such as sending messages, changing player gamemodes, killing, kicking, banning, and granting or removing operator rights. -- **Version Compatibility:** Some actions depend on the Minecraft server version (s +- **Version Compatibility:** Some actions depend on the Minecraft server version (s) ### Management -- **Customize Settings:** Configure application settings through the 'BlazorMinecraftServerSettings.json' file. (Dashboard WIP) +- **Customize Settings:** Configure application settings through the 'BlazorMinecraftServerSettings.json' file. - **Adjust Visibility:** Customize the maximum number of visible console messages. @@ -48,6 +48,12 @@ For more information about forks, environments, and versions see here: [spigotmc - **Recommended Version:** Only versions 1.17 or higher are really "supported" due to specific needed message formats. +### HTTPS/HTTP Configuration + +- **Secure Connection:** The application supports HTTPS for secure connections using Let's Encrypt. For users who wish to enable HTTPS, configuration is required in the `appsettings.json` and `BlazorMinecraftServerSettings.json` files. + +- **Port Usage:** When HTTPS is enabled, the server listens on port 443. If HTTPS is not enabled, the server defaults to HTTP on port 5000. It is recommended to use HTTPS for better security and user trust. + ## Installation and Usage ### Prerequisites @@ -74,13 +80,35 @@ Follow these steps to install and use Blazor Minecraft Server Manager: 1. **Download:** Download the latest release from the [Releases](https://github.com/liebki/MinecraftBlazorSuite/releases) section of the repository. -2. **Configuration:** Customize the settings by editing the 'BlazorMinecraftServerSettings.json' file. This includes specifying the server jar file path and Java cmd arguments. - -3. **Launch:** Run the application and therefore the Minecraft server, using .NET Core `dotnet [MinecraftBlazorSuite.dll/MinecraftBlazorSuite.exe]` - -4. **Access:** Open your web browser and access the web interface by entering the appropriate URL. - -- **The url should be http://server-ip:5000** +2. **Configuration:** + - **BlazorMinecraftServerSettings.json:** Customize the Minecraft server settings, such as the server jar file path and Java command arguments. + - **Enabling HTTPS and a Domain Name with Let's Encrypt:** + If you want to use HTTPS with a custom domain and automatically generate SSL certificates using Let's Encrypt, you'll need to update the following configuration files: + + - In the `appsettings.json` file, under the `LettuceEncrypt` section, provide the necessary details for the certificate generation: + ```json + "LettuceEncrypt": { + "AcceptTermsOfService": true, + "DomainNames": [ "yourdomain.com", "www.yourdomain.de" ], + "EmailAddress": "your-email@server.com" + } + ``` + - Replace the `DomainNames` with your actual domain and subdomain (if applicable). + - Provide a valid email address in the `EmailAddress` field. This is required for Let's Encrypt to contact you regarding certificate expiration and updates. + + - In the `BlazorMinecraftServerSettings.json` file, set the option `"UseLetsEncrypt"` to `true`: + ```json + "UseLetsEncrypt": true + ``` + - When `"UseLetsEncrypt": true`, the server will automatically use HTTPS on port 443. If this option is set to `false`, the server will use HTTP on port 5000 by default. + +3. **Launch:** Run the application along with the Minecraft server using .NET Core: `dotnet [MinecraftBlazorSuite.dll/MinecraftBlazorSuite.exe]` + +4. **Access:** +- If HTTPS is enabled and configured with Let's Encrypt, open your web browser and access the web interface by entering the following URL: + - `https://yourdomain.com` +- If HTTPS is not enabled, the web interface will be accessible at: + - `http://server-ip:5000` ### Version limitations: @@ -93,27 +121,35 @@ Please be aware that this is work in progress, and there are some issues: - **Using older Versions than 1.17:** - You can use theoretically any version, most features will just not work as expected or at all because the messages can't be parsed but the console for example should work at least. - ### Troubleshooting If you encounter any issues during installation or usage, refer to the following troubleshooting tips [or create an issue](https://github.com/liebki/MinecraftBlazorSuite/issues): -- **Q: The MinecraftBlazorSuite console says something like "Error: Unable to access jarfile x.... .jar"** - - A: Make sure the path in the settings file is correct, it sounds like it is not! +- **Q: The MinecraftBlazorSuite console says something like "Error: Unable to access jarfile x.... .jar"** + **A:** Make sure the path in the settings file is correct. It sounds like the specified path does not point to the actual JAR file. + + +- **Q: How do I start the server after I started the interface?** + **A:** Simply log in and visit the console page at `/console`. The server should start after a few seconds. If it doesn’t, verify that the location of the server JAR file is correct. + + +- **Q: The MinecraftBlazorSuite console says something like "File/Process is locked x...."** + **A:** This usually indicates that another server instance is already running. Try closing all running server instances or restart your entire system to resolve this more quickly. + + +- **Q: How do I log in to the panel?** + **A:** The default password to log in is '12345678'. Please change it after your first login! Note that sessions are only valid for about three hours; if you try to access the panel after this period, you will need to log in again. Multiple users can access the interface simultaneously, but there are no checks in place for concurrent logins. + -- **Q: How do I start the server after I started the interface?** - - A: Simply login and visit the console page under /console and the server should start after a few seconds, if not verify that the location of the server-jar is correct etc. +- **Q: After logging in, I can't open the /console page; I get a red bar at the bottom which says "an error occurred."** + **A:** This issue likely arises because the server JAR file is not set correctly, or the file is incompatible with the server. Please ensure the path to the JAR file is correct before reporting the problem. -- **Q: The MinecraftBlazorSuite console says something like "File/Process is locked x...."** - - A: This sounds like another server is already running, try closing all servers or better just restart the whole system to solve this faster. -- **Q: How to log in the panel?** - - A: The password to login is '12345678', please change it after logging in! - - Also a "Session" is only valid for about three hours, so entering the page after the initial login three hours ago, you have to login again. - - Multiple people *could* be online in the interface but there aren't any checks. +- **Q: What do I need to do to use Let's Encrypt with my domain name?** + **A:** To use Let's Encrypt for SSL certification with your domain name, ensure that your domain is correctly configured to point to the server where the application is running. + This is essential for Let's Encrypt to verify ownership of the domain. You can typically do this by setting an A record in your domain's DNS settings that directs the domain to your server's IP address. + Once the domain points to your server, the application will be able to request and validate the SSL certificate. [Getting Started with Let's Encrypt](https://letsencrypt.org/getting-started/). -- **Q: After login I can't open the /console page, I get a red bar at the bottom which says "an error occured"..** - - A: This propably comes up because the server jar file is not set or the file is not a server or another problem relating to it, please be sure that is correct before reporting a problem. ## Screenshots / Videos