Skip to content

Commit

Permalink
V0.3: HTTPS with LetsEncrypt and ReadMe changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim committed Oct 6, 2024
1 parent fe970e8 commit 50e21b9
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 57 deletions.
32 changes: 31 additions & 1 deletion MinecraftBlazorSuite/Manager/Utils.cs
Original file line number Diff line number Diff line change
@@ -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";

/// <summary>
/// Uses mc-heads.net to get the heads of minecraft skins
/// </summary>
/// <param name="uuid"></param>
/// <param name="username"></param>
/// <param name="userSelection"></param>
/// <param name="size"></param>
/// <returns>URL with selected type</returns>
public static string GetUserSkin(string uuid, string username, SkinSelectionType userSelection, int size)
{
if (string.IsNullOrEmpty(uuid))
Expand All @@ -27,4 +39,22 @@ public static string GetUserSkin(string uuid, string username, SkinSelectionType
_ => $"https://mc-heads.net/avatar/{uuid}/{size}"
};
}

/// <summary>
/// Central method to get settings as a ServerWrapperConfig object
/// </summary>
/// <returns>ServerWrapperConfig</returns>
public static ServerWrapperConfig? ReadFile()
{
if (File.Exists(AppSettingsFile))
{
string settingsFileContent = File.ReadAllText(AppSettingsFile);
ServerWrapperConfig? configObj = JsonConvert.DeserializeObject<ServerWrapperConfig>(settingsFileContent);

return configObj;
}

Environment.Exit(1);
return null;
}
}
6 changes: 6 additions & 0 deletions MinecraftBlazorSuite/MinecraftBlazorSuite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
<Copyright>liebki</Copyright>
<PackageProjectUrl>https://github.com/liebki/MinecraftBlazorSuite</PackageProjectUrl>
<RepositoryUrl>https://github.com/liebki/MinecraftBlazorSuite</RepositoryUrl>
<AssemblyVersion>0.3</AssemblyVersion>
<FileVersion>0.3</FileVersion>
</PropertyGroup>

<ItemGroup>
<Content Include="License.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\README.md">
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="BCrypt.Net-Next.StrongName" Version="4.0.3" />
<PackageReference Include="LettuceEncrypt" Version="1.3.3" />
<PackageReference Include="MudBlazor" Version="7.8.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
5 changes: 3 additions & 2 deletions MinecraftBlazorSuite/MinecraftBlazorSuiteSettings.json
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 10 additions & 1 deletion MinecraftBlazorSuite/Models/ServerWrapperConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MinecraftBlazorSuite.Models;
using Newtonsoft.Json;

namespace MinecraftBlazorSuite.Models;

public class ServerWrapperConfig
{
Expand All @@ -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);
}
}
40 changes: 34 additions & 6 deletions MinecraftBlazorSuite/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
<MinecraftBlazorSuite - Minecraft Server Wrapper>
Copyright (C) <2024> <liebki>
Copyright (C) <2024> <liebki>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
Expand All @@ -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 <https://www.gnu.org/licenses/>.
*/

using System.Net;
using MinecraftBlazorSuite.Manager;
using MinecraftBlazorSuite.Models;
using MinecraftBlazorSuite.Services;
using MudBlazor.Services;

Expand All @@ -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.");

Expand All @@ -46,22 +49,47 @@ public static void Main(string[] args)

builder.Services.AddSingleton<NotificationService>();
builder.Services.AddScoped<SqliteService>();

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();
}
}
26 changes: 5 additions & 21 deletions MinecraftBlazorSuite/Services/SettingsService.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
using MinecraftBlazorSuite.Manager;
using MinecraftBlazorSuite.Models;
using Newtonsoft.Json;

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<ServerWrapperConfig>(settingsFileContent);

return configObj;
}

CreateErrorFile();
Environment.Exit(1);

return null;
}

private static void CreateErrorFile()
{
using FileStream fileStream = new(ErrorFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
Expand Down
8 changes: 7 additions & 1 deletion MinecraftBlazorSuite/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"LettuceEncrypt": {
"AcceptTermsOfService": true,
"DomainNames": [ "yourdomain.com", "www.yourdomain.de" ],
"EmailAddress": "[email protected]"
}
}
}
9 changes: 7 additions & 2 deletions MinecraftBlazorSuite/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
"AllowedHosts": "*",
"LettuceEncrypt": {
"AcceptTermsOfService": true,
"DomainNames": [ "yourdomain.com", "www.yourdomain.de" ],
"EmailAddress": "[email protected]"
}
}
82 changes: 59 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand All @@ -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
Expand All @@ -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": "[email protected]"
}
```
- 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:

Expand All @@ -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

Expand Down

0 comments on commit 50e21b9

Please sign in to comment.