Skip to content

Commit 2fe1747

Browse files
Merge pull request #204 from Moonlight-Panel/SwitchToNewConfigSystem
Switched to new config system
2 parents 678da30 + 609cf8c commit 2fe1747

39 files changed

+399
-343
lines changed
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
namespace Moonlight.App.Configuration;
2+
3+
using System;
4+
using Newtonsoft.Json;
5+
6+
public class ConfigV1
7+
{
8+
[JsonProperty("Moonlight")] public MoonlightData Moonlight { get; set; } = new();
9+
10+
public class MoonlightData
11+
{
12+
[JsonProperty("AppUrl")] public string AppUrl { get; set; } = "http://your-moonlight-url-without-slash";
13+
14+
[JsonProperty("Database")] public DatabaseData Database { get; set; } = new();
15+
16+
[JsonProperty("DiscordBotApi")] public DiscordBotData DiscordBotApi { get; set; } = new();
17+
18+
[JsonProperty("DiscordBot")] public DiscordBotData DiscordBot { get; set; } = new();
19+
20+
[JsonProperty("Domains")] public DomainsData Domains { get; set; } = new();
21+
22+
[JsonProperty("Html")] public HtmlData Html { get; set; } = new();
23+
24+
[JsonProperty("Marketing")] public MarketingData Marketing { get; set; } = new();
25+
26+
[JsonProperty("OAuth2")] public OAuth2Data OAuth2 { get; set; } = new();
27+
28+
[JsonProperty("Security")] public SecurityData Security { get; set; } = new();
29+
30+
[JsonProperty("Mail")] public MailData Mail { get; set; } = new();
31+
32+
[JsonProperty("Cleanup")] public CleanupData Cleanup { get; set; } = new();
33+
34+
[JsonProperty("Subscriptions")] public SubscriptionsData Subscriptions { get; set; } = new();
35+
36+
[JsonProperty("DiscordNotifications")]
37+
public DiscordNotificationsData DiscordNotifications { get; set; } = new();
38+
39+
[JsonProperty("Statistics")] public StatisticsData Statistics { get; set; } = new();
40+
41+
[JsonProperty("Rating")] public RatingData Rating { get; set; } = new();
42+
43+
[JsonProperty("SmartDeploy")] public SmartDeployData SmartDeploy { get; set; } = new();
44+
45+
[JsonProperty("Sentry")] public SentryData Sentry { get; set; } = new();
46+
}
47+
48+
public class CleanupData
49+
{
50+
[JsonProperty("Cpu")] public long Cpu { get; set; } = 90;
51+
52+
[JsonProperty("Memory")] public long Memory { get; set; } = 8192;
53+
54+
[JsonProperty("Wait")] public long Wait { get; set; } = 15;
55+
56+
[JsonProperty("Uptime")] public long Uptime { get; set; } = 6;
57+
58+
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
59+
60+
[JsonProperty("MinUptime")] public long MinUptime { get; set; } = 10;
61+
}
62+
63+
public class DatabaseData
64+
{
65+
[JsonProperty("Database")] public string Database { get; set; } = "moonlight_db";
66+
67+
[JsonProperty("Host")] public string Host { get; set; } = "your.database.host";
68+
69+
[JsonProperty("Password")] public string Password { get; set; } = "secret";
70+
71+
[JsonProperty("Port")] public long Port { get; set; } = 3306;
72+
73+
[JsonProperty("Username")] public string Username { get; set; } = "moonlight_user";
74+
}
75+
76+
public class DiscordBotData
77+
{
78+
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
79+
80+
[JsonProperty("Token")] public string Token { get; set; } = "discord token here";
81+
82+
[JsonProperty("PowerActions")] public bool PowerActions { get; set; } = false;
83+
[JsonProperty("SendCommands")] public bool SendCommands { get; set; } = false;
84+
}
85+
86+
public class DiscordNotificationsData
87+
{
88+
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
89+
90+
[JsonProperty("WebHook")] public string WebHook { get; set; } = "http://your-discord-webhook-url";
91+
}
92+
93+
public class DomainsData
94+
{
95+
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
96+
[JsonProperty("AccountId")] public string AccountId { get; set; } = "cloudflare acc id";
97+
98+
[JsonProperty("Email")] public string Email { get; set; } = "[email protected]";
99+
100+
[JsonProperty("Key")] public string Key { get; set; } = "secret";
101+
}
102+
103+
public class HtmlData
104+
{
105+
[JsonProperty("Headers")] public HeadersData Headers { get; set; } = new();
106+
}
107+
108+
public class HeadersData
109+
{
110+
[JsonProperty("Color")] public string Color { get; set; } = "#4b27e8";
111+
112+
[JsonProperty("Description")] public string Description { get; set; } = "the next generation hosting panel";
113+
114+
[JsonProperty("Keywords")] public string Keywords { get; set; } = "moonlight";
115+
116+
[JsonProperty("Title")] public string Title { get; set; } = "Moonlight - endelon.link";
117+
}
118+
119+
public class MailData
120+
{
121+
[JsonProperty("Email")] public string Email { get; set; } = "[email protected]";
122+
123+
[JsonProperty("Server")] public string Server { get; set; } = "your.mail.host";
124+
125+
[JsonProperty("Password")] public string Password { get; set; } = "secret";
126+
127+
[JsonProperty("Port")] public int Port { get; set; } = 465;
128+
129+
[JsonProperty("Ssl")] public bool Ssl { get; set; } = true;
130+
}
131+
132+
public class MarketingData
133+
{
134+
[JsonProperty("BrandName")] public string BrandName { get; set; } = "Endelon Hosting";
135+
136+
[JsonProperty("Imprint")] public string Imprint { get; set; } = "https://your-site.xyz/imprint";
137+
138+
[JsonProperty("Privacy")] public string Privacy { get; set; } = "https://your-site.xyz/privacy";
139+
[JsonProperty("About")] public string About { get; set; } = "https://your-site.xyz/about";
140+
[JsonProperty("Website")] public string Website { get; set; } = "https://your-site.xyz";
141+
}
142+
143+
public class OAuth2Data
144+
{
145+
[JsonProperty("OverrideUrl")] public string OverrideUrl { get; set; } = "https://only-for-development.cases";
146+
147+
[JsonProperty("EnableOverrideUrl")] public bool EnableOverrideUrl { get; set; } = false;
148+
149+
[JsonProperty("Providers")]
150+
public OAuth2ProviderData[] Providers { get; set; } = Array.Empty<OAuth2ProviderData>();
151+
}
152+
153+
public class OAuth2ProviderData
154+
{
155+
[JsonProperty("Id")] public string Id { get; set; }
156+
157+
[JsonProperty("ClientId")] public string ClientId { get; set; }
158+
159+
[JsonProperty("ClientSecret")] public string ClientSecret { get; set; }
160+
}
161+
162+
public class RatingData
163+
{
164+
[JsonProperty("Enabled")] public bool Enabled { get; set; } = false;
165+
166+
[JsonProperty("Url")] public string Url { get; set; } = "https://link-to-google-or-smth";
167+
168+
[JsonProperty("MinRating")] public int MinRating { get; set; } = 4;
169+
170+
[JsonProperty("DaysSince")] public int DaysSince { get; set; } = 5;
171+
}
172+
173+
public class SecurityData
174+
{
175+
[JsonProperty("Token")] public string Token { get; set; } = Guid.NewGuid().ToString();
176+
177+
[JsonProperty("ReCaptcha")] public ReCaptchaData ReCaptcha { get; set; }
178+
}
179+
180+
public class ReCaptchaData
181+
{
182+
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
183+
184+
[JsonProperty("SiteKey")] public string SiteKey { get; set; } = "recaptcha site key here";
185+
186+
[JsonProperty("SecretKey")] public string SecretKey { get; set; } = "recaptcha secret here";
187+
}
188+
189+
public class SentryData
190+
{
191+
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
192+
193+
[JsonProperty("Dsn")] public string Dsn { get; set; } = "http://your-sentry-url-here";
194+
}
195+
196+
public class SmartDeployData
197+
{
198+
[JsonProperty("Server")] public SmartDeployServerData Server { get; set; } = new();
199+
}
200+
201+
public class SmartDeployServerData
202+
{
203+
[JsonProperty("EnableOverride")] public bool EnableOverride { get; set; } = false;
204+
205+
[JsonProperty("OverrideNode")] public long OverrideNode { get; set; } = 1;
206+
}
207+
208+
public class StatisticsData
209+
{
210+
[JsonProperty("Enabled")] public bool Enabled { get; set; } = false;
211+
212+
[JsonProperty("Wait")] public long Wait { get; set; } = 15;
213+
}
214+
215+
public class SubscriptionsData
216+
{
217+
[JsonProperty("SellPass")] public SellPassData SellPass { get; set; } = new();
218+
}
219+
220+
public class SellPassData
221+
{
222+
[JsonProperty("Enable")] public bool Enable { get; set; } = false;
223+
224+
[JsonProperty("Url")] public string Url { get; set; } = "https://not-implemented-yet";
225+
}
226+
}

Moonlight/App/Database/DataContext.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
5252
if (!optionsBuilder.IsConfigured)
5353
{
5454
var config = ConfigService
55-
.GetSection("Moonlight")
56-
.GetSection("Database");
55+
.Get()
56+
.Moonlight.Database;
5757

58-
var connectionString = $"host={config.GetValue<string>("Host")};" +
59-
$"port={config.GetValue<int>("Port")};" +
60-
$"database={config.GetValue<string>("Database")};" +
61-
$"uid={config.GetValue<string>("Username")};" +
62-
$"pwd={config.GetValue<string>("Password")}";
58+
var connectionString = $"host={config.Host};" +
59+
$"port={config.Port};" +
60+
$"database={config.Database};" +
61+
$"uid={config.Username};" +
62+
$"pwd={config.Password}";
6363

6464
optionsBuilder.UseMySql(
6565
connectionString,

Moonlight/App/Helpers/DatabaseCheckupService.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,14 @@ public async Task BackupDatabase()
6565

6666
var configService = new ConfigService(new StorageService());
6767
var dateTimeService = new DateTimeService();
68-
69-
var config = configService
70-
.GetSection("Moonlight")
71-
.GetSection("Database");
7268

73-
var connectionString = $"host={config.GetValue<string>("Host")};" +
74-
$"port={config.GetValue<int>("Port")};" +
75-
$"database={config.GetValue<string>("Database")};" +
76-
$"uid={config.GetValue<string>("Username")};" +
77-
$"pwd={config.GetValue<string>("Password")}";
69+
var config = configService.Get().Moonlight.Database;
70+
71+
var connectionString = $"host={config.Host};" +
72+
$"port={config.Port};" +
73+
$"database={config.Database};" +
74+
$"uid={config.Username};" +
75+
$"pwd={config.Password}";
7876

7977
string file = PathBuilder.File("storage", "backups", $"{dateTimeService.GetCurrentUnix()}-mysql.sql");
8078

Moonlight/App/Helpers/Files/WingsFileAccess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public override async Task Upload(string name, Stream dataStream, Action<int>? p
111111
request.AddParameter("name", "files");
112112
request.AddParameter("filename", name);
113113
request.AddHeader("Content-Type", "multipart/form-data");
114-
request.AddHeader("Origin", ConfigService.GetSection("Moonlight").GetValue<string>("AppUrl"));
114+
request.AddHeader("Origin", ConfigService.Get().Moonlight.AppUrl);
115115
request.AddFile("files", () =>
116116
{
117117
return new StreamProgressHelper(dataStream)

Moonlight/App/Helpers/Wings/WingsConsoleHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public WingsConsoleHelper(
2020
{
2121
ServerRepository = serverRepository;
2222

23-
AppUrl = configService.GetSection("Moonlight").GetValue<string>("AppUrl");
23+
AppUrl = configService.Get().Moonlight.AppUrl;
2424
}
2525

2626
public async Task ConnectWings(WingsConsole console, Server server)

Moonlight/App/Helpers/Wings/WingsJwtHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public WingsJwtHelper(ConfigService configService)
1515
{
1616
ConfigService = configService;
1717

18-
AppUrl = ConfigService.GetSection("Moonlight").GetValue<string>("AppUrl");
18+
AppUrl = ConfigService.Get().Moonlight.AppUrl;
1919
}
2020

2121
public string Generate(string secret, Action<Dictionary<string, string>> claimsAction)

Moonlight/App/Http/Controllers/Api/Moonlight/DiscordBotController.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public DiscordBotController(
3030
ServerService = serverService;
3131

3232
var config = configService
33-
.GetSection("Moonlight")
34-
.GetSection("DiscordBotApi");
33+
.Get()
34+
.Moonlight.DiscordBotApi;
3535

36-
Enable = config.GetValue<bool>("Enable");
36+
Enable = config.Enable;
3737

3838
if (Enable)
3939
{
40-
Token = config.GetValue<string>("Token");
40+
Token = config.Token;
4141
}
4242
}
4343

Moonlight/App/Services/Background/CleanupService.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ public CleanupService(
4242
StartedAt = DateTimeService.GetCurrent();
4343
CompletedAt = DateTimeService.GetCurrent();
4444
IsRunning = false;
45-
46-
var config = ConfigService.GetSection("Moonlight").GetSection("Cleanup");
4745

48-
if (!config.GetValue<bool>("Enable") || ConfigService.DebugMode)
46+
var config = ConfigService.Get().Moonlight.Cleanup;
47+
48+
if (!config.Enable || ConfigService.DebugMode)
4949
{
5050
Logger.Info("Disabling cleanup service");
5151
return;
5252
}
5353

54-
Timer = new(TimeSpan.FromMinutes(config.GetValue<int>("Wait")));
54+
Timer = new(TimeSpan.FromMinutes(config.Wait));
5555

5656
Task.Run(Run);
5757
}
@@ -63,12 +63,12 @@ private async Task Run()
6363
IsRunning = true;
6464

6565
using var scope = ServiceScopeFactory.CreateScope();
66-
var config = ConfigService.GetSection("Moonlight").GetSection("Cleanup");
66+
var config = ConfigService.Get().Moonlight.Cleanup;
6767

68-
var maxCpu = config.GetValue<int>("Cpu");
69-
var minMemory = config.GetValue<int>("Memory");
70-
var maxUptime = config.GetValue<int>("Uptime");
71-
var minUptime = config.GetValue<int>("MinUptime");
68+
var maxCpu = config.Cpu;
69+
var minMemory = config.Memory;
70+
var maxUptime = config.Uptime;
71+
var minUptime = config.MinUptime;
7272

7373
var nodeRepository = scope.ServiceProvider.GetRequiredService<NodeRepository>();
7474
var nodeService = scope.ServiceProvider.GetRequiredService<NodeService>();

Moonlight/App/Services/Background/DiscordNotificationService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public DiscordNotificationService(
2222
Event = eventSystem;
2323
ResourceService = resourceService;
2424

25-
var config = configService.GetSection("Moonlight").GetSection("DiscordNotifications");
25+
var config = configService.Get().Moonlight.DiscordNotifications;
2626

27-
if (config.GetValue<bool>("Enable"))
27+
if (config.Enable)
2828
{
2929
Logger.Info("Discord notifications enabled");
3030

31-
Client = new(config.GetValue<string>("WebHook"));
32-
AppUrl = configService.GetSection("Moonlight").GetValue<string>("AppUrl");
31+
Client = new(config.WebHook);
32+
AppUrl = configService.Get().Moonlight.AppUrl;
3333

3434
Event.On<User>("supportChat.new", this, OnNewSupportChat);
3535
Event.On<SupportChatMessage>("supportChat.message", this, OnSupportChatMessage);

0 commit comments

Comments
 (0)