attempt to preserve IIS bindings so future installations can restore them
This commit is contained in:
@@ -62,6 +62,11 @@
|
||||
<Reference Include="Microsoft.Owin.Security, Version=4.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Owin.Security.4.2.2\lib\net45\Microsoft.Owin.Security.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Administration, Version=7.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\Installer\Microsoft.Web.Administration.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
|
||||
@@ -371,6 +376,7 @@
|
||||
<Compile Include="Interop\DiscoServices\LicenseValidationTask.cs" />
|
||||
<Compile Include="Interop\DiscoServices\PluginLibrary.cs" />
|
||||
<Compile Include="Interop\DiscoServices\PluginLibraryUpdateTask.cs" />
|
||||
<Compile Include="Interop\IIS\PreserveIisBindingsTask.cs" />
|
||||
<Compile Include="Interop\MimeTypes.cs" />
|
||||
<Compile Include="Interop\VicEduDept\VicSmart.cs" />
|
||||
<Compile Include="Interop\DiscoServices\UpdateQuery.cs" />
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Services.Tasks;
|
||||
using Microsoft.Web.Administration;
|
||||
using Microsoft.Win32;
|
||||
using Quartz;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Disco.Services.Interop.DiscoServices
|
||||
{
|
||||
public class PreserveIisBindingsTask : ScheduledTask
|
||||
{
|
||||
private const string DiscoRegistryKey = @"SOFTWARE\Disco";
|
||||
|
||||
public override string TaskName { get { return "Disco ICT - Preserve IIS Bindings"; } }
|
||||
public override bool SingleInstanceTask { get { return true; } }
|
||||
public override bool CancelInitiallySupported { get { return false; } }
|
||||
|
||||
public override void InitalizeScheduledTask(DiscoDataContext Database)
|
||||
{
|
||||
TriggerBuilder triggerBuilder = TriggerBuilder.Create()
|
||||
.StartAt(DateTimeOffset.Now.AddMinutes(10));
|
||||
|
||||
ScheduleTask(triggerBuilder);
|
||||
}
|
||||
|
||||
protected override void ExecuteTask()
|
||||
{
|
||||
// retrieve IIS bindings
|
||||
var bindings = GetWebsiteBindings();
|
||||
|
||||
if (bindings == null || !bindings.Any())
|
||||
{
|
||||
ScheduledTasksLog.LogScheduledTaskInformation(Status.TaskName, Status.SessionId, "Bindings for IIS Web Site 'Disco' not found");
|
||||
return;
|
||||
}
|
||||
|
||||
using (var key = Registry.LocalMachine.CreateSubKey(DiscoRegistryKey))
|
||||
{
|
||||
key.SetValue("WebsiteBindings", bindings, RegistryValueKind.MultiString);
|
||||
}
|
||||
}
|
||||
|
||||
private string[] GetWebsiteBindings()
|
||||
{
|
||||
using (var manager = new ServerManager())
|
||||
{
|
||||
var site = manager.Sites["Disco"];
|
||||
|
||||
if (site == null)
|
||||
return null;
|
||||
|
||||
var bindings = site.Bindings;
|
||||
var sb = new StringBuilder();
|
||||
var result = new string[bindings.Count];
|
||||
for (int i = 0; i < bindings.Count; i++)
|
||||
{
|
||||
var binding = bindings[i];
|
||||
sb.Append(binding.BindingInformation);
|
||||
sb.Append(';');
|
||||
sb.Append(binding.Protocol);
|
||||
if (string.Equals(binding.Protocol, "https", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
sb.Append(';');
|
||||
sb.Append(Convert.ToBase64String(binding.CertificateHash));
|
||||
sb.Append(';');
|
||||
sb.Append(binding.CertificateStoreName);
|
||||
}
|
||||
|
||||
result[i] = sb.ToString();
|
||||
sb.Clear();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,10 @@ EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Disco.Services", "Disco.Services\Disco.Services.csproj", "{B80A737F-BD6A-4986-9182-DD7B932BD950}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Disco.Web", "Disco.Web\Disco.Web.csproj", "{241F4F43-6ACB-482D-8CBF-8F4E4B4DB0FE}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{15BD9561-A3C7-4608-9F7E-F1A1CFB60055} = {15BD9561-A3C7-4608-9F7E-F1A1CFB60055}
|
||||
{D6B85A86-0FAA-4B04-BC9E-D01A08C03387} = {D6B85A86-0FAA-4B04-BC9E-D01A08C03387}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Disco.Client", "Disco.Client\Disco.Client.csproj", "{D6B85A86-0FAA-4B04-BC9E-D01A08C03387}"
|
||||
EndProject
|
||||
|
||||
Reference in New Issue
Block a user