public void GetCustomErrors(ServerManager srvman, WebAppVirtualDirectory virtualDir)
        {
            var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath);
            //
            var httpErrorsSection = config.GetSection(Constants.HttpErrorsSection);

            virtualDir.ErrorMode        = (HttpErrorsMode)httpErrorsSection.GetAttributeValue("errorMode");
            virtualDir.ExistingResponse = (HttpErrorsExistingResponse)httpErrorsSection.GetAttributeValue("existingResponse");
            //
            var errorsCollection = httpErrorsSection.GetCollection();
            //
            var errors = new List <HttpError>();

            //
            foreach (var item in errorsCollection)
            {
                var item2Get = GetHttpError(item, virtualDir);
                //
                if (item2Get == null)
                {
                    continue;
                }
                //
                errors.Add(item2Get);
            }
            //
            virtualDir.HttpErrors = errors.ToArray();
        }
Esempio n. 2
0
 internal void RemoveScriptMaps(WebAppVirtualDirectory virtualDir, IEnumerable <string> extensions, string processor)
 {
     if (String.IsNullOrEmpty(processor))
     {
         return;
     }
     //
     if (virtualDir == null)
     {
         return;
     }
     //
     using (var srvman = GetServerManager())
     {
         var config = srvman.GetApplicationHostConfiguration();
         //
         var handlersSection    = config.GetSection(Constants.HandlersSection, virtualDir.FullQualifiedPath);
         var handlersCollection = handlersSection.GetCollection();
         //
         foreach (string extension in extensions)
         {
             var extParts        = extension.Split(',');
             var path            = extParts[0];
             var existentHandler = FindHandlerAction(handlersCollection, path, processor);
             // remove handler if exists
             if (existentHandler != null)
             {
                 handlersCollection.Remove(existentHandler);
             }
         }
         //
         srvman.CommitChanges();
     }
 }
        private HttpError GetHttpError(ConfigurationElement element, WebAppVirtualDirectory virtualDir)
        {
            if (element == null || virtualDir == null)
            {
                return(null);
            }
            // skip inherited http errors
            if (!element.IsLocallyStored)
            {
                return(null);
            }
            //
            var error = new HttpError
            {
                ErrorCode    = Convert.ToString(element.GetAttributeValue(StatusCodeAttribute)),
                ErrorSubcode = Convert.ToString(element.GetAttributeValue(SubStatusCodeAttribute)),
                ErrorContent = Convert.ToString(element.GetAttributeValue(PathAttribute)),
                HandlerType  = Enum.GetName(typeof(HttpErrorResponseMode), element.GetAttributeValue(ResponseModeAttribute))
            };

            // Make error path relative to the virtual directory's root folder
            if (error.HandlerType.Equals("File") &&          // 0 is supposed to be File
                error.ErrorContent.Length > virtualDir.ContentPath.Length)
            {
                error.ErrorContent = error.ErrorContent.Substring(virtualDir.ContentPath.Length);
            }
            //
            return(error);
        }
        public WebAppVirtualDirectory[] GetZooApplications(ServerManager srvman, string siteId)
        {
            if (!SiteExists(srvman, siteId))
            {
                return new WebAppVirtualDirectory[] { }
            }
            ;

            var vdirs     = new List <WebAppVirtualDirectory>();
            var iisObject = srvman.Sites[siteId];

            //
            foreach (var item in iisObject.Applications)
            {
                Configuration cfg = item.GetWebConfiguration();

                string location = siteId + ConfigurationUtility.GetQualifiedVirtualPath(item.Path);
                ConfigurationSection section;
                try
                {
                    section = cfg.GetSection("system.webServer/heliconZoo", location);
                }
                catch (Exception)
                {
                    // looks like Helicon Zoo is not installed, return empty array
                    return(vdirs.ToArray());
                }

                if (section.GetCollection().Count > 0)
                {
                    WebAppVirtualDirectory vdir = new WebAppVirtualDirectory
                    {
                        Name        = ConfigurationUtility.GetNonQualifiedVirtualPath(item.Path),
                        ContentPath = item.VirtualDirectories[0].PhysicalPath
                    };

                    ConfigurationElement           zooAppElement = section.GetCollection()[0];
                    ConfigurationElementCollection envColl       = zooAppElement.GetChildElement("environmentVariables").GetCollection();

                    foreach (ConfigurationElement env in  envColl)
                    {
                        if ((string)env.GetAttributeValue("name") == "CONSOLE_URL")
                        {
                            vdir.ConsoleUrl = ConfigurationUtility.GetQualifiedVirtualPath(item.Path);
                            if (!vdir.ConsoleUrl.EndsWith("/"))
                            {
                                vdir.ConsoleUrl += "/";
                            }
                            vdir.ConsoleUrl += (string)env.GetAttributeValue("value");
                        }
                    }

                    vdirs.Add(vdir);
                }
            }

            return(vdirs.ToArray());
        }
 public void SaveWebItem(WebAppVirtualDirectory item)
 {
     item.AspInstalled    = chkAsp.Checked;
     item.AspNetInstalled = ddlAspNet.SelectedValue;
     item.PhpInstalled    = ddlPhp.SelectedValue;
     item.PerlInstalled   = chkPerl.Checked;
     item.PythonInstalled = chkPython.Checked;
     item.CgiBinInstalled = chkCgiBin.Checked;
 }
Esempio n. 6
0
        public void GetAuthenticationSettings(ServerManager srvman, WebAppVirtualDirectory virtualDir)
        {
            var config = srvman.GetApplicationHostConfiguration();
            //
            var section = config.GetSection(Constants.BasicAuthenticationSection, virtualDir.FullQualifiedPath);

            //
            virtualDir.EnableBasicAuthentication = Convert.ToBoolean(section.GetAttributeValue(EnabledAttribute));
        }
Esempio n. 7
0
        /// <summary>
        /// Saves mime types from virtual iisDirObject description into configuration file.
        /// </summary>
        /// <param name="vdir">Virtual iisDirObject description.</param>
        public void SetMimeMaps(WebAppVirtualDirectory virtualDir)
        {
            #region Revert to parent settings (inherited)
            using (var srvman = GetServerManager())
            {
                var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath);
                //
                var section = config.GetSection(Constants.StaticContentSection);
                //
                section.RevertToParent();
                //
                srvman.CommitChanges();
            }
            #endregion

            // Ensure mime maps are set
            if (virtualDir.MimeMaps == null || virtualDir.MimeMaps.Length == 0)
            {
                return;
            }

            #region Put the change in effect
            using (var srvman = GetServerManager())
            {
                var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath);
                //
                var section = config.GetSection(Constants.StaticContentSection);
                //
                var typesCollection = section.GetCollection();
                //
                foreach (var item in virtualDir.MimeMaps)
                {
                    // Make sure mime-type mapping file extension is formatted exactly as it should be
                    if (!item.Extension.StartsWith("."))
                    {
                        item.Extension = "." + item.Extension;
                    }
                    //
                    int indexOf = FindMimeMap(typesCollection, item);
                    //
                    if (indexOf > -1)
                    {
                        var item2Renew = typesCollection[indexOf];
                        //
                        FillConfigurationElementWithData(item2Renew, item);
                        //
                        continue;
                    }
                    //
                    typesCollection.Add(CreateMimeMap(typesCollection, item));
                }
                //
                srvman.CommitChanges();
            }
            #endregion
        }
Esempio n. 8
0
        private void BindWebPublishingProfileFtpAccounts(WebAppVirtualDirectory item)
        {
            var ftpAccounts = ES.Services.FtpServers.GetFtpAccounts(PanelSecurity.PackageId, false);

            //
            MyFtpAccountList.DataSource = Array.FindAll(ftpAccounts, x => x.Folder.Equals(item.ContentPath));
            MyFtpAccountList.DataBind();
            //
            MyFtpAccountList.Items.Insert(0, new ListItem(GetLocalizedString("WebPublishing.ChooseFtpAccountPrompt"), String.Empty));
        }
Esempio n. 9
0
 public void SetClassicAspSettings(WebAppVirtualDirectory virtualDir)
 {
     using (var srvman = GetServerManager())
     {
         var config = srvman.GetApplicationHostConfiguration();
         //
         var aspSection = config.GetSection(SectionName, virtualDir.FullQualifiedPath);
         //
         aspSection.SetAttributeValue(EnableParentPathsAttribute, virtualDir.EnableParentPaths);
         //
         srvman.CommitChanges();
     }
 }
Esempio n. 10
0
        public void BindWebItem(WebAppVirtualDirectory item)
        {
            //
            var webSite = item as WebSite;

            // Skip processing virtual directories, otherwise we will likely run into a trouble
            if (webSite == null)
            {
                return;
            }
            SiteId = item.Id;
            RefreshControlLayout();
        }
Esempio n. 11
0
 public void SetAuthenticationSettings(WebAppVirtualDirectory virtualDir)
 {
     using (var srvman = GetServerManager())
     {
         var config = srvman.GetApplicationHostConfiguration();
         //
         var section = config.GetSection(Constants.BasicAuthenticationSection, virtualDir.FullQualifiedPath);
         //
         section.SetAttributeValue(EnabledAttribute, virtualDir.EnableBasicAuthentication);
         //
         srvman.CommitChanges();
     }
 }
Esempio n. 12
0
        private void ToggleWmSvcControls(WebAppVirtualDirectory item)
        {
            if (!item.GetValue <bool>(WebAppVirtualDirectory.WmSvcAvailable))
            {
                pnlWmcSvcManagement.Visible = false;
                pnlNotInstalled.Visible     = true;
                //
                return;
            }
            //
            pnlWmcSvcManagement.Visible = true;
            pnlNotInstalled.Visible     = false;

            //
            string wmSvcAccountName  = item.GetValue <string>(WebAppVirtualDirectory.WmSvcAccountName);
            bool   wmcSvcSiteEnabled = item.GetValue <bool>(WebAppVirtualDirectory.WmSvcSiteEnabled);

            btnWmSvcSiteEnable.Visible  = true;
            txtWmSvcAccountName.Visible = true;

            //
            txtWmSvcAccountPassword.Text = txtWmSvcAccountPassword.Attributes["value"] = String.Empty;
            //
            txtWmSvcAccountPasswordC.Text = txtWmSvcAccountPasswordC.Attributes["value"] = String.Empty;

            // Disable edit mode if WmSvc account name is set
            if (wmcSvcSiteEnabled)
            {
                btnWmSvcSiteEnable.Visible  = false;
                txtWmSvcAccountName.Visible = false;

                //
                txtWmSvcAccountPassword.Text = PasswordControl.EMPTY_PASSWORD;
                txtWmSvcAccountPassword.Attributes["value"] = PasswordControl.EMPTY_PASSWORD;

                //
                txtWmSvcAccountPasswordC.Text = PasswordControl.EMPTY_PASSWORD;
                txtWmSvcAccountPasswordC.Attributes["value"] = PasswordControl.EMPTY_PASSWORD;
            }

            //
            litWmSvcAccountName.Visible  = wmcSvcSiteEnabled;
            btnWmSvcSiteDisable.Visible  = wmcSvcSiteEnabled;
            btnWmSvcChangePassw.Visible  = wmcSvcSiteEnabled;
            pnlWmSvcSiteDisabled.Visible = !wmcSvcSiteEnabled;
            pnlWmSvcSiteEnabled.Visible  = wmcSvcSiteEnabled;

            //
            txtWmSvcAccountName.Text = wmSvcAccountName;
            litWmSvcAccountName.Text = wmSvcAccountName;
        }
Esempio n. 13
0
        public void BindWebItem(WebAppVirtualDirectory item)
        {
            IIs7 = item.IIs7;

            // bind error mode
            ddlErrorMode.Items.Add(HttpErrorsMode.DetailedLocalOnly.ToString());
            ddlErrorMode.Items.Add(HttpErrorsMode.Custom.ToString());
            ddlErrorMode.Items.Add(HttpErrorsMode.Detailed.ToString());

            ddlErrorMode.SelectedValue = item.ErrorMode.ToString();

            // bind errors list
            gvErrorPages.DataSource = item.HttpErrors;
            gvErrorPages.DataBind();
        }
Esempio n. 14
0
        public void SetHttpRedirectSettings(WebAppVirtualDirectory virtualDir)
        {
            #region Revert to parent settings (inherited)
            using (var srvman = GetServerManager())
            {
                // Load web site configuration
                var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath);
                // Load corresponding section
                var section = config.GetSection(Constants.HttpRedirectSection);
                //
                section.RevertToParent();
                //
                srvman.CommitChanges();
            }
            #endregion

            // HttpRedirect property is not specified so defaults to the parent
            if (String.IsNullOrEmpty(virtualDir.HttpRedirect))
            {
                return;
            }

            #region Put changes in effect
            using (var srvman = GetServerManager())
            {
                // Load web site configuration
                var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath);
                // Load corresponding section
                var section = config.GetSection(Constants.HttpRedirectSection);
                // Enable http redirect feature
                section.SetAttributeValue(EnabledAttribute, true);
                section.SetAttributeValue(ExactDestinationAttribute, virtualDir.RedirectExactUrl);
                section.SetAttributeValue(DestinationAttribute, virtualDir.HttpRedirect);
                section.SetAttributeValue(ChildOnlyAttribute, virtualDir.RedirectDirectoryBelow);
                // Configure HTTP Response Status
                if (virtualDir.RedirectPermanent)
                {
                    section.SetAttributeValue(HttpResponseStatusAttribute, "Permanent");
                }
                else
                {
                    section.SetAttributeValue(HttpResponseStatusAttribute, "Found");
                }
                //
                srvman.CommitChanges();
            }
            #endregion
        }
Esempio n. 15
0
        public ApplicationPool GetApplicationPool(ServerManager srvman, WebAppVirtualDirectory virtualDir)
        {
            if (virtualDir == null)
            {
                throw new ArgumentNullException("vdir");
            }
            // read app pool
            var appPool = srvman.ApplicationPools[virtualDir.ApplicationPool];

            //
            if (appPool == null)
            {
                throw new ApplicationException("ApplicationPoolNotFound");
            }
            //
            return(appPool);
        }
Esempio n. 16
0
        private string  AutoSuggestWmSvcAccontName(WebAppVirtualDirectory item, string suffix)
        {
            string autoSuggestedPart = item.Name;

            //
            if (autoSuggestedPart.Length > 14)
            {
                autoSuggestedPart = autoSuggestedPart.Substring(0, 14);
                //
                while (!String.IsNullOrEmpty(autoSuggestedPart) &&
                       !Char.IsLetterOrDigit(autoSuggestedPart[autoSuggestedPart.Length - 1]))
                {
                    autoSuggestedPart = autoSuggestedPart.Substring(0, autoSuggestedPart.Length - 1);
                }
            }
            //
            return(autoSuggestedPart + suffix);
        }
Esempio n. 17
0
        public bool AppVirtualDirectoryExists(string siteId, string directoryName)
        {
            using (var srvman = GetServerManager())
            {
                if (!SiteExists(srvman, siteId))
                {
                    return(false);
                }

                var vdir = new WebAppVirtualDirectory
                {
                    Name           = directoryName,
                    ParentSiteName = siteId
                };
                //
                return(srvman.Sites[siteId].Applications[vdir.VirtualPath] != null);
            }
        }
Esempio n. 18
0
        public void GetHttpRedirectSettings(ServerManager srvman, WebAppVirtualDirectory virtualDir)
        {
            // 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)));
        }
Esempio n. 19
0
        public void DeleteAppVirtualDirectory(WebAppVirtualDirectory virtualDir)
        {
            using (var srvman = GetServerManager())
            {
                if (!SiteExists(srvman, virtualDir.ParentSiteName))
                {
                    return;
                }

                var iisSiteObject = srvman.Sites[virtualDir.ParentSiteName];
                var iisAppObject  = iisSiteObject.Applications[virtualDir.VirtualPath];
                //
                if (iisAppObject != null)
                {
                    iisSiteObject.Applications.Remove(iisAppObject);
                }
                //
                srvman.CommitChanges();
            }
        }
Esempio n. 20
0
        private void ChangeAppVirtualDirectoryProperties(WebAppVirtualDirectory vdir,
                                                         ApplicationWebSetting[] settings)
        {
            if (settings == null)
            {
                return;
            }

            // get type properties
            Type vdirType = vdir.GetType();

            foreach (ApplicationWebSetting setting in settings)
            {
                PropertyInfo prop = vdirType.GetProperty(setting.Name,
                                                         BindingFlags.Public | BindingFlags.Instance);

                if (prop != null)
                {
                    prop.SetValue(vdir, ObjectUtils.Cast(setting.Value, prop.PropertyType), null);
                }
            }
        }
Esempio n. 21
0
 public void ConfigureConnectAsFeature(WebAppVirtualDirectory virtualDir)
 {
     // read website
     using (var srvman = GetServerManager())
     {
         var webSite = String.IsNullOrEmpty(virtualDir.ParentSiteName) ? srvman.Sites[virtualDir.Name] : srvman.Sites[virtualDir.ParentSiteName];
         //
         if (webSite != null)
         {
             // get root iisAppObject
             var webApp = webSite.Applications[virtualDir.VirtualPath];
             //
             if (webApp != null)
             {
                 var vdir = webApp.VirtualDirectories["/"];
                 //
                 if (vdir != null)
                 {
                     vdir.LogonMethod = AuthenticationLogonMethod.ClearText;
                     //
                     if (virtualDir.DedicatedApplicationPool)
                     {
                         var appPool = GetApplicationPool(srvman, virtualDir);
                         vdir.UserName = appPool.ProcessModel.UserName;
                         vdir.Password = appPool.ProcessModel.Password;
                     }
                     else
                     {
                         vdir.UserName = virtualDir.AnonymousUsername;
                         vdir.Password = virtualDir.AnonymousUserPassword;
                     }
                     //
                     srvman.CommitChanges();
                 }
             }
         }
     }
 }
Esempio n. 22
0
        /// <summary>
        /// Loads available mime maps into supplied virtual iisDirObject description.
        /// </summary>
        /// <param name="vdir">Virtual iisDirObject description.</param>
        public void GetMimeMaps(ServerManager srvman, WebAppVirtualDirectory virtualDir)
        {
            var config = srvman.GetWebConfiguration(virtualDir.FullQualifiedPath);
            //
            var section = config.GetSection(Constants.StaticContentSection);
            //
            var mappings = new List <MimeMap>();

            //
            foreach (var item in section.GetCollection())
            {
                var item2Get = GetMimeMap(item);
                //
                if (item2Get == null)
                {
                    continue;
                }
                //
                mappings.Add(item2Get);
            }
            //
            virtualDir.MimeMaps = mappings.ToArray();
        }
        private void BindVirtualDir()
        {
            WebAppVirtualDirectory vdir = null;

            try
            {
                vdir = ES.Services.WebServers.GetAppVirtualDirectory(PanelRequest.ItemID, PanelRequest.VirtDir);
            }
            catch (Exception ex)
            {
                ShowErrorMessage("WEB_GET_VDIR", ex);
                return;
            }

            if (vdir == null)
            {
                RedirectToBrowsePage();
            }

            // IIS 7.0 mode
            IIs7 = vdir.IIs7;

            PackageId = vdir.PackageId;

            // bind site
            string fullName = vdir.ParentSiteName + "/" + vdir.Name;

            lnkSiteName.Text        = fullName;
            lnkSiteName.NavigateUrl = "http://" + fullName;

            // bind controls
            webSitesHomeFolderControl.BindWebItem(PackageId, vdir);
            webSitesExtensionsControl.BindWebItem(PackageId, vdir);
            webSitesMimeTypesControl.BindWebItem(vdir);
            webSitesCustomHeadersControl.BindWebItem(vdir);
            webSitesCustomErrorsControl.BindWebItem(vdir);
        }
Esempio n. 24
0
        private void ToggleWebDeployPublishingControls(WebAppVirtualDirectory item)
        {
            // Disable all child controls
            DisableChildControlsOfType(tabWebDeployPublishing, typeof(PlaceHolder), typeof(Button), typeof(TextBox), typeof(Literal));

            // Cleanup password text boxes
            WDeployPublishingPasswordTextBox.Text        = WDeployPublishingPasswordTextBox.Attributes["value"] = String.Empty;
            WDeployPublishingConfirmPasswordTextBox.Text = WDeployPublishingConfirmPasswordTextBox.Attributes["value"] = String.Empty;

            // Step 1: Web Deploy feature is not installed on the server
            if (item.WebDeployPublishingAvailable == false)
            {
                // Enable panels
                EnableControlsInBulk(PanelWDeployNotInstalled);
                //
                return;
            }

            // Step 2: Web Deploy feature is available but not publishing enabled for the web site yet
            if (item.WebDeploySitePublishingEnabled == false)
            {
                // Enable controls
                EnableControlsInBulk(
                    PanelWDeploySitePublishingDisabled,
                    PanelWDeployPublishingCredentials,
                    WDeployEnabePublishingButton,
                    WDeployPublishingAccountTextBox,
                    WDeployPublishingPasswordTextBox,
                    WDeployPublishingConfirmPasswordTextBox,
                    WDeployPublishingAccountRequiredFieldValidator);

                WDeployPublishingAccountTextBox.Text = AutoSuggestWmSvcAccontName(item, "_dploy");
                //
                WDeployPublishingAccountRequiredFieldValidator.Enabled = true;
                //
                return;
            }
            // Step 3: Publishing has been enabled for the web site
            if (item.WebDeploySitePublishingEnabled == true)
            {
                // Enable controls
                EnableControlsInBulk(
                    PanelWDeployPublishingCredentials,
                    WDeployChangePublishingPasswButton,
                    WDeployDisablePublishingButton,
                    WDeployPublishingAccountLiteral,
                    WDeployPublishingPasswordTextBox,
                    WDeployPublishingConfirmPasswordTextBox);
                // Disable user name validation
                WDeployPublishingAccountRequiredFieldValidator.Enabled = false;
                // Display plain-text publishing account name
                WDeployPublishingAccountLiteral.Text = item.WebDeployPublishingAccount;
                // Miscellaneous
                // Enable empty publishing password for stylistic purposes
                WDeployPublishingPasswordTextBox.Text = PasswordControl.EMPTY_PASSWORD;
                WDeployPublishingPasswordTextBox.Attributes["value"] = PasswordControl.EMPTY_PASSWORD;
                // Enable empty publishing password confirmation for stylistic purposes
                WDeployPublishingConfirmPasswordTextBox.Text = PasswordControl.EMPTY_PASSWORD;
                WDeployPublishingConfirmPasswordTextBox.Attributes["value"] = PasswordControl.EMPTY_PASSWORD;
            }
            // Step 4: Publishing has been enabled and publishing profile has been built
            if (item.WebDeploySitePublishingEnabled == true)
            {
                // Enable controls
                EnableControlsInBulk(PanelWDeployManagePublishingProfile);
                // Save web site name as a command argument for the link
                WDeployDownloadPubProfileLink.CommandArgument = item.Name;
            }
        }
        public void BindWebItem(int packageId, WebAppVirtualDirectory item)
        {
            fileLookup.PackageId    = item.PackageId;
            fileLookup.SelectedFile = item.ContentPath;

            string resSuffix = item.IIs7 ? "IIS7" : "";

            chkRedirectExactUrl.Text       = GetLocalizedString("chkRedirectExactUrl.Text" + resSuffix);
            chkRedirectDirectoryBelow.Text = GetLocalizedString("chkRedirectDirectoryBelow.Text" + resSuffix);
            chkRedirectPermanent.Text      = GetLocalizedString("chkRedirectPermanent.Text" + resSuffix);

            chkRedirectExactUrl.Checked       = item.RedirectExactUrl;
            chkRedirectDirectoryBelow.Checked = item.RedirectDirectoryBelow;
            chkRedirectPermanent.Checked      = item.RedirectPermanent;

            chkDirectoryBrowsing.Checked = item.EnableDirectoryBrowsing;
            chkParentPaths.Checked       = item.EnableParentPaths;
            chkWrite.Checked             = item.EnableWritePermissions;

            chkDedicatedPool.Checked = item.DedicatedApplicationPool;
            chkDedicatedPool.Enabled = !item.SharePointInstalled;

            chkAuthAnonymous.Checked      = item.EnableAnonymousAccess;
            chkAuthWindows.Checked        = item.EnableWindowsAuthentication;
            chkAuthBasic.Checked          = item.EnableBasicAuthentication;
            chkDynamicCompression.Checked = item.EnableDynamicCompression;
            chkStaticCompression.Checked  = item.EnableStaticCompression;

            // default documents
            txtDefaultDocs.Text = String.Join("\n", item.DefaultDocs.Split(',', ';'));

            // redirection
            txtRedirectUrl.Text = item.HttpRedirect;
            bool redirectionEnabled = !String.IsNullOrEmpty(item.HttpRedirect);

            rbLocationFolder.Checked   = !redirectionEnabled;
            rbLocationRedirect.Checked = redirectionEnabled;
            valRedirection.Enabled     = redirectionEnabled;

            // store app pool value
            ViewState["ApplicationPool"] = item.ApplicationPool;

            ToggleLocationControls();

            // toggle controls by quotas
            fileLookup.Enabled         = PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_HOMEFOLDERS);
            rbLocationRedirect.Visible = PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_REDIRECTIONS);
            bool customSecurity = PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_SECURITY);

            chkWrite.Visible = customSecurity;
            // hide authentication options if not allowed
            pnlCustomAuth.Visible = customSecurity;
            //
            chkDedicatedPool.Visible    = PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_APPPOOLS);
            pnlDefaultDocuments.Visible = PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_DEFAULTDOCS);

            UserSettings settings = ES.Services.Users.GetUserSettings(PanelSecurity.SelectedUserId, "WebPolicy");

            if (Utils.ParseBool(settings["EnableDedicatedPool"], false) == true)
            {
                chkDedicatedPool.Checked = true;
            }

            chkDedicatedPool.Enabled = !(Utils.ParseBool(settings["EnableDedicatedPool"], false));
        }
Esempio n. 26
0
        public int InstallWebApplication(InstallationInfo inst)
        {
            // place log record
            TaskManager.StartTask("APP_INSTALLER", "INSTALL_APPLICATION", inst.PackageId);

            TaskManager.WriteParameter("Virtual directory", inst.VirtualDir);
            TaskManager.WriteParameter("Database group", inst.DatabaseGroup);

            try
            {
                // get application info
                app = GetApplication(inst.PackageId, inst.ApplicationId);

                BackgroundTask topTask = TaskManager.TopTask;

                topTask.ItemName = app.Name;

                TaskController.UpdateTask(topTask);

                // check web site for existance
                WebSite webSite = WebServerController.GetWebSite(inst.WebSiteId);

                if (webSite == null)
                {
                    return(BusinessErrorCodes.ERROR_WEB_INSTALLER_WEBSITE_NOT_EXISTS);
                }

                TaskManager.WriteParameter("Web site", webSite.Name);

                webSiteName = webSite.Name;
                siteId      = webSite.SiteId;

                // change web site properties if required
                if (String.IsNullOrEmpty(inst.VirtualDir))
                {
                    ChangeAppVirtualDirectoryProperties(webSite, app.WebSettings);
                    WebServerController.UpdateWebSite(webSite);
                }

                // get OS service
                int osId = PackageController.GetPackageServiceId(inst.PackageId, "os");
                os = new OS.OperatingSystem();
                ServiceProviderProxy.Init(os, osId);

                // get remote content path
                contentPath = webSite.ContentPath;

                // create virtual dir if required
                if (!String.IsNullOrEmpty(inst.VirtualDir))
                {
                    // check if the required virtual dir already exists
                    contentPath = Path.Combine(contentPath, inst.VirtualDir);

                    WebAppVirtualDirectory vdir = null;
                    int result = WebServerController.AddAppVirtualDirectory(inst.WebSiteId, inst.VirtualDir, contentPath);
                    if (result == BusinessErrorCodes.ERROR_VDIR_ALREADY_EXISTS)
                    {
                        // the directory alredy exists
                        vdir = WebServerController.GetAppVirtualDirectory(
                            inst.WebSiteId, inst.VirtualDir);

                        contentPath = vdir.ContentPath;
                    }
                    else
                    {
                        vdir = WebServerController.GetAppVirtualDirectory(
                            inst.WebSiteId, inst.VirtualDir);

                        inst[PROPERTY_VDIR_CREATED] = "True";
                    }

                    // change virtual directory properties if required
                    ChangeAppVirtualDirectoryProperties(vdir, app.WebSettings);
                    WebServerController.UpdateAppVirtualDirectory(inst.WebSiteId, vdir);
                }

                // deploy application codebase ZIP and then unpack it
                string codebasePath       = app.Codebase;
                string remoteCodebasePath = Path.Combine(contentPath, Path.GetFileName(app.Codebase));

                // make content path absolute
                string absContentPath = FilesController.GetFullPackagePath(inst.PackageId, contentPath);

                // save content path
                inst[PROPERTY_CONTENT_PATH]          = contentPath;
                inst[PROPERTY_ABSOLUTE_CONTENT_PATH] = absContentPath;

                // copy ZIP to the target server
                FileStream stream        = File.OpenRead(codebasePath);
                int        BUFFER_LENGTH = 5000000;

                byte[] buffer    = new byte[BUFFER_LENGTH];
                int    readBytes = 0;
                while (true)
                {
                    readBytes = stream.Read(buffer, 0, BUFFER_LENGTH);

                    if (readBytes < BUFFER_LENGTH)
                    {
                        Array.Resize <byte>(ref buffer, readBytes);
                    }

                    FilesController.AppendFileBinaryChunk(inst.PackageId, remoteCodebasePath, buffer);

                    if (readBytes < BUFFER_LENGTH)
                    {
                        break;
                    }
                }



                // unpack codebase
                inst[PROPERTY_INSTALLED_FILES] = String.Join(";",
                                                             FilesController.UnzipFiles(inst.PackageId, new string[] { remoteCodebasePath }));

                // delete codebase zip
                FilesController.DeleteFiles(inst.PackageId, new string[] { remoteCodebasePath });

                // check/create databases
                if (!String.IsNullOrEmpty(inst.DatabaseGroup) &&
                    String.Compare(inst.DatabaseGroup, "None", true) != 0)
                {
                    // database
                    if (inst.DatabaseId == 0)
                    {
                        TaskManager.WriteParameter("Database name", inst.DatabaseName);

                        // we should create a new database
                        SqlDatabase db = new SqlDatabase();
                        db.PackageId    = inst.PackageId;
                        db.Name         = inst.DatabaseName;
                        inst.DatabaseId = DatabaseServerController.AddSqlDatabase(db, inst.DatabaseGroup);
                        if (inst.DatabaseId < 0)
                        {
                            // rollback installation
                            RollbackInstallation(inst);

                            // return error
                            return(inst.DatabaseId); // there was an error when creating database
                        }

                        inst[PROPERTY_DATABASE_CREATED] = "True";
                    }
                    else
                    {
                        // existing database
                        SqlDatabase db = DatabaseServerController.GetSqlDatabase(inst.DatabaseId);
                        inst.DatabaseName = db.Name;

                        TaskManager.WriteParameter("Database name", inst.DatabaseName);
                    }

                    SqlUser user = null;
                    // database user
                    if (inst.UserId == 0)
                    {
                        TaskManager.WriteParameter("Database user", inst.Username);

                        // NEW USER
                        user           = new SqlUser();
                        user.PackageId = inst.PackageId;
                        user.Name      = inst.Username;
                        user.Databases = new string[] { inst.DatabaseName };
                        user.Password  = inst.Password;
                        inst.UserId    = DatabaseServerController.AddSqlUser(user, inst.DatabaseGroup);
                        if (inst.UserId < 0)
                        {
                            // rollback installation
                            RollbackInstallation(inst);

                            // return error
                            return(inst.UserId); // error while adding user
                        }

                        inst[PROPERTY_USER_CREATED] = "True";
                    }
                    else
                    {
                        // EXISTING USER
                        user          = DatabaseServerController.GetSqlUser(inst.UserId);
                        inst.Username = user.Name;

                        TaskManager.WriteParameter("Database user", inst.Username);

                        List <string> databases = new List <string>();
                        databases.AddRange(user.Databases);

                        if (!databases.Contains(inst.DatabaseName))
                        {
                            databases.Add(inst.DatabaseName);

                            user.Databases = databases.ToArray();
                            DatabaseServerController.UpdateSqlUser(user);
                        }
                    }

                    // check connectivity with SQL Server and credentials provided
                    // load user item
                    int sqlServiceId = PackageController.GetPackageServiceId(inst.PackageId, inst.DatabaseGroup);
                    sql = new DatabaseServer();
                    ServiceProviderProxy.Init(sql, sqlServiceId);

                    if (!sql.CheckConnectivity(inst.DatabaseName, inst.Username,
                                               inst.Password))
                    {
                        // can't connect to the database
                        RollbackInstallation(inst);

                        return(BusinessErrorCodes.ERROR_WEB_INSTALLER_CANT_CONNECT_DATABASE);
                    }

                    // read SQL server settings
                    StringDictionary settings = ServerController.GetServiceSettings(sqlServiceId);
                    serverIpAddressExternal = settings["ExternalAddress"];
                    if (settings.ContainsKey("InternalAddress"))
                    {
                        serverIpAddressInternal = settings["InternalAddress"];
                    }
                }

                // ********* RUN INSTALL SCENARIO ***********
                int scriptResult = RunInstallScenario(inst);
                if (scriptResult < 0)
                {
                    // rollback installation
                    RollbackInstallation(inst);

                    // return error
                    return(scriptResult);
                }

                // add new installation to the database
                return(0);
            }
            catch (Exception ex)
            {
                // rollback installation
                RollbackInstallation(inst);

                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
 public void SaveWebItem(WebAppVirtualDirectory item)
 {
     item.HttpHeaders = CollectFormData(false).ToArray();
 }
Esempio n. 28
0
        public void SetCustomHttpHeaders(WebAppVirtualDirectory virtualDir)
        {
            #region Revert to parent settings (inherited)
            using (var srvman = GetServerManager())
            {
                var config = srvman.GetApplicationHostConfiguration();
                //
                var section = config.GetSection(Constants.HttpProtocolSection, virtualDir.FullQualifiedPath);
                //
                section.RevertToParent();
                //
                srvman.CommitChanges();
            }
            #endregion

            // Ensure virtual directory has Custom HTTP Headers set
            if (virtualDir.HttpHeaders == null || virtualDir.HttpHeaders.Length == 0)
            {
                return;
            }

            #region Put the change in effect
            using (var srvman = GetServerManager())
            {
                var config = srvman.GetApplicationHostConfiguration();
                //
                var section = config.GetSection(Constants.HttpProtocolSection, virtualDir.FullQualifiedPath);
                //
                var headersCollection = section.GetCollection("customHeaders");
                // Clean the collection to avoid duplicates collision on the root and nested levels
                headersCollection.Clear();
                // Iterate over custom http headers are being set
                foreach (var item in virtualDir.HttpHeaders)
                {
                    // Trying to find out whether the header is being updated
                    int indexOf = FindCustomHttpHeader(headersCollection, item);
                    //
                    if (indexOf > -1)
                    {
                        // Obtain the custom http header to update
                        var item2Renew = headersCollection[indexOf];
                        // Apply changes to the element
                        FillConfigurationElementWithData(item2Renew, item);
                        // Loop the next item
                        continue;
                    }
                    // Creating a new custom http header
                    var item2Add = CreateCustomHttpHeader(headersCollection, item);
                    // Checking results of the create operation
                    if (item2Add == null)
                    {
                        continue;
                    }
                    // Adding the newly created custom http header
                    headersCollection.Add(item2Add);
                }
                // Commit changes
                srvman.CommitChanges();
            }
            #endregion
        }
        public void BindWebItem(int packageId, WebAppVirtualDirectory item)
        {
            // IIS 7.0 mode
            IIs7 = item.IIs7;

            chkAsp.Checked = item.AspInstalled;
            Utils.SelectListItem(ddlAspNet, item.AspNetInstalled);
            Utils.SelectListItem(ddlPhp, item.PhpInstalled);
            chkPerl.Checked   = item.PerlInstalled;
            chkPython.Checked = item.PythonInstalled;
            chkCgiBin.Checked = item.CgiBinInstalled;

            // toggle controls by quotas
            rowAsp.Visible = PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_ASP);

            // IIS 7 does not support web sites w/o ASP.NET, so do we
            if (IIs7)
            {
                ddlAspNet.Items.Remove(ddlAspNet.Items.FindByValue(""));
            }

            // asp.net
            if (!PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_ASPNET11))
            {
                ddlAspNet.Items.Remove(ddlAspNet.Items.FindByValue("1"));
            }

            if (!PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_ASPNET20))
            {
                ddlAspNet.Items.Remove(ddlAspNet.Items.FindByValue("2"));
            }

            if (!PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_ASPNET40))
            {
                ddlAspNet.Items.Remove(ddlAspNet.Items.FindByValue("4"));
            }

            if (!IIs7 || !PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_ASPNET20))
            {
                ddlAspNet.Items.Remove(ddlAspNet.Items.FindByValue("2I"));
            }

            if (!IIs7 || !PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_ASPNET40))
            {
                ddlAspNet.Items.Remove(ddlAspNet.Items.FindByValue("4I"));
            }

            // php
            if (PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_PHP4))
            {
                ddlPhp.Items.Add("4");
            }

            var allowSingleValueInPhpDropDown = false;

            if (PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_PHP5))
            {
                if (!string.IsNullOrEmpty(item.Php5VersionsInstalled))
                {
                    // Remove empty item. Not allows for PHP5 FastCGI. There is no way to disable a handler without removing it or removing some vital info. If we do that, the user can not choose to run PHP5 FastCGI later
                    ddlPhp.Items.Remove(ddlPhp.Items.FindByValue(""));
                    // Add items from list
                    ddlPhp.Items.AddRange(item.Php5VersionsInstalled.Split('|').Select(v => new ListItem(v.Split(';')[1], "5|" + v.Split(';')[0])).OrderBy(i => i.Text).ToArray());

                    allowSingleValueInPhpDropDown = true;
                }
                else
                {
                    ddlPhp.Items.Add("5");
                }
            }
            Utils.SelectListItem(ddlPhp, item.PhpInstalled);
            rowPhp.Visible = ddlPhp.Items.Count > 1 || allowSingleValueInPhpDropDown && ddlPhp.Items.Count > 0;

            rowPerl.Visible   = PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_PERL);
            rowCgiBin.Visible = PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_CGIBIN);

            // Left Python support along IIS 7
            rowPython.Visible = !IIs7 && PackagesHelper.CheckGroupQuotaEnabled(packageId, ResourceGroups.Web, Quotas.WEB_PYTHON);
        }
 public void BindWebItem(WebAppVirtualDirectory item)
 {
     gvCustomHeaders.DataSource = item.HttpHeaders;
     gvCustomHeaders.DataBind();
 }