Skip to content

Commit e7bcdf6

Browse files
Merge pull request #7 from atc-net/feature/maintenance
Feature/maintenance
2 parents f4d5c49 + 99cf2d7 commit e7bcdf6

File tree

56 files changed

+2124
-630
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2124
-630
lines changed

Directory.Build.props

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
<ItemGroup Label="Code Analyzers">
4242
<PackageReference Include="AsyncFixer" Version="1.6.0" PrivateAssets="All" />
4343
<PackageReference Include="Asyncify" Version="0.9.7" PrivateAssets="All" />
44-
<PackageReference Include="Meziantou.Analyzer" Version="2.0.92" PrivateAssets="All" />
44+
<PackageReference Include="Meziantou.Analyzer" Version="2.0.103" PrivateAssets="All" />
4545
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.7" PrivateAssets="All" />
4646
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507" PrivateAssets="All" />
47-
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.11.0.78383" PrivateAssets="All" />
47+
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.12.0.78982" PrivateAssets="All" />
4848
</ItemGroup>
4949

5050
</Project>

src/Atc.Installer.Integration.Azure/Atc.Installer.Integration.Azure.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Atc" Version="2.0.360" />
10-
<PackageReference Include="Azure.Identity" Version="1.10.1" />
11-
<PackageReference Include="Azure.Storage.Blobs" Version="12.18.0" />
9+
<PackageReference Include="Atc" Version="2.0.386" />
10+
<PackageReference Include="Azure.Identity" Version="1.10.3" />
11+
<PackageReference Include="Azure.Storage.Blobs" Version="12.19.0-beta.1" />
1212
</ItemGroup>
1313

1414
</Project>
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
global using System.Diagnostics.CodeAnalysis;
22
global using System.Runtime.CompilerServices;
3+
global using System.Security.Cryptography.X509Certificates;
34
global using System.ServiceProcess;
45
global using System.Xml.Linq;
6+
57
global using Atc.Helpers;
8+
global using Atc.Installer.Integration.Helpers;
69

710
global using Microsoft.Web.Administration;
811
global using Microsoft.Win32;

src/Atc.Installer.Integration.InternetInformationServer/IInternetInformationServerInstallerService.cs

+22
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ Task<bool> CreateApplicationPool(
4444
ushort timeoutInSeconds = 60,
4545
CancellationToken cancellationToken = default);
4646

47+
Task<bool> DeleteApplicationPool(
48+
string applicationPoolName,
49+
ushort timeoutInSeconds = 60,
50+
CancellationToken cancellationToken = default);
51+
4752
Task<bool> CreateWebsite(
4853
string websiteName,
4954
string applicationPoolName,
@@ -66,6 +71,11 @@ Task<bool> CreateWebsite(
6671
ushort timeoutInSeconds = 60,
6772
CancellationToken cancellationToken = default);
6873

74+
Task<bool> DeleteWebsite(
75+
string websiteName,
76+
ushort timeoutInSeconds = 60,
77+
CancellationToken cancellationToken = default);
78+
6979
Task<bool> StopApplicationPool(
7080
string applicationPoolName,
7181
ushort timeoutInSeconds = 60,
@@ -97,4 +107,16 @@ Task<bool> StartWebsiteAndApplicationPool(
97107
string applicationPoolName,
98108
ushort timeoutInSeconds = 60,
99109
CancellationToken cancellationToken = default);
110+
111+
IList<X509Certificate2> GetX509Certificates();
112+
113+
X509Certificate2? GetWebsiteX509Certificate(
114+
string websiteName);
115+
116+
bool AssignX509CertificateToWebsite(
117+
string websiteName,
118+
X509Certificate2 certificate);
119+
120+
bool UnAssignX509CertificateOnWebsite(
121+
string websiteName);
100122
}

src/Atc.Installer.Integration.InternetInformationServer/InternetInformationServerInstallerService.cs

+184-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ReSharper disable StringLiteralTypo
2+
// ReSharper disable LoopCanBeConvertedToQuery
23
namespace Atc.Installer.Integration.InternetInformationServer;
34

45
/// <summary>
@@ -168,7 +169,7 @@ public bool IsComponentInstalledUrlRewriteModule2()
168169
}
169170

170171
public string? ResolvedVirtualRootFolder(
171-
string folder)
172+
string? folder)
172173
=> folder is not null &&
173174
folder.StartsWith(@".\", StringComparison.Ordinal) &&
174175
IsInstalled &&
@@ -184,7 +185,7 @@ public bool IsComponentInstalledUrlRewriteModule2()
184185
arguments: "unlock config -section:\"system.webServer/modules\"")
185186
.ConfigureAwait(false);
186187

187-
if (isSuccessful && output is not null)
188+
if (isSuccessful && !string.IsNullOrEmpty(output))
188189
{
189190
return (IsSucceeded: false, ErrorMessage: null);
190191
}
@@ -222,7 +223,7 @@ await FileHelper
222223
public ComponentRunningState GetApplicationPoolState(
223224
string applicationPoolName)
224225
{
225-
ArgumentNullException.ThrowIfNull(applicationPoolName);
226+
ArgumentException.ThrowIfNullOrEmpty(applicationPoolName);
226227

227228
try
228229
{
@@ -252,7 +253,7 @@ public ComponentRunningState GetApplicationPoolState(
252253
public ComponentRunningState GetWebsiteState(
253254
string websiteName)
254255
{
255-
ArgumentNullException.ThrowIfNull(websiteName);
256+
ArgumentException.ThrowIfNullOrEmpty(websiteName);
256257

257258
try
258259
{
@@ -285,7 +286,7 @@ public Task<bool> CreateApplicationPool(
285286
ushort timeoutInSeconds = 60,
286287
CancellationToken cancellationToken = default)
287288
{
288-
ArgumentNullException.ThrowIfNull(applicationPoolName);
289+
ArgumentException.ThrowIfNullOrEmpty(applicationPoolName);
289290

290291
var applicationPoolState = GetApplicationPoolState(applicationPoolName);
291292
if (applicationPoolState != ComponentRunningState.NotAvailable)
@@ -311,6 +312,38 @@ public Task<bool> CreateApplicationPool(
311312
}
312313
}
313314

315+
public Task<bool> DeleteApplicationPool(
316+
string applicationPoolName,
317+
ushort timeoutInSeconds = 60,
318+
CancellationToken cancellationToken = default)
319+
{
320+
ArgumentException.ThrowIfNullOrEmpty(applicationPoolName);
321+
322+
var applicationPoolState = GetApplicationPoolState(applicationPoolName);
323+
if (applicationPoolState == ComponentRunningState.NotAvailable)
324+
{
325+
return Task.FromResult(false);
326+
}
327+
328+
try
329+
{
330+
using var serverManager = new ServerManager();
331+
var applicationPool = serverManager.ApplicationPools[applicationPoolName];
332+
if (applicationPool is null)
333+
{
334+
return Task.FromResult(false);
335+
}
336+
337+
applicationPool.Delete();
338+
serverManager.CommitChanges();
339+
return Task.FromResult(true);
340+
}
341+
catch
342+
{
343+
return Task.FromResult(false);
344+
}
345+
}
346+
314347
public Task<bool> CreateWebsite(
315348
string websiteName,
316349
string applicationPoolName,
@@ -345,8 +378,8 @@ public async Task<bool> CreateWebsite(
345378
ushort timeoutInSeconds = 60,
346379
CancellationToken cancellationToken = default)
347380
{
348-
ArgumentNullException.ThrowIfNull(websiteName);
349-
ArgumentNullException.ThrowIfNull(applicationPoolName);
381+
ArgumentException.ThrowIfNullOrEmpty(websiteName);
382+
ArgumentException.ThrowIfNullOrEmpty(applicationPoolName);
350383
ArgumentNullException.ThrowIfNull(physicalPath);
351384

352385
var websiteState = GetWebsiteState(websiteName);
@@ -416,6 +449,38 @@ public async Task<bool> CreateWebsite(
416449
}
417450
}
418451

452+
public Task<bool> DeleteWebsite(
453+
string websiteName,
454+
ushort timeoutInSeconds = 60,
455+
CancellationToken cancellationToken = default)
456+
{
457+
ArgumentException.ThrowIfNullOrEmpty(websiteName);
458+
459+
var websiteState = GetWebsiteState(websiteName);
460+
if (websiteState == ComponentRunningState.NotAvailable)
461+
{
462+
return Task.FromResult(false);
463+
}
464+
465+
try
466+
{
467+
using var serverManager = new ServerManager();
468+
var site = serverManager.Sites[websiteName];
469+
if (site is null)
470+
{
471+
return Task.FromResult(false);
472+
}
473+
474+
site.Delete();
475+
serverManager.CommitChanges();
476+
return Task.FromResult(true);
477+
}
478+
catch
479+
{
480+
return Task.FromResult(false);
481+
}
482+
}
483+
419484
public async Task<bool> StopApplicationPool(
420485
string applicationPoolName,
421486
ushort timeoutInSeconds = 60,
@@ -604,6 +669,118 @@ public async Task<bool> StartWebsiteAndApplicationPool(
604669
=> await StartApplicationPool(applicationPoolName, timeoutInSeconds, cancellationToken).ConfigureAwait(false) &&
605670
await StartWebsite(websiteName, timeoutInSeconds, cancellationToken).ConfigureAwait(false);
606671

672+
public IList<X509Certificate2> GetX509Certificates()
673+
=> CryptographyHelper.GetX509Certificates();
674+
675+
public X509Certificate2? GetWebsiteX509Certificate(
676+
string websiteName)
677+
{
678+
ArgumentException.ThrowIfNullOrEmpty(websiteName);
679+
680+
try
681+
{
682+
using var serverManager = new ServerManager();
683+
var site = serverManager.Sites[websiteName];
684+
if (site is null)
685+
{
686+
return null;
687+
}
688+
689+
foreach (var siteBinding in site.Bindings)
690+
{
691+
if (siteBinding.SslFlags == SslFlags.None ||
692+
!"https".Equals(siteBinding.Protocol, StringComparison.OrdinalIgnoreCase))
693+
{
694+
continue;
695+
}
696+
697+
return CryptographyHelper.FindX509Certificate(
698+
siteBinding.CertificateHash.ToHex(),
699+
Enum<StoreName>.Parse(siteBinding.CertificateStoreName));
700+
}
701+
702+
return null;
703+
}
704+
catch
705+
{
706+
return null;
707+
}
708+
}
709+
710+
public bool AssignX509CertificateToWebsite(
711+
string websiteName,
712+
X509Certificate2 certificate)
713+
{
714+
ArgumentException.ThrowIfNullOrEmpty(websiteName);
715+
ArgumentNullException.ThrowIfNull(certificate);
716+
717+
try
718+
{
719+
using var serverManager = new ServerManager();
720+
var site = serverManager.Sites[websiteName];
721+
if (site is null)
722+
{
723+
return false;
724+
}
725+
726+
foreach (var siteBinding in site.Bindings)
727+
{
728+
if (!"https".Equals(siteBinding.Protocol, StringComparison.OrdinalIgnoreCase))
729+
{
730+
continue;
731+
}
732+
733+
siteBinding.CertificateHash = certificate.GetCertHash();
734+
siteBinding.CertificateStoreName = nameof(StoreName.My);
735+
siteBinding.SslFlags = SslFlags.Sni;
736+
serverManager.CommitChanges();
737+
return true;
738+
}
739+
740+
return false;
741+
}
742+
catch
743+
{
744+
return false;
745+
}
746+
}
747+
748+
public bool UnAssignX509CertificateOnWebsite(
749+
string websiteName)
750+
{
751+
ArgumentException.ThrowIfNullOrEmpty(websiteName);
752+
753+
try
754+
{
755+
using var serverManager = new ServerManager();
756+
var site = serverManager.Sites[websiteName];
757+
if (site is null)
758+
{
759+
return false;
760+
}
761+
762+
foreach (var siteBinding in site.Bindings)
763+
{
764+
if (!"https".Equals(siteBinding.Protocol, StringComparison.OrdinalIgnoreCase))
765+
{
766+
continue;
767+
}
768+
769+
siteBinding.CertificateHash = null;
770+
siteBinding.CertificateStoreName = null;
771+
siteBinding.SslFlags = SslFlags.None;
772+
serverManager.CommitChanges();
773+
return true;
774+
}
775+
776+
return false;
777+
}
778+
catch
779+
{
780+
return false;
781+
}
782+
}
783+
607784
private string? GetResourceDefaultNodeJsUrlWebConfig()
608785
=> GetResourceTextFile("default-nodejs-urlrewrite-webconfig");
609786

src/Atc.Installer.Integration.PostgreSql/Atc.Installer.Integration.PostgreSql.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Npgsql" Version="8.0.0-preview.4" />
9+
<PackageReference Include="Npgsql" Version="8.0.0-rc.2" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

src/Atc.Installer.Integration.WindowsApplication/Atc.Installer.Integration.WindowsApplication.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Atc" Version="2.0.360" />
10-
<PackageReference Include="System.ServiceProcess.ServiceController" Version="8.0.0-rc.1.23419.4" />
9+
<PackageReference Include="Atc" Version="2.0.386" />
10+
<PackageReference Include="System.ServiceProcess.ServiceController" Version="8.0.0-rc.2.23479.6" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

src/Atc.Installer.Integration/Atc.Installer.Integration.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Atc" Version="2.0.360" />
21+
<PackageReference Include="Atc" Version="2.0.386" />
2222
</ItemGroup>
2323

2424
</Project>

0 commit comments

Comments
 (0)