diff --git a/Moonlight/App/Services/WebsiteService.cs b/Moonlight/App/Services/WebsiteService.cs index 44b2994..ad85d48 100644 --- a/Moonlight/App/Services/WebsiteService.cs +++ b/Moonlight/App/Services/WebsiteService.cs @@ -16,12 +16,14 @@ public class WebsiteService private readonly WebsiteRepository WebsiteRepository; private readonly PleskServerRepository PleskServerRepository; private readonly PleskApiHelper PleskApiHelper; + private readonly UserRepository UserRepository; - public WebsiteService(WebsiteRepository websiteRepository, PleskApiHelper pleskApiHelper, PleskServerRepository pleskServerRepository) + public WebsiteService(WebsiteRepository websiteRepository, PleskApiHelper pleskApiHelper, PleskServerRepository pleskServerRepository, UserRepository userRepository) { WebsiteRepository = websiteRepository; PleskApiHelper = pleskApiHelper; PleskServerRepository = pleskServerRepository; + UserRepository = userRepository; } public async Task Create(string baseDomain, User owner, PleskServer? ps = null) @@ -149,8 +151,6 @@ public class WebsiteService { var website = EnsureData(w); var certs = new List(); - - Logger.Debug("1"); var data = await ExecuteCli(website.PleskServer, "certificate", p => { @@ -158,9 +158,7 @@ public class WebsiteService p.Add("-domain"); p.Add(w.BaseDomain); }); - - Logger.Debug("2"); - + string[] lines = data.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) @@ -169,11 +167,6 @@ public class WebsiteService { string[] parts = line.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); - foreach (var part in parts) - { - Logger.Debug(part); - } - if(parts.Length > 6) certs.Add($"{parts[4]} {parts[5]} {parts[6]}"); } @@ -187,9 +180,66 @@ public class WebsiteService return certs.ToArray(); } - public async Task CreateSslCertificate() + public async Task CreateSslCertificate(Website w) { - + var website = EnsureData(w); + + await ExecuteCli(website.PleskServer, "extension", p => + { + p.Add("--exec"); + p.Add("letsencrypt"); + p.Add("cli.php"); + p.Add("-d"); + p.Add(website.BaseDomain); + p.Add("-m"); + p.Add(website.Owner.Email); + }); + } + + public async Task DeleteSslCertificate(Website w, string name) + { + var website = EnsureData(w); + + try + { + await ExecuteCli(website.PleskServer, "site", p => + { + p.Add("-u"); + p.Add(website.BaseDomain); + p.Add("-ssl"); + p.Add("false"); + }); + + try + { + await ExecuteCli(website.PleskServer, "certificate", p => + { + p.Add("--remove"); + p.Add(name); + p.Add("-domain"); + p.Add(website.BaseDomain); + }); + } + catch (Exception e) + { + Logger.Warn("Error removing ssl certificate"); + Logger.Warn(e); + + throw new DisplayException("An unknown error occured while removing ssl certificate"); + } + } + catch (DisplayException) + { + // Redirect all display exception to soft error handler + throw; + } + catch (Exception e) + { + Logger.Warn("Error disabling ssl certificate"); + Logger.Warn(e); + + throw new DisplayException("An unknown error occured while disabling ssl certificate"); + } } public async Task CreateFileAccess(Website w) @@ -225,10 +275,11 @@ public class WebsiteService private Website EnsureData(Website website) { - if (website.PleskServer == null) + if (website.PleskServer == null || website.Owner == null) return WebsiteRepository .Get() .Include(x => x.PleskServer) + .Include(x => x.Owner) .First(x => x.Id == website.Id); return website; diff --git a/Moonlight/Shared/Components/WebsiteControl/WebsiteDashboard.razor b/Moonlight/Shared/Components/WebsiteControl/WebsiteDashboard.razor index 54cef8a..d499e87 100644 --- a/Moonlight/Shared/Components/WebsiteControl/WebsiteDashboard.razor +++ b/Moonlight/Shared/Components/WebsiteControl/WebsiteDashboard.razor @@ -15,11 +15,20 @@
- +
- SSL certificates + + SSL certificates + +
+ + +
@if (Certs.Any()) @@ -47,11 +56,6 @@ @(cert) - - - No SSL certificate found + No SSL certificates found
}
@@ -85,17 +89,23 @@ private string[] Certs; + private LazyLoader LazyLoader; + private async Task Load(LazyLoader lazyLoader) { await lazyLoader.SetText("Loading certificates"); Certs = await WebsiteService.GetSslCertificates(CurrentWebsite); } - private async Task UseCertificate(string name) + private async Task CreateCertificate() { + await WebsiteService.CreateSslCertificate(CurrentWebsite); + await LazyLoader.Reload(); } private async Task DeleteCertificate(string name) { + await WebsiteService.DeleteSslCertificate(CurrentWebsite, name); + await LazyLoader.Reload(); } } \ No newline at end of file diff --git a/Moonlight/Shared/Components/WebsiteControl/WebsiteNavigation.razor b/Moonlight/Shared/Components/WebsiteControl/WebsiteNavigation.razor index a2a16d8..bec6068 100644 --- a/Moonlight/Shared/Components/WebsiteControl/WebsiteNavigation.razor +++ b/Moonlight/Shared/Components/WebsiteControl/WebsiteNavigation.razor @@ -1,6 +1,6 @@ @using Moonlight.App.Database.Entities -
+
diff --git a/Moonlight/Shared/Views/Website/Index.razor b/Moonlight/Shared/Views/Website/Index.razor index 1cc614a..cc21a6b 100644 --- a/Moonlight/Shared/Views/Website/Index.razor +++ b/Moonlight/Shared/Views/Website/Index.razor @@ -4,9 +4,11 @@ @using Moonlight.App.Services @using Moonlight.Shared.Components.WebsiteControl @using Microsoft.EntityFrameworkCore +@using Moonlight.App.Services.Interop @inject WebsiteRepository WebsiteRepository @inject WebsiteService WebsiteService +@inject ToastService ToastService @if (CurrentWebsite == null) diff --git a/Moonlight/resources/lang/de_de.lang b/Moonlight/resources/lang/de_de.lang index 3bc9b90..a4f49ce 100644 --- a/Moonlight/resources/lang/de_de.lang +++ b/Moonlight/resources/lang/de_de.lang @@ -500,3 +500,9 @@ Ftp Password;Ftp Password Use;Use SSL Certificates;SSL Certificates SSL certificates;SSL certificates +Issue certificate;Issue certificate +New plesk server;New plesk server +Api url;Api url +Host system offline;Host system offline +The host system the website is running on is currently offline;The host system the website is running on is currently offline +No SSL certificates found;No SSL certificates found