From eb64f1322145f3c7cd14bbb75c7cda811215674a Mon Sep 17 00:00:00 2001 From: feodor_fitsner Date: Mon, 12 Dec 2011 15:04:33 -0800 Subject: [PATCH] Re-factored IIS 7 provider to improve GetSite() operation performance. --- .../Web/WebSite.cs | 1 - .../HyperVForPC.cs | 135 +- .../Authentication/AnonymAuthModuleService.cs | 29 +- .../Authentication/BasicAuthModuleService.cs | 15 +- .../WindowsAuthenticationModuleService.cs | 19 +- .../ClassicAsp/ClassicAspModuleService.cs | 23 +- .../Common/ConfigurationModuleService.cs | 2 + .../DefaultDocumentModuleService.cs | 37 +- .../DirectoryBrowseModuleService.cs | 23 +- .../Extensions/ExtensionsModuleService.cs | 39 +- .../Handlers/HandlersModuleService.cs | 43 +- .../HttpRedirect/HttpRedirectModuleService.cs | 29 +- .../WebsitePanel.Providers.Web.IIS70/IIs70.cs | 1279 +++++++++-------- .../MimeTypes/MimeTypesModuleService.cs | 31 +- .../SSL/SSLModuleService.cs | 8 +- .../CustomHttpErrorsModuleService.cs | 34 +- .../CustomHttpHeadersModuleService.cs | 41 +- .../WebObjects/WebObjectsModuleService.cs | 299 ++-- .../WebsitePanel.Providers.Web.IIs70.csproj | 1 + .../WebsitePanel.Providers.Web.IIs60/IIs60.cs | 26 +- ...irtualizationServerForPrivateCloud.asmx.cs | 2 +- 21 files changed, 1058 insertions(+), 1058 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Web/WebSite.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Web/WebSite.cs index 50d9eea9..3560648f 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Web/WebSite.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Web/WebSite.cs @@ -47,7 +47,6 @@ namespace WebsitePanel.Providers.Web private string siteId; private string siteIPAddress; private int siteIPAddressId; - private string logsPath; private string dataPath; private ServerBinding[] bindings; private bool frontPageAvailable; diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperVForPC/HyperVForPC.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperVForPC/HyperVForPC.cs index 94ad56d3..5fb2e918 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperVForPC/HyperVForPC.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperVForPC/HyperVForPC.cs @@ -908,7 +908,7 @@ namespace WebsitePanel.Providers.VirtualizationForPC steps.AppendLine("VM created"); } } - catch (System.TimeoutException ex) + catch (System.TimeoutException) { vmTemplate.ProvisioningStatus = VirtualMachineProvisioningStatus.InProgress; } @@ -1064,38 +1064,32 @@ namespace WebsitePanel.Providers.VirtualizationForPC { List result = new List(); - try + using (WSPVirtualMachineManagementServiceClient client = GetVMMSClient()) { - using (WSPVirtualMachineManagementServiceClient client = GetVMMSClient()) + VirtualizationForPC.SVMMService.VirtualNetworkInfo[] networks = client.GetVirtualNetworkByHost(hostInfo); + foreach (var item in networks) { - VirtualizationForPC.SVMMService.VirtualNetworkInfo[] networks = client.GetVirtualNetworkByHost(hostInfo); - foreach (var item in networks) - { - result.Add( - new Virtualization.VirtualNetworkInfo - { - BoundToVMHost = item.BoundToVMHost, - DefaultGatewayAddress = item.DefaultGatewayAddress, - Description = item.Description, - DNSServers = item.DNSServers, - EnablingIPAddress = item.EnablingIPAddress, - HighlyAvailable = item.HighlyAvailable, - HostBoundVlanId = item.HostBoundVlanId, - Id = item.Id, - Name = item.Name, - NetworkAddress = item.NetworkAddress, - NetworkMask = item.NetworkMask, - Tag = item.Tag, - VMHost = item.VMHost.ComputerName, - VMHostId = item.VMHostId, - WINServers = item.WINServers - }); - } + result.Add( + new Virtualization.VirtualNetworkInfo + { + BoundToVMHost = item.BoundToVMHost, + DefaultGatewayAddress = item.DefaultGatewayAddress, + Description = item.Description, + DNSServers = item.DNSServers, + EnablingIPAddress = item.EnablingIPAddress, + HighlyAvailable = item.HighlyAvailable, + HostBoundVlanId = item.HostBoundVlanId, + Id = item.Id, + Name = item.Name, + NetworkAddress = item.NetworkAddress, + NetworkMask = item.NetworkMask, + Tag = item.Tag, + VMHost = item.VMHost.ComputerName, + VMHostId = item.VMHostId, + WINServers = item.WINServers + }); } } - catch (Exception ex) - { - } return result.ToArray(); @@ -1287,35 +1281,29 @@ namespace WebsitePanel.Providers.VirtualizationForPC List ret = new List(); - try + using (WSPVirtualMachineManagementServiceClient client = GetVMMSClient()) { - using (WSPVirtualMachineManagementServiceClient client = GetVMMSClient()) - { - VMCheckpointInfo[] chkPtnList = client.GetVirtualMachineByName(vmId).VMCheckpoints; + VMCheckpointInfo[] chkPtnList = client.GetVirtualMachineByName(vmId).VMCheckpoints; - if (chkPtnList != null) + if (chkPtnList != null) + { + foreach (VMCheckpointInfo curr in chkPtnList) { - foreach (VMCheckpointInfo curr in chkPtnList) + ret.Add(new VirtualMachineSnapshot() { - ret.Add(new VirtualMachineSnapshot() - { - Created = curr.AddedTime - , - Id = curr.Id.ToString() - , - Name = curr.Name - , - CheckPointId = curr.CheckpointID - , - ParentId = curr.ParentCheckpointID - }); - } + Created = curr.AddedTime + , + Id = curr.Id.ToString() + , + Name = curr.Name + , + CheckPointId = curr.CheckpointID + , + ParentId = curr.ParentCheckpointID + }); } } } - catch (Exception e) - { - } return ret; } @@ -1338,7 +1326,7 @@ namespace WebsitePanel.Providers.VirtualizationForPC client.NewVirtualMachineCheckpoint(vm.Id, String.Format("{0} - {1}", vm.Name, DateTime.Now), String.Empty); } } - catch (TimeoutException ext) + catch (TimeoutException) { ret.ReturnValue = ReturnCode.JobStarted; } @@ -1368,7 +1356,7 @@ namespace WebsitePanel.Providers.VirtualizationForPC client.RestoreVirtualMachineCheckpoint(snapshotId); } } - catch (TimeoutException ext) + catch (TimeoutException) { error = true; ret.ReturnValue = ReturnCode.JobStarted; @@ -1856,25 +1844,19 @@ namespace WebsitePanel.Providers.VirtualizationForPC public WSPVirtualMachineManagementServiceClient GetVMMSClient() { WSPVirtualMachineManagementServiceClient ret; - try + + if (!String.IsNullOrWhiteSpace(SCVMMServer) + && !String.IsNullOrWhiteSpace(SCVMMPrincipalName)) { - if (!String.IsNullOrWhiteSpace(SCVMMServer) - && !String.IsNullOrWhiteSpace(SCVMMPrincipalName)) - { - EndpointAddress endPointAddress = GetEndPointAddress(SCVMMServer, SCVMMPrincipalName); + EndpointAddress endPointAddress = GetEndPointAddress(SCVMMServer, SCVMMPrincipalName); - ret = new WSPVirtualMachineManagementServiceClient(new WSHttpBinding("WSHttpBinding_IVirtualMachineManagementService"), endPointAddress); + ret = new WSPVirtualMachineManagementServiceClient(new WSHttpBinding("WSHttpBinding_IVirtualMachineManagementService"), endPointAddress); - VersionInfo ver = new VersionInfo(); - } - else - { - throw new Exception("SCVMMServer or SCVMMPrincipalName is empty"); - } + VersionInfo ver = new VersionInfo(); } - catch (Exception ex) + else { - throw; + throw new Exception("SCVMMServer or SCVMMPrincipalName is empty"); } return ret; @@ -1884,23 +1866,16 @@ namespace WebsitePanel.Providers.VirtualizationForPC { WSPMonitoringServiceClient ret; - try + if (!String.IsNullOrWhiteSpace(SCOMServer) + && !String.IsNullOrWhiteSpace(SCOMPrincipalName)) { - if (!String.IsNullOrWhiteSpace(SCOMServer) - && !String.IsNullOrWhiteSpace(SCOMPrincipalName)) - { - EndpointAddress endPointAddress = GetEndPointAddress(SCOMServer, SCOMPrincipalName); + EndpointAddress endPointAddress = GetEndPointAddress(SCOMServer, SCOMPrincipalName); - ret = new WSPMonitoringServiceClient(new WSHttpBinding("WSHttpBinding_IMonitoringService"), endPointAddress); - } - else - { - throw new Exception("MonitoringServer or MonitoringPrincipalName is empty"); - } + ret = new WSPMonitoringServiceClient(new WSHttpBinding("WSHttpBinding_IMonitoringService"), endPointAddress); } - catch (Exception ex) + else { - throw; + throw new Exception("MonitoringServer or MonitoringPrincipalName is empty"); } return ret; diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Authentication/AnonymAuthModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Authentication/AnonymAuthModuleService.cs index fc210b1b..36083d3b 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Authentication/AnonymAuthModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Authentication/AnonymAuthModuleService.cs @@ -41,23 +41,20 @@ namespace WebsitePanel.Providers.Web.Iis.Authentication public const string UserNameAttribute = "userName"; public const string PasswordAttribute = "password"; - public PropertyBag GetAuthenticationSettings(string siteId) + public PropertyBag GetAuthenticationSettings(ServerManager srvman, string siteId) { - using (var srvman = GetServerManager()) - { - var config = srvman.GetApplicationHostConfiguration(); - // - var section = config.GetSection(Constants.AnonymousAuthenticationSection, siteId); - // - PropertyBag bag = new PropertyBag(); - // - bag[AuthenticationGlobals.AnonymousAuthenticationUserName] = Convert.ToString(section.GetAttributeValue(UserNameAttribute)); - bag[AuthenticationGlobals.AnonymousAuthenticationPassword] = Convert.ToString(section.GetAttributeValue(PasswordAttribute)); - bag[AuthenticationGlobals.Enabled] = Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute)); - bag[AuthenticationGlobals.IsLocked] = section.IsLocked; - // - return bag; - } + var config = srvman.GetApplicationHostConfiguration(); + // + var section = config.GetSection(Constants.AnonymousAuthenticationSection, siteId); + // + PropertyBag bag = new PropertyBag(); + // + bag[AuthenticationGlobals.AnonymousAuthenticationUserName] = Convert.ToString(section.GetAttributeValue(UserNameAttribute)); + bag[AuthenticationGlobals.AnonymousAuthenticationPassword] = Convert.ToString(section.GetAttributeValue(PasswordAttribute)); + bag[AuthenticationGlobals.Enabled] = Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute)); + bag[AuthenticationGlobals.IsLocked] = section.IsLocked; + // + return bag; } public void SetAuthenticationSettings(string virtualPath, string userName, diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Authentication/BasicAuthModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Authentication/BasicAuthModuleService.cs index 8b72bebc..ac0c2fa6 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Authentication/BasicAuthModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Authentication/BasicAuthModuleService.cs @@ -37,16 +37,13 @@ namespace WebsitePanel.Providers.Web.Iis.Authentication { public const string EnabledAttribute = "enabled"; - public void GetAuthenticationSettings(WebVirtualDirectory virtualDir) + public void GetAuthenticationSettings(ServerManager srvman, WebVirtualDirectory virtualDir) { - using (var srvman = GetServerManager()) - { - var config = srvman.GetApplicationHostConfiguration(); - // - var section = config.GetSection(Constants.BasicAuthenticationSection, virtualDir.FullQualifiedPath); - // - virtualDir.EnableBasicAuthentication = Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute)); - } + var config = srvman.GetApplicationHostConfiguration(); + // + var section = config.GetSection(Constants.BasicAuthenticationSection, virtualDir.FullQualifiedPath); + // + virtualDir.EnableBasicAuthentication = Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute)); } public void SetAuthenticationSettings(WebVirtualDirectory virtualDir) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Authentication/WindowsAuthenticationModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Authentication/WindowsAuthenticationModuleService.cs index 5c03b509..4e38e096 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Authentication/WindowsAuthenticationModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Authentication/WindowsAuthenticationModuleService.cs @@ -37,20 +37,15 @@ namespace WebsitePanel.Providers.Web.Iis.Authentication { public const string EnabledAttribute = "enabled"; - public PropertyBag GetAuthenticationSettings(string siteId) + public PropertyBag GetAuthenticationSettings(ServerManager srvman, string siteId) { PropertyBag bag = new PropertyBag(); - // - using (var srvman = GetServerManager()) - { - var config = srvman.GetApplicationHostConfiguration(); - // - var section = config.GetSection(Constants.WindowsAuthenticationSection, siteId); - // - bag[AuthenticationGlobals.IsLocked] = section.IsLocked; - bag[AuthenticationGlobals.Enabled] = Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute)); - } - // + var config = srvman.GetApplicationHostConfiguration(); + // + var section = config.GetSection(Constants.WindowsAuthenticationSection, siteId); + // + bag[AuthenticationGlobals.IsLocked] = section.IsLocked; + bag[AuthenticationGlobals.Enabled] = Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute)); return bag; } diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/ClassicAsp/ClassicAspModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/ClassicAsp/ClassicAspModuleService.cs index 2bac9440..81429281 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/ClassicAsp/ClassicAspModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/ClassicAsp/ClassicAspModuleService.cs @@ -40,20 +40,17 @@ namespace WebsitePanel.Providers.Web.Iis.ClassicAsp public const string SectionName = "system.webServer/asp"; public const string EnableParentPathsAttribute = "enableParentPaths"; - public PropertyBag GetClassicAspSettings(string siteId) + public PropertyBag GetClassicAspSettings(ServerManager srvman, string siteId) { - using (var srvman = GetServerManager()) - { - var config = srvman.GetApplicationHostConfiguration(); - // - var aspSection = config.GetSection(SectionName, siteId); - // - PropertyBag bag = new PropertyBag(); - // - bag[ClassicAspGlobals.EnableParentPaths] = Convert.ToBoolean(aspSection.GetAttributeValue(EnableParentPathsAttribute)); - // - return bag; - } + var config = srvman.GetApplicationHostConfiguration(); + // + var aspSection = config.GetSection(SectionName, siteId); + // + PropertyBag bag = new PropertyBag(); + // + bag[ClassicAspGlobals.EnableParentPaths] = Convert.ToBoolean(aspSection.GetAttributeValue(EnableParentPathsAttribute)); + // + return bag; } public void SetClassicAspSettings(WebVirtualDirectory virtualDir) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Common/ConfigurationModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Common/ConfigurationModuleService.cs index 4cdf8806..a087b946 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Common/ConfigurationModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Common/ConfigurationModuleService.cs @@ -31,12 +31,14 @@ namespace WebsitePanel.Providers.Web.Iis.Common using System; using System.Collections.Generic; using System.Text; + using System.Web; using Microsoft.Web.Administration; using Microsoft.Web.Management.Server; public abstract class ConfigurationModuleService { + private const string ServerManagerContextKey = "ServerManagerContextKey"; /// /// We'll use it in the future to implement management of web farm with shared configuration enabled /// diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/DefaultDocuments/DefaultDocumentModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/DefaultDocuments/DefaultDocumentModuleService.cs index 60f8e162..afba44a2 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/DefaultDocuments/DefaultDocumentModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/DefaultDocuments/DefaultDocumentModuleService.cs @@ -43,31 +43,28 @@ namespace WebsitePanel.Providers.Web.Iis.DefaultDocuments { public const string ValueAttribute = "value"; - public string GetDefaultDocumentSettings(string siteId) + public string GetDefaultDocumentSettings(ServerManager srvman, string siteId) { - using (var srvman = GetServerManager()) + // Load web site configuration + var config = srvman.GetWebConfiguration(siteId); + // Load corresponding section + var section = config.GetSection(Constants.DefaultDocumentsSection); + // + var filesCollection = section.GetCollection("files"); + // Build default documents + var defaultDocs = new List(); + // + foreach (var item in filesCollection) { - // Load web site configuration - var config = srvman.GetWebConfiguration(siteId); - // Load corresponding section - var section = config.GetSection(Constants.DefaultDocumentsSection); + var item2Get = GetDefaultDocument(item); // - var filesCollection = section.GetCollection("files"); - // Build default documents - var defaultDocs = new List(); + if (String.IsNullOrEmpty(item2Get)) + continue; // - foreach (var item in filesCollection) - { - var item2Get = GetDefaultDocument(item); - // - if (String.IsNullOrEmpty(item2Get)) - continue; - // - defaultDocs.Add(item2Get); - } - // - return String.Join(",", defaultDocs.ToArray()); + defaultDocs.Add(item2Get); } + // + return String.Join(",", defaultDocs.ToArray()); } public void SetDefaultDocumentsEnabled(string siteId, bool enabled) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/DirectoryBrowse/DirectoryBrowseModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/DirectoryBrowse/DirectoryBrowseModuleService.cs index 25c53cad..ab69354f 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/DirectoryBrowse/DirectoryBrowseModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/DirectoryBrowse/DirectoryBrowseModuleService.cs @@ -35,20 +35,17 @@ namespace WebsitePanel.Providers.Web.Iis.DirectoryBrowse internal sealed class DirectoryBrowseModuleService : ConfigurationModuleService { - public PropertyBag GetDirectoryBrowseSettings(string siteId) + public PropertyBag GetDirectoryBrowseSettings(ServerManager srvman, string siteId) { - using (var srvman = GetServerManager()) - { - var config = srvman.GetWebConfiguration(siteId); - // - DirectoryBrowseSection directoryBrowseSection = (DirectoryBrowseSection)config.GetSection(Constants.DirectoryBrowseSection, typeof(DirectoryBrowseSection)); - // - PropertyBag bag = new PropertyBag(); - bag[DirectoryBrowseGlobals.Enabled] = directoryBrowseSection.Enabled; - bag[DirectoryBrowseGlobals.ShowFlags] = (int)directoryBrowseSection.ShowFlags; - bag[DirectoryBrowseGlobals.ReadOnly] = directoryBrowseSection.IsLocked; - return bag; - } + var config = srvman.GetWebConfiguration(siteId); + // + DirectoryBrowseSection directoryBrowseSection = (DirectoryBrowseSection)config.GetSection(Constants.DirectoryBrowseSection, typeof(DirectoryBrowseSection)); + // + PropertyBag bag = new PropertyBag(); + bag[DirectoryBrowseGlobals.Enabled] = directoryBrowseSection.Enabled; + bag[DirectoryBrowseGlobals.ShowFlags] = (int)directoryBrowseSection.ShowFlags; + bag[DirectoryBrowseGlobals.ReadOnly] = directoryBrowseSection.IsLocked; + return bag; } public void SetDirectoryBrowseEnabled(string siteId, bool enabled) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Extensions/ExtensionsModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Extensions/ExtensionsModuleService.cs index 172c1360..ab42e310 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Extensions/ExtensionsModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Extensions/ExtensionsModuleService.cs @@ -58,36 +58,33 @@ using System.Collections.Specialized; { Constants.AspNet40x64PathSetting, @"\Framework64\v4.0.30128\aspnet_isapi.dll" } }; - public SettingPair[] GetISAPIExtensionsInstalled() + public SettingPair[] GetISAPIExtensionsInstalled(ServerManager srvman) { List settings = new List(); // - using (var srvman = GetServerManager()) + var config = srvman.GetApplicationHostConfiguration(); + // + var section = config.GetSection(Constants.IsapiCgiRestrictionSection); + // + foreach (var item in section.GetCollection()) { - var config = srvman.GetApplicationHostConfiguration(); + var isapiModulePath = Convert.ToString(item.GetAttributeValue(PathAttribute)); // - var section = config.GetSection(Constants.IsapiCgiRestrictionSection); - // - foreach (var item in section.GetCollection()) + for (int i = 0; i < ISAPI_MODULES.Keys.Count; i++) { - var isapiModulePath = Convert.ToString(item.GetAttributeValue(PathAttribute)); + var pathExt = ISAPI_MODULES.Get(i); // - for (int i = 0; i < ISAPI_MODULES.Keys.Count; i++) + if (isapiModulePath.EndsWith(pathExt)) { - var pathExt = ISAPI_MODULES.Get(i); - // - if (isapiModulePath.EndsWith(pathExt)) + settings.Add(new SettingPair { - settings.Add(new SettingPair - { - // Retrieve key name - Name = ISAPI_MODULES.GetKey(i), - // Evaluate ISAPI module path - Value = isapiModulePath - }); - // - break; - } + // Retrieve key name + Name = ISAPI_MODULES.GetKey(i), + // Evaluate ISAPI module path + Value = isapiModulePath + }); + // + break; } } } diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Handlers/HandlersModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Handlers/HandlersModuleService.cs index 6bebab26..b1a86208 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Handlers/HandlersModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/Handlers/HandlersModuleService.cs @@ -87,45 +87,22 @@ namespace WebsitePanel.Providers.Web.Handlers } } - public void SetHandlersAccessPolicy(string fqPath, HandlerAccessPolicy policy) + public void SetHandlersAccessPolicy(ServerManager srvman, string fqPath, HandlerAccessPolicy policy) { + var config = srvman.GetWebConfiguration(fqPath); // - using (var srvman = GetServerManager()) - { - var config = srvman.GetWebConfiguration(fqPath); - // - HandlersSection section = (HandlersSection)config.GetSection(Constants.HandlersSection, typeof(HandlersSection)); - // - section.AccessPolicy = policy; - // - srvman.CommitChanges(); - } + HandlersSection section = (HandlersSection)config.GetSection(Constants.HandlersSection, typeof(HandlersSection)); + // + section.AccessPolicy = policy; } - public HandlerAccessPolicy GetHandlersAccessPolicy(string fqPath) + public HandlerAccessPolicy GetHandlersAccessPolicy(ServerManager srvman, string fqPath) { + var config = srvman.GetWebConfiguration(fqPath); // - using (var srvman = GetServerManager()) - { - var config = srvman.GetWebConfiguration(fqPath); - // - HandlersSection section = (HandlersSection)config.GetSection(Constants.HandlersSection, typeof(HandlersSection)); - // - return section.AccessPolicy; - } - } - - internal ConfigurationElementCollection GetHandlers(WebVirtualDirectory virtualDir) - { - // - using (var srvman = GetServerManager()) - { - var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath); - // - var section = config.GetSection(Constants.HandlersSection); - // - return section.GetCollection(); - } + HandlersSection section = (HandlersSection)config.GetSection(Constants.HandlersSection, typeof(HandlersSection)); + // + return section.AccessPolicy; } /// diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/HttpRedirect/HttpRedirectModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/HttpRedirect/HttpRedirectModuleService.cs index 5ec41635..973c44b6 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/HttpRedirect/HttpRedirectModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/HttpRedirect/HttpRedirectModuleService.cs @@ -44,23 +44,20 @@ namespace WebsitePanel.Providers.Web.HttpRedirect public const string DestinationAttribute = "destination"; public const string HttpResponseStatusAttribute = "httpResponseStatus"; - public void LoadHttpRedirectSettings(WebVirtualDirectory virtualDir) + public void GetHttpRedirectSettings(ServerManager srvman, WebVirtualDirectory virtualDir) { - using (var srvman = GetServerManager()) - { - // Load web site configuration - var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath); - // Load corresponding section - var section = config.GetSection(Constants.HttpRedirectSection); - // - if (!Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute))) - return; - // - virtualDir.RedirectExactUrl = Convert.ToBoolean(section.GetAttributeValue(ExactDestinationAttribute)); - virtualDir.RedirectDirectoryBelow = Convert.ToBoolean(section.GetAttributeValue(ChildOnlyAttribute)); - virtualDir.HttpRedirect = Convert.ToString(section.GetAttributeValue(DestinationAttribute)); - virtualDir.RedirectPermanent = String.Equals("301", Convert.ToString(section.GetAttributeValue(HttpResponseStatusAttribute))); - } + // Load web site configuration + var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath); + // Load corresponding section + var section = config.GetSection(Constants.HttpRedirectSection); + // + if (!Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute))) + return; + // + virtualDir.RedirectExactUrl = Convert.ToBoolean(section.GetAttributeValue(ExactDestinationAttribute)); + virtualDir.RedirectDirectoryBelow = Convert.ToBoolean(section.GetAttributeValue(ChildOnlyAttribute)); + virtualDir.HttpRedirect = Convert.ToString(section.GetAttributeValue(DestinationAttribute)); + virtualDir.RedirectPermanent = String.Equals("301", Convert.ToString(section.GetAttributeValue(HttpResponseStatusAttribute))); } public void SetHttpRedirectSettings(WebVirtualDirectory virtualDir) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/IIs70.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/IIs70.cs index c4d7ca29..d34e3174 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/IIs70.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/IIs70.cs @@ -598,31 +598,31 @@ namespace WebsitePanel.Providers.Web } } - private void FillVirtualDirectoryFromIISObject(WebVirtualDirectory virtualDir) + private void FillVirtualDirectoryFromIISObject(ServerManager srvman, WebVirtualDirectory virtualDir) { // Set physical path. - virtualDir.ContentPath = webObjectsSvc.GetPhysicalPath(virtualDir); + virtualDir.ContentPath = webObjectsSvc.GetPhysicalPath(srvman, virtualDir); // load iisDirObject browse - PropertyBag bag = dirBrowseSvc.GetDirectoryBrowseSettings(virtualDir.FullQualifiedPath); + PropertyBag bag = dirBrowseSvc.GetDirectoryBrowseSettings(srvman, virtualDir.FullQualifiedPath); virtualDir.EnableDirectoryBrowsing = (bool)bag[DirectoryBrowseGlobals.Enabled]; // load anonym auth - bag = anonymAuthSvc.GetAuthenticationSettings(virtualDir.FullQualifiedPath); + bag = anonymAuthSvc.GetAuthenticationSettings(srvman, virtualDir.FullQualifiedPath); virtualDir.AnonymousUsername = (string)bag[AuthenticationGlobals.AnonymousAuthenticationUserName]; virtualDir.AnonymousUserPassword = (string)bag[AuthenticationGlobals.AnonymousAuthenticationPassword]; virtualDir.EnableAnonymousAccess = (bool)bag[AuthenticationGlobals.Enabled]; // load windows auth - bag = winAuthSvc.GetAuthenticationSettings(virtualDir.FullQualifiedPath); + bag = winAuthSvc.GetAuthenticationSettings(srvman, virtualDir.FullQualifiedPath); virtualDir.EnableWindowsAuthentication = (bool)bag[AuthenticationGlobals.Enabled]; // load basic auth - basicAuthSvc.GetAuthenticationSettings(virtualDir); + basicAuthSvc.GetAuthenticationSettings(srvman, virtualDir); // load default docs - virtualDir.DefaultDocs = defaultDocSvc.GetDefaultDocumentSettings(virtualDir.FullQualifiedPath); + virtualDir.DefaultDocs = defaultDocSvc.GetDefaultDocumentSettings(srvman, virtualDir.FullQualifiedPath); // load classic asp - bag = classicAspSvc.GetClassicAspSettings(virtualDir.FullQualifiedPath); + bag = classicAspSvc.GetClassicAspSettings(srvman, virtualDir.FullQualifiedPath); virtualDir.EnableParentPaths = (bool)bag[ClassicAspGlobals.EnableParentPaths]; // virtualDir.IIs7 = true; @@ -643,63 +643,62 @@ namespace WebsitePanel.Providers.Web classicAspSvc.SetClassicAspSettings(virtualDir); } - private void FillVirtualDirectoryRestFromIISObject(WebVirtualDirectory virtualDir) + private void FillVirtualDirectoryRestFromIISObject(ServerManager srvman, WebVirtualDirectory virtualDir) { // HTTP REDIRECT - httpRedirectSvc.LoadHttpRedirectSettings(virtualDir); + httpRedirectSvc.GetHttpRedirectSettings(srvman, virtualDir); // HTTP HEADERS - customHeadersSvc.GetCustomHttpHeaders(virtualDir); + customHeadersSvc.GetCustomHttpHeaders(srvman, virtualDir); // HTTP ERRORS - customErrorsSvc.GetCustomErrors(virtualDir); + customErrorsSvc.GetCustomErrors(srvman, virtualDir); // MIME MAPPINGS - mimeTypesSvc.GetMimeMaps(virtualDir); + mimeTypesSvc.GetMimeMaps(srvman, virtualDir); // SCRIPT MAPS // Load installed script maps. - using (var srvman = handlersSvc.GetServerManager()) + + virtualDir.AspInstalled = false; // not installed + virtualDir.PhpInstalled = ""; // none + virtualDir.PerlInstalled = false; // not installed + virtualDir.PythonInstalled = false; // not installed + virtualDir.ColdFusionInstalled = false; // not installed + // + var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath); + var handlersSection = config.GetSection(Constants.HandlersSection); + + // Loop through available maps and fill installed processors + foreach (ConfigurationElement action in handlersSection.GetCollection()) { - virtualDir.AspInstalled = false; // not installed - virtualDir.PhpInstalled = ""; // none - virtualDir.PerlInstalled = false; // not installed - virtualDir.PythonInstalled = false; // not installed - virtualDir.ColdFusionInstalled = false; // not installed + // Extract and evaluate scripting processor path + string processor = FileUtils.EvaluateSystemVariables( + Convert.ToString(action.GetAttributeValue("scriptProcessor"))); // - var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath); - var handlersSection = config.GetSection(Constants.HandlersSection); + string actionName = Convert.ToString(action.GetAttributeValue("name")); - // Loop through available maps and fill installed processors - foreach (ConfigurationElement action in handlersSection.GetCollection()) - { - // Extract and evaluate scripting processor path - string processor = FileUtils.EvaluateSystemVariables( - Convert.ToString(action.GetAttributeValue("scriptProcessor"))); - // - string actionName = Convert.ToString(action.GetAttributeValue("name")); + // Detect whether ASP scripting is enabled + if (!String.IsNullOrEmpty(AspPath) && String.Equals(AspPath, processor, StringComparison.InvariantCultureIgnoreCase)) + virtualDir.AspInstalled = true; - // Detect whether ASP scripting is enabled - if (!String.IsNullOrEmpty(AspPath) && String.Equals(AspPath, processor, StringComparison.InvariantCultureIgnoreCase)) - virtualDir.AspInstalled = true; + // Detect whether PHP 5 scripting is enabled + if (!String.IsNullOrEmpty(PhpExecutablePath) && String.Equals(PhpExecutablePath, processor, StringComparison.InvariantCultureIgnoreCase)) + virtualDir.PhpInstalled = PHP_5; - // Detect whether PHP 5 scripting is enabled - if (!String.IsNullOrEmpty(PhpExecutablePath) && String.Equals(PhpExecutablePath, processor, StringComparison.InvariantCultureIgnoreCase)) - virtualDir.PhpInstalled = PHP_5; + // Detect whether PHP 4 scripting is enabled + if (!String.IsNullOrEmpty(Php4Path) && String.Equals(Php4Path, processor, StringComparison.InvariantCultureIgnoreCase)) + virtualDir.PhpInstalled = PHP_4; - // Detect whether PHP 4 scripting is enabled - if (!String.IsNullOrEmpty(Php4Path) && String.Equals(Php4Path, processor, StringComparison.InvariantCultureIgnoreCase)) - virtualDir.PhpInstalled = PHP_4; + // Detect whether ColdFusion scripting is enabled + if (!String.IsNullOrEmpty(ColdFusionPath) && String.Compare(ColdFusionPath, processor, true) == 0 && actionName.Contains(".cfm")) + virtualDir.ColdFusionInstalled = true; - // Detect whether ColdFusion scripting is enabled - if (!String.IsNullOrEmpty(ColdFusionPath) && String.Compare(ColdFusionPath, processor, true) == 0 && actionName.Contains(".cfm")) - virtualDir.ColdFusionInstalled = true; - - // Detect whether Perl scripting is enabled - if (!String.IsNullOrEmpty(PerlPath) && String.Equals(PerlPath, processor, StringComparison.InvariantCultureIgnoreCase)) - virtualDir.PerlInstalled = true; - } + // Detect whether Perl scripting is enabled + if (!String.IsNullOrEmpty(PerlPath) && String.Equals(PerlPath, processor, StringComparison.InvariantCultureIgnoreCase)) + virtualDir.PerlInstalled = true; } + // string fqPath = virtualDir.FullQualifiedPath; if (!fqPath.EndsWith(@"/")) @@ -707,14 +706,14 @@ namespace WebsitePanel.Providers.Web // fqPath += CGI_BIN_FOLDER; // - HandlerAccessPolicy policy = handlersSvc.GetHandlersAccessPolicy(fqPath); + HandlerAccessPolicy policy = handlersSvc.GetHandlersAccessPolicy(srvman, fqPath); virtualDir.CgiBinInstalled = (policy & HandlerAccessPolicy.Execute) > 0; // ASP.NET - FillAspNetSettingsFromIISObject(virtualDir); + FillAspNetSettingsFromIISObject(srvman, virtualDir); } - private void FillAspNetSettingsFromIISObject(WebVirtualDirectory vdir) + private void FillAspNetSettingsFromIISObject(ServerManager srvman, WebVirtualDirectory vdir) { // Read ASP.NET settings if (String.IsNullOrEmpty(vdir.ApplicationPool)) @@ -722,47 +721,43 @@ namespace WebsitePanel.Providers.Web // try { + var appool = srvman.ApplicationPools[vdir.ApplicationPool]; // - using (var srvman = webObjectsSvc.GetServerManager()) + var aphl = new WebAppPoolHelper(ProviderSettings); + // ASP.NET 2.0 pipeline is supposed by default + var dotNetVersion = SiteAppPoolMode.dotNetFramework2; + // + #region Iterate over managed runtime keys of the helper class to properly evaluate ASP.NET version installed + foreach (var k in WebAppPool.AspNetVersions) { - var appool = srvman.ApplicationPools[vdir.ApplicationPool]; - // - var aphl = new WebAppPoolHelper(ProviderSettings); - // ASP.NET 2.0 pipeline is supposed by default - var dotNetVersion = SiteAppPoolMode.dotNetFramework2; - // - #region Iterate over managed runtime keys of the helper class to properly evaluate ASP.NET version installed - foreach (var k in WebAppPool.AspNetVersions) + if (k.Value.Equals(appool.ManagedRuntimeVersion)) { - if (k.Value.Equals(appool.ManagedRuntimeVersion)) - { - dotNetVersion = k.Key; - break; - } + dotNetVersion = k.Key; + break; } - #endregion - // Detect pipeline mode being used - if (appool.ManagedPipelineMode == ManagedPipelineMode.Classic) - dotNetVersion |= SiteAppPoolMode.Classic; - else - dotNetVersion |= SiteAppPoolMode.Integrated; - // - var aspNetVersion = String.Empty; - #region Iterate over supported ASP.NET versions based on result of the previous runtime version assesement - foreach (var item in WebAppPoolHelper.SupportedAppPoolModes) - { - if (item.Value == dotNetVersion) - { - // Obtain ASP.NET version installed - aspNetVersion = item.Key; - // - break; - } - } - #endregion - // Assign the result of assesement - vdir.AspNetInstalled = aspNetVersion; } + #endregion + // Detect pipeline mode being used + if (appool.ManagedPipelineMode == ManagedPipelineMode.Classic) + dotNetVersion |= SiteAppPoolMode.Classic; + else + dotNetVersion |= SiteAppPoolMode.Integrated; + // + var aspNetVersion = String.Empty; + #region Iterate over supported ASP.NET versions based on result of the previous runtime version assesement + foreach (var item in WebAppPoolHelper.SupportedAppPoolModes) + { + if (item.Value == dotNetVersion) + { + // Obtain ASP.NET version installed + aspNetVersion = item.Key; + // + break; + } + } + #endregion + // Assign the result of assesement + vdir.AspNetInstalled = aspNetVersion; } catch (Exception ex) { @@ -780,23 +775,24 @@ namespace WebsitePanel.Providers.Web // var dedicatedPools = Array.FindAll(aphl.SupportedAppPools.ToArray(), x => aphl.isolation(x.Mode) == SiteAppPoolMode.Dedicated); + // cleanup app pools - foreach (var item in dedicatedPools) - { - using (var srvman = webObjectsSvc.GetServerManager()) - { - // - string poolName = WSHelper.InferAppPoolName(item.Name, siteName, item.Mode); - // - ApplicationPool pool = srvman.ApplicationPools[poolName]; - if (pool == null) - continue; - // - srvman.ApplicationPools.Remove(pool); - // - srvman.CommitChanges(); - } - } + using (var srvman = webObjectsSvc.GetServerManager()) + { + foreach (var item in dedicatedPools) + { + string poolName = WSHelper.InferAppPoolName(item.Name, siteName, item.Mode); + // + ApplicationPool pool = srvman.ApplicationPools[poolName]; + if (pool == null) + continue; + // + srvman.ApplicationPools.Remove(pool); + } + + // save changes + srvman.CommitChanges(); + } } catch (Exception ex) { @@ -936,21 +932,29 @@ namespace WebsitePanel.Providers.Web // fqPath += CGI_BIN_FOLDER; string cgiBinPath = Path.Combine(virtualDir.ContentPath, CGI_BIN_FOLDER); - // - HandlerAccessPolicy policy = handlersSvc.GetHandlersAccessPolicy(fqPath); - policy &= ~HandlerAccessPolicy.Execute; - // - if (virtualDir.CgiBinInstalled) - { - // create folder if not exists - if (!FileUtils.DirectoryExists(cgiBinPath)) - FileUtils.CreateDirectory(cgiBinPath); - // - policy |= HandlerAccessPolicy.Execute; - } - // - if (FileUtils.DirectoryExists(cgiBinPath)) - handlersSvc.SetHandlersAccessPolicy(fqPath, policy); + + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + // + HandlerAccessPolicy policy = handlersSvc.GetHandlersAccessPolicy(srvman, fqPath); + policy &= ~HandlerAccessPolicy.Execute; + // + if (virtualDir.CgiBinInstalled) + { + // create folder if not exists + if (!FileUtils.DirectoryExists(cgiBinPath)) + FileUtils.CreateDirectory(cgiBinPath); + // + policy |= HandlerAccessPolicy.Execute; + } + + // + if (FileUtils.DirectoryExists(cgiBinPath)) + handlersSvc.SetHandlersAccessPolicy(srvman, fqPath, policy); + + // save + srvman.CommitChanges(); + } } /// @@ -1025,13 +1029,13 @@ namespace WebsitePanel.Providers.Web site.ApplicationPool = WSHelper.InferAppPoolName(siteAppPool.Name, site.Name, siteAppPool.Mode); } - private void CheckEnableWritePermissions(WebVirtualDirectory virtualDir) + private void CheckEnableWritePermissions(ServerManager srvman, WebVirtualDirectory virtualDir) { string anonymousUsername = virtualDir.AnonymousUsername; // if (virtualDir.DedicatedApplicationPool) { - ApplicationPool appPool = webObjectsSvc.GetApplicationPool(virtualDir); + ApplicationPool appPool = webObjectsSvc.GetApplicationPool(srvman, virtualDir); // if (appPool != null) anonymousUsername = appPool.ProcessModel.UserName; @@ -1053,122 +1057,148 @@ namespace WebsitePanel.Providers.Web public override ServerState GetSiteState(string siteId) { - return webObjectsSvc.GetSiteState(siteId); + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + return GetSiteState(srvman, siteId); + } } + public ServerState GetSiteState(ServerManager srvman, string siteId) + { + return webObjectsSvc.GetSiteState(srvman, siteId); + } + public override bool SiteExists(string siteId) { - return webObjectsSvc.SiteExists(siteId); + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + return webObjectsSvc.SiteExists(srvman, siteId); + } } public override string[] GetSites() { - return webObjectsSvc.GetSites(); + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + return webObjectsSvc.GetSites(srvman); + } } public new string GetSiteId(string siteName) { - return webObjectsSvc.GetWebSiteNameFromIIS(siteName); + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + return webObjectsSvc.GetWebSiteNameFromIIS(srvman, siteName); + } } public override WebSite GetSite(string siteId) { - WebAppPoolHelper aphl = new WebAppPoolHelper(ProviderSettings); - // - WebSite site = webObjectsSvc.GetWebSiteFromIIS(siteId); - // - site.Bindings = webObjectsSvc.GetSiteBindings(siteId); - // - FillVirtualDirectoryFromIISObject(site); - // - FillVirtualDirectoryRestFromIISObject(site); + WebSite site = null; + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + WebAppPoolHelper aphl = new WebAppPoolHelper(ProviderSettings); + // + site = webObjectsSvc.GetWebSiteFromIIS(srvman, siteId); + // + site.Bindings = webObjectsSvc.GetSiteBindings(srvman, siteId); + // + FillVirtualDirectoryFromIISObject(srvman, site); + // + FillVirtualDirectoryRestFromIISObject(srvman, site); - // check frontpage - site.FrontPageAvailable = IsFrontPageSystemInstalled(); - site.FrontPageInstalled = IsFrontPageInstalled(siteId); + // check frontpage + site.FrontPageAvailable = IsFrontPageSystemInstalled(); + site.FrontPageInstalled = IsFrontPageInstalled(srvman, siteId); - //check ColdFusion - if (IsColdFusionSystemInstalled()) - { - if (IsColdFusion7Installed()) - { - site.ColdFusionVersion = "7"; - site.ColdFusionAvailable = true; - } - else - { - if (IsColdFusion8Installed()) - { - site.ColdFusionVersion = "8"; - site.ColdFusionAvailable = true; - } - } + //check ColdFusion + if (IsColdFusionSystemInstalled()) + { + if (IsColdFusion7Installed()) + { + site.ColdFusionVersion = "7"; + site.ColdFusionAvailable = true; + } + else + { + if (IsColdFusion8Installed()) + { + site.ColdFusionVersion = "8"; + site.ColdFusionAvailable = true; + } + } - if (IsColdFusion9Installed()) - { - site.ColdFusionVersion = "9"; - site.ColdFusionAvailable = true; - } - } - else - { - site.ColdFusionAvailable = false; - } + if (IsColdFusion9Installed()) + { + site.ColdFusionVersion = "9"; + site.ColdFusionAvailable = true; + } + } + else + { + site.ColdFusionAvailable = false; + } - site.CreateCFVirtualDirectories = ColdFusionDirectoriesAdded(siteId); + site.CreateCFVirtualDirectories = ColdFusionDirectoriesAdded(srvman, siteId); - //site.ColdFusionInstalled = IsColdFusionEnabledOnSite(GetSiteId(site.Name)); + //site.ColdFusionInstalled = IsColdFusionEnabledOnSite(GetSiteId(site.Name)); - // check sharepoint - site.SharePointInstalled = false; - // - site.DedicatedApplicationPool = !aphl.is_shared_pool(site.ApplicationPool); - // - CheckEnableWritePermissions(site); - // - ReadWebManagementAccessDetails(site); - // - ReadWebDeployPublishingAccessDetails(site); - // - site.SecuredFoldersInstalled = IsSecuredFoldersInstalled(siteId); + // check sharepoint + site.SharePointInstalled = false; + // + site.DedicatedApplicationPool = !aphl.is_shared_pool(site.ApplicationPool); + // + CheckEnableWritePermissions(srvman, site); + // + ReadWebManagementAccessDetails(srvman, site); + // + ReadWebDeployPublishingAccessDetails(site); + // + site.SecuredFoldersInstalled = IsSecuredFoldersInstalled(srvman, siteId); - // check Helicon Ape - HeliconApeStatus heliconApeStatus = GetHeliconApeStatus(siteId); - site.HeliconApeInstalled = heliconApeStatus.IsInstalled; - site.HeliconApeEnabled = heliconApeStatus.IsEnabled; + // check Helicon Ape + HeliconApeStatus heliconApeStatus = GetHeliconApeStatus(srvman, siteId); + site.HeliconApeInstalled = heliconApeStatus.IsInstalled; + site.HeliconApeEnabled = heliconApeStatus.IsEnabled; - // - site.SiteState = GetSiteState(siteId); - // - site.SecuredFoldersInstalled = IsSecuredFoldersInstalled(siteId); - // - site.SiteState = GetSiteState(siteId); - // + // + site.SiteState = GetSiteState(srvman, siteId); + // + site.SecuredFoldersInstalled = IsSecuredFoldersInstalled(srvman, siteId); + // + site.SiteState = GetSiteState(srvman, siteId); + // + } return site; } public new string[] GetSitesAccounts(string[] siteIds) { - List accounts = new List(); - // - for (int i = 0; i < siteIds.Length; i++) - { - try - { - accounts.Add((string)anonymAuthSvc.GetAuthenticationSettings(siteIds[i])[AuthenticationGlobals.AnonymousAuthenticationUserName]); - } - catch (Exception ex) - { - Log.WriteError(String.Format("Web site {0} is either deleted or doesn't exist", siteIds[i]), ex); - } - } - // + List accounts = new List(); + + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + for (int i = 0; i < siteIds.Length; i++) + { + try + { + accounts.Add((string)anonymAuthSvc.GetAuthenticationSettings(srvman, siteIds[i])[AuthenticationGlobals.AnonymousAuthenticationUserName]); + } + catch (Exception ex) + { + Log.WriteError(String.Format("Web site {0} is either deleted or doesn't exist", siteIds[i]), ex); + } + } + } return accounts.ToArray(); } public override ServerBinding[] GetSiteBindings(string siteId) { - return webObjectsSvc.GetSiteBindings(siteId); + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + return webObjectsSvc.GetSiteBindings(srvman, siteId); + } } public override string CreateSite(WebSite site) @@ -1316,22 +1346,25 @@ namespace WebsitePanel.Providers.Web } #region ColdFusion Virtual Directories - if (ColdFusionDirectoriesAdded(site.SiteId)) - { - if (!site.CreateCFVirtualDirectories) - { - DeleteCFVirtualDirectories(site.SiteId); - site.CreateCFVirtualDirectories = false; - } - } - else - { - if (site.CreateCFVirtualDirectories) - { - CreateCFVirtualDirectories(site.SiteId); - site.CreateCFVirtualDirectories = true; - } - } + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + if (ColdFusionDirectoriesAdded(srvman, site.SiteId)) + { + if (!site.CreateCFVirtualDirectories) + { + DeleteCFVirtualDirectories(site.SiteId); + site.CreateCFVirtualDirectories = false; + } + } + else + { + if (site.CreateCFVirtualDirectories) + { + CreateCFVirtualDirectories(site.SiteId); + site.CreateCFVirtualDirectories = true; + } + } + } #endregion // remove dedicated pools if any @@ -1429,23 +1462,31 @@ namespace WebsitePanel.Providers.Web /// virtual directories that belong to site with supplied id. public override WebVirtualDirectory[] GetVirtualDirectories(string siteId) { - // get all virt dirs - WebVirtualDirectory[] virtDirs = webObjectsSvc.GetVirtualDirectories(siteId); - - // filter - string sharedToolsFolder = GetMicrosoftSharedFolderPath(); - List result = new List(); - foreach (WebVirtualDirectory dir in virtDirs) - { - // check if this is a system (FrontPage or SharePoint) virtual iisDirObject - if (!String.IsNullOrEmpty(sharedToolsFolder) - && dir.ContentPath.ToLower().StartsWith(sharedToolsFolder.ToLower())) - continue; - result.Add(dir); - } - return result.ToArray(); + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + return GetVirtualDirectories(srvman, siteId); + } } + private WebVirtualDirectory[] GetVirtualDirectories(ServerManager srvman, string siteId) + { + // get all virt dirs + WebVirtualDirectory[] virtDirs = webObjectsSvc.GetVirtualDirectories(srvman, siteId); + + // filter + string sharedToolsFolder = GetMicrosoftSharedFolderPath(); + List result = new List(); + foreach (WebVirtualDirectory dir in virtDirs) + { + // check if this is a system (FrontPage or SharePoint) virtual iisDirObject + if (!String.IsNullOrEmpty(sharedToolsFolder) + && dir.ContentPath.ToLower().StartsWith(sharedToolsFolder.ToLower())) + continue; + result.Add(dir); + } + return result.ToArray(); + } + /// /// Gets virtual iisDirObject description that belongs to site with supplied id and has specified name. /// @@ -1454,22 +1495,25 @@ namespace WebsitePanel.Providers.Web /// virtual iisDirObject description that belongs to site with supplied id and has specified name. public override WebVirtualDirectory GetVirtualDirectory(string siteId, string directoryName) { - WebAppPoolHelper aphl = new WebAppPoolHelper(ProviderSettings); - // - WebVirtualDirectory webVirtualDirectory = webObjectsSvc.GetVirtualDirectory(siteId, directoryName); - // - this.FillVirtualDirectoryFromIISObject(webVirtualDirectory); - this.FillVirtualDirectoryRestFromIISObject(webVirtualDirectory); - // - webVirtualDirectory.DedicatedApplicationPool = !aphl.is_shared_pool(webVirtualDirectory.ApplicationPool); - // - CheckEnableWritePermissions(webVirtualDirectory); - // - ReadWebManagementAccessDetails(webVirtualDirectory); - // - ReadWebDeployPublishingAccessDetails(webVirtualDirectory); - // - return webVirtualDirectory; + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + WebAppPoolHelper aphl = new WebAppPoolHelper(ProviderSettings); + // + WebVirtualDirectory webVirtualDirectory = webObjectsSvc.GetVirtualDirectory(siteId, directoryName); + // + this.FillVirtualDirectoryFromIISObject(srvman, webVirtualDirectory); + this.FillVirtualDirectoryRestFromIISObject(srvman, webVirtualDirectory); + // + webVirtualDirectory.DedicatedApplicationPool = !aphl.is_shared_pool(webVirtualDirectory.ApplicationPool); + // + CheckEnableWritePermissions(srvman, webVirtualDirectory); + // + ReadWebManagementAccessDetails(srvman, webVirtualDirectory); + // + ReadWebDeployPublishingAccessDetails(webVirtualDirectory); + // + return webVirtualDirectory; + } } /// @@ -1492,13 +1536,16 @@ namespace WebsitePanel.Providers.Web directory.ApplicationPool = webSite.ApplicationPool; // Create record in IIS's configuration. webObjectsSvc.CreateVirtualDirectory(siteId, directory.VirtualPath, directory.ContentPath); - // - PropertyBag bag = anonymAuthSvc.GetAuthenticationSettings(siteId); - directory.AnonymousUsername = (string)bag[AuthenticationGlobals.AnonymousAuthenticationUserName]; - directory.AnonymousUserPassword = (string)bag[AuthenticationGlobals.AnonymousAuthenticationPassword]; - directory.EnableAnonymousAccess = (bool)bag[AuthenticationGlobals.Enabled]; - // Update virtual iisDirObject. - this.UpdateVirtualDirectory(siteId, directory); + + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + PropertyBag bag = anonymAuthSvc.GetAuthenticationSettings(srvman, siteId); + directory.AnonymousUsername = (string)bag[AuthenticationGlobals.AnonymousAuthenticationUserName]; + directory.AnonymousUserPassword = (string)bag[AuthenticationGlobals.AnonymousAuthenticationPassword]; + directory.EnableAnonymousAccess = (bool)bag[AuthenticationGlobals.Enabled]; + // Update virtual iisDirObject. + this.UpdateVirtualDirectory(siteId, directory); + } } /// @@ -1508,35 +1555,41 @@ namespace WebsitePanel.Providers.Web /// Web iisDirObject that needs to be updated. public override void UpdateVirtualDirectory(string siteId, WebVirtualDirectory directory) { - if (this.webObjectsSvc.SiteExists(siteId)) - { - WebAppPoolHelper aphl = new WebAppPoolHelper(ProviderSettings); - // - bool dedicatedPool = !aphl.is_shared_pool(directory.ApplicationPool); - // - SiteAppPoolMode sisMode = dedicatedPool ? SiteAppPoolMode.Dedicated : SiteAppPoolMode.Shared; - // - directory.ParentSiteName = siteId; - // - string origPath = webObjectsSvc.GetPhysicalPath(directory); - // remove unnecessary permissions - // if original folder has been changed - if (String.Compare(origPath, directory.ContentPath, true) != 0) - RemoveWebFolderPermissions(origPath, GetNonQualifiedAccountName(directory.AnonymousUsername)); - // set folder permissions - SetWebFolderPermissions(directory.ContentPath, GetNonQualifiedAccountName(directory.AnonymousUsername), - directory.EnableWritePermissions, dedicatedPool); - // - var pool = Array.Find(aphl.SupportedAppPools.ToArray(), - x => x.AspNetInstalled.Equals(directory.AspNetInstalled) && aphl.isolation(x.Mode) == sisMode); - // Assign to virtual iisDirObject iisAppObject pool - directory.ApplicationPool = WSHelper.InferAppPoolName(pool.Name, siteId, pool.Mode); - // - webObjectsSvc.UpdateVirtualDirectory(directory); - // - this.FillIISObjectFromVirtualDirectory(directory); - this.FillIISObjectFromVirtualDirectoryRest(directory); - } + string origPath = null; + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + if (!this.webObjectsSvc.SiteExists(srvman, siteId)) + return; + + // get original path + origPath = webObjectsSvc.GetPhysicalPath(srvman, directory); + } + + WebAppPoolHelper aphl = new WebAppPoolHelper(ProviderSettings); + // + bool dedicatedPool = !aphl.is_shared_pool(directory.ApplicationPool); + // + SiteAppPoolMode sisMode = dedicatedPool ? SiteAppPoolMode.Dedicated : SiteAppPoolMode.Shared; + // + directory.ParentSiteName = siteId; + + // remove unnecessary permissions + // if original folder has been changed + if (String.Compare(origPath, directory.ContentPath, true) != 0) + RemoveWebFolderPermissions(origPath, GetNonQualifiedAccountName(directory.AnonymousUsername)); + // set folder permissions + SetWebFolderPermissions(directory.ContentPath, GetNonQualifiedAccountName(directory.AnonymousUsername), + directory.EnableWritePermissions, dedicatedPool); + // + var pool = Array.Find(aphl.SupportedAppPools.ToArray(), + x => x.AspNetInstalled.Equals(directory.AspNetInstalled) && aphl.isolation(x.Mode) == sisMode); + // Assign to virtual iisDirObject iisAppObject pool + directory.ApplicationPool = WSHelper.InferAppPoolName(pool.Name, siteId, pool.Mode); + // + webObjectsSvc.UpdateVirtualDirectory(directory); + // + this.FillIISObjectFromVirtualDirectory(directory); + this.FillIISObjectFromVirtualDirectoryRest(directory); } /// @@ -1567,31 +1620,43 @@ namespace WebsitePanel.Providers.Web protected override bool IsSecuredFoldersInstalled(string siteId) { - using (var srvman = webObjectsSvc.GetServerManager()) - { - // - var appConfig = srvman.GetApplicationHostConfiguration(); - // - var modulesSection = appConfig.GetSection(Constants.ModulesSection, siteId); - // - var modulesCollection = modulesSection.GetCollection(); - // - foreach (var moduleEntry in modulesCollection) - { - if (String.Equals(moduleEntry["name"].ToString(), Constants.WEBSITEPANEL_IISMODULES, StringComparison.InvariantCultureIgnoreCase)) - return true; - } - } - // - return false; + using (var srvman = webObjectsSvc.GetServerManager()) + { + return IsSecuredFoldersInstalled(srvman, siteId); + } } - protected override string GetSiteContentPath(string siteId) + private bool IsSecuredFoldersInstalled(ServerManager srvman, string siteId) + { + var appConfig = srvman.GetApplicationHostConfiguration(); + // + var modulesSection = appConfig.GetSection(Constants.ModulesSection, siteId); + // + var modulesCollection = modulesSection.GetCollection(); + // + foreach (var moduleEntry in modulesCollection) + { + if (String.Equals(moduleEntry["name"].ToString(), Constants.WEBSITEPANEL_IISMODULES, StringComparison.InvariantCultureIgnoreCase)) + return true; + } + // + return false; + } + + protected override string GetSiteContentPath(string siteId) + { + using (var srvman = webObjectsSvc.GetServerManager()) + { + return GetSiteContentPath(srvman, siteId); + } + } + + protected string GetSiteContentPath(ServerManager srvman, string siteId) { - var webSite = webObjectsSvc.GetWebSiteFromIIS(siteId); + var webSite = webObjectsSvc.GetWebSiteFromIIS(srvman, siteId); // if (webSite != null) - return webObjectsSvc.GetPhysicalPath(webSite); + return webObjectsSvc.GetPhysicalPath(srvman, webSite); // return String.Empty; } @@ -1604,68 +1669,70 @@ namespace WebsitePanel.Providers.Web /// public override void InstallSecuredFolders(string siteId) { - // - if (String.IsNullOrEmpty(siteId)) - throw new ArgumentNullException("siteId"); + using (var srvman = webObjectsSvc.GetServerManager()) + { + // + if (String.IsNullOrEmpty(siteId)) + throw new ArgumentNullException("siteId"); - // WebsitePanel.IIsModules works for apps working in Integrated Pipeline mode - #region Switch automatically to the app pool with Integrated Pipeline enabled - var webSite = webObjectsSvc.GetWebSiteFromIIS(siteId); - // - if (webSite == null) - throw new ApplicationException(String.Format("Could not find a web site with the following identifier: {0}.", siteId)); - // - var aphl = new WebAppPoolHelper(ProviderSettings); - // Fill ASP.NET settings - FillAspNetSettingsFromIISObject(webSite); - // - var currentPool = aphl.match_webapp_pool(webSite); - var dotNetVersion = aphl.dotNetVersion(currentPool.Mode); - var sisMode = aphl.isolation(currentPool.Mode); - // AT least ASP.NET 2.0 is allowed to provide such capabilities... - if (dotNetVersion == SiteAppPoolMode.dotNetFramework1) - dotNetVersion = SiteAppPoolMode.dotNetFramework2; - // and Integrated pipeline... - if (aphl.pipeline(currentPool.Mode) != SiteAppPoolMode.Integrated) - { - // Lookup for the opposite pool matching the criteria - var oppositePool = Array.Find(aphl.SupportedAppPools.ToArray(), - x => aphl.dotNetVersion(x.Mode) == dotNetVersion && aphl.isolation(x.Mode) == sisMode - && aphl.pipeline(x.Mode) == SiteAppPoolMode.Integrated); - // - webSite.AspNetInstalled = oppositePool.AspNetInstalled; - // - SetWebSiteApplicationPool(webSite, false); - // - using (var srvman = webObjectsSvc.GetServerManager()) - { - var iisSiteObject = srvman.Sites[siteId]; - iisSiteObject.Applications["/"].ApplicationPoolName = webSite.ApplicationPool; - // - srvman.CommitChanges(); - } - } + // WebsitePanel.IIsModules works for apps working in Integrated Pipeline mode + #region Switch automatically to the app pool with Integrated Pipeline enabled + var webSite = webObjectsSvc.GetWebSiteFromIIS(srvman, siteId); + // + if (webSite == null) + throw new ApplicationException(String.Format("Could not find a web site with the following identifier: {0}.", siteId)); + // + var aphl = new WebAppPoolHelper(ProviderSettings); + // Fill ASP.NET settings + FillAspNetSettingsFromIISObject(srvman, webSite); + // + var currentPool = aphl.match_webapp_pool(webSite); + var dotNetVersion = aphl.dotNetVersion(currentPool.Mode); + var sisMode = aphl.isolation(currentPool.Mode); + // AT least ASP.NET 2.0 is allowed to provide such capabilities... + if (dotNetVersion == SiteAppPoolMode.dotNetFramework1) + dotNetVersion = SiteAppPoolMode.dotNetFramework2; + // and Integrated pipeline... + if (aphl.pipeline(currentPool.Mode) != SiteAppPoolMode.Integrated) + { + // Lookup for the opposite pool matching the criteria + var oppositePool = Array.Find(aphl.SupportedAppPools.ToArray(), + x => aphl.dotNetVersion(x.Mode) == dotNetVersion && aphl.isolation(x.Mode) == sisMode + && aphl.pipeline(x.Mode) == SiteAppPoolMode.Integrated); + // + webSite.AspNetInstalled = oppositePool.AspNetInstalled; + // + SetWebSiteApplicationPool(webSite, false); + // + + var iisSiteObject = srvman.Sites[siteId]; + iisSiteObject.Applications["/"].ApplicationPoolName = webSite.ApplicationPool; + // + srvman.CommitChanges(); + } + } #endregion #region Disable automatically Integrated Windows Authentication - PropertyBag winAuthBag = winAuthSvc.GetAuthenticationSettings(siteId); - // - if ((bool)winAuthBag[AuthenticationGlobals.Enabled]) - { - // - using (var srvman = webObjectsSvc.GetServerManager()) - { - Configuration config = srvman.GetApplicationHostConfiguration(); + // + using (var srvman = webObjectsSvc.GetServerManager()) + { + PropertyBag winAuthBag = winAuthSvc.GetAuthenticationSettings(srvman, siteId); + // + if ((bool)winAuthBag[AuthenticationGlobals.Enabled]) + { - ConfigurationSection windowsAuthenticationSection = config.GetSection( - "system.webServer/security/authentication/windowsAuthentication", - siteId); - // - windowsAuthenticationSection["enabled"] = false; - // - srvman.CommitChanges(); - } - } + Configuration config = srvman.GetApplicationHostConfiguration(); + + ConfigurationSection windowsAuthenticationSection = config.GetSection( + "system.webServer/security/authentication/windowsAuthentication", + siteId); + // + windowsAuthenticationSection["enabled"] = false; + // + srvman.CommitChanges(); + } + } #endregion // @@ -1730,34 +1797,40 @@ namespace WebsitePanel.Providers.Web #region Helicon Ape - public override HeliconApeStatus GetHeliconApeStatus(string siteId) + public override HeliconApeStatus GetHeliconApeStatus(string siteId) + { + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + return GetHeliconApeStatus(srvman, siteId); + } + } + + private HeliconApeStatus GetHeliconApeStatus(ServerManager srvman, string siteId) { string installDir = GetHeliconApeInstallDir(siteId); string registrationInfo = GetRegistrationInfo(siteId, installDir); - return new HeliconApeStatus { - IsEnabled = IsHeliconApeEnabled(siteId), + return new HeliconApeStatus + { + IsEnabled = IsHeliconApeEnabled(srvman, siteId), InstallDir = installDir, - IsInstalled = IsHeliconApeInstalled(siteId, installDir), + IsInstalled = IsHeliconApeInstalled(srvman, siteId, installDir), Version = GetHeliconApeVersion(siteId, installDir), IsRegistered = IsHeliconApeRegistered(siteId, registrationInfo), RegistrationInfo = registrationInfo }; } - private bool IsHeliconApeEnabled(string siteId) + private bool IsHeliconApeEnabled(ServerManager srvman, string siteId) { - using (var srvman = webObjectsSvc.GetServerManager()) - { - var appConfig = srvman.GetApplicationHostConfiguration(); - var modulesSection = appConfig.GetSection(Constants.ModulesSection, siteId); - var modulesCollection = modulesSection.GetCollection(); + var appConfig = srvman.GetApplicationHostConfiguration(); + var modulesSection = appConfig.GetSection(Constants.ModulesSection, siteId); + var modulesCollection = modulesSection.GetCollection(); - foreach (var moduleEntry in modulesCollection) - { - if (String.Equals(moduleEntry["name"].ToString(), Constants.HeliconApeModule, StringComparison.InvariantCultureIgnoreCase)) - return true; - } + foreach (var moduleEntry in modulesCollection) + { + if (String.Equals(moduleEntry["name"].ToString(), Constants.HeliconApeModule, StringComparison.InvariantCultureIgnoreCase)) + return true; } // return false; @@ -1794,10 +1867,14 @@ namespace WebsitePanel.Providers.Web private void RemoveDelegationRulesRestrictions(string siteName, string accountName) { + WebSite webSite = null; + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + webSite = webObjectsSvc.GetWebSiteFromIIS(srvman, siteName); + } var moduleService = new DelegationRulesModuleService(); // Adjust web publishing permissions to the user accordingly to deny some rules for shared app pools - var webSite = webObjectsSvc.GetWebSiteFromIIS(siteName); - // + var fqUsername = GetFullQualifiedAccountName(accountName); // Instantiate application pool helper to retrieve the app pool mode web site is running in WebAppPoolHelper aphl = new WebAppPoolHelper(ProviderSettings); @@ -1814,10 +1891,14 @@ namespace WebsitePanel.Providers.Web public void EnforceDelegationRulesRestrictions(string siteName, string accountName) { + WebSite webSite = null; + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + webSite = webObjectsSvc.GetWebSiteFromIIS(srvman, siteName); + } + var moduleService = new DelegationRulesModuleService(); // Adjust web publishing permissions to the user accordingly to deny some rules for shared app pools - var webSite = webObjectsSvc.GetWebSiteFromIIS(siteName); - // var fqUsername = GetFullQualifiedAccountName(accountName); // Instantiate application pool helper to retrieve the app pool mode web site is running in WebAppPoolHelper aphl = new WebAppPoolHelper(ProviderSettings); @@ -1843,7 +1924,7 @@ namespace WebsitePanel.Providers.Web return Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Helicon\\Ape", "InstallDir", string.Empty) as string; } - private bool IsHeliconApeInstalled(string siteId, string installDir) + private bool IsHeliconApeInstalled(ServerManager srvman, string siteId, string installDir) { //Check global registration bool result = !string.IsNullOrEmpty(installDir); @@ -1851,7 +1932,7 @@ namespace WebsitePanel.Providers.Web if (!result && !string.IsNullOrEmpty(siteId)) { //Check per-site installation - string sitepath = GetSiteContentPath(siteId); + string sitepath = GetSiteContentPath(srvman, siteId); string dllPath = Path.Combine(sitepath, "Bin\\Helicon.Ape.dll"); result = File.Exists(dllPath); @@ -1982,21 +2063,26 @@ namespace WebsitePanel.Providers.Web public override void EnableHeliconApe(string siteId) { - // - if (String.IsNullOrEmpty(siteId)) - throw new ArgumentNullException("siteId"); + WebSite webSite = null; + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + // + if (String.IsNullOrEmpty(siteId)) + throw new ArgumentNullException("siteId"); + + // Helicon.Ape.ApeModule works for apps working in Integrated Pipeline mode + // Switch automatically to the app pool with Integrated Pipeline enabled + webSite = webObjectsSvc.GetWebSiteFromIIS(srvman, siteId); + // + if (webSite == null) + throw new ApplicationException(String.Format("Could not find a web site with the following identifier: {0}.", siteId)); + + // Fill ASP.NET settings + FillAspNetSettingsFromIISObject(srvman, webSite); + } - // Helicon.Ape.ApeModule works for apps working in Integrated Pipeline mode - #region Switch automatically to the app pool with Integrated Pipeline enabled - var webSite = webObjectsSvc.GetWebSiteFromIIS(siteId); - // - if (webSite == null) - throw new ApplicationException(String.Format("Could not find a web site with the following identifier: {0}.", siteId)); // var aphl = new WebAppPoolHelper(ProviderSettings); - // Fill ASP.NET settings - FillAspNetSettingsFromIISObject(webSite); - // var currentPool = aphl.match_webapp_pool(webSite); var dotNetVersion = aphl.dotNetVersion(currentPool.Mode); var sisMode = aphl.isolation(currentPool.Mode); @@ -2023,15 +2109,13 @@ namespace WebsitePanel.Providers.Web srvman.CommitChanges(); } } - #endregion #region Disable automatically Integrated Windows Authentication - PropertyBag winAuthBag = winAuthSvc.GetAuthenticationSettings(siteId); - // - if ((bool)winAuthBag[AuthenticationGlobals.Enabled]) + using (var srvman = webObjectsSvc.GetServerManager()) { + PropertyBag winAuthBag = winAuthSvc.GetAuthenticationSettings(srvman, siteId); // - using (var srvman = webObjectsSvc.GetServerManager()) + if ((bool)winAuthBag[AuthenticationGlobals.Enabled]) { Configuration config = srvman.GetApplicationHostConfiguration(); @@ -2255,7 +2339,7 @@ namespace WebsitePanel.Providers.Web return string.Format("{0}:{1}", user.Realm, PasswdHelper.DigestEncode(user.Name, user.Password, user.Realm)); } - public List GetHeliconApeUsers(string siteId) + public override List GetHeliconApeUsers(string siteId) { string rootPath = GetSiteContentPath(siteId); List users = new List(); @@ -2284,7 +2368,7 @@ namespace WebsitePanel.Providers.Web return users; } - public HtaccessUser GetHeliconApeUser(string siteId, string userName) + public override HtaccessUser GetHeliconApeUser(string siteId, string userName) { // load users file string rootPath = GetSiteContentPath(siteId); @@ -2348,7 +2432,7 @@ namespace WebsitePanel.Providers.Web return user; } - public void UpdateHeliconApeUser(string siteId, HtaccessUser user) + public override void UpdateHeliconApeUser(string siteId, HtaccessUser user) { UpdateHeliconApeUser(siteId, user, false); } @@ -2462,7 +2546,7 @@ namespace WebsitePanel.Providers.Web HtaccessFolder.WriteLinesFile(groupsPath, groupLines); } - public void DeleteHeliconApeUser(string siteId, string userName) + public override void DeleteHeliconApeUser(string siteId, string userName) { string rootPath = GetSiteContentPath(siteId); HtaccessUser user = new HtaccessUser(); @@ -2477,7 +2561,7 @@ namespace WebsitePanel.Providers.Web #endregion #region Secured Helicon Ape Groups - public List GetHeliconApeGroups(string siteId) + public override List GetHeliconApeGroups(string siteId) { string rootPath = GetSiteContentPath(siteId); List groups = new List(); @@ -2502,7 +2586,7 @@ namespace WebsitePanel.Providers.Web return groups; } - public WebGroup GetHeliconApeGroup(string siteId, string groupName) + public override WebGroup GetHeliconApeGroup(string siteId, string groupName) { string rootPath = GetSiteContentPath(siteId); // open groups file @@ -2531,7 +2615,7 @@ namespace WebsitePanel.Providers.Web return group; } - public void UpdateHeliconApeGroup(string siteId, WebGroup group) + public override void UpdateHeliconApeGroup(string siteId, WebGroup group) { UpdateHeliconApeGroup(siteId, group, false); } @@ -2581,7 +2665,7 @@ namespace WebsitePanel.Providers.Web HtaccessFolder.WriteLinesFile(groupsPath, updatedGroups); } - public void DeleteHeliconApeGroup(string siteId, string groupName) + public override void DeleteHeliconApeGroup(string siteId, string groupName) { string rootPath = GetSiteContentPath(siteId); @@ -2600,31 +2684,41 @@ namespace WebsitePanel.Providers.Web public override bool IsFrontPageInstalled(string siteId) { - // Get IIS web site id - string m_webSiteId = webObjectsSvc.GetWebSiteIdFromIIS(siteId, "W3SVC/{0}"); - // site port - RegistryKey sitePortKey = Registry.LocalMachine.OpenSubKey(String.Format("{0}Port /LM/{1}:", - FRONTPAGE_PORT_REGLOC, m_webSiteId)); - - if (sitePortKey == null) - return false; - - // get required keys - string keyAuthoring = (string)sitePortKey.GetValue("authoring"); - string keyFrontPageRoot = (string)sitePortKey.GetValue("frontpageroot"); - - return (keyAuthoring != null && keyAuthoring.ToUpper() == "ENABLED" && - keyFrontPageRoot != null && keyFrontPageRoot.IndexOf("\\50") != -1); + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + return IsFrontPageInstalled(srvman, siteId); + } } + private bool IsFrontPageInstalled(ServerManager srvman, string siteId) + { + // Get IIS web site id + string m_webSiteId = webObjectsSvc.GetWebSiteIdFromIIS(srvman, siteId, "W3SVC/{0}"); + // site port + RegistryKey sitePortKey = Registry.LocalMachine.OpenSubKey(String.Format("{0}Port /LM/{1}:", + FRONTPAGE_PORT_REGLOC, m_webSiteId)); + + if (sitePortKey == null) + return false; + + // get required keys + string keyAuthoring = (string)sitePortKey.GetValue("authoring"); + string keyFrontPageRoot = (string)sitePortKey.GetValue("frontpageroot"); + + return (keyAuthoring != null && keyAuthoring.ToUpper() == "ENABLED" && + keyFrontPageRoot != null && keyFrontPageRoot.IndexOf("\\50") != -1); + } + public override bool InstallFrontPage(string siteId, string username, string password) { // Ensure requested user account doesn't exist if (SecurityUtils.UserExists(username, ServerSettings, UsersOU)) return false; + // Ensure a web site exists if (!SiteExists(siteId)) return false; + // create user account SystemUser user = new SystemUser { @@ -2643,45 +2737,46 @@ namespace WebsitePanel.Providers.Web try { - string cmdPath = null; - string cmdArgs = null; - // - string m_webSiteId = webObjectsSvc.GetWebSiteIdFromIIS(siteId, null); + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + string cmdPath = null; + string cmdArgs = null; + // + string m_webSiteId = webObjectsSvc.GetWebSiteIdFromIIS(srvman, siteId, null); - // try to install FPSE2002 - // add registry key for anonymous group if not exists - RegistryKey portsKey = Registry.LocalMachine.OpenSubKey(FRONTPAGE_ALLPORTS_REGLOC, true); - portsKey.SetValue("anonusergroupprefix", "anonfp"); + // try to install FPSE2002 + // add registry key for anonymous group if not exists + RegistryKey portsKey = Registry.LocalMachine.OpenSubKey(FRONTPAGE_ALLPORTS_REGLOC, true); + portsKey.SetValue("anonusergroupprefix", "anonfp"); - #region Create anonymous group to get FPSE work + #region Create anonymous group to get FPSE work - string groupName = "anonfp_" + m_webSiteId; - if (!SecurityUtils.GroupExists(groupName, ServerSettings, GroupsOU)) - { - SystemGroup fpseGroup = new SystemGroup(); - fpseGroup.Name = groupName; - fpseGroup.Description = "Anonymous FPSE group for " + siteId + " web site"; - fpseGroup.Members = new string[] { username }; - SecurityUtils.CreateGroup(fpseGroup, ServerSettings, UsersOU, GroupsOU); - } + string groupName = "anonfp_" + m_webSiteId; + if (!SecurityUtils.GroupExists(groupName, ServerSettings, GroupsOU)) + { + SystemGroup fpseGroup = new SystemGroup(); + fpseGroup.Name = groupName; + fpseGroup.Description = "Anonymous FPSE group for " + siteId + " web site"; + fpseGroup.Members = new string[] { username }; + SecurityUtils.CreateGroup(fpseGroup, ServerSettings, UsersOU, GroupsOU); + } - #endregion + #endregion - #region Install FPSE 2002 to the website by owsadm.exe install command + #region Install FPSE 2002 to the website by owsadm.exe install command - cmdPath = Environment.ExpandEnvironmentVariables(FPSE2002_OWSADM_PATH); - cmdArgs = String.Format("-o install -p /LM/W3SVC/{0} -u {1}", m_webSiteId, username); - Log.WriteInfo("Command path: " + cmdPath); - Log.WriteInfo("Command path: " + cmdArgs); - Log.WriteInfo("FPSE2002 Install Log: " + FileUtils.ExecuteSystemCommand(cmdPath, cmdArgs)); + cmdPath = Environment.ExpandEnvironmentVariables(FPSE2002_OWSADM_PATH); + cmdArgs = String.Format("-o install -p /LM/W3SVC/{0} -u {1}", m_webSiteId, username); + Log.WriteInfo("Command path: " + cmdPath); + Log.WriteInfo("Command path: " + cmdArgs); + Log.WriteInfo("FPSE2002 Install Log: " + FileUtils.ExecuteSystemCommand(cmdPath, cmdArgs)); - #endregion + #endregion + } - #region Enable Windows Authentication mode + // Enable Windows Authentication mode + winAuthSvc.SetEnabled(siteId, true); - winAuthSvc.SetEnabled(siteId, true); - - #endregion } catch (Exception ex) { @@ -2695,44 +2790,47 @@ namespace WebsitePanel.Providers.Web public override void UninstallFrontPage(string siteId, string username) { - // Ensure a web site exists - if (!SiteExists(siteId)) - return; + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + // Ensure a web site exists + if (!webObjectsSvc.SiteExists(srvman, siteId)) + return; - try - { - string m_webSiteId = webObjectsSvc.GetWebSiteIdFromIIS(siteId, null); + try + { + string m_webSiteId = webObjectsSvc.GetWebSiteIdFromIIS(srvman, siteId, null); - // remove anonymous group - string groupName = "anonfp_" + m_webSiteId; - if (SecurityUtils.GroupExists(groupName, ServerSettings, GroupsOU)) - SecurityUtils.DeleteGroup(groupName, ServerSettings, GroupsOU); + // remove anonymous group + string groupName = "anonfp_" + m_webSiteId; + if (SecurityUtils.GroupExists(groupName, ServerSettings, GroupsOU)) + SecurityUtils.DeleteGroup(groupName, ServerSettings, GroupsOU); - #region Trying to uninstall FPSE2002 from the web site + #region Trying to uninstall FPSE2002 from the web site - // - string cmdPath = null; - string cmdArgs = null; + // + string cmdPath = null; + string cmdArgs = null; - cmdPath = Environment.ExpandEnvironmentVariables(FPSE2002_OWSADM_PATH); - cmdArgs = String.Format("-o fulluninstall -p /LM/W3SVC/{0}", m_webSiteId); + cmdPath = Environment.ExpandEnvironmentVariables(FPSE2002_OWSADM_PATH); + cmdArgs = String.Format("-o fulluninstall -p /LM/W3SVC/{0}", m_webSiteId); - // launch system process - Log.WriteInfo("FPSE2002 Uninstall Log: " + FileUtils.ExecuteSystemCommand(cmdPath, cmdArgs)); + // launch system process + Log.WriteInfo("FPSE2002 Uninstall Log: " + FileUtils.ExecuteSystemCommand(cmdPath, cmdArgs)); - #endregion + #endregion - // delete user account - if (SecurityUtils.UserExists(username, ServerSettings, UsersOU)) - SecurityUtils.DeleteUser(username, ServerSettings, UsersOU); + // delete user account + if (SecurityUtils.UserExists(username, ServerSettings, UsersOU)) + SecurityUtils.DeleteUser(username, ServerSettings, UsersOU); - // Disable Windows Authentication mode - winAuthSvc.SetEnabled(siteId, false); - } - catch (Exception ex) - { - Log.WriteError(String.Format("FPSE2002 uninstall error. Web site: {0}.", siteId), ex); - } + // Disable Windows Authentication mode + winAuthSvc.SetEnabled(siteId, false); + } + catch (Exception ex) + { + Log.WriteError(String.Format("FPSE2002 uninstall error. Web site: {0}.", siteId), ex); + } + } } public override bool IsFrontPageSystemInstalled() @@ -2802,11 +2900,11 @@ namespace WebsitePanel.Providers.Web } - public bool ColdFusionDirectoriesAdded(string siteId) + public bool ColdFusionDirectoriesAdded(ServerManager srvman, string siteId) { int identifier = 0; - WebVirtualDirectory[] dirs = GetVirtualDirectories(siteId); + WebVirtualDirectory[] dirs = GetVirtualDirectories(srvman, siteId); foreach (WebVirtualDirectory dir in dirs) { @@ -2820,27 +2918,30 @@ namespace WebsitePanel.Providers.Web { bool isCFenabled = false; - string ID = webObjectsSvc.GetWebSiteIdFromIIS(siteId, "{0}"); + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + string ID = webObjectsSvc.GetWebSiteIdFromIIS(srvman, siteId, "{0}"); - if (IsColdFusionSystemInstalled()) - { - string pathWsConfigSettings = Path.Combine(GetColdFusionRootPath(), @"runtime\lib\wsconfig\wsconfig.properties"); - StreamReader file = new StreamReader(pathWsConfigSettings); - string line = String.Empty; - int counter = 0; - while ((line = file.ReadLine()) != null) - { - if (line.Contains(String.Format("=IIS,{0},", ID))) - { - isCFenabled = true; - break; - } - counter++; - } - file.Close(); - } + if (IsColdFusionSystemInstalled()) + { + string pathWsConfigSettings = Path.Combine(GetColdFusionRootPath(), @"runtime\lib\wsconfig\wsconfig.properties"); + StreamReader file = new StreamReader(pathWsConfigSettings); + string line = String.Empty; + int counter = 0; + while ((line = file.ReadLine()) != null) + { + if (line.Contains(String.Format("=IIS,{0},", ID))) + { + isCFenabled = true; + break; + } + counter++; + } + file.Close(); + } - return isCFenabled; + return isCFenabled; + } } #endregion @@ -2848,17 +2949,21 @@ namespace WebsitePanel.Providers.Web #region HostingServiceProvider methods public override SettingPair[] GetProviderDefaultSettings() { - List allSettings = new List(); - allSettings.AddRange(extensionsSvc.GetISAPIExtensionsInstalled()); + List allSettings = new List(); - // add default web management settings - WebManagementServiceSettings wmSettings = GetWebManagementServiceSettings(); - if (wmSettings != null) - { - allSettings.Add(new SettingPair("WmSvc.Port", wmSettings.Port)); - allSettings.Add(new SettingPair("WmSvc.ServiceUrl", wmSettings.ServiceUrl)); - allSettings.Add(new SettingPair("WmSvc.RequiresWindowsCredentials", wmSettings.RequiresWindowsCredentials.ToString())); - } + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + allSettings.AddRange(extensionsSvc.GetISAPIExtensionsInstalled(srvman)); + + // add default web management settings + WebManagementServiceSettings wmSettings = GetWebManagementServiceSettings(); + if (wmSettings != null) + { + allSettings.Add(new SettingPair("WmSvc.Port", wmSettings.Port)); + allSettings.Add(new SettingPair("WmSvc.ServiceUrl", wmSettings.ServiceUrl)); + allSettings.Add(new SettingPair("WmSvc.RequiresWindowsCredentials", wmSettings.RequiresWindowsCredentials.ToString())); + } + } // return settings return allSettings.ToArray(); @@ -3315,7 +3420,7 @@ namespace WebsitePanel.Providers.Web get { return ProviderSettings["WmSvc.CredentialsMode"]; } } - public new bool CheckWebManagementAccountExists(string accountName) + public override bool CheckWebManagementAccountExists(string accountName) { // Preserve setting to restore it back bool adEnabled = ServerSettings.ADEnabled; @@ -3336,7 +3441,7 @@ namespace WebsitePanel.Providers.Web } } - public new ResultObject CheckWebManagementPasswordComplexity(string accountPassword) + public override ResultObject CheckWebManagementPasswordComplexity(string accountPassword) { // Preserve setting to restore it back bool adEnabled = ServerSettings.ADEnabled; @@ -3365,7 +3470,7 @@ namespace WebsitePanel.Providers.Web return result; } - public new void GrantWebManagementAccess(string siteName, string accountName, string accountPassword) + public override void GrantWebManagementAccess(string siteName, string accountName, string accountPassword) { // Remote Management Access feature requires Modify permissions on the web site's wwwroot folder GrantWebManagementAccessInternally(siteName, accountName, accountPassword, NTFSPermission.Modify); @@ -3415,29 +3520,32 @@ namespace WebsitePanel.Providers.Web // Log.WriteInfo("FQ Account Name: {0};", accountName); } - // - ManagementAuthorization.Grant(accountName, fqWebPath, false); - // - WebSite site = webObjectsSvc.GetWebSiteFromIIS(siteName); - // - string contentPath = webObjectsSvc.GetPhysicalPath(site); - // - Log.WriteInfo("Site Content Path: {0};", contentPath); - // - if (IdentityCredentialsMode == "IISMNGR") - { - SecurityUtils.GrantNtfsPermissionsBySid(contentPath, SystemSID.LOCAL_SERVICE, permissions, true, true); - } - else - { - SecurityUtils.GrantNtfsPermissions(contentPath, accountName, permissions, true, true, ServerSettings, String.Empty, String.Empty); - } - // Restore setting back - ServerSettings.ADEnabled = adEnabled; + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + // + ManagementAuthorization.Grant(accountName, fqWebPath, false); + // + WebSite site = webObjectsSvc.GetWebSiteFromIIS(srvman, siteName); + // + string contentPath = webObjectsSvc.GetPhysicalPath(srvman, site); + // + Log.WriteInfo("Site Content Path: {0};", contentPath); + // + if (IdentityCredentialsMode == "IISMNGR") + { + SecurityUtils.GrantNtfsPermissionsBySid(contentPath, SystemSID.LOCAL_SERVICE, permissions, true, true); + } + else + { + SecurityUtils.GrantNtfsPermissions(contentPath, accountName, permissions, true, true, ServerSettings, String.Empty, String.Empty); + } + // Restore setting back + ServerSettings.ADEnabled = adEnabled; + } } - - public new void ChangeWebManagementAccessPassword(string accountName, string accountPassword) + + public override void ChangeWebManagementAccessPassword(string accountName, string accountPassword) { // Preserve setting to restore it back bool adEnabled = ServerSettings.ADEnabled; @@ -3465,7 +3573,7 @@ namespace WebsitePanel.Providers.Web ServerSettings.ADEnabled = adEnabled; } - public new void RevokeWebManagementAccess(string siteName, string accountName) + public override void RevokeWebManagementAccess(string siteName, string accountName) { // Preserve setting to restore it back bool adEnabled = ServerSettings.ADEnabled; @@ -3477,27 +3585,31 @@ namespace WebsitePanel.Providers.Web // Trace input parameters Log.WriteInfo("Site Name: {0}; Account Name: {1}; FqWebPath: {2};", siteName, accountName, fqWebPath); - // - WebSite site = webObjectsSvc.GetWebSiteFromIIS(siteName); - // - string contentPath = webObjectsSvc.GetPhysicalPath(site); - // - Log.WriteInfo("Site Content Path: {0};", contentPath); - // Revoke access permissions - if (IdentityCredentialsMode == "IISMNGR") - { - ManagementAuthorization.Revoke(accountName, fqWebPath); - ManagementAuthentication.DeleteUser(accountName); - SecurityUtils.RemoveNtfsPermissionsBySid(contentPath, SystemSID.LOCAL_SERVICE); - } - else - { - ManagementAuthorization.Revoke(GetFullQualifiedAccountName(accountName), fqWebPath); - SecurityUtils.RemoveNtfsPermissions(contentPath, accountName, ServerSettings, String.Empty, String.Empty); - SecurityUtils.DeleteUser(accountName, ServerSettings, String.Empty); - } - // Restore setting back - ServerSettings.ADEnabled = adEnabled; + + using (ServerManager srvman = webObjectsSvc.GetServerManager()) + { + // + WebSite site = webObjectsSvc.GetWebSiteFromIIS(srvman, siteName); + // + string contentPath = webObjectsSvc.GetPhysicalPath(srvman, site); + // + Log.WriteInfo("Site Content Path: {0};", contentPath); + // Revoke access permissions + if (IdentityCredentialsMode == "IISMNGR") + { + ManagementAuthorization.Revoke(accountName, fqWebPath); + ManagementAuthentication.DeleteUser(accountName); + SecurityUtils.RemoveNtfsPermissionsBySid(contentPath, SystemSID.LOCAL_SERVICE); + } + else + { + ManagementAuthorization.Revoke(GetFullQualifiedAccountName(accountName), fqWebPath); + SecurityUtils.RemoveNtfsPermissions(contentPath, accountName, ServerSettings, String.Empty, String.Empty); + SecurityUtils.DeleteUser(accountName, ServerSettings, String.Empty); + } + // Restore setting back + ServerSettings.ADEnabled = adEnabled; + } } private void ReadWebDeployPublishingAccessDetails(WebVirtualDirectory iisObject) @@ -3533,7 +3645,7 @@ namespace WebsitePanel.Providers.Web private bool? isWmSvcInstalled; - protected void ReadWebManagementAccessDetails(WebVirtualDirectory iisObject) + protected void ReadWebManagementAccessDetails(ServerManager srvman, WebVirtualDirectory iisObject) { bool wmSvcAvailable = IsWebManagementServiceInstalled(); // @@ -3546,35 +3658,32 @@ namespace WebsitePanel.Providers.Web WebVirtualDirectory.WmSvcSiteEnabled, IsWebManagementAccessEnabled(iisObject)); - using (var serverManager = webObjectsSvc.GetServerManager()) + // + string fqWebPath = @"/" + iisObject.FullQualifiedPath; + // + Configuration config = srvman.GetAdministrationConfiguration(); + ConfigurationSection authorizationSection = config.GetSection("system.webServer/management/authorization"); + ConfigurationElementCollection authorizationRulesCollection = authorizationSection.GetCollection("authorizationRules"); + + ConfigurationElement scopeElement = FindElement(authorizationRulesCollection, "scope", "path", fqWebPath); + + Log.WriteInfo("FQ WebPath: " + fqWebPath); + + if (scopeElement != null) { - // - string fqWebPath = @"/" + iisObject.FullQualifiedPath; - // - Configuration config = serverManager.GetAdministrationConfiguration(); - ConfigurationSection authorizationSection = config.GetSection("system.webServer/management/authorization"); - ConfigurationElementCollection authorizationRulesCollection = authorizationSection.GetCollection("authorizationRules"); - - ConfigurationElement scopeElement = FindElement(authorizationRulesCollection, "scope", "path", fqWebPath); - - Log.WriteInfo("FQ WebPath: " + fqWebPath); - - if (scopeElement != null) + ConfigurationElementCollection scopeCollection = scopeElement.GetCollection(); + // Retrieve account name + if (scopeCollection.Count > 0) { - ConfigurationElementCollection scopeCollection = scopeElement.GetCollection(); - // Retrieve account name - if (scopeCollection.Count > 0) - { - iisObject.SetValue( - WebSite.WmSvcAccountName, - GetNonQualifiedAccountName((String)scopeCollection[0]["name"])); - // - iisObject.SetValue( - WebSite.WmSvcServiceUrl, ProviderSettings["WmSvc.ServiceUrl"]); - // - iisObject.SetValue( - WebSite.WmSvcServicePort, ProviderSettings["WmSvc.Port"]); - } + iisObject.SetValue( + WebSite.WmSvcAccountName, + GetNonQualifiedAccountName((String)scopeCollection[0]["name"])); + // + iisObject.SetValue( + WebSite.WmSvcServiceUrl, ProviderSettings["WmSvc.ServiceUrl"]); + // + iisObject.SetValue( + WebSite.WmSvcServicePort, ProviderSettings["WmSvc.Port"]); } } } diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/MimeTypes/MimeTypesModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/MimeTypes/MimeTypesModuleService.cs index 288d1bfa..a9496bd8 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/MimeTypes/MimeTypesModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/MimeTypes/MimeTypesModuleService.cs @@ -44,28 +44,25 @@ namespace WebsitePanel.Providers.Web.MimeTypes /// Loads available mime maps into supplied virtual iisDirObject description. /// /// Virtual iisDirObject description. - public void GetMimeMaps(WebVirtualDirectory virtualDir) + public void GetMimeMaps(ServerManager srvman, WebVirtualDirectory virtualDir) { - using (var srvman = GetServerManager()) + var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath); + // + var section = config.GetSection(Constants.StaticContentSection); + // + var mappings = new List(); + // + foreach (var item in section.GetCollection()) { - var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath); + var item2Get = GetMimeMap(item); // - var section = config.GetSection(Constants.StaticContentSection); + if (item2Get == null) + continue; // - var mappings = new List(); - // - foreach (var item in section.GetCollection()) - { - var item2Get = GetMimeMap(item); - // - if (item2Get == null) - continue; - // - mappings.Add(item2Get); - } - // - virtualDir.MimeMaps = mappings.ToArray(); + mappings.Add(item2Get); } + // + virtualDir.MimeMaps = mappings.ToArray(); } /// diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/SSL/SSLModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/SSL/SSLModuleService.cs index a5ffb3e0..b87fb167 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/SSL/SSLModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/SSL/SSLModuleService.cs @@ -339,7 +339,7 @@ namespace WebsitePanel.Providers.Web.Iis public void AddBinding(SSLCertificate certificate, WebSite website) { - using (ServerManager sm = GetServerManager()) + using (ServerManager srvman = GetServerManager()) { // Not sure why do we need to work with X.509 store here, so commented it out and lets see what happens X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine); @@ -348,7 +348,7 @@ namespace WebsitePanel.Providers.Web.Iis List bindings = new List(); // Retrieve existing site bindings to figure out what do we have here WebObjectsModuleService webObjSvc = new WebObjectsModuleService(); - bindings.AddRange(webObjSvc.GetSiteBindings(website.SiteId)); + bindings.AddRange(webObjSvc.GetSiteBindings(srvman, website.SiteId)); // Look for dedicated ip bool dedicatedIp = bindings.Exists(binding => String.IsNullOrEmpty(binding.Host) && binding.IP != "*"); // @@ -357,11 +357,11 @@ namespace WebsitePanel.Providers.Web.Iis bindingInformation = dedicatedIp ? string.Format("{0}:443:", website.SiteIPAddress) : string.Format("{0}:443:{1}", website.SiteIPAddress, certificate.Hostname); // - sm.Sites[website.SiteId].Bindings.Add(bindingInformation, certificate.Hash, store.Name); + srvman.Sites[website.SiteId].Bindings.Add(bindingInformation, certificate.Hash, store.Name); // store.Close(); // - sm.CommitChanges(); + srvman.CommitChanges(); } } diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebObjects/CustomHttpErrorsModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebObjects/CustomHttpErrorsModuleService.cs index 209f6ab4..7cac48ad 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebObjects/CustomHttpErrorsModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebObjects/CustomHttpErrorsModuleService.cs @@ -49,31 +49,27 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects public const string ResponseModeAttribute = "responseMode"; public const string PrefixLanguageFilePath = "prefixLanguageFilePath"; - public void GetCustomErrors(WebVirtualDirectory virtualDir) + public void GetCustomErrors(ServerManager srvman, WebVirtualDirectory virtualDir) { + var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath); // - using (var srvman = GetServerManager()) + var httpErrorsSection = config.GetSection(Constants.HttpErrorsSection); + // + var errorsCollection = httpErrorsSection.GetCollection(); + // + var errors = new List(); + // + foreach (var item in errorsCollection) { - var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath); + var item2Get = GetHttpError(item, virtualDir); // - var httpErrorsSection = config.GetSection(Constants.HttpErrorsSection); + if (item2Get == null) + continue; // - var errorsCollection = httpErrorsSection.GetCollection(); - // - var errors = new List(); - // - foreach (var item in errorsCollection) - { - var item2Get = GetHttpError(item, virtualDir); - // - if (item2Get == null) - continue; - // - errors.Add(item2Get); - } - // - virtualDir.HttpErrors = errors.ToArray(); + errors.Add(item2Get); } + // + virtualDir.HttpErrors = errors.ToArray(); } public void SetCustomErrors(WebVirtualDirectory virtualDir) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebObjects/CustomHttpHeadersModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebObjects/CustomHttpHeadersModuleService.cs index 91b21877..e08132d1 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebObjects/CustomHttpHeadersModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebObjects/CustomHttpHeadersModuleService.cs @@ -40,33 +40,30 @@ namespace WebsitePanel.Providers.Web.WebObjects public const string NameAttribute = "name"; public const string ValueAttribute = "value"; - public void GetCustomHttpHeaders(WebVirtualDirectory virtualDir) + public void GetCustomHttpHeaders(ServerManager srvman, WebVirtualDirectory virtualDir) { - using (var srvman = GetServerManager()) + var config = srvman.GetApplicationHostConfiguration(); + // + var httpProtocolSection = config.GetSection(Constants.HttpProtocolSection, virtualDir.FullQualifiedPath); + // + if (httpProtocolSection == null) + return; + // + var headersCollection = httpProtocolSection.GetCollection("customHeaders"); + // + var headers = new List(); + // + foreach (var item in headersCollection) { - var config = srvman.GetApplicationHostConfiguration(); + var item2Get = GetCustomHttpHeader(item); // - var httpProtocolSection = config.GetSection(Constants.HttpProtocolSection, virtualDir.FullQualifiedPath); + if (item2Get == null) + continue; // - if (httpProtocolSection == null) - return; - // - var headersCollection = httpProtocolSection.GetCollection("customHeaders"); - // - var headers = new List(); - // - foreach (var item in headersCollection) - { - var item2Get = GetCustomHttpHeader(item); - // - if (item2Get == null) - continue; - // - headers.Add(item2Get); - } - // - virtualDir.HttpHeaders = headers.ToArray(); + headers.Add(item2Get); } + // + virtualDir.HttpHeaders = headers.ToArray(); } public void SetCustomHttpHeaders(WebVirtualDirectory virtualDir) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebObjects/WebObjectsModuleService.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebObjects/WebObjectsModuleService.cs index 34369e9c..9919e630 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebObjects/WebObjectsModuleService.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebObjects/WebObjectsModuleService.cs @@ -133,7 +133,7 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects // if (virtualDir.DedicatedApplicationPool) { - var appPool = GetApplicationPool(virtualDir); + var appPool = GetApplicationPool(srvman, virtualDir); vdir.UserName = appPool.ProcessModel.UserName; vdir.Password = appPool.ProcessModel.Password; } @@ -150,20 +150,17 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects } } - public ApplicationPool GetApplicationPool(WebVirtualDirectory virtualDir) + public ApplicationPool GetApplicationPool(ServerManager srvman, WebVirtualDirectory virtualDir) { if (virtualDir == null) throw new ArgumentNullException("vdir"); // read app pool - using (var srvman = GetServerManager()) - { - var appPool = srvman.ApplicationPools[virtualDir.ApplicationPool]; - // - if (appPool == null) - throw new ApplicationException("ApplicationPoolNotFound"); - // - return appPool; - } + var appPool = srvman.ApplicationPools[virtualDir.ApplicationPool]; + // + if (appPool == null) + throw new ApplicationException("ApplicationPoolNotFound"); + // + return appPool; } public void CreateApplicationPool(string appPoolName, string appPoolUsername, @@ -324,126 +321,105 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects } } - public ServerState GetSiteState(string siteId) + public ServerState GetSiteState(ServerManager srvman, string siteId) { - using (var srvman = GetServerManager()) + // ensure website exists + if (srvman.Sites[siteId] == null) + return ServerState.Unknown; + // + var siteState = ServerState.Unknown; + // + switch (srvman.Sites[siteId].State) { - // ensure website exists - if (srvman.Sites[siteId] == null) - return ServerState.Unknown; - // - var siteState = ServerState.Unknown; - // - switch (srvman.Sites[siteId].State) - { - case ObjectState.Started: - siteState = ServerState.Started; - break; - case ObjectState.Starting: - siteState = ServerState.Starting; - break; - case ObjectState.Stopped: - siteState = ServerState.Stopped; - break; - case ObjectState.Stopping: - siteState = ServerState.Stopping; - break; - } - // - return siteState; + case ObjectState.Started: + siteState = ServerState.Started; + break; + case ObjectState.Starting: + siteState = ServerState.Starting; + break; + case ObjectState.Stopped: + siteState = ServerState.Stopped; + break; + case ObjectState.Stopping: + siteState = ServerState.Stopping; + break; } + // + return siteState; } - public bool SiteExists(string siteId) + public bool SiteExists(ServerManager srvman, string siteId) { - using (var srvman = GetServerManager()) - { - return (srvman.Sites[siteId] != null); - } + return (srvman.Sites[siteId] != null); } - public string[] GetSites() + public string[] GetSites(ServerManager srvman) { - using (var srvman = GetServerManager()) - { - var iisObjects = new List(); - // - foreach (var item in srvman.Sites) - iisObjects.Add(item.Name); - // - return iisObjects.ToArray(); - } + var iisObjects = new List(); + // + foreach (var item in srvman.Sites) + iisObjects.Add(item.Name); + // + return iisObjects.ToArray(); } - public string GetWebSiteNameFromIIS(string siteName) + public string GetWebSiteNameFromIIS(ServerManager srvman, string siteName) { - using (var srvman = GetServerManager()) - { - if (srvman.Sites[siteName] != null) - return srvman.Sites[siteName].Name; - // - return null; - } + if (srvman.Sites[siteName] != null) + return srvman.Sites[siteName].Name; + // + return null; } - public string GetWebSiteIdFromIIS(string siteId, string format) + public string GetWebSiteIdFromIIS(ServerManager srvman, string siteId, string format) { - using (var srvman = GetServerManager()) - { - var iisObject = srvman.Sites[siteId]; - // Format string is empty - if (String.IsNullOrEmpty(format)) - return Convert.ToString(iisObject.Id); - // - return String.Format(format, iisObject.Id); - } + var iisObject = srvman.Sites[siteId]; + // Format string is empty + if (String.IsNullOrEmpty(format)) + return Convert.ToString(iisObject.Id); + // + return String.Format(format, iisObject.Id); } - public WebSite GetWebSiteFromIIS(string siteId) + public WebSite GetWebSiteFromIIS(ServerManager srvman, string siteId) { - using (var srvman = GetServerManager()) + var webSite = new WebSite(); + // + var iisObject = srvman.Sites[siteId]; + // + webSite.SiteId = webSite.Name = iisObject.Name; + // + if (iisObject.LogFile.Enabled) { - var webSite = new WebSite(); - // - var iisObject = srvman.Sites[siteId]; - // - webSite.SiteId = webSite.Name = iisObject.Name; - // - if (iisObject.LogFile.Enabled) - { - webSite.LogsPath = iisObject.LogFile.Directory; - webSite[WebSite.IIS7_LOG_EXT_FILE_FIELDS] = iisObject.LogFile.LogExtFileFlags.ToString(); - } - // Read instant website id - webSite[WebSite.IIS7_SITE_ID] = GetWebSiteIdFromIIS(siteId, "W3SVC{0}"); - // Read web site iisAppObject pool name - webSite.ApplicationPool = iisObject.Applications["/"].ApplicationPoolName; - // - return webSite; + webSite.LogsPath = iisObject.LogFile.Directory; + webSite[WebSite.IIS7_LOG_EXT_FILE_FIELDS] = iisObject.LogFile.LogExtFileFlags.ToString(); } + // Read instant website id + webSite[WebSite.IIS7_SITE_ID] = GetWebSiteIdFromIIS(srvman, siteId, "W3SVC{0}"); + // Read web site iisAppObject pool name + webSite.ApplicationPool = iisObject.Applications["/"].ApplicationPoolName; + // + return webSite; } - public ServerBinding[] GetSiteBindings(string siteId) + public ServerBinding[] GetSiteBindings(ServerManager srvman, string siteId) { - using (var srvman = GetServerManager()) + var iisObject = srvman.Sites[siteId]; + // get server bingings + var bindings = new List(); + // + foreach (var bindingObj in iisObject.Bindings) { - var iisObject = srvman.Sites[siteId]; - // get server bingings - var bindings = new List(); - // - foreach (var bindingObj in iisObject.Bindings) - { - // return only "http" bindings - if (String.Equals(bindingObj.Protocol, Uri.UriSchemeHttp, StringComparison.InvariantCultureIgnoreCase)) - { - string[] parts = bindingObj.BindingInformation.Split(':'); - // append binding - bindings.Add(new ServerBinding(bindingObj.Protocol, parts[0], parts[1], parts[2])); - } - } - // - return bindings.ToArray(); + // return only "http" bindings + if (String.Equals(bindingObj.Protocol, Uri.UriSchemeHttp, StringComparison.InvariantCultureIgnoreCase)) + { + string[] parts = bindingObj.BindingInformation.Split(':'); + // append binding + bindings.Add(new ServerBinding(bindingObj.Protocol, parts[0], parts[1], parts[2])); + } } + // + return bindings.ToArray(); } private void SyncWebSiteBindingsChanges(string siteId, ServerBinding[] bindings) @@ -487,40 +463,40 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects public void UpdateSiteBindings(string siteId, ServerBinding[] bindings) { - // Ensure web site exists - if (!SiteExists(siteId)) - return; + using (ServerManager srvman = GetServerManager()) + { + // Ensure web site exists + if (!SiteExists(srvman, siteId)) + return; + } // SyncWebSiteBindingsChanges(siteId, bindings); } - public string GetPhysicalPath(WebVirtualDirectory virtualDir) + public string GetPhysicalPath(ServerManager srvman, WebVirtualDirectory virtualDir) { - using (var srvman = GetServerManager()) - { - string siteId = (virtualDir.ParentSiteName == null) - ? virtualDir.Name : virtualDir.ParentSiteName; - // - var iisObject = srvman.Sites[siteId]; + string siteId = (virtualDir.ParentSiteName == null) + ? virtualDir.Name : virtualDir.ParentSiteName; + // + var iisObject = srvman.Sites[siteId]; - if (iisObject == null) - return null; + if (iisObject == null) + return null; - // - var iisAppObject = iisObject.Applications[virtualDir.VirtualPath]; + // + var iisAppObject = iisObject.Applications[virtualDir.VirtualPath]; - if (iisAppObject == null) - return null; + if (iisAppObject == null) + return null; - // - var iisDirObject = iisAppObject.VirtualDirectories["/"]; + // + var iisDirObject = iisAppObject.VirtualDirectories["/"]; - if (iisDirObject == null) - return null; + if (iisDirObject == null) + return null; - // - return iisDirObject.PhysicalPath; - } + // + return iisDirObject.PhysicalPath; } public void DeleteApplicationPool(params string[] appPoolNames) @@ -552,11 +528,11 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects public void DeleteSite(string siteId) { - if (!SiteExists(siteId)) - return; - // using (var srvman = GetServerManager()) { + if (!SiteExists(srvman, siteId)) + return; + // var indexOf = srvman.Sites.IndexOf(srvman.Sites[siteId]); srvman.Sites.RemoveAt(indexOf); @@ -565,31 +541,28 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects } } - public WebVirtualDirectory[] GetVirtualDirectories(string siteId) + public WebVirtualDirectory[] GetVirtualDirectories(ServerManager srvman, string siteId) { - if (!SiteExists(siteId)) - return new WebVirtualDirectory[] { }; + if (!SiteExists(srvman, siteId)) + return new WebVirtualDirectory[] { }; - using (var srvman = GetServerManager()) + var vdirs = new List(); + var iisObject = srvman.Sites[siteId]; + // + foreach (var item in iisObject.Applications) { - var vdirs = new List(); - var iisObject = srvman.Sites[siteId]; + // Skip root application which is web site itself + if (item.Path == "/") + continue; // - foreach (var item in iisObject.Applications) + vdirs.Add(new WebVirtualDirectory { - // Skip root application which is web site itself - if (item.Path == "/") - continue; - // - vdirs.Add(new WebVirtualDirectory - { - Name = ConfigurationUtility.GetNonQualifiedVirtualPath(item.Path), - ContentPath = item.VirtualDirectories[0].PhysicalPath - }); - } - // - return vdirs.ToArray(); + Name = ConfigurationUtility.GetNonQualifiedVirtualPath(item.Path), + ContentPath = item.VirtualDirectories[0].PhysicalPath + }); } + // + return vdirs.ToArray(); } public WebVirtualDirectory GetVirtualDirectory(string siteId, string directoryName) @@ -601,11 +574,11 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects if (String.IsNullOrEmpty(directoryName)) throw new ArgumentNullException("directoryName"); // - if (!SiteExists(siteId)) - return null; - // using (var srvman = GetServerManager()) { + if (!SiteExists(srvman, siteId)) + return null; + var site = srvman.Sites[siteId]; // var vdir = new WebVirtualDirectory @@ -622,11 +595,11 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects public void CreateVirtualDirectory(string siteId, string directoryName, string physicalPath) { - if (!SiteExists(siteId)) - throw new ApplicationException(); - // using (var srvman = GetServerManager()) { + if (!SiteExists(srvman, siteId)) + throw new ApplicationException(); + var iisSiteObject = srvman.Sites[siteId]; var iisAppObject = iisSiteObject.Applications.Add(directoryName, physicalPath); // @@ -636,11 +609,11 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects public bool VirtualDirectoryExists(string siteId, string directoryName) { - if (!SiteExists(siteId)) - return false; - using (var srvman = GetServerManager()) { + if (!SiteExists(srvman, siteId)) + return false; + var vdir = new WebVirtualDirectory { Name = directoryName, @@ -653,11 +626,11 @@ namespace WebsitePanel.Providers.Web.Iis.WebObjects public void DeleteVirtualDirectory(WebVirtualDirectory virtualDir) { - if (!SiteExists(virtualDir.ParentSiteName)) - return; - // using (var srvman = GetServerManager()) { + if (!SiteExists(srvman, virtualDir.ParentSiteName)) + return; + var iisSiteObject = srvman.Sites[virtualDir.ParentSiteName]; var iisAppObject = iisSiteObject.Applications[virtualDir.VirtualPath]; // diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebsitePanel.Providers.Web.IIs70.csproj b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebsitePanel.Providers.Web.IIs70.csproj index b8d01464..6e34c920 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebsitePanel.Providers.Web.IIs70.csproj +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIS70/WebsitePanel.Providers.Web.IIs70.csproj @@ -71,6 +71,7 @@ + diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIs60/IIs60.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIs60/IIs60.cs index 15ac8752..0862cd2d 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIs60/IIs60.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Web.IIs60/IIs60.cs @@ -2392,37 +2392,37 @@ namespace WebsitePanel.Providers.Web throw new NotImplementedException(); } - public List GetHeliconApeUsers(string siteId) + public virtual List GetHeliconApeUsers(string siteId) { throw new NotImplementedException(); } - public HtaccessUser GetHeliconApeUser(string siteId, string userName) + public virtual HtaccessUser GetHeliconApeUser(string siteId, string userName) { throw new NotImplementedException(); } - public void UpdateHeliconApeUser(string siteId, HtaccessUser user) + public virtual void UpdateHeliconApeUser(string siteId, HtaccessUser user) { throw new NotImplementedException(); } - public void DeleteHeliconApeUser(string siteId, string userName) + public virtual void DeleteHeliconApeUser(string siteId, string userName) { throw new NotImplementedException(); } - public List GetHeliconApeGroups(string siteId) + public virtual List GetHeliconApeGroups(string siteId) { throw new NotImplementedException(); } - public WebGroup GetHeliconApeGroup(string siteId, string groupName) + public virtual WebGroup GetHeliconApeGroup(string siteId, string groupName) { throw new NotImplementedException(); } - public void UpdateHeliconApeGroup(string siteId, WebGroup group) + public virtual void UpdateHeliconApeGroup(string siteId, WebGroup group) { throw new NotImplementedException(); } @@ -2437,7 +2437,7 @@ namespace WebsitePanel.Providers.Web throw new NotSupportedException(); } - public void DeleteHeliconApeGroup(string siteId, string groupName) + public virtual void DeleteHeliconApeGroup(string siteId, string groupName) { throw new NotImplementedException(); } @@ -3630,27 +3630,27 @@ namespace WebsitePanel.Providers.Web #endregion #region Remote Management Access - public void GrantWebManagementAccess(string siteName, string accountName, string accountPassword) + public virtual void GrantWebManagementAccess(string siteName, string accountName, string accountPassword) { throw new NotSupportedException(); } - public void RevokeWebManagementAccess(string siteName, string accountName) + public virtual void RevokeWebManagementAccess(string siteName, string accountName) { throw new NotSupportedException(); } - public void ChangeWebManagementAccessPassword(string accountName, string accountPassword) + public virtual void ChangeWebManagementAccessPassword(string accountName, string accountPassword) { throw new NotSupportedException(); } - public bool CheckWebManagementAccountExists(string accountName) + public virtual bool CheckWebManagementAccountExists(string accountName) { throw new NotSupportedException(); } - public ResultObject CheckWebManagementPasswordComplexity(string accountPassword) + public virtual ResultObject CheckWebManagementPasswordComplexity(string accountPassword) { throw new NotSupportedException(); } diff --git a/WebsitePanel/Sources/WebsitePanel.Server/VirtualizationServerForPrivateCloud.asmx.cs b/WebsitePanel/Sources/WebsitePanel.Server/VirtualizationServerForPrivateCloud.asmx.cs index a7584621..68de0d43 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server/VirtualizationServerForPrivateCloud.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server/VirtualizationServerForPrivateCloud.asmx.cs @@ -154,7 +154,7 @@ namespace WebsitePanel.Server Log.WriteEnd("'{0}' CreateVMFromVM", ProviderSettings.ProviderName); return result; } - catch (System.TimeoutException ex) + catch (System.TimeoutException) { return result; }