private void CreateSite(PortalConfig portal, InstallConfig installConfig)
        {

            var domain = "";
            if ((HttpContext.Current != null))
            {
                domain = Globals.GetDomainName(HttpContext.Current.Request, true).ToLowerInvariant().Replace("/install/launchautoinstall", "").Replace("/install", "").Replace("/runinstall", "");
            }

            var portalController = new PortalController();
            var serverPath = Globals.ApplicationMapPath + "\\";

            //Get the Portal Alias
            var portalAlias = domain;
            if (portal.PortAliases.Count > 0) portalAlias = portal.PortAliases[0];

            //Verify that portal alias is not present
            if (PortalAliasController.GetPortalAliasLookup(portalAlias.ToLower()) != null)
            {
                string description = Localization.Localization.GetString("SkipCreatingSite", LocalInstallResourceFile);
                Details = string.Format(description, portalAlias);
                return;
            }
            
            //Create default email
            var email = portal.AdminEmail;
            if (string.IsNullOrEmpty(email))
            {
                email = "admin@" + domain.Replace("www.", "");
                //Remove any domain subfolder information ( if it exists )
                if (email.IndexOf("/") != -1)
                {
                    email = email.Substring(0, email.IndexOf("/"));
                }
            }

            //install LP if installing in a different language            
            string culture = installConfig.InstallCulture;
            if (!culture.Equals("en-us", StringComparison.InvariantCultureIgnoreCase))
            {
                string installFolder = HttpContext.Current.Server.MapPath("~/Install/language");
                Upgrade.InstallPackage(installFolder + "\\installlanguage.resources", "Language", false);
            }

            var template = Upgrade.FindBestTemplate(portal.TemplateFileName);
            UserInfo userInfo;
            
            if (!String.IsNullOrEmpty(portal.AdminUserName))
                userInfo = Upgrade.CreateUserInfo(portal.AdminFirstName, portal.AdminLastName, portal.AdminUserName, portal.AdminPassword, email);
            else
                userInfo = Upgrade.CreateUserInfo(installConfig.SuperUser.FirstName, installConfig.SuperUser.LastName, installConfig.SuperUser.UserName, installConfig.SuperUser.Password, installConfig.SuperUser.Email);

            var childPath = string.Empty;
            if (portal.IsChild)
                childPath = portalAlias.Substring(portalAlias.LastIndexOf("/") + 1);
            
            //Create Portal
            var portalId = portalController.CreatePortal(portal.PortalName,
                                                     userInfo,
                                                     portal.Description,
                                                     portal.Keywords,
                                                     template,
                                                     portal.HomeDirectory,
                                                     portalAlias,
                                                     serverPath,
                                                     serverPath + childPath,
                                                     portal.IsChild);

            if (portalId > -1)
            {
                foreach (var alias in portal.PortAliases)
                {
                    portalController.AddPortalAlias(portalId, alias);
                }
            }

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

            //Log user in to site
            var loginStatus = UserLoginStatus.LOGIN_FAILURE;
            UserController.UserLogin(portalId, userInfo.Username, installConfig.SuperUser.Password, "", "", "", ref loginStatus, false);

            InstallController.Instance.RemoveFromInstallConfig("//dotnetnuke/superuser/password");
        }
Beispiel #2
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///   AddPortal manages the Installation of a new DotNetNuke Portal
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        ///   [cnurse]	11/06/2004	created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static int AddPortal(XmlNode node, bool status, int indent)
        {

            int portalId = -1;
            try
            {
                string hostMapPath = Globals.HostMapPath;
                string childPath = "";
                string domain = "";

                if ((HttpContext.Current != null))
                {
                    domain = Globals.GetDomainName(HttpContext.Current.Request, true).ToLowerInvariant().Replace("/install", "");
                }
                DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "AddPortal:" + domain);
                string portalName = XmlUtils.GetNodeValue(node.CreateNavigator(), "portalname");
                if (status)
                {
                    if (HttpContext.Current != null)
                    {
                        HtmlUtils.WriteFeedback(HttpContext.Current.Response, indent, "Creating Site: " + portalName + "<br>");
                    }
                }

                var portalController = new PortalController();
                XmlNode adminNode = node.SelectSingleNode("administrator");
                if (adminNode != null)
                {
                    string firstName = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "firstname");
                    string lastName = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "lastname");
                    string username = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "username");
                    string password = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "password");
                    string email = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "email");
                    string description = XmlUtils.GetNodeValue(node.CreateNavigator(), "description");
                    string keyWords = XmlUtils.GetNodeValue(node.CreateNavigator(), "keywords");
                    string templateFileName = XmlUtils.GetNodeValue(node.CreateNavigator(), "templatefile");
                    string serverPath = Globals.ApplicationMapPath + "\\";
                    bool isChild = bool.Parse(XmlUtils.GetNodeValue(node.CreateNavigator(), "ischild"));
                    string homeDirectory = XmlUtils.GetNodeValue(node.CreateNavigator(), "homedirectory");

                    //Get the Portal Alias
                    XmlNodeList portalAliases = node.SelectNodes("portalaliases/portalalias");
                    string strPortalAlias = domain;
                    if (portalAliases != null)
                    {
                        if (portalAliases.Count > 0)
                        {
                            if (!string.IsNullOrEmpty(portalAliases[0].InnerText))
                            {
                                strPortalAlias = portalAliases[0].InnerText;
                            }
                        }
                    }

                    //Create default email
                    if (string.IsNullOrEmpty(email))
                    {
                        email = "admin@" + domain.Replace("www.", "");
                        //Remove any domain subfolder information ( if it exists )
                        if (email.IndexOf("/") != -1)
                        {
                            email = email.Substring(0, email.IndexOf("/"));
                        }
                    }

                    if (isChild)
                    {
                        childPath = PortalController.GetPortalFolder(strPortalAlias);
                    }

                    var template = FindBestTemplate(templateFileName);
                    var userInfo = CreateUserInfo(firstName, lastName, username, password, email);

                    //Create Portal
                    portalId = portalController.CreatePortal(portalName, 
                                                             userInfo,
                                                             description,
                                                             keyWords,
                                                             template,
                                                             homeDirectory,
                                                             strPortalAlias,
                                                             serverPath,
                                                             serverPath + childPath,
                                                             isChild);

                    if (portalId > -1)
                    {
                        //Add Extra Aliases
                        if (portalAliases != null)
                        {
                            foreach (XmlNode portalAlias in portalAliases)
                            {
                                if (!string.IsNullOrEmpty(portalAlias.InnerText))
                                {
                                    if (status)
                                    {
                                        if (HttpContext.Current != null)
                                        {
                                            HtmlUtils.WriteFeedback(HttpContext.Current.Response, indent, "Creating Site Alias: " + portalAlias.InnerText + "<br>");
                                        }
                                    }
                                    portalController.AddPortalAlias(portalId, portalAlias.InnerText);
                                }
                            }
                        }

                        //Force Administrator to Update Password on first log in
                        PortalInfo portal = portalController.GetPortal(portalId);
                        UserInfo adminUser = UserController.GetUserById(portalId, portal.AdministratorId);
                        adminUser.Membership.UpdatePassword = true;
                        UserController.UpdateUser(portalId, adminUser);
                    }


                    return portalId;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                if (HttpContext.Current != null)
                {
                    HtmlUtils.WriteFeedback(HttpContext.Current.Response, indent, "<font color='red'>Error: " + ex.Message + ex.StackTrace + "</font><br>");
					DnnInstallLogger.InstallLogError(ex);
                }
                // failure
                portalId = - 1;
            }
            return portalId;
        }
Beispiel #3
0
        /// <summary>
        /// AddPortal manages the Installation of a new DotNetNuke Portal
        /// </summary>
        /// <remarks>
        /// </remarks>
        public static int AddPortal(XmlNode node, bool status, int indent)
        {
            try
            {
                int intPortalId;
                string strHostPath = Globals.HostMapPath;
                string strChildPath = "";
                string strDomain = "";

                if (HttpContext.Current != null)
                {
                    strDomain = Globals.GetDomainName(HttpContext.Current.Request, true).Replace("/Install", "");
                }

                string strPortalName = XmlUtils.GetNodeValue(node, "portalname", "");
                if (status)
                {
                    HtmlUtils.WriteFeedback(HttpContext.Current.Response, indent, "Creating Portal: " + strPortalName + "<br>");
                }

                PortalController objPortalController = new PortalController();
                PortalSecurity objSecurity = new PortalSecurity();
                XmlNode adminNode = node.SelectSingleNode("administrator");
                string strFirstName = XmlUtils.GetNodeValue(adminNode, "firstname", "");
                string strLastName = XmlUtils.GetNodeValue(adminNode, "lastname", "");
                string strUserName = XmlUtils.GetNodeValue(adminNode, "username", "");
                string strPassword = XmlUtils.GetNodeValue(adminNode, "password", "");
                string strEmail = XmlUtils.GetNodeValue(adminNode, "email", "");
                string strDescription = XmlUtils.GetNodeValue(node, "description", "");
                string strKeyWords = XmlUtils.GetNodeValue(node, "keywords", "");
                string strTemplate = XmlUtils.GetNodeValue(node, "templatefile", "");
                string strServerPath = Globals.ApplicationMapPath + "\\";
                bool isChild = bool.Parse(XmlUtils.GetNodeValue(node, "ischild", ""));
                string strHomeDirectory = XmlUtils.GetNodeValue(node, "homedirectory", "");

                //Get the Portal Alias
                XmlNodeList portalAliases = node.SelectNodes("portalaliases/portalalias");
                string strPortalAlias = strDomain;
                if (portalAliases.Count > 0)
                {
                    if (portalAliases[0].InnerText != "")
                    {
                        strPortalAlias = portalAliases[0].InnerText;
                    }
                }

                //Create default email
                if (strEmail == "")
                {
                    strEmail = "admin@" + strDomain.Replace("www.", "");
                    //Remove any domain subfolder information ( if it exists )
                    if (strEmail.IndexOf("/") != -1)
                    {
                        strEmail = strEmail.Substring(0, strEmail.IndexOf("/"));
                    }
                }

                if (isChild)
                {

                    strChildPath = strPortalAlias.Substring(strPortalAlias.LastIndexOf("/") + 1 - 1);
                }

                //Create Portal
                intPortalId = objPortalController.CreatePortal(strPortalName, strFirstName, strLastName, strUserName, objSecurity.Encrypt(Convert.ToString(Globals.HostSettings["EncryptionKey"]), strPassword), strEmail, strDescription, strKeyWords, strHostPath, strTemplate, strHomeDirectory, strPortalAlias, strServerPath, strServerPath + strChildPath, isChild);

                if (intPortalId > -1)
                {
                    //Add Extra Aliases
                    foreach (XmlNode portalAlias in portalAliases)
                    {
                        if (!String.IsNullOrEmpty(portalAlias.InnerText))
                        {
                            if (status)
                            {
                                HtmlUtils.WriteFeedback(HttpContext.Current.Response, indent, "Creating Portal Alias: " + portalAlias.InnerText + "<br>");
                            }
                            objPortalController.AddPortalAlias(intPortalId, portalAlias.InnerText);
                        }
                    }
                }

                return intPortalId;
            }
            catch (Exception ex)
            {
                HtmlUtils.WriteFeedback(HttpContext.Current.Response, indent, "<font color='red'>Error: " + ex.Message + "</font><br>");                
                return -1; // failure
            }
        }