10 Commits
v1b7 ... v1b8

Author SHA1 Message Date
Marcel Baumgartner
432e441972 Change moonlight service to always fetch the changelog 2023-06-18 02:37:07 +02:00
Marcel Baumgartner
1dae5150bd Merge pull request #178 from Moonlight-Panel/RewriteNotificationSystem
Rewrite notification system
2023-06-18 02:32:33 +02:00
Marcel Baumgartner
72c6f636ee Rewritten notification system 2023-06-17 20:47:07 +02:00
Daniel Balk
e54d04277d Merge pull request #177 from Moonlight-Panel/ShowMoonlightAppInSessions
added check for moonlight app for getting the device
2023-06-17 17:52:41 +02:00
Daniel Balk
f559f08e8d added check for moonlight app for getting the device 2023-06-17 17:51:34 +02:00
Daniel Balk
2674fb3fa7 Update Debugging.razor 2023-06-17 14:10:24 +02:00
Marcel Baumgartner
d5d77ae7da Merge pull request #175 from Moonlight-Panel/AddMoonlightSideDnsCheckSsl
Added moonlight side dns check for ssl
2023-06-17 13:39:25 +02:00
Marcel Baumgartner
3ae905038c Added moonlight side dns check for ssl 2023-06-17 13:38:32 +02:00
Marcel Baumgartner
6707d722e0 Merge pull request #174 from Moonlight-Panel/SomeHotfixes
Fixed cleanup, error handling missing and missing gif
2023-06-17 13:00:12 +02:00
Marcel Baumgartner
bc9fecf6d9 Fixed cleanup, error handling missing and missing gif 2023-06-17 12:57:01 +02:00
17 changed files with 434 additions and 285 deletions

View File

@@ -5,6 +5,8 @@ namespace Moonlight.App.Exceptions;
[Serializable] [Serializable]
public class DisplayException : Exception public class DisplayException : Exception
{ {
public bool DoNotTranslate { get; set; } = false;
// //
// For guidelines regarding the creation of new exception types, see // For guidelines regarding the creation of new exception types, see
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
@@ -19,6 +21,11 @@ public class DisplayException : Exception
public DisplayException(string message) : base(message) public DisplayException(string message) : base(message)
{ {
} }
public DisplayException(string message, bool doNotTranslate) : base(message)
{
DoNotTranslate = doNotTranslate;
}
public DisplayException(string message, Exception inner) : base(message, inner) public DisplayException(string message, Exception inner) : base(message, inner)
{ {

View File

@@ -1,7 +1,9 @@
using System.Net.WebSockets; using System.Net.WebSockets;
using System.Text; using System.Text;
using Logging.Net;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Moonlight.App.Database.Entities;
using Moonlight.App.Database.Entities.Notification; using Moonlight.App.Database.Entities.Notification;
using Moonlight.App.Models.Notifications; using Moonlight.App.Models.Notifications;
using Moonlight.App.Repositories; using Moonlight.App.Repositories;
@@ -12,135 +14,156 @@ using Newtonsoft.Json;
namespace Moonlight.App.Http.Controllers.Api.Moonlight.Notifications; namespace Moonlight.App.Http.Controllers.Api.Moonlight.Notifications;
public class ListenController : ControllerBase [ApiController]
[Route("api/moonlight/notification/listen")]
public class ListenController : Controller
{ {
internal WebSocket ws; private WebSocket WebSocket;
private bool active = true;
private bool isAuth = false;
private NotificationClient Client; private NotificationClient Client;
private CancellationTokenSource CancellationTokenSource = new();
private readonly IdentityService IdentityService;
private readonly NotificationRepository NotificationRepository;
private readonly OneTimeJwtService OneTimeJwtService;
private readonly NotificationClientService NotificationClientService;
private readonly NotificationServerService NotificationServerService;
public ListenController(IdentityService identityService, private User? CurrentUser;
NotificationRepository notificationRepository,
OneTimeJwtService oneTimeJwtService, private readonly OneTimeJwtService OneTimeJwtService;
NotificationClientService notificationClientService, private readonly NotificationServerService NotificationServerService;
NotificationServerService notificationServerService) private readonly Repository<NotificationClient> NotificationClientRepository;
public ListenController(
OneTimeJwtService oneTimeJwtService,
NotificationServerService notificationServerService, Repository<NotificationClient> notificationClientRepository)
{ {
IdentityService = identityService;
NotificationRepository = notificationRepository;
OneTimeJwtService = oneTimeJwtService; OneTimeJwtService = oneTimeJwtService;
NotificationClientService = notificationClientService;
NotificationServerService = notificationServerService; NotificationServerService = notificationServerService;
NotificationClientRepository = notificationClientRepository;
} }
[Route("/api/moonlight/notifications/listen")] [Route("/api/moonlight/notifications/listen")]
public async Task Get() public async Task<ActionResult> Get()
{ {
if (HttpContext.WebSockets.IsWebSocketRequest) if (HttpContext.WebSockets.IsWebSocketRequest)
{ {
using var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync(); WebSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
ws = webSocket;
await Echo(); await ProcessWebsocket();
return new EmptyResult();
} }
else else
{ {
HttpContext.Response.StatusCode = StatusCodes.Status403Forbidden; return StatusCode(400);
} }
} }
private async Task Echo() private async Task ProcessWebsocket()
{ {
while (active) while (!CancellationTokenSource.Token.IsCancellationRequested && WebSocket.State == WebSocketState.Open)
{ {
byte[] bytes = new byte[1024 * 16]; try
var asg = new ArraySegment<byte>(bytes);
var res = await ws.ReceiveAsync(asg, CancellationToken.None);
var text = Encoding.UTF8.GetString(bytes).Trim('\0');
var obj = JsonConvert.DeserializeObject<BasicWSModel>(text);
if (!string.IsNullOrWhiteSpace(obj.Action))
{ {
await HandleRequest(text, obj.Action); byte[] buffer = new byte[1024 * 16];
_ = await WebSocket.ReceiveAsync(buffer, CancellationTokenSource.Token);
var text = Encoding.UTF8.GetString(buffer).Trim('\0');
var basicWsModel = JsonConvert.DeserializeObject<BasicWSModel>(text) ?? new();
if (!string.IsNullOrWhiteSpace(basicWsModel.Action))
{
await HandleRequest(text, basicWsModel.Action);
}
if (WebSocket.State != WebSocketState.Open)
{
CancellationTokenSource.Cancel();
}
}
catch (WebSocketException e)
{
CancellationTokenSource.Cancel();
} }
active = ws.State == WebSocketState.Open;
} }
await NotificationServerService.UnRegisterClient(Client);
} }
private async Task HandleRequest(string text, string action) private async Task HandleRequest(string text, string action)
{ {
if (!isAuth && action == "login") if (CurrentUser == null && action != "login")
await Login(text);
else if (!isAuth)
await ws.SendAsync(Encoding.UTF8.GetBytes("{\"error\": \"Unauthorised\"}"), WebSocketMessageType.Text,
WebSocketMessageFlags.EndOfMessage, CancellationToken.None);
else switch (action)
{ {
await Send("{\"error\": \"Unauthorised\"}");
}
switch (action)
{
case "login":
await Login(text);
break;
case "received": case "received":
await Received(text); await Received(text);
break; break;
case "read": case "read":
await Read(text); await Read(text);
break; break;
default:
break;
} }
} }
private async Task Send(string text)
{
await WebSocket.SendAsync(
Encoding.UTF8.GetBytes(text),
WebSocketMessageType.Text,
WebSocketMessageFlags.EndOfMessage, CancellationTokenSource.Token
);
}
private async Task Login(string json) private async Task Login(string json)
{ {
var jwt = JsonConvert.DeserializeObject<Login>(json).token; var loginModel = JsonConvert.DeserializeObject<Login>(json) ?? new();
var dict = await OneTimeJwtService.Validate(jwt); var dict = await OneTimeJwtService.Validate(loginModel.Token);
if (dict == null) if (dict == null)
{ {
string error = "{\"status\":false}"; await Send("{\"status\":false}");
var bytes = Encoding.UTF8.GetBytes(error);
await ws.SendAsync(bytes, WebSocketMessageType.Text, WebSocketMessageFlags.EndOfMessage, CancellationToken.None);
return; return;
} }
var _clientId = dict["clientId"]; if (!int.TryParse(dict["clientId"], out int clientId))
var clientId = int.Parse(_clientId); {
await Send("{\"status\":false}");
return;
}
var client = NotificationRepository.GetClients().Include(x => x.User).First(x => x.Id == clientId); Client = NotificationClientRepository
.Get()
.Include(x => x.User)
.First(x => x.Id == clientId);
Client = client; CurrentUser = Client.User;
await InitWebsocket();
string success = "{\"status\":true}";
var byt = Encoding.UTF8.GetBytes(success);
await ws.SendAsync(byt, WebSocketMessageType.Text, WebSocketMessageFlags.EndOfMessage, CancellationToken.None);
}
private async Task InitWebsocket() await NotificationServerService.RegisterClient(WebSocket, Client);
{
NotificationClientService.listenController = this;
NotificationClientService.WebsocketReady(Client);
isAuth = true; await Send("{\"status\":true}");
} }
private async Task Received(string json) private async Task Received(string json)
{ {
var id = JsonConvert.DeserializeObject<NotificationById>(json).notification; var id = JsonConvert.DeserializeObject<NotificationById>(json).Notification;
//TODO: Implement ws notification received //TODO: Implement ws notification received
} }
private async Task Read(string json) private async Task Read(string json)
{ {
var id = JsonConvert.DeserializeObject<NotificationById>(json).notification; var model = JsonConvert.DeserializeObject<NotificationById>(json) ?? new();
await NotificationServerService.SendAction(NotificationClientService.User, await NotificationServerService.SendAction(
JsonConvert.SerializeObject(new NotificationById() {Action = "hide", notification = id})); CurrentUser!,
JsonConvert.SerializeObject(
new NotificationById()
{
Action = "hide", Notification = model.Notification
}
)
);
} }
} }

View File

@@ -0,0 +1,19 @@
using System.Net.WebSockets;
using System.Text;
using Moonlight.App.Database.Entities.Notification;
namespace Moonlight.App.Models.Misc;
public class ActiveNotificationClient
{
public WebSocket WebSocket { get; set; }
public NotificationClient Client { get; set; }
public async Task SendAction(string action)
{
await WebSocket.SendAsync(
Encoding.UTF8.GetBytes(action),
WebSocketMessageType.Text,
WebSocketMessageFlags.EndOfMessage, CancellationToken.None);
}
}

View File

@@ -1,6 +1,8 @@
namespace Moonlight.App.Models.Notifications; using Newtonsoft.Json;
namespace Moonlight.App.Models.Notifications;
public class Login : BasicWSModel public class Login : BasicWSModel
{ {
public string token { get; set; } [JsonProperty("token")] public string Token { get; set; } = "";
} }

View File

@@ -1,6 +1,9 @@
namespace Moonlight.App.Models.Notifications; using Newtonsoft.Json;
namespace Moonlight.App.Models.Notifications;
public class NotificationById : BasicWSModel public class NotificationById : BasicWSModel
{ {
public int notification { get; set; } [JsonProperty("notification")]
public int Notification { get; set; }
} }

View File

@@ -46,13 +46,11 @@ public class CleanupService
var config = ConfigService.GetSection("Moonlight").GetSection("Cleanup"); var config = ConfigService.GetSection("Moonlight").GetSection("Cleanup");
/* if (!config.GetValue<bool>("Enable") || ConfigService.DebugMode)
* if (!config.GetValue<bool>("Enable") || ConfigService.DebugMode)
{ {
Logger.Info("Disabling cleanup service"); Logger.Info("Disabling cleanup service");
return; return;
} }
*/
Timer = new(TimeSpan.FromMinutes(config.GetValue<int>("Wait"))); Timer = new(TimeSpan.FromMinutes(config.GetValue<int>("Wait")));

View File

@@ -33,9 +33,6 @@ public class MoonlightService
private async Task FetchChangeLog() private async Task FetchChangeLog()
{ {
if(AppVersion == "unknown")
return;
if (ConfigService.DebugMode) if (ConfigService.DebugMode)
{ {
ChangeLog.Add(new[] ChangeLog.Add(new[]

View File

@@ -1,43 +0,0 @@
using System.Net.WebSockets;
using System.Text;
using Moonlight.App.Database.Entities;
using Moonlight.App.Database.Entities.Notification;
using Moonlight.App.Http.Controllers.Api.Moonlight.Notifications;
using Moonlight.App.Repositories;
using Moonlight.App.Services.Sessions;
namespace Moonlight.App.Services.Notifications;
public class NotificationClientService
{
private readonly NotificationRepository NotificationRepository;
private readonly NotificationServerService NotificationServerService;
internal ListenController listenController;
public NotificationClientService(NotificationRepository notificationRepository, NotificationServerService notificationServerService)
{
NotificationRepository = notificationRepository;
NotificationServerService = notificationServerService;
}
public User User => NotificationClient.User;
public NotificationClient NotificationClient { get; set; }
public async Task SendAction(string action)
{
await listenController.ws.SendAsync(Encoding.UTF8.GetBytes(action), WebSocketMessageType.Text,
WebSocketMessageFlags.EndOfMessage, CancellationToken.None);
}
public void WebsocketReady(NotificationClient client)
{
NotificationClient = client;
NotificationServerService.AddClient(this);
}
public void WebsocketClosed()
{
NotificationServerService.RemoveClient(this);
}
}

View File

@@ -1,84 +1,113 @@
using Microsoft.EntityFrameworkCore; using System.Net.WebSockets;
using System.Text;
using Microsoft.EntityFrameworkCore;
using Moonlight.App.Database.Entities; using Moonlight.App.Database.Entities;
using Moonlight.App.Database.Entities.Notification; using Moonlight.App.Database.Entities.Notification;
using Moonlight.App.Events;
using Moonlight.App.Models.Misc;
using Moonlight.App.Repositories; using Moonlight.App.Repositories;
namespace Moonlight.App.Services.Notifications; namespace Moonlight.App.Services.Notifications;
public class NotificationServerService public class NotificationServerService
{ {
private UserRepository UserRepository; private readonly List<ActiveNotificationClient> ActiveClients = new();
private NotificationRepository NotificationRepository;
private readonly IServiceScopeFactory ServiceScopeFactory; private readonly IServiceScopeFactory ServiceScopeFactory;
private IServiceScope ServiceScope; private readonly EventSystem Event;
public NotificationServerService(IServiceScopeFactory serviceScopeFactory) public NotificationServerService(IServiceScopeFactory serviceScopeFactory, EventSystem eventSystem)
{ {
ServiceScopeFactory = serviceScopeFactory; ServiceScopeFactory = serviceScopeFactory;
Task.Run(Run); Event = eventSystem;
}
private Task Run()
{
ServiceScope = ServiceScopeFactory.CreateScope();
UserRepository = ServiceScope
.ServiceProvider
.GetRequiredService<UserRepository>();
NotificationRepository = ServiceScope
.ServiceProvider
.GetRequiredService<NotificationRepository>();
return Task.CompletedTask;
} }
private List<NotificationClientService> connectedClients = new(); public Task<ActiveNotificationClient[]> GetActiveClients()
public List<NotificationClientService> GetConnectedClients()
{ {
return connectedClients.ToList(); lock (ActiveClients)
{
return Task.FromResult(ActiveClients.ToArray());
}
} }
public List<NotificationClientService> GetConnectedClients(User user) public Task<ActiveNotificationClient[]> GetUserClients(User user)
{ {
return connectedClients.Where(x => x.User == user).ToList(); lock (ActiveClients)
{
return Task.FromResult(
ActiveClients
.Where(x => x.Client.User.Id == user.Id)
.ToArray()
);
}
} }
public async Task SendAction(User user, string action) public async Task SendAction(User user, string action)
{ {
var clients = NotificationRepository.GetClients().Include(x => x.User).Where(x => x.User == user).ToList(); using var scope = ServiceScopeFactory.CreateScope();
var notificationClientRepository =
scope.ServiceProvider.GetRequiredService<Repository<NotificationClient>>();
var clients = notificationClientRepository
.Get()
.Include(x => x.User)
.Where(x => x.User == user)
.ToList();
foreach (var client in clients) foreach (var client in clients)
{ {
var notificationAction = new NotificationAction() ActiveNotificationClient[] connectedUserClients;
{
Action = action,
NotificationClient = client
};
var connected = connectedClients.Where(x => x.NotificationClient.Id == client.Id).ToList();
if (connected.Count > 0) lock (ActiveClients)
{ {
var clientService = connected[0]; connectedUserClients = ActiveClients
await clientService.SendAction(action); .Where(x => x.Client.Id == user.Id)
.ToArray();
}
if (connectedUserClients.Length > 0)
{
await connectedUserClients[0].SendAction(action);
} }
else else
{ {
NotificationRepository.AddAction(notificationAction); var notificationAction = new NotificationAction()
{
Action = action,
NotificationClient = client
};
var notificationActionsRepository =
scope.ServiceProvider.GetRequiredService<Repository<NotificationAction>>();
notificationActionsRepository.Add(notificationAction);
} }
} }
} }
public void AddClient(NotificationClientService notificationClientService) public async Task RegisterClient(WebSocket webSocket, NotificationClient notificationClient)
{ {
connectedClients.Add(notificationClientService); var newClient = new ActiveNotificationClient()
{
WebSocket = webSocket,
Client = notificationClient
};
lock (ActiveClients)
{
ActiveClients.Add(newClient);
}
await Event.Emit("notifications.addClient", notificationClient);
} }
public void RemoveClient(NotificationClientService notificationClientService) public async Task UnRegisterClient(NotificationClient client)
{ {
connectedClients.Remove(notificationClientService); lock (ActiveClients)
{
ActiveClients.RemoveAll(x => x.Client == client);
}
await Event.Emit("notifications.removeClient", client);
} }
} }

View File

@@ -159,8 +159,17 @@ public class IdentityService
try try
{ {
var userAgent = HttpContextAccessor.HttpContext.Request.Headers.UserAgent.ToString();
if (userAgent.Contains("Moonlight.App"))
{
var version = userAgent.Remove(0, "Moonlight.App/".Length).Split(' ').FirstOrDefault();
return "Moonlight App " + version;
}
var uaParser = Parser.GetDefault(); var uaParser = Parser.GetDefault();
var info = uaParser.Parse(HttpContextAccessor.HttpContext.Request.Headers.UserAgent); var info = uaParser.Parse(userAgent);
return $"{info.OS} - {info.Device}"; return $"{info.OS} - {info.Device}";
} }

View File

@@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore; using System.Net;
using DnsClient;
using Logging.Net;
using Microsoft.EntityFrameworkCore;
using Moonlight.App.ApiClients.CloudPanel; using Moonlight.App.ApiClients.CloudPanel;
using Moonlight.App.ApiClients.CloudPanel.Requests; using Moonlight.App.ApiClients.CloudPanel.Requests;
using Moonlight.App.Database.Entities; using Moonlight.App.Database.Entities;
@@ -18,7 +21,8 @@ public class WebSpaceService
private readonly CloudPanelApiHelper CloudPanelApiHelper; private readonly CloudPanelApiHelper CloudPanelApiHelper;
public WebSpaceService(Repository<CloudPanel> cloudPanelRepository, Repository<WebSpace> webSpaceRepository, CloudPanelApiHelper cloudPanelApiHelper, Repository<MySqlDatabase> databaseRepository) public WebSpaceService(Repository<CloudPanel> cloudPanelRepository, Repository<WebSpace> webSpaceRepository,
CloudPanelApiHelper cloudPanelApiHelper, Repository<MySqlDatabase> databaseRepository)
{ {
CloudPanelRepository = cloudPanelRepository; CloudPanelRepository = cloudPanelRepository;
WebSpaceRepository = webSpaceRepository; WebSpaceRepository = webSpaceRepository;
@@ -37,7 +41,7 @@ public class WebSpaceService
var ftpPassword = StringHelper.GenerateString(16); var ftpPassword = StringHelper.GenerateString(16);
var phpVersion = "8.1"; // TODO: Add config option or smth var phpVersion = "8.1"; // TODO: Add config option or smth
var w = new WebSpace() var w = new WebSpace()
{ {
CloudPanel = cloudPanel, CloudPanel = cloudPanel,
@@ -83,9 +87,9 @@ public class WebSpaceService
{ {
await DeleteDatabase(webSpace, database); await DeleteDatabase(webSpace, database);
} }
await CloudPanelApiHelper.Delete(webSpace.CloudPanel, $"site/{webSpace.Domain}", null); await CloudPanelApiHelper.Delete(webSpace.CloudPanel, $"site/{webSpace.Domain}", null);
WebSpaceRepository.Delete(webSpace); WebSpaceRepository.Delete(webSpace);
} }
@@ -109,7 +113,7 @@ public class WebSpaceService
return false; return false;
} }
public async Task<bool> IsHostUp(WebSpace w) public async Task<bool> IsHostUp(WebSpace w)
{ {
var webSpace = EnsureData(w); var webSpace = EnsureData(w);
@@ -121,6 +125,52 @@ public class WebSpaceService
{ {
var webspace = EnsureData(w); var webspace = EnsureData(w);
var dns = new LookupClient(new LookupClientOptions()
{
CacheFailedResults = false,
UseCache = false
});
var ipOfWebspaceQuery = await dns.QueryAsync(
webspace.Domain,
QueryType.A
);
var ipOfWebspaceWwwQuery = await dns.QueryAsync(
"www." + webspace.Domain,
QueryType.CNAME
);
var ipOfWebspace = ipOfWebspaceQuery.Answers.ARecords().FirstOrDefault();
var ipOfWebspaceWww = ipOfWebspaceWwwQuery.Answers.CnameRecords().FirstOrDefault();
if (ipOfWebspace == null)
throw new DisplayException($"Unable to find any a records for {webspace.Domain}", true);
if (ipOfWebspaceWww == null)
throw new DisplayException($"Unable to find any cname records for www.{webspace.Domain}", true);
var ipOfHostQuery = await dns.QueryAsync(
webspace.CloudPanel.Host,
QueryType.A
);
var ipOfHost = ipOfHostQuery.Answers.ARecords().FirstOrDefault();
if (ipOfHost == null)
throw new DisplayException("Unable to find a record of host system");
if (ipOfHost.Address.ToString() != ipOfWebspace.Address.ToString())
throw new DisplayException("The dns records of your webspace do not point to the host system");
Logger.Debug($"{ipOfWebspaceWww.CanonicalName.Value}");
if (ipOfWebspaceWww.CanonicalName.Value != webspace.CloudPanel.Host + ".")
throw new DisplayException(
$"The dns record www.{webspace.Domain} does not point to {webspace.CloudPanel.Host}", true);
await CloudPanelApiHelper.Post(webspace.CloudPanel, "letsencrypt/install/certificate", new InstallLetsEncrypt() await CloudPanelApiHelper.Post(webspace.CloudPanel, "letsencrypt/install/certificate", new InstallLetsEncrypt()
{ {
DomainName = webspace.Domain DomainName = webspace.Domain
@@ -158,7 +208,7 @@ public class WebSpaceService
DatabaseUserName = database.UserName, DatabaseUserName = database.UserName,
DatabaseUserPassword = database.Password DatabaseUserPassword = database.Password
}); });
webspace.Databases.Add(database); webspace.Databases.Add(database);
WebSpaceRepository.Update(webspace); WebSpaceRepository.Update(webspace);
} }
@@ -166,7 +216,7 @@ public class WebSpaceService
public async Task DeleteDatabase(WebSpace w, MySqlDatabase database) public async Task DeleteDatabase(WebSpace w, MySqlDatabase database)
{ {
var webspace = EnsureData(w); var webspace = EnsureData(w);
await CloudPanelApiHelper.Delete(webspace.CloudPanel, $"db/{database.UserName}", null); await CloudPanelApiHelper.Delete(webspace.CloudPanel, $"db/{database.UserName}", null);
webspace.Databases.Remove(database); webspace.Databases.Remove(database);
@@ -180,7 +230,8 @@ public class WebSpaceService
var webspace = EnsureData(w); var webspace = EnsureData(w);
return Task.FromResult<FileAccess>( return Task.FromResult<FileAccess>(
new SftpFileAccess(webspace.CloudPanel.Host, webspace.UserName, webspace.Password, 22, true, $"/htdocs/{webspace.Domain}") new SftpFileAccess(webspace.CloudPanel.Host, webspace.UserName, webspace.Password, 22, true,
$"/htdocs/{webspace.Domain}")
); );
} }
@@ -192,7 +243,7 @@ public class WebSpaceService
.Include(x => x.CloudPanel) .Include(x => x.CloudPanel)
.Include(x => x.Owner) .Include(x => x.Owner)
.First(x => x.Id == webSpace.Id); .First(x => x.Id == webSpace.Id);
return webSpace; return webSpace;
} }
} }

View File

@@ -21,6 +21,7 @@
<PackageReference Include="CurrieTechnologies.Razor.SweetAlert2" Version="5.4.0" /> <PackageReference Include="CurrieTechnologies.Razor.SweetAlert2" Version="5.4.0" />
<PackageReference Include="Discord.Net" Version="3.10.0" /> <PackageReference Include="Discord.Net" Version="3.10.0" />
<PackageReference Include="Discord.Net.Webhook" Version="3.10.0" /> <PackageReference Include="Discord.Net.Webhook" Version="3.10.0" />
<PackageReference Include="DnsClient" Version="1.7.0" />
<PackageReference Include="FluentFTP" Version="46.0.2" /> <PackageReference Include="FluentFTP" Version="46.0.2" />
<PackageReference Include="GravatarSharp.Core" Version="1.0.1.2" /> <PackageReference Include="GravatarSharp.Core" Version="1.0.1.2" />
<PackageReference Include="JWT" Version="10.0.2" /> <PackageReference Include="JWT" Version="10.0.2" />

View File

@@ -118,7 +118,6 @@ namespace Moonlight
builder.Services.AddScoped<OneTimeJwtService>(); builder.Services.AddScoped<OneTimeJwtService>();
builder.Services.AddSingleton<NotificationServerService>(); builder.Services.AddSingleton<NotificationServerService>();
builder.Services.AddScoped<NotificationAdminService>(); builder.Services.AddScoped<NotificationAdminService>();
builder.Services.AddScoped<NotificationClientService>();
builder.Services.AddScoped<ModalService>(); builder.Services.AddScoped<ModalService>();
builder.Services.AddScoped<SmartDeployService>(); builder.Services.AddScoped<SmartDeployService>();
builder.Services.AddScoped<WebSpaceService>(); builder.Services.AddScoped<WebSpaceService>();

View File

@@ -47,9 +47,18 @@ else
if (exception is DisplayException displayException) if (exception is DisplayException displayException)
{ {
await AlertService.Error( if (displayException.DoNotTranslate)
SmartTranslateService.Translate(displayException.Message) {
); await AlertService.Error(
displayException.Message
);
}
else
{
await AlertService.Error(
SmartTranslateService.Translate(displayException.Message)
);
}
} }
else if (exception is CloudflareException cloudflareException) else if (exception is CloudflareException cloudflareException)
{ {

View File

@@ -40,116 +40,120 @@
} }
} }
<CascadingValue Value="User"> <GlobalErrorBoundary>
<PageTitle>@(string.IsNullOrEmpty(title) ? "Dashboard - " : title)Moonlight</PageTitle> <CascadingValue Value="User">
<PageTitle>@(string.IsNullOrEmpty(title) ? "Dashboard - " : title)Moonlight</PageTitle>
<div class="d-flex flex-column flex-root app-root" id="kt_app_root"> <div class="d-flex flex-column flex-root app-root" id="kt_app_root">
<div class="app-page flex-column flex-column-fluid" id="kt_app_page"> <div class="app-page flex-column flex-column-fluid" id="kt_app_page">
<canvas id="snow" class="snow-canvas"></canvas> <canvas id="snow" class="snow-canvas"></canvas>
@{ @{
//TODO: Add a way to disable the snow //TODO: Add a way to disable the snow
} }
<PageHeader></PageHeader> <PageHeader></PageHeader>
<div class="app-wrapper flex-column flex-row-fluid" id="kt_app_wrapper"> <div class="app-wrapper flex-column flex-row-fluid" id="kt_app_wrapper">
<Sidebar></Sidebar> <Sidebar></Sidebar>
<div class="app-main flex-column flex-row-fluid" id="kt_app_main"> <div class="app-main flex-column flex-row-fluid" id="kt_app_main">
<div class="d-flex flex-column flex-column-fluid"> <div class="d-flex flex-column flex-column-fluid">
<div id="kt_app_content" class="app-content flex-column-fluid" style="background-position: center; background-size: cover; background-repeat: no-repeat; background-attachment: fixed; background-image: url('@(DynamicBackgroundService.BackgroundImageUrl)')"> <div id="kt_app_content" class="app-content flex-column-fluid" style="background-position: center; background-size: cover; background-repeat: no-repeat; background-attachment: fixed; background-image: url('@(DynamicBackgroundService.BackgroundImageUrl)')">
<div id="kt_app_content_container" class="app-container container-fluid"> <div id="kt_app_content_container" class="app-container container-fluid">
<div class="mt-10"> <div class="mt-10">
@if (!IsIpBanned) <SoftErrorBoundary>
{ @if (!IsIpBanned)
if (UserProcessed)
{
if (uri.LocalPath != "/login" &&
uri.LocalPath != "/passwordreset" &&
uri.LocalPath != "/register")
{ {
if (User == null) if (UserProcessed)
{ {
<Login></Login> if (uri.LocalPath != "/login" &&
} uri.LocalPath != "/passwordreset" &&
else uri.LocalPath != "/register")
{
if (User.Status == UserStatus.Banned)
{ {
<BannedAlert></BannedAlert> if (User == null)
} {
else if (User.Status == UserStatus.Disabled) <Login></Login>
{ }
<DisabledAlert></DisabledAlert> else
} {
else if (User.Status == UserStatus.PasswordPending) if (User.Status == UserStatus.Banned)
{ {
<PasswordChangeView></PasswordChangeView> <BannedAlert></BannedAlert>
} }
else if (User.Status == UserStatus.DataPending) else if (User.Status == UserStatus.Disabled)
{ {
<UserDataSetView></UserDataSetView> <DisabledAlert></DisabledAlert>
}
else if (User.Status == UserStatus.PasswordPending)
{
<PasswordChangeView></PasswordChangeView>
}
else if (User.Status == UserStatus.DataPending)
{
<UserDataSetView></UserDataSetView>
}
else
{
@Body
<RatingPopup/>
}
}
} }
else else
{ {
@Body if (uri.LocalPath == "/login")
{
<RatingPopup/> <Login></Login>
}
else if (uri.LocalPath == "/register")
{
<Register></Register>
}
else if (uri.LocalPath == "/passwordreset")
{
<PasswordReset></PasswordReset>
}
} }
} }
else
{
<div class="modal d-block">
<div class="modal-dialog modal-dialog-centered mw-900px">
<div class="modal-content">
<div class="pt-2 modal-body py-lg-10 px-lg-10">
<h2>@(SmartTranslateService.Translate("Authenticating"))...</h2>
<p class="mt-3 fw-normal fs-6">@(SmartTranslateService.Translate("Verifying token, loading user data"))</p>
</div>
</div>
</div>
</div>
}
} }
else else
{ {
if (uri.LocalPath == "/login") <div class="modal d-block">
{ <div class="modal-dialog modal-dialog-centered mw-900px">
<Login></Login> <div class="modal-content">
} <div class="pt-2 modal-body py-lg-10 px-lg-10">
else if (uri.LocalPath == "/register") <h2>@(SmartTranslateService.Translate("Your ip has been banned"))</h2>
{ <p class="mt-3 fw-normal fs-6">@(SmartTranslateService.Translate("Your ip address has been banned by an admin"))</p>
<Register></Register> </div>
}
else if (uri.LocalPath == "/passwordreset")
{
<PasswordReset></PasswordReset>
}
}
}
else
{
<div class="modal d-block">
<div class="modal-dialog modal-dialog-centered mw-900px">
<div class="modal-content">
<div class="pt-2 modal-body py-lg-10 px-lg-10">
<h2>@(SmartTranslateService.Translate("Authenticating"))...</h2>
<p class="mt-3 fw-normal fs-6">@(SmartTranslateService.Translate("Verifying token, loading user data"))</p>
</div> </div>
</div> </div>
</div> </div>
</div> }
} </SoftErrorBoundary>
} </div>
else
{
<div class="modal d-block">
<div class="modal-dialog modal-dialog-centered mw-900px">
<div class="modal-content">
<div class="pt-2 modal-body py-lg-10 px-lg-10">
<h2>@(SmartTranslateService.Translate("Your ip has been banned"))</h2>
<p class="mt-3 fw-normal fs-6">@(SmartTranslateService.Translate("Your ip address has been banned by an admin"))</p>
</div>
</div>
</div>
</div>
}
</div> </div>
</div> </div>
</div> </div>
<Footer></Footer>
</div> </div>
<Footer></Footer>
</div> </div>
</div> </div>
</div> </div>
</div> </CascadingValue>
</CascadingValue> </GlobalErrorBoundary>
@code @code
{ {

View File

@@ -1,33 +1,74 @@
@page "/admin/notifications/debugging" @page "/admin/notifications/debugging"
@using Moonlight.App.Services.Notifications @using Moonlight.App.Services.Notifications
@using Moonlight.App.Models.Misc
@using Moonlight.App.Events
@using BlazorTable
@using Moonlight.App.Database.Entities.Notification
@using Moonlight.App.Services
@inject NotificationServerService NotificationServerService @inject NotificationServerService NotificationServerService
@inject SmartTranslateService SmartTranslateService
@inject EventSystem Event
@implements IDisposable
<OnlyAdmin> <OnlyAdmin>
<LazyLoader Load="Load"> <LazyLoader Load="Load">
<h1>Notification Debugging</h1> <div class="card card-body">
@foreach (var client in Clients) <Table TableItem="ActiveNotificationClient" Items="Clients" PageSize="25" TableClass="table table-row-bordered table-row-gray-100 align-middle gs-0 gy-3" TableHeadClass="fw-bold text-muted">
{ <Column TableItem="ActiveNotificationClient" Title="@(SmartTranslateService.Translate("Id"))" Field="@(x => x.Client.Id)" Sortable="false" Filterable="true"/>
<hr/> <Column TableItem="ActiveNotificationClient" Title="@(SmartTranslateService.Translate("User"))" Field="@(x => x.Client.User.Email)" Sortable="false" Filterable="true"/>
<div> <Column TableItem="ActiveNotificationClient" Title="" Field="@(x => x.Client.Id)" Sortable="false" Filterable="false">
<p>Id: @client.NotificationClient.Id User: @client.User.Email</p> <Template>
<button @onclick="async () => await SendSampleNotification(client)"></button> <WButton Text="@(SmartTranslateService.Translate("Send notification"))"
</div> WorkingText="@(SmartTranslateService.Translate("Working"))"
} CssClasses="btn-primary"
OnClick="() => SendSampleNotification(context)">
</WButton>
</Template>
</Column>
<Pager ShowPageNumber="true" ShowTotalCount="true"/>
</Table>
</div>
</LazyLoader> </LazyLoader>
</OnlyAdmin> </OnlyAdmin>
@code { @code
private List<NotificationClientService> Clients; {
private ActiveNotificationClient[] Clients;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await Event.On<NotificationClient>("notifications.addClient", this, async client =>
{
Clients = await NotificationServerService.GetActiveClients();
await InvokeAsync(StateHasChanged);
});
await Event.On<NotificationClient>("notifications.removeClient", this, async client =>
{
Clients = await NotificationServerService.GetActiveClients();
await InvokeAsync(StateHasChanged);
});
}
}
private async Task Load(LazyLoader loader) private async Task Load(LazyLoader loader)
{ {
Clients = NotificationServerService.GetConnectedClients(); Clients = await NotificationServerService.GetActiveClients();
} }
private async Task SendSampleNotification(NotificationClientService client) private async Task SendSampleNotification(ActiveNotificationClient client)
{ {
await client.SendAction(@"{""action"": ""notify"",""notification"":{""id"":999,""channel"":""Sample Channel"",""content"":""This is a sample Notification"",""title"":""Sample Notification""}}"); await client.SendAction(@"{""action"": ""notify"",""notification"":{""id"":999,""channel"":""Sample Channel"",""content"":""This is a sample Notification"",""title"":""Sample Notification"",""url"":""server/9b724fe2-d882-49c9-8c34-3414c7e4a17e""}}");
}
public async void Dispose()
{
await Event.Off("notifications.addClient", this);
await Event.Off("notifications.removeClient", this);
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB