Ejemplo n.º 1
0
		/// <summary>
		/// Creates if needed dedicated iisAppObject pools and assigns to specified site iisAppObject pool according to 
		/// selected ASP.NET version.
		/// </summary>
		/// <param name="site">WEb site to operate on.</param>
		/// <param name="createAppPools">A value which shows whether iisAppObject pools has to be created.</param>
        private void SetWebSiteApplicationPool(WebSite site, bool createAppPools)
        {
			var aphl = new WebAppPoolHelper(ProviderSettings);
			// Site isolation mode
			var sisMode = site.DedicatedApplicationPool ? SiteAppPoolMode.Dedicated : SiteAppPoolMode.Shared;
			// Create dedicated iisAppObject pool name for the site with installed ASP.NET version
			if (createAppPools && site.DedicatedApplicationPool)
			{
				// Find dedicated app pools
				var dedicatedPools = Array.FindAll<WebAppPool>(aphl.SupportedAppPools.ToArray(),
					x => aphl.isolation(x.Mode) == SiteAppPoolMode.Dedicated);
				// Generate dedicated iisAppObject pools names and create them.
				foreach (var item in dedicatedPools)
				{
					// Retrieve .NET Framework version
					var dotNetVersion = aphl.dotNetVersion(item.Mode);
					//
					var enable32BitAppOnWin64 = Enable32BitAppOnWin64;
					// Force "enable32BitAppOnWin64" set to true for .NET v1.1
					if (dotNetVersion == SiteAppPoolMode.dotNetFramework1)
						enable32BitAppOnWin64 = true;
					//
					var poolName = WSHelper.InferAppPoolName(item.Name, site.Name, item.Mode);
					// Ensure we are not going to add an existing app pool
					if (webObjectsSvc.IsApplicationPoolExist(poolName))
						continue;
					//
					using (var srvman = webObjectsSvc.GetServerManager())
					{
						// Create iisAppObject pool
						var pool = srvman.ApplicationPools.Add(poolName);
						pool.ManagedRuntimeVersion = aphl.aspnet_runtime(item.Mode);
						pool.ManagedPipelineMode = aphl.runtime_pipeline(item.Mode);
						pool.Enable32BitAppOnWin64 = enable32BitAppOnWin64;
						pool.AutoStart = true;
						// Identity
						pool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
						pool.ProcessModel.UserName = GetQualifiedAccountName(site.AnonymousUsername);
						pool.ProcessModel.Password = site.AnonymousUserPassword;
						// Commit changes
						srvman.CommitChanges();
					}
				}
			}
			// Find
			var siteAppPool = Array.Find<WebAppPool>(aphl.SupportedAppPools.ToArray(),
				x => x.AspNetInstalled.Equals(site.AspNetInstalled) && aphl.isolation(x.Mode) == sisMode);
			// Assign iisAppObject pool according to ASP.NET version installed and isolation mode specified.
			site.ApplicationPool = WSHelper.InferAppPoolName(siteAppPool.Name, site.Name, siteAppPool.Mode);
        }
Ejemplo n.º 2
0
		private void DeleteDedicatedPoolsAllocated(string siteName)
		{
			try
			{
				WebAppPoolHelper aphl = new WebAppPoolHelper(ProviderSettings);
				//
				var dedicatedPools = Array.FindAll<WebAppPool>(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();
					}
				}
			}
			catch (Exception ex)
			{
				Log.WriteError(ex);
				throw (ex);
			}
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Installs the provider.
		/// </summary>
		/// <returns>Error messsages if any specified.</returns>
		public override string[] Install()
		{
			List<string> messages = new List<string>();

			string[] cfgMsgs = webObjectsSvc.GrantConfigurationSectionAccess(INSTALL_SECTIONS_ALLOWED);
			//
			if (cfgMsgs.Length > 0)
			{
				messages.AddRange(cfgMsgs);
				return messages.ToArray();
			}

			try
			{
				SecurityUtils.EnsureOrganizationalUnitsExist(ServerSettings, UsersOU, GroupsOU);
			}
			catch (Exception ex)
			{
				Log.WriteError(ex);
				messages.Add(String.Format("Could not check/create Organizational Units: {0}", ex.Message));
				return messages.ToArray();
			}

			// Create web group name.
			if (String.IsNullOrEmpty(WebGroupName))
			{
				messages.Add("Web Group can not be blank");
			}
			else
			{
				try
				{
					// create group
					if (!SecurityUtils.GroupExists(WebGroupName, ServerSettings, GroupsOU))
					{
						SystemGroup group = new SystemGroup();
						group.Name = WebGroupName;
						group.Members = new string[] { };
						group.Description = "WebsitePanel System Group";

						SecurityUtils.CreateGroup(group, ServerSettings, UsersOU, GroupsOU);
					}
				}
				catch (Exception ex)
				{
					Log.WriteError(ex);
					messages.Add(String.Format("There was an error while adding '{0}' group: {1}",
						WebGroupName, ex.Message));
				}
			}

			// Setting up shared iisAppObject pools.
			try
			{
				WebAppPoolHelper aphl = new WebAppPoolHelper(ProviderSettings);
				// Find shared pools
				var sharedPools = Array.FindAll<WebAppPool>(aphl.SupportedAppPools.ToArray(), 
					x => aphl.isolation(x.Mode) == SiteAppPoolMode.Shared);
				//
				foreach (var item in sharedPools)
				{
					using (var srvman = webObjectsSvc.GetServerManager())
					{
						// Local variables
						bool enable32BitAppOnWin64 = (aphl.dotNetVersion(item.Mode) == SiteAppPoolMode.dotNetFramework1) ? true : false;
						//
						if (srvman.ApplicationPools[item.Name] == null)
						{
							ApplicationPool pool = srvman.ApplicationPools.Add(item.Name);
							//
							pool.ManagedRuntimeVersion = aphl.aspnet_runtime(item.Mode);
							pool.ManagedPipelineMode = aphl.runtime_pipeline(item.Mode);
							pool.ProcessModel.IdentityType = ProcessModelIdentityType.NetworkService;
							pool.AutoStart = true;
							pool.Enable32BitAppOnWin64 = enable32BitAppOnWin64;
							//
							srvman.CommitChanges();
						}
					}
				}
			}
			catch (Exception ex)
			{
				Log.WriteError(ex);
				//
				messages.Add(String.Format("There was an error while creating shared iisAppObject pools: {0}", ex.Message));
			}

			// Ensure logging settings are configured correctly on a web server level
			try
			{
				webObjectsSvc.SetWebServerDefaultLoggingSettings(LogExtFileFlags.SiteName
					| LogExtFileFlags.BytesRecv | LogExtFileFlags.BytesSent | LogExtFileFlags.Date);
			}
			catch (Exception ex)
			{
				Log.WriteError(ex);
				//
				messages.Add(String.Format(@"There was an error while configure web server's default 
					logging settings. Reason: {0}", ex.StackTrace));
			}

			// Ensure logging settings are configured correctly on a web server level
			try
			{
				webObjectsSvc.SetWebServerDefaultLoggingSettings(LogExtFileFlags.SiteName
					| LogExtFileFlags.BytesRecv | LogExtFileFlags.BytesSent | LogExtFileFlags.Date);
			}
			catch (Exception ex)
			{
				Log.WriteError(ex);
				//
				messages.Add(String.Format(@"There was an error while configure web server's default 
					logging settings. Reason: {0}", ex.StackTrace));
			}

			return messages.ToArray();
		}
Ejemplo n.º 4
0
		/// <summary>
		/// 
		/// </summary>
		/// <exception cref="System.ArgumentNullException" />
		/// <exception cref="System.ApplicationException" />
		/// <param name="siteId"></param>
        public override void InstallSecuredFolders(string siteId)
        {
			//
			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<WebAppPool>(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();
				}
			}
			#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();

					ConfigurationSection windowsAuthenticationSection = config.GetSection(
						"system.webServer/security/authentication/windowsAuthentication",
						siteId);
					//
					windowsAuthenticationSection["enabled"] = false;
					//
					srvman.CommitChanges();
				}
			}
			#endregion
			
			//
			using (var srvman = webObjectsSvc.GetServerManager())
			{
				//
				Configuration appConfig = srvman.GetApplicationHostConfiguration();
				//
				ConfigurationSection modulesSection = appConfig.GetSection(Constants.ModulesSection, siteId);
				//
				ConfigurationElementCollection modulesCollection = modulesSection.GetCollection();
				//
				ConfigurationElement moduleAdd = modulesCollection.CreateElement("add");
				//
				moduleAdd["name"] = Constants.WEBSITEPANEL_IISMODULES;
				moduleAdd["type"] = SecureFoldersModuleAssembly;
				moduleAdd["preCondition"] = "managedHandler";
				//
				modulesCollection.Add(moduleAdd);
				//
				srvman.CommitChanges();
			}
			
        }
Ejemplo n.º 5
0
		/// <summary>
		/// Updates virtual iisDirObject settings.
		/// </summary>
		/// <param name="siteId">Site's id that owns supplied iisDirObject.</param>
		/// <param name="iisDirObject">Web iisDirObject that needs to be updated.</param>
        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<WebAppPool>(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);
			}
		}
Ejemplo n.º 6
0
        /// <summary>
        /// Enables Helicon Ape module & handler on the web site or server globally.
        /// </summary>
        /// <param name="siteId">
        /// Web site id or empty string ("") for server-wide enabling
        /// </param>
        public override void EnableHeliconApe(string siteId)
        {
            if (null == siteId)
            {
                throw new ArgumentNullException("siteId");
            }

            if ("" != siteId)
            {
                // prepare enabling Ape for web site

                WebSite webSite = null;
                using (ServerManager srvman = webObjectsSvc.GetServerManager())
                {
                    // 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);
                }

                //
                var aphl = new WebAppPoolHelper(ProviderSettings);
                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<WebAppPool>(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();
                    }
                }

                #region Disable automatically Integrated Windows Authentication

                using (var srvman = webObjectsSvc.GetServerManager())
                {
                    PropertyBag winAuthBag = winAuthSvc.GetAuthenticationSettings(srvman, siteId);
                    //
                    if ((bool) winAuthBag[AuthenticationGlobals.Enabled])
                    {
                        Configuration config = srvman.GetApplicationHostConfiguration();

                        ConfigurationSection windowsAuthenticationSection = config.GetSection(
                            "system.webServer/security/authentication/windowsAuthentication",
                            siteId);
                        //
                        windowsAuthenticationSection["enabled"] = false;
                        //
                        srvman.CommitChanges();
                    }
                }

                #endregion

                #region Disable automatically Secured Folders

                if (IsSecuredFoldersInstalled(siteId))
                {
                    UninstallSecuredFolders(siteId);
                }

                #endregion
            }

            using (var srvman = webObjectsSvc.GetServerManager())
            {
                if (!IsHeliconApeEnabled(srvman, siteId))
                {

                    Configuration appConfig = srvman.GetApplicationHostConfiguration();

                    // add Helicon.Ape module
                    ConfigurationSection modulesSection = appConfig.GetSection(Constants.ModulesSection, siteId);
                    ConfigurationElementCollection modulesCollection = modulesSection.GetCollection();

                    // <add name="Helicon.Ape" />
                    ConfigurationElement heliconApeModuleEntry = modulesCollection.CreateElement("add");
                    heliconApeModuleEntry["name"] = Constants.HeliconApeModule;
                    heliconApeModuleEntry["type"] = GetHeliconApeModuleType(siteId);

                    // this way make <clear/> and copy all modules list from ancestor
                    //modulesCollection.AddAt(0, heliconApeModuleEntry);
                    // this way just insert single ape module entry
                    modulesCollection.Add(heliconApeModuleEntry);

                    // add Helicon.Ape handler
                    ConfigurationSection handlersSection = appConfig.GetSection(Constants.HandlersSection, siteId);
                    ConfigurationElementCollection handlersCollection = handlersSection.GetCollection();

                    // <add name="Helicon.Ape" />
                    ConfigurationElement heliconApeHandlerEntry = handlersCollection.CreateElement("add");
                    heliconApeHandlerEntry["name"] = Constants.HeliconApeHandler;
                    heliconApeHandlerEntry["type"] = GetHeliconApeHandlerType(siteId);
                    heliconApeHandlerEntry["path"] = Constants.HeliconApeHandlerPath;
                    heliconApeHandlerEntry["verb"] = "*";
                    heliconApeHandlerEntry["resourceType"] = "Unspecified";

                    handlersCollection.AddAt(0, heliconApeHandlerEntry);

                    srvman.CommitChanges();
                }
            }
        }