Exemplo n.º 1
0
        private void InstallApplication()
        {
            //the application uses a two step installation process. The first step is used to update
            //the Web.config with any configuration settings - which forces an application restart.
            //The second step finishes the installation process and provisions the site.

            string installationDate = Config.GetSetting("InstallationDate");

            if (installationDate == null || String.IsNullOrEmpty(installationDate))
            {
                string strError = Config.UpdateMachineKey();
                if (String.IsNullOrEmpty(strError))
                {
                    //send a new request to the application to initiate step 2
                    Response.Redirect(HttpContext.Current.Request.RawUrl, true);
                }
                else
                {
                    //403-3 Error - Redirect to ErrorPage
                    //403.3 means directory permissions issue
                    string strURL = "~/ErrorPage.aspx?status=403_3&error=" + strError;
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Server.Transfer(strURL);
                }
            }
            else
            {
                var synchConnectionString = new SynchConnectionStringStep();
                synchConnectionString.Execute();
                if (synchConnectionString.Status == StepStatus.AppRestart)
                {
                    //send a new request to the application to initiate step 2
                    Response.Redirect(HttpContext.Current.Request.RawUrl, true);
                }

                //Start Timer
                Upgrade.Upgrade.StartTimer();

                //Write out Header
                HtmlUtils.WriteHeader(Response, "install");

                //get path to script files
                string strProviderPath = DataProvider.Instance().GetProviderPath();
                if (!strProviderPath.StartsWith("ERROR:"))
                {
                    Response.Write("<h2>Version: " + Globals.FormatVersion(DotNetNukeContext.Current.Application.Version) + "</h2>");
                    Response.Flush();

                    Response.Write("<br><br>");
                    Response.Write("<h2>Installation Status Report</h2>");
                    Response.Flush();

                    if (!CheckPermissions())
                    {
                        return;
                    }

                    var installConfig = InstallController.Instance.GetInstallConfig();

                    Upgrade.Upgrade.InstallDNN(strProviderPath);
                    //remove en-US from portal if installing in a different language
                    if (!installConfig.InstallCulture.Equals("en-us", StringComparison.InvariantCultureIgnoreCase))
                    {
                        var locale = LocaleController.Instance.GetLocale("en-US");
                        Localization.Localization.RemoveLanguageFromPortal(0, locale.LanguageId);
                    }


                    var  licenseConfig     = (installConfig != null) ? installConfig.License : null;
                    bool IsProOrEnterprise = (File.Exists(HttpContext.Current.Server.MapPath("~\\bin\\DotNetNuke.Professional.dll")) || File.Exists(HttpContext.Current.Server.MapPath("~\\bin\\DotNetNuke.Enterprise.dll")));
                    if (IsProOrEnterprise && licenseConfig != null && !String.IsNullOrEmpty(licenseConfig.AccountEmail) && !String.IsNullOrEmpty(licenseConfig.InvoiceNumber))
                    {
                        Upgrade.Upgrade.ActivateLicense();
                    }

                    //Adding ClientDependency Resources config to web.config
                    if (!ClientResourceManager.IsInstalled())
                    {
                        ClientResourceManager.AddConfiguration();
                    }

                    Response.Write("<h2>Installation Complete</h2>");
                    Response.Write("<br><br><h2><a href='../Default.aspx'>Click Here To Access Your Site</a></h2><br><br>");
                    Response.Flush();

                    //remove installwizard files
                    Upgrade.Upgrade.DeleteInstallerFiles();

                    //log APPLICATION_START event
                    Initialize.LogStart();

                    //Start Scheduler
                    Initialize.StartScheduler();
                }
                else
                {
                    //upgrade error
                    Response.Write("<h2>Upgrade Error: " + strProviderPath + "</h2>");
                    Response.Flush();
                }

                //Write out Footer
                HtmlUtils.WriteFooter(Response);
            }
        }
Exemplo n.º 2
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Page_Load runs when the Page loads
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        ///     [cnurse]	02/09/2007	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        protected override void OnLoad(EventArgs e)
        {
            SetBrowserLanguage();
            LocalizePage();

            base.OnLoad(e);
            visitSite.Click += VisitSiteClick;

            //Register jquery reference.
            jQuery.RequestRegistration();

            //Create Status Files
            if (!File.Exists(StatusFile))
            {
                File.CreateText(StatusFile).Close();
            }

            // Hide Licensing Step if no License Info is available
            LicenseActivation.Visible = IsProOrEnterprise && !String.IsNullOrEmpty(_installConfig.License.AccountEmail) && !String.IsNullOrEmpty(_installConfig.License.InvoiceNumber);

            if ((!IsProOrEnterprise) && templateList.Items.FindItemByValue("Mobile Website.template") != null)
            {
                templateList.Items.Remove(templateList.Items.FindItemByValue("Mobile Website.template"));
            }

            if (HttpContext.Current.Request.RawUrl.EndsWith("&initiateinstall"))
            {
                var synchConnectionString = new SynchConnectionStringStep();
                synchConnectionString.Execute();
                Response.Redirect(HttpContext.Current.Request.RawUrl.Replace("&initiateinstall", "&executeinstall"), true);
            }
            else if (HttpContext.Current.Request.RawUrl.EndsWith("&executeinstall"))
            {
                try
                {
                    _installerRunning = true;
                    LaunchAutoInstall();
                }
                catch (Exception)
                {
                    //Redirect back to first page
                    Response.Redirect(HttpContext.Current.Request.RawUrl.Replace("&executeinstall", ""), true);
                }
            }
            else if (!Page.IsPostBack)
            {
                if (_installerRunning)
                {
                    LaunchAutoInstall();
                }
                else
                {
                    SetupDatabaseInfo();
                    BindLanguageList();

                    if (CheckDatabaseConnection())
                    {
                        Initialise();
                    }
                    else
                    {
                        //Install but connection string not configured to point at a valid SQL Server
                        UpdateMachineKey();
                    }

                    if (!Regex.IsMatch(Request.Url.Host, "^([a-zA-Z0-9.-]+)$", RegexOptions.IgnoreCase))
                    {
                        lblError.Visible = true;
                        lblError.Text    = Localization.Localization.GetString("HostWarning", LocalResourceFile);
                    }

                    //ensure web.config is not read-only
                    var configPath = Server.MapPath("~/web.config");
                    try
                    {
                        var attributes = File.GetAttributes(configPath);
                        //file is read only
                        if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                        {
                            attributes = attributes & ~FileAttributes.ReadOnly;
                            File.SetAttributes(configPath, attributes);
                        }
                    }
                    catch (Exception ex)
                    {
                        lblError.Visible = true;
                        lblError.Text    = ex.ToString();
                        return;
                    }

                    //Adding ClientDependency Resources config to web.config
                    if (!ClientResourceManager.IsInstalled())
                    {
                        ClientResourceManager.AddConfiguration();
                        Response.Redirect(Request.RawUrl);
                        //TODO - this may cause infinite loop
                    }

                    //Ensure connection strings are in synch
                    var synchConnectionString = new SynchConnectionStringStep();
                    synchConnectionString.Execute();
                    if (synchConnectionString.Status == StepStatus.AppRestart)
                    {
                        Response.Redirect(HttpContext.Current.Request.RawUrl, true);
                    }

                    txtUsername.Text = _installConfig.SuperUser.UserName;
                    if (_installConfig.Portals.Count > 0)
                    {
                        txtWebsiteName.Text = _installConfig.Portals[0].PortalName;
                        //TODO Language and Template
                    }
                }
            }
        }