Switched to new config system

This commit is contained in:
Marcel Baumgartner
2023-07-02 02:16:44 +02:00
parent 678da30b09
commit 609cf8cfac
39 changed files with 399 additions and 343 deletions

View File

@@ -0,0 +1,226 @@
namespace Moonlight.App.Configuration;
using System;
using Newtonsoft.Json;
public class ConfigV1
{
[JsonProperty("Moonlight")] public MoonlightData Moonlight { get; set; } = new();
public class MoonlightData
{
[JsonProperty("AppUrl")] public string AppUrl { get; set; } = "http://your-moonlight-url-without-slash";
[JsonProperty("Database")] public DatabaseData Database { get; set; } = new();
[JsonProperty("DiscordBotApi")] public DiscordBotData DiscordBotApi { get; set; } = new();
[JsonProperty("DiscordBot")] public DiscordBotData DiscordBot { get; set; } = new();
[JsonProperty("Domains")] public DomainsData Domains { get; set; } = new();
[JsonProperty("Html")] public HtmlData Html { get; set; } = new();
[JsonProperty("Marketing")] public MarketingData Marketing { get; set; } = new();
[JsonProperty("OAuth2")] public OAuth2Data OAuth2 { get; set; } = new();
[JsonProperty("Security")] public SecurityData Security { get; set; } = new();
[JsonProperty("Mail")] public MailData Mail { get; set; } = new();
[JsonProperty("Cleanup")] public CleanupData Cleanup { get; set; } = new();
[JsonProperty("Subscriptions")] public SubscriptionsData Subscriptions { get; set; } = new();
[JsonProperty("DiscordNotifications")]
public DiscordNotificationsData DiscordNotifications { get; set; } = new();
[JsonProperty("Statistics")] public StatisticsData Statistics { get; set; } = new();
[JsonProperty("Rating")] public RatingData Rating { get; set; } = new();
[JsonProperty("SmartDeploy")] public SmartDeployData SmartDeploy { get; set; } = new();
[JsonProperty("Sentry")] public SentryData Sentry { get; set; } = new();
}
public class CleanupData
{
[JsonProperty("Cpu")] public long Cpu { get; set; } = 90;
[JsonProperty("Memory")] public long Memory { get; set; } = 8192;
[JsonProperty("Wait")] public long Wait { get; set; } = 15;
[JsonProperty("Uptime")] public long Uptime { get; set; } = 6;
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
[JsonProperty("MinUptime")] public long MinUptime { get; set; } = 10;
}
public class DatabaseData
{
[JsonProperty("Database")] public string Database { get; set; } = "moonlight_db";
[JsonProperty("Host")] public string Host { get; set; } = "your.database.host";
[JsonProperty("Password")] public string Password { get; set; } = "secret";
[JsonProperty("Port")] public long Port { get; set; } = 3306;
[JsonProperty("Username")] public string Username { get; set; } = "moonlight_user";
}
public class DiscordBotData
{
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
[JsonProperty("Token")] public string Token { get; set; } = "discord token here";
[JsonProperty("PowerActions")] public bool PowerActions { get; set; } = false;
[JsonProperty("SendCommands")] public bool SendCommands { get; set; } = false;
}
public class DiscordNotificationsData
{
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
[JsonProperty("WebHook")] public string WebHook { get; set; } = "http://your-discord-webhook-url";
}
public class DomainsData
{
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
[JsonProperty("AccountId")] public string AccountId { get; set; } = "cloudflare acc id";
[JsonProperty("Email")] public string Email { get; set; } = "cloudflare@acc.email";
[JsonProperty("Key")] public string Key { get; set; } = "secret";
}
public class HtmlData
{
[JsonProperty("Headers")] public HeadersData Headers { get; set; } = new();
}
public class HeadersData
{
[JsonProperty("Color")] public string Color { get; set; } = "#4b27e8";
[JsonProperty("Description")] public string Description { get; set; } = "the next generation hosting panel";
[JsonProperty("Keywords")] public string Keywords { get; set; } = "moonlight";
[JsonProperty("Title")] public string Title { get; set; } = "Moonlight - endelon.link";
}
public class MailData
{
[JsonProperty("Email")] public string Email { get; set; } = "username@your.mail.host";
[JsonProperty("Server")] public string Server { get; set; } = "your.mail.host";
[JsonProperty("Password")] public string Password { get; set; } = "secret";
[JsonProperty("Port")] public int Port { get; set; } = 465;
[JsonProperty("Ssl")] public bool Ssl { get; set; } = true;
}
public class MarketingData
{
[JsonProperty("BrandName")] public string BrandName { get; set; } = "Endelon Hosting";
[JsonProperty("Imprint")] public string Imprint { get; set; } = "https://your-site.xyz/imprint";
[JsonProperty("Privacy")] public string Privacy { get; set; } = "https://your-site.xyz/privacy";
[JsonProperty("About")] public string About { get; set; } = "https://your-site.xyz/about";
[JsonProperty("Website")] public string Website { get; set; } = "https://your-site.xyz";
}
public class OAuth2Data
{
[JsonProperty("OverrideUrl")] public string OverrideUrl { get; set; } = "https://only-for-development.cases";
[JsonProperty("EnableOverrideUrl")] public bool EnableOverrideUrl { get; set; } = false;
[JsonProperty("Providers")]
public OAuth2ProviderData[] Providers { get; set; } = Array.Empty<OAuth2ProviderData>();
}
public class OAuth2ProviderData
{
[JsonProperty("Id")] public string Id { get; set; }
[JsonProperty("ClientId")] public string ClientId { get; set; }
[JsonProperty("ClientSecret")] public string ClientSecret { get; set; }
}
public class RatingData
{
[JsonProperty("Enabled")] public bool Enabled { get; set; } = false;
[JsonProperty("Url")] public string Url { get; set; } = "https://link-to-google-or-smth";
[JsonProperty("MinRating")] public int MinRating { get; set; } = 4;
[JsonProperty("DaysSince")] public int DaysSince { get; set; } = 5;
}
public class SecurityData
{
[JsonProperty("Token")] public string Token { get; set; } = Guid.NewGuid().ToString();
[JsonProperty("ReCaptcha")] public ReCaptchaData ReCaptcha { get; set; }
}
public class ReCaptchaData
{
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
[JsonProperty("SiteKey")] public string SiteKey { get; set; } = "recaptcha site key here";
[JsonProperty("SecretKey")] public string SecretKey { get; set; } = "recaptcha secret here";
}
public class SentryData
{
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
[JsonProperty("Dsn")] public string Dsn { get; set; } = "http://your-sentry-url-here";
}
public class SmartDeployData
{
[JsonProperty("Server")] public SmartDeployServerData Server { get; set; } = new();
}
public class SmartDeployServerData
{
[JsonProperty("EnableOverride")] public bool EnableOverride { get; set; } = false;
[JsonProperty("OverrideNode")] public long OverrideNode { get; set; } = 1;
}
public class StatisticsData
{
[JsonProperty("Enabled")] public bool Enabled { get; set; } = false;
[JsonProperty("Wait")] public long Wait { get; set; } = 15;
}
public class SubscriptionsData
{
[JsonProperty("SellPass")] public SellPassData SellPass { get; set; } = new();
}
public class SellPassData
{
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
[JsonProperty("Url")] public string Url { get; set; } = "https://not-implemented-yet";
}
}

View File

@@ -52,14 +52,14 @@ public class DataContext : DbContext
if (!optionsBuilder.IsConfigured)
{
var config = ConfigService
.GetSection("Moonlight")
.GetSection("Database");
.Get()
.Moonlight.Database;
var connectionString = $"host={config.GetValue<string>("Host")};" +
$"port={config.GetValue<int>("Port")};" +
$"database={config.GetValue<string>("Database")};" +
$"uid={config.GetValue<string>("Username")};" +
$"pwd={config.GetValue<string>("Password")}";
var connectionString = $"host={config.Host};" +
$"port={config.Port};" +
$"database={config.Database};" +
$"uid={config.Username};" +
$"pwd={config.Password}";
optionsBuilder.UseMySql(
connectionString,

View File

@@ -65,16 +65,14 @@ public class DatabaseCheckupService
var configService = new ConfigService(new StorageService());
var dateTimeService = new DateTimeService();
var config = configService
.GetSection("Moonlight")
.GetSection("Database");
var connectionString = $"host={config.GetValue<string>("Host")};" +
$"port={config.GetValue<int>("Port")};" +
$"database={config.GetValue<string>("Database")};" +
$"uid={config.GetValue<string>("Username")};" +
$"pwd={config.GetValue<string>("Password")}";
var config = configService.Get().Moonlight.Database;
var connectionString = $"host={config.Host};" +
$"port={config.Port};" +
$"database={config.Database};" +
$"uid={config.Username};" +
$"pwd={config.Password}";
string file = PathBuilder.File("storage", "backups", $"{dateTimeService.GetCurrentUnix()}-mysql.sql");

View File

@@ -111,7 +111,7 @@ public class WingsFileAccess : FileAccess
request.AddParameter("name", "files");
request.AddParameter("filename", name);
request.AddHeader("Content-Type", "multipart/form-data");
request.AddHeader("Origin", ConfigService.GetSection("Moonlight").GetValue<string>("AppUrl"));
request.AddHeader("Origin", ConfigService.Get().Moonlight.AppUrl);
request.AddFile("files", () =>
{
return new StreamProgressHelper(dataStream)

View File

@@ -20,7 +20,7 @@ public class WingsConsoleHelper
{
ServerRepository = serverRepository;
AppUrl = configService.GetSection("Moonlight").GetValue<string>("AppUrl");
AppUrl = configService.Get().Moonlight.AppUrl;
}
public async Task ConnectWings(WingsConsole console, Server server)

View File

@@ -15,7 +15,7 @@ public class WingsJwtHelper
{
ConfigService = configService;
AppUrl = ConfigService.GetSection("Moonlight").GetValue<string>("AppUrl");
AppUrl = ConfigService.Get().Moonlight.AppUrl;
}
public string Generate(string secret, Action<Dictionary<string, string>> claimsAction)

View File

@@ -30,14 +30,14 @@ public class DiscordBotController : Controller
ServerService = serverService;
var config = configService
.GetSection("Moonlight")
.GetSection("DiscordBotApi");
.Get()
.Moonlight.DiscordBotApi;
Enable = config.GetValue<bool>("Enable");
Enable = config.Enable;
if (Enable)
{
Token = config.GetValue<string>("Token");
Token = config.Token;
}
}

View File

@@ -42,16 +42,16 @@ public class CleanupService
StartedAt = DateTimeService.GetCurrent();
CompletedAt = DateTimeService.GetCurrent();
IsRunning = false;
var config = ConfigService.GetSection("Moonlight").GetSection("Cleanup");
if (!config.GetValue<bool>("Enable") || ConfigService.DebugMode)
var config = ConfigService.Get().Moonlight.Cleanup;
if (!config.Enable || ConfigService.DebugMode)
{
Logger.Info("Disabling cleanup service");
return;
}
Timer = new(TimeSpan.FromMinutes(config.GetValue<int>("Wait")));
Timer = new(TimeSpan.FromMinutes(config.Wait));
Task.Run(Run);
}
@@ -63,12 +63,12 @@ public class CleanupService
IsRunning = true;
using var scope = ServiceScopeFactory.CreateScope();
var config = ConfigService.GetSection("Moonlight").GetSection("Cleanup");
var config = ConfigService.Get().Moonlight.Cleanup;
var maxCpu = config.GetValue<int>("Cpu");
var minMemory = config.GetValue<int>("Memory");
var maxUptime = config.GetValue<int>("Uptime");
var minUptime = config.GetValue<int>("MinUptime");
var maxCpu = config.Cpu;
var minMemory = config.Memory;
var maxUptime = config.Uptime;
var minUptime = config.MinUptime;
var nodeRepository = scope.ServiceProvider.GetRequiredService<NodeRepository>();
var nodeService = scope.ServiceProvider.GetRequiredService<NodeService>();

View File

@@ -22,14 +22,14 @@ public class DiscordNotificationService
Event = eventSystem;
ResourceService = resourceService;
var config = configService.GetSection("Moonlight").GetSection("DiscordNotifications");
var config = configService.Get().Moonlight.DiscordNotifications;
if (config.GetValue<bool>("Enable"))
if (config.Enable)
{
Logger.Info("Discord notifications enabled");
Client = new(config.GetValue<string>("WebHook"));
AppUrl = configService.GetSection("Moonlight").GetValue<string>("AppUrl");
Client = new(config.WebHook);
AppUrl = configService.Get().Moonlight.AppUrl;
Event.On<User>("supportChat.new", this, OnNewSupportChat);
Event.On<SupportChatMessage>("supportChat.message", this, OnSupportChatMessage);

View File

@@ -1,15 +1,14 @@
using System.Text;
using Microsoft.Extensions.Primitives;
using Moonlight.App.Configuration;
using Moonlight.App.Helpers;
using Moonlight.App.Services.Files;
using Newtonsoft.Json;
namespace Moonlight.App.Services;
public class ConfigService : IConfiguration
public class ConfigService
{
private readonly StorageService StorageService;
private IConfiguration Configuration;
private ConfigV1 Configuration;
public bool DebugMode { get; private set; } = false;
public bool SqlDebugMode { get; private set; } = false;
@@ -41,33 +40,22 @@ public class ConfigService : IConfiguration
public void Reload()
{
Configuration = new ConfigurationBuilder().AddJsonStream(
new MemoryStream(Encoding.ASCII.GetBytes(
File.ReadAllText(
PathBuilder.File("storage", "configs", "config.json")
)
)
)).Build();
var path = PathBuilder.File("storage", "configs", "config.json");
if (!File.Exists(path))
{
File.WriteAllText(path, "{}");
}
Configuration = JsonConvert.DeserializeObject<ConfigV1>(
File.ReadAllText(path)
) ?? new ConfigV1();
File.WriteAllText(path, JsonConvert.SerializeObject(Configuration));
}
public IEnumerable<IConfigurationSection> GetChildren()
public ConfigV1 Get()
{
return Configuration.GetChildren();
}
public IChangeToken GetReloadToken()
{
return Configuration.GetReloadToken();
}
public IConfigurationSection GetSection(string key)
{
return Configuration.GetSection(key);
}
public string this[string key]
{
get => Configuration[key];
set => Configuration[key] = value;
return Configuration;
}
}

View File

@@ -29,7 +29,7 @@ public class ServerListCommand : BaseModule
{
embed = dcs.EmbedBuilderModule.StandardEmbed("Sorry ;( \n Please first create and/or link a Account to Discord! \n Press the Button to register/log in.", Color.Red, command.User);
components = new ComponentBuilder();
components.WithButton("Click Here", style: ButtonStyle.Link, url: ConfigService.GetSection("Moonlight").GetValue<String>("AppUrl"));
components.WithButton("Click Here", style: ButtonStyle.Link, url: ConfigService.Get().Moonlight.AppUrl);
await command.RespondAsync(embed: embed.Build(), components: components.Build(), ephemeral: true);
return;
@@ -57,7 +57,7 @@ public class ServerListCommand : BaseModule
components.WithButton("Panel",
emote: Emote.Parse("<a:Earth:1092814004113657927>"),
style: ButtonStyle.Link,
url: $"{ConfigService.GetSection("Moonlight").GetValue<string>("AppUrl")}");
url: $"{ConfigService.Get().Moonlight.AppUrl}");
if (servers.Count > 25)
{

View File

@@ -44,10 +44,10 @@ public DiscordBotService(
ServiceScope = ServiceScopeFactory.CreateScope();
var discordConfig = ConfigService
.GetSection("Moonlight")
.GetSection("DiscordBot");
.Get()
.Moonlight.DiscordBot;
if (!discordConfig.GetValue<bool>("Enable"))
if (!discordConfig.Enable)
return;
Client.Log += Log;
@@ -67,7 +67,7 @@ public DiscordBotService(
await ActivityStatusModule.UpdateActivityStatusList();
await Client.LoginAsync(TokenType.Bot, discordConfig.GetValue<string>("Token"));
await Client.LoginAsync(TokenType.Bot, discordConfig.Token);
await Client.StartAsync();
await Task.Delay(-1);

View File

@@ -87,8 +87,8 @@ public class EmbedBuilderModule : BaseModule
int[] randomNumbers = new int[] { 1, 3, 8, 11, 20 };
if (randomNumbers.Contains(random.Next(1, 24)))
return new EmbedAuthorBuilder().WithName(Client.CurrentUser.Username + " - The Rick version").WithUrl(ConfigService.GetSection("Moonlight").GetValue<string>("AppUrl")).WithIconUrl("https://cdn.discordapp.com/attachments/750696464014901268/1092783310129860618/rick.gif");
return new EmbedAuthorBuilder().WithName(Client.CurrentUser.Username + " - The Rick version").WithUrl(ConfigService.Get().Moonlight.AppUrl).WithIconUrl("https://cdn.discordapp.com/attachments/750696464014901268/1092783310129860618/rick.gif");
return new EmbedAuthorBuilder().WithName(Client.CurrentUser.Username).WithUrl(ConfigService.GetSection("Moonlight").GetValue<string>("AppUrl")).WithIconUrl(Client.CurrentUser.GetAvatarUrl());
return new EmbedAuthorBuilder().WithName(Client.CurrentUser.Username).WithUrl(ConfigService.Get().Moonlight.AppUrl).WithIconUrl(Client.CurrentUser.GetAvatarUrl());
}
}

View File

@@ -72,7 +72,7 @@ public class ServerListComponentHandlerModule : BaseModule
// stopping
// offline
// installing
if (!ConfigService.GetSection("Moonlight").GetSection("DiscordBot").GetValue<bool>("PowerActions") && costomId[1] is "Start" or "Restart" or "Stop" or "Kill" or "Update")
if (!ConfigService.Get().Moonlight.DiscordBot.PowerActions && costomId[1] is "Start" or "Restart" or "Stop" or "Kill" or "Update")
{
embed = dcs.EmbedBuilderModule.StandardEmbed($"This feature is disabled for Security reasons! \n If you believe this is a error please contact the Administrators from this panel.", Color.Red, component.User);
await component.RespondAsync(embed: embed.Build(), ephemeral: true);
@@ -80,7 +80,7 @@ public class ServerListComponentHandlerModule : BaseModule
return;
}
if (!ConfigService.GetSection("Moonlight").GetSection("DiscordBot").GetValue<bool>("SendCommands") && costomId[1] is "SendCommand")
if (!ConfigService.Get().Moonlight.DiscordBot.SendCommands && costomId[1] is "SendCommand")
{
embed = dcs.EmbedBuilderModule.StandardEmbed($"This feature is disabled for Security reasons! \n If you believe this is a error please contact the Administrators from this panel.", Color.Red, component.User);
await component.RespondAsync(embed: embed.Build(), ephemeral: true);
@@ -302,7 +302,7 @@ public class ServerListComponentHandlerModule : BaseModule
{
embed = dcs.EmbedBuilderModule.StandardEmbed("Sorry ;( \n Please first create and/or link a Account to Discord! \n Press the Button to register/log in.", Color.Red, component.User);
components = new ComponentBuilder();
components.WithButton("Click Here", style: ButtonStyle.Link, url: ConfigService.GetSection("Moonlight").GetValue<String>("AppUrl"));
components.WithButton("Click Here", style: ButtonStyle.Link, url: ConfigService.Get().Moonlight.AppUrl);
await component.RespondAsync(embed: embed.Build(), components: components.Build(), ephemeral: true);
return;
@@ -332,7 +332,7 @@ public class ServerListComponentHandlerModule : BaseModule
components.WithButton("Panel",
emote: Emote.Parse("<a:Earth:1092814004113657927>"),
style: ButtonStyle.Link,
url: $"{ConfigService.GetSection("Moonlight").GetValue<string>("AppUrl")}");
url: $"{ConfigService.Get().Moonlight.AppUrl}");
components.WithButton("Previous-page",
emote: Emote.Parse("<:ArrowLeft:1101547474180649030>"),
@@ -378,7 +378,7 @@ public class ServerListComponentHandlerModule : BaseModule
var components = new ComponentBuilder();
if (ConfigService.GetSection("Moonlight").GetSection("DiscordBot").GetValue<bool>("PowerActions"))
if (ConfigService.Get().Moonlight.DiscordBot.PowerActions)
{
components.WithButton("Start", style: ButtonStyle.Success, customId: $"Sm.Start.{server.Id}", disabled: false);
components.WithButton("Restart", style: ButtonStyle.Primary, customId: $"Sm.Restart.{server.Id}", disabled: false);
@@ -389,14 +389,14 @@ public class ServerListComponentHandlerModule : BaseModule
components.WithButton("Way2Server",
emote: Emote.Parse("<a:Earth:1092814004113657927>"),
style: ButtonStyle.Link,
url: $"{ConfigService.GetSection("Moonlight").GetValue<string>("AppUrl")}/server/{server.Uuid}");
url: $"{ConfigService.Get().Moonlight.AppUrl}/server/{server.Uuid}");
components.WithButton("Update",
emote: Emote.Parse("<:refresh:1101547898803605605>"),
style: ButtonStyle.Secondary,
customId: $"Sm.Update.{server.Id}");
if (ConfigService.GetSection("Moonlight").GetSection("DiscordBot").GetValue<bool>("SendCommands"))
if (ConfigService.Get().Moonlight.DiscordBot.SendCommands)
{
components.WithButton("SendCommand",
emote: Emote.Parse("<:Console:1101547358157819944>"),

View File

@@ -33,15 +33,15 @@ public class DomainService
SharedDomainRepository = sharedDomainRepository;
var config = configService
.GetSection("Moonlight")
.GetSection("Domains");
.Get()
.Moonlight.Domains;
AccountId = config.GetValue<string>("AccountId");
AccountId = config.AccountId;
Client = new(
new ApiKeyAuthentication(
config.GetValue<string>("Email"),
config.GetValue<string>("Key")
config.Email,
config.Key
)
);
}

View File

@@ -8,7 +8,7 @@ public class ResourceService
public ResourceService(ConfigService configService)
{
AppUrl = configService.GetSection("Moonlight").GetValue<string>("AppUrl");
AppUrl = configService.Get().Moonlight.AppUrl;
}
public string Image(string name)

View File

@@ -25,16 +25,15 @@ public class ReCaptchaService
ConfigService = configService;
var recaptchaConfig = ConfigService
.GetSection("Moonlight")
.GetSection("Security")
.GetSection("ReCaptcha");
.Get()
.Moonlight.Security.ReCaptcha;
Enable = recaptchaConfig.GetValue<bool>("Enable");
Enable = recaptchaConfig.Enable;
if (Enable)
{
SiteKey = recaptchaConfig.GetValue<string>("SiteKey");
SecretKey = recaptchaConfig.GetValue<string>("SecretKey");
SiteKey = recaptchaConfig.SiteKey;
SecretKey = recaptchaConfig.SecretKey;
}
}

View File

@@ -17,14 +17,14 @@ public class MailService
public MailService(ConfigService configService)
{
var mailConfig = configService
.GetSection("Moonlight")
.GetSection("Mail");
.Get()
.Moonlight.Mail;
Server = mailConfig.GetValue<string>("Server");
Password = mailConfig.GetValue<string>("Password");
Email = mailConfig.GetValue<string>("Email");
Port = mailConfig.GetValue<int>("Port");
Ssl = mailConfig.GetValue<bool>("Ssl");
Server = mailConfig.Server;
Password = mailConfig.Password;
Email = mailConfig.Email;
Port = mailConfig.Port;
Ssl = mailConfig.Ssl;
}
public async Task SendMail(

View File

@@ -1,4 +1,5 @@
using Moonlight.App.Database.Entities;
using Mappy.Net;
using Moonlight.App.Database.Entities;
using Moonlight.App.Exceptions;
using Moonlight.App.Helpers;
using Moonlight.App.Models.Misc;
@@ -24,14 +25,17 @@ public class OAuth2Service
ConfigService = configService;
ServiceScopeFactory = serviceScopeFactory;
var config = ConfigService.GetSection("Moonlight").GetSection("OAuth2");
var config = ConfigService
.Get()
.Moonlight.OAuth2;
Configs = config.GetSection("Providers").Get<OAuth2ProviderConfig[]>()
?? Array.Empty<OAuth2ProviderConfig>();
Configs = config.Providers
.Select(Mapper.Map<OAuth2ProviderConfig>)
.ToArray();
OverrideUrl = config.GetValue<string>("OverrideUrl");
EnableOverrideUrl = config.GetValue<bool>("EnableOverrideUrl");
AppUrl = configService.GetSection("Moonlight").GetValue<string>("AppUrl");
OverrideUrl = config.OverrideUrl;
EnableOverrideUrl = config.EnableOverrideUrl;
AppUrl = configService.Get().Moonlight.AppUrl;
// Register additional providers here
RegisterOAuth2<DiscordOAuth2Provider>("discord");

View File

@@ -25,10 +25,9 @@ public class OneTimeJwtService
var opt = new Dictionary<string, string>();
options.Invoke(opt);
string secret = ConfigService
.GetSection("Moonlight")
.GetSection("Security")
.GetValue<string>("Token");
var secret = ConfigService
.Get()
.Moonlight.Security.Token;
var id = StringHelper.GenerateString(16);
@@ -55,10 +54,9 @@ public class OneTimeJwtService
public async Task<Dictionary<string, string>?> Validate(string token)
{
string secret = ConfigService
.GetSection("Moonlight")
.GetSection("Security")
.GetValue<string>("Token");
var secret = ConfigService
.Get()
.Moonlight.Security.Token;
string json;

View File

@@ -26,12 +26,12 @@ public class RatingService
Event = eventSystem;
UserRepository = userRepository;
var config = configService.GetSection("Moonlight").GetSection("Rating");
var config = configService.Get().Moonlight.Rating;
Enabled = config.GetValue<bool>("Enabled");
Url = config.GetValue<string>("Url");
MinRating = config.GetValue<int>("MinRating");
DaysSince = config.GetValue<int>("DaysSince");
Enabled = config.Enabled;
Url = config.Url;
MinRating = config.MinRating;
DaysSince = config.DaysSince;
}
public async Task<bool> ShouldRate()

View File

@@ -30,9 +30,8 @@ public class IdentityService
HttpContextAccessor = httpContextAccessor;
Secret = configService
.GetSection("Moonlight")
.GetSection("Security")
.GetValue<string>("Token");
.Get()
.Moonlight.Security.Token;
}
public async Task<User?> Get()

View File

@@ -28,13 +28,12 @@ public class SmartDeployService
public async Task<Node?> GetNode()
{
var config = ConfigService
.GetSection("Moonlight")
.GetSection("SmartDeploy")
.GetSection("Server");
.Get()
.Moonlight.SmartDeploy.Server;
if (config.GetValue<bool>("EnableOverride"))
if (config.EnableOverride)
{
var nodeId = config.GetValue<int>("OverrideNode");
var nodeId = config.OverrideNode;
return NodeRepository.Get().FirstOrDefault(x => x.Id == nodeId);
}

View File

@@ -17,13 +17,13 @@ public class StatisticsCaptureService
DateTimeService = dateTimeService;
var config = configService
.GetSection("Moonlight")
.GetSection("Statistics");
.Get()
.Moonlight.Statistics;
if(!config.GetValue<bool>("Enabled"))
if(!config.Enabled)
return;
var period = TimeSpan.FromMinutes(config.GetValue<int>("Wait"));
var period = TimeSpan.FromMinutes(config.Wait);
Timer = new(period);
Logger.Info("Starting statistics system");

View File

@@ -38,9 +38,8 @@ public class UserService
DateTimeService = dateTimeService;
JwtSecret = configService
.GetSection("Moonlight")
.GetSection("Security")
.GetValue<string>("Token");
.Get()
.Moonlight.Security.Token;
}
public async Task<string> Register(string email, string password, string firstname, string lastname)

View File

@@ -103,4 +103,12 @@
<AdditionalFiles Include="Shared\Views\Server\Settings\ServerResetSetting.razor" />
</ItemGroup>
<ItemGroup>
<Content Update="storage\configs\config.json.bak">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
</Project>

View File

@@ -11,12 +11,12 @@
@{
var headerConfig = ConfigService
.GetSection("Moonlight")
.GetSection("Html")
.GetSection("Headers");
.Get()
.Moonlight.Html.Headers;
var moonlightConfig = ConfigService
.GetSection("Moonlight");
.Get()
.Moonlight;
}
<!DOCTYPE html>
@@ -26,16 +26,16 @@
<meta property="og:locale" content="de_DE"/>
<meta property="og:type" content="article"/>
<meta content="@(headerConfig.GetValue<string>("Title"))" property="og:title"/>
<meta content="@(headerConfig.GetValue<string>("Description"))" property="og:description"/>
<meta content="@(moonlightConfig.GetValue<string>("AppUrl"))" property="og:url"/>
<meta content="@(moonlightConfig.GetValue<string>("AppUrl"))/api/moonlight/resources/images/logolong.png" property="og:image"/>
<meta content="@(headerConfig.GetValue<string>("Color"))" data-react-helmet="true" name="theme-color"/>
<meta content="@(headerConfig.Title)" property="og:title"/>
<meta content="@(headerConfig.Description)" property="og:description"/>
<meta content="@(moonlightConfig.AppUrl)" property="og:url"/>
<meta content="@(moonlightConfig.AppUrl)/api/moonlight/resources/images/logolong.png" property="og:image"/>
<meta content="@(headerConfig.Color)" data-react-helmet="true" name="theme-color"/>
<meta content="@(headerConfig.GetValue<string>("Description"))" name="description"/>
<meta content="@(headerConfig.GetValue<string>("Keywords"))" name="keywords"/>
<meta content="@(headerConfig.Description)" name="description"/>
<meta content="@(headerConfig.Keywords)" name="keywords"/>
<link rel="shortcut icon" href="@(moonlightConfig.GetValue<string>("AppUrl"))/api/moonlight/resources/images/logo.svg"/>
<link rel="shortcut icon" href="@(moonlightConfig.AppUrl)/api/moonlight/resources/images/logo.svg"/>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700"/>
@@ -75,7 +75,7 @@
<div id="flashbang" class="flashbanglight"></div>
<div class="app-page-loader flex-column">
<img alt="Logo" src="@(moonlightConfig.GetValue<string>("AppUrl"))/api/moonlight/resources/images/logo.svg" class="h-25px"/>
<img alt="Logo" src="@(moonlightConfig.AppUrl)/api/moonlight/resources/images/logo.svg" class="h-25px"/>
@{
string loadingMessage;

View File

@@ -43,9 +43,8 @@ namespace Moonlight
// This will also copy all default config files
var configService = new ConfigService(new StorageService());
var shouldUseSentry = configService
.GetSection("Moonlight")
.GetSection("Sentry")
.GetValue<bool>("Enable");
.Get()
.Moonlight.Sentry.Enable;
if (configService.DebugMode)
{
@@ -139,9 +138,8 @@ namespace Moonlight
builder.WebHost.UseSentry(options =>
{
options.Dsn = configService
.GetSection("Moonlight")
.GetSection("Sentry")
.GetValue<string>("Dsn");
.Get()
.Moonlight.Sentry.Dsn;
options.Debug = configService.DebugMode;
options.DiagnosticLevel = SentryLevel.Warning;

View File

@@ -1,16 +1,12 @@
@using Moonlight.App.Services
@using Moonlight.App.Services.Files
@inject ConfigService ConfigService
@{
var moonlightConfig = ConfigService
.GetSection("Moonlight");
}
@inject ResourceService ResourceService
<div class="card card-flush w-lg-650px py-5">
<div class="card-body py-15 py-lg-20">
<div class="mb-14">
<img alt="Logo" src="@(moonlightConfig.GetValue<string>("AppUrl"))/api/moonlight/resources/images/logolong.png" class="h-40px">
<img alt="Logo" src="@(ResourceService.Image("logolong.png"))" class="h-40px">
</div>
<h1 class="fw-bolder text-gray-900 mb-5"><TL>Your account is banned from moonlight</TL></h1>
<div class="fw-semibold fs-6 text-gray-500 mb-8">

View File

@@ -1,16 +1,12 @@
@using Moonlight.App.Services
@using Moonlight.App.Services.Files
@inject ConfigService ConfigService
@{
var moonlightConfig = ConfigService
.GetSection("Moonlight");
}
@inject ResourceService ResourceService
<div class="card card-flush w-lg-650px py-5">
<div class="card-body py-15 py-lg-20">
<div class="mb-14">
<img alt="Logo" src="@(moonlightConfig.GetValue<string>("AppUrl"))/api/moonlight/resources/images/logolong.png" class="h-40px">
<img alt="Logo" src="@(ResourceService.Image("logolong.png"))" class="h-40px">
</div>
<h1 class="fw-bolder text-gray-900 mb-5"><TL>Your moonlight account is disabled</TL></h1>
<div class="fw-semibold fs-6 text-gray-500 mb-8">

View File

@@ -4,31 +4,31 @@
@{
var marketingConfig = ConfigService
.GetSection("Moonlight")
.GetSection("Marketing");
.Get()
.Moonlight.Marketing;
}
<div id="kt_app_footer" class="app-footer">
<div class="app-container container-fluid d-flex flex-column flex-md-row flex-center flex-md-stack py-3">
<div class="text-dark order-2 order-md-1">
<span class="text-muted fw-semibold me-1">2022 - @DateTime.Now.Year©</span>
<a href="@(marketingConfig.GetValue<string>("Website"))" target="_blank" class="text-gray-800 text-hover-primary">
@(marketingConfig.GetValue<string>("BrandName"))
<a href="@(marketingConfig.Website)" target="_blank" class="text-gray-800 text-hover-primary">
@(marketingConfig.BrandName)
</a>
</div>
<ul class="menu menu-gray-600 menu-hover-primary fw-semibold order-1">
<li class="menu-item">
<a href="@(marketingConfig.GetValue<string>("About"))" target="_blank" class="menu-link px-2">
<a href="@(marketingConfig.About)" target="_blank" class="menu-link px-2">
<TL>About us</TL>
</a>
</li>
<li class="menu-item">
<a href="@(marketingConfig.GetValue<string>("Imprint"))" target="_blank" class="menu-link px-2">
<a href="@(marketingConfig.Imprint)" target="_blank" class="menu-link px-2">
<TL>Imprint</TL>
</a>
</li>
<li class="menu-item">
<a href="@(marketingConfig.GetValue<string>("Privacy"))" target="_blank" class="menu-link px-2">
<a href="@(marketingConfig.Privacy)" target="_blank" class="menu-link px-2">
<TL>Privacy</TL>
</a>
</li>

View File

@@ -1,10 +1,6 @@
@using Moonlight.App.Services
@using Moonlight.App.Services.Files
@inject ConfigService ConfigService
@{
var moonlightConfig = ConfigService.GetSection("Moonlight");
}
@inject ResourceService ResourceService
<div id="kt_app_header" class="app-header">
<div class="app-container container-fluid d-flex align-items-stretch justify-content-between">
@@ -15,7 +11,7 @@
</div>
<div class="d-flex align-items-center flex-grow-1 flex-lg-grow-0">
<a href="/" class="d-lg-none">
<img alt="Logo" src="@(moonlightConfig.GetValue<string>("AppUrl"))/api/moonlight/resources/images/logo.svg" class="h-30px"/>
<img alt="Logo" src="@(ResourceService.Image("logo.svg"))" class="h-30px"/>
</a>
</div>
<div class="d-flex align-items-stretch justify-content-between flex-lg-grow-1" id="kt_app_header_wrapper">

View File

@@ -1,32 +1,28 @@
@using Moonlight.App.Services.Sessions
@using Moonlight.App.Database.Entities
@using Moonlight.App.Services
@using Moonlight.App.Services.Files
@inject IdentityService IdentityService
@inject ConfigService ConfigService
@inject ResourceService ResourceService
@inject IJSRuntime JsRuntime
@{
var moonlightConfig = ConfigService
.GetSection("Moonlight");
}
<div id="kt_app_sidebar" class="app-sidebar flex-column" data-kt-drawer="true" data-kt-drawer-name="app-sidebar" data-kt-drawer-activate="{default: true, lg: false}" data-kt-drawer-overlay="true" data-kt-drawer-width="225px" data-kt-drawer-direction="start" data-kt-drawer-toggle="#kt_app_sidebar_mobile_toggle">
<div class="app-sidebar-logo px-6" id="kt_app_sidebar_logo">
<a href="@(User != null ? "/" : "/login")">
@if (sidebar == "dark-sidebar")
{
<img alt="Logo" src="@(moonlightConfig.GetValue<string>("AppUrl"))/api/moonlight/resources/images/logolong.png" class="h-45px app-sidebar-logo-default"/>
<img alt="Logo" src="@(ResourceService.Image("logolong.png"))" class="h-45px app-sidebar-logo-default"/>
}
else
{
if (sidebar == "light-sidebar")
{
<img alt="Logo" src="@(moonlightConfig.GetValue<string>("AppUrl"))/api/moonlight/resources/images/logo.svg" class="theme-light-show h-20px app-sidebar-logo-default"/>
<img alt="Logo" src="@(moonlightConfig.GetValue<string>("AppUrl"))/api/moonlight/resources/images/logo.svg" class="theme-dark-show h-20px app-sidebar-logo-default"/>
<img alt="Logo" src="@(ResourceService.Image("logo.svg"))" class="theme-light-show h-20px app-sidebar-logo-default"/>
<img alt="Logo" src="@(ResourceService.Image("logo.svg"))" class="theme-dark-show h-20px app-sidebar-logo-default"/>
}
}
<img alt="Logo" src="@(moonlightConfig.GetValue<string>("AppUrl"))/api/moonlight/resources/images/logo.svg" class="h-20px app-sidebar-logo-minimize"/>
<img alt="Logo" src="@(ResourceService.Image("logo.svg"))" class="h-20px app-sidebar-logo-minimize"/>
</a>
<div id="kt_app_sidebar_toggle" class="app-sidebar-toggle btn btn-icon btn-shadow btn-sm btn-color-muted btn-active-color-primary body-bg h-30px w-30px position-absolute top-50 start-100 translate-middle rotate" data-kt-toggle="true" data-kt-toggle-state="active" data-kt-toggle-target="body" data-kt-toggle-name="app-sidebar-minimize">

View File

@@ -1,20 +0,0 @@
@using Moonlight.App.Services
@inject ConfigService ConfigService
@{
var setupComplete = ConfigService
.GetSection("Moonlight")
.GetValue<bool>("SetupComplete");
}
@if (!setupComplete)
{
@ChildContent
}
@code
{
[Parameter]
public RenderFragment ChildContent { get; set; }
}

View File

@@ -1,20 +0,0 @@
@using Moonlight.App.Services
@inject ConfigService ConfigService
@{
var setupComplete = ConfigService
.GetSection("Moonlight")
.GetValue<bool>("SetupComplete");
}
@if (setupComplete)
{
@ChildContent
}
@code
{
[Parameter]
public RenderFragment ChildContent { get; set; }
}

View File

@@ -151,8 +151,8 @@
await lazyLoader.SetText("Loading health check data");
var appUrl = ConfigService
.GetSection("Moonlight")
.GetValue<string>("AppUrl");
.Get()
.Moonlight.AppUrl;
try
{

View File

@@ -4,12 +4,10 @@
@using Moonlight.App.Services
@inject NodeRepository NodeRepository
@inject SmartTranslateService SmartTranslateService
@inject ConfigService ConfigService
@inject NavigationManager NavigationManager
@{
var appUrl = ConfigService.GetSection("Moonlight").GetValue<string>("AppUrl");
var appUrl = ConfigService.Get().Moonlight.AppUrl;
}
<OnlyAdmin>

View File

@@ -24,12 +24,11 @@
@if (Subscription == null)
{
var config = ConfigService
.GetSection("Moonlight")
.GetSection("Subscriptions")
.GetSection("Sellpass");
.Get()
.Moonlight.Subscriptions.SellPass;
var enableSellpass = config.GetValue<bool>("Enable");
var url = config.GetValue<string>("Url");
var enableSellpass = config.Enable;
var url = config.Url;
<h3 class="mb-2">
<div class="input-group mb-3">

View File

@@ -1,101 +0,0 @@
{
"Moonlight": {
"AppUrl": "http://your-moonlight-url.test",
"Database": {
"Database": "database_name",
"Host": "your-moonlight-database-host.de",
"Password": "s3cr3t",
"Port": "10324",
"Username": "user_name"
},
"DiscordBotApi": {
"Enable": false,
"Token": "you api key here"
},
"DiscordBot": {
"Enable": false,
"Token": "Discord.Token.Here",
"PowerActions": false
},
"Domains": {
"_comment": "Cloudflare Api Credentials",
"AccountId": "Account Id here",
"Email": "Cloudflare Email here",
"Key": "Api Key Here"
},
"Html": {
"Headers": {
"Color": "#4b27e8",
"Description": "the next generation hosting panel",
"Keywords": "moonlight",
"Title": "Moonlight - moonlight.tld"
}
},
"Marketing": {
"BrandName": "My cool project",
"Imprint": "https://mycoolproject.de/imprint",
"Privacy": "https://mycoolproject.de/privacy",
"Website": "https://mycoolproject.de/"
},
"OAuth2": {
"_exampleProviders": [
{
"Id": "discord",
"ClientId": "",
"ClientSecret": ""
},
{
"Id": "google",
"ClientId": "",
"ClientSecret": ""
}
],
"Providers": [],
"EnableOverrideUrl": false,
"OverrideUrl": "http://your-moonlight-url.test"
},
"Security": {
"Token": "RANDOM UUID HERE"
},
"Mail": {
"Email": "no-reply@mycoolproject.de",
"Server": "mycoolproject.de",
"Password": "s3cr3t",
"Port": 465,
"Ssl": true
},
"Cleanup": {
"Cpu": 90,
"Memory": 8192,
"Wait": 15,
"Uptime": 6,
"Enable": false,
"MinUptime": 10
},
"Subscriptions": {
"_comment": "Not implemented",
"SellPass": {
"Enable": false,
"Url": ""
}
},
"DiscordNotifications": {
"Enable": false,
"WebHook": ""
},
"Statistics": {
"Enabled": true,
"Wait": 15
},
"Rating": {
"Enabled": true,
"Url": "link-to-google.page",
"MinRating": 4,
"DaysSince": 5
},
"Sentry": {
"Enable": false,
"Dsn": ""
}
}
}