private bool IsHttpAliasValid(string strAlias)
        {
            bool isValid = true;

            if (string.IsNullOrEmpty(strAlias))
            {
                isValid = false;
            }
            else
            {
                if (strAlias.IndexOf("://", StringComparison.Ordinal) != -1)
                {
                    strAlias = strAlias.Remove(0, strAlias.IndexOf("://", StringComparison.Ordinal) + 3);
                }
                if (strAlias.IndexOf("\\\\", StringComparison.Ordinal) != -1)
                {
                    strAlias = strAlias.Remove(0, strAlias.IndexOf("\\\\", StringComparison.Ordinal) + 2);
                }

                //Validate Alias, this needs to be done with lowercase, downstream we only check with lowercase variables
                if (!PortalAliasController.ValidateAlias(strAlias.ToLowerInvariant(), false))
                {
                    isValid = false;
                }
            }
            return(isValid);
        }
예제 #2
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// cmdUpdate_Click runs when the Update button is clicked
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        ///     [cnurse]	5/10/2004	Updated to reflect design changes for Help, 508 support
        ///                       and localisation
        /// </history>
        /// -----------------------------------------------------------------------------
        private void cmdUpdate_Click(Object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                PortalController.PortalTemplateInfo template = LoadPortalTemplateInfoForSelectedItem();

                try
                {
                    bool   blnChild;
                    string strPortalAlias;
                    string strChildPath  = string.Empty;
                    var    closePopUpStr = string.Empty;

                    var objPortalController = new PortalController();

                    //check template validity
                    var    messages       = new ArrayList();
                    string schemaFilename = Server.MapPath(string.Concat(AppRelativeTemplateSourceDirectory, "portal.template.xsd"));
                    string xmlFilename    = template.TemplateFilePath;
                    var    xval           = new PortalTemplateValidator();
                    if (!xval.Validate(xmlFilename, schemaFilename))
                    {
                        UI.Skins.Skin.AddModuleMessage(this, "", String.Format(Localization.GetString("InvalidTemplate", LocalResourceFile), Path.GetFileName(template.TemplateFilePath)), ModuleMessage.ModuleMessageType.RedError);
                        messages.AddRange(xval.Errors);
                        lstResults.Visible    = true;
                        lstResults.DataSource = messages;
                        lstResults.DataBind();
                        validationPanel.Visible = true;
                        return;
                    }

                    //Set Portal Name
                    txtPortalAlias.Text = txtPortalAlias.Text.ToLowerInvariant();
                    txtPortalAlias.Text = txtPortalAlias.Text.Replace("http://", "");

                    //Validate Portal Name
                    if (!Globals.IsHostTab(PortalSettings.ActiveTab.TabID))
                    {
                        blnChild       = true;
                        strPortalAlias = txtPortalAlias.Text;
                    }
                    else
                    {
                        blnChild = (optType.SelectedValue == "C");

                        strPortalAlias = blnChild ? PortalController.GetPortalFolder(txtPortalAlias.Text) : txtPortalAlias.Text;
                    }

                    string message = String.Empty;
                    ModuleMessage.ModuleMessageType messageType = ModuleMessage.ModuleMessageType.RedError;
                    if (!PortalAliasController.ValidateAlias(strPortalAlias, blnChild))
                    {
                        message = Localization.GetString("InvalidName", LocalResourceFile);
                    }

                    //check whether have conflict between tab path and portal alias.
                    var checkTabPath = string.Format("//{0}", strPortalAlias);
                    if (TabController.GetTabByTabPath(PortalSettings.PortalId, checkTabPath, string.Empty) != Null.NullInteger ||
                        TabController.GetTabByTabPath(Null.NullInteger, checkTabPath, string.Empty) != Null.NullInteger)
                    {
                        message = Localization.GetString("DuplicateWithTab", LocalResourceFile);
                    }

                    //Validate Password
                    if (txtPassword.Text != txtConfirm.Text)
                    {
                        if (!String.IsNullOrEmpty(message))
                        {
                            message += "<br/>";
                        }
                        message += Localization.GetString("InvalidPassword", LocalResourceFile);
                    }
                    string strServerPath = Globals.GetAbsoluteServerPath(Request);

                    //Set Portal Alias for Child Portals
                    if (String.IsNullOrEmpty(message))
                    {
                        if (blnChild)
                        {
                            strChildPath = strServerPath + strPortalAlias;

                            if (Directory.Exists(strChildPath))
                            {
                                message = Localization.GetString("ChildExists", LocalResourceFile);
                            }
                            else
                            {
                                if (!Globals.IsHostTab(PortalSettings.ActiveTab.TabID))
                                {
                                    strPortalAlias = Globals.GetDomainName(Request, true) + "/" + strPortalAlias;
                                }
                                else
                                {
                                    strPortalAlias = txtPortalAlias.Text;
                                }
                            }
                        }
                    }

                    //Get Home Directory
                    string homeDir = txtHomeDirectory.Text != @"Portals/[PortalID]" ? txtHomeDirectory.Text : "";

                    //Validate Home Folder
                    if (!string.IsNullOrEmpty(homeDir))
                    {
                        if (string.IsNullOrEmpty(String.Format("{0}\\{1}\\", Globals.ApplicationMapPath, homeDir).Replace("/", "\\")))
                        {
                            message = Localization.GetString("InvalidHomeFolder", LocalResourceFile);
                        }
                        if (homeDir.Contains("admin") || homeDir.Contains("DesktopModules") || homeDir.ToLowerInvariant() == "portals/")
                        {
                            message = Localization.GetString("InvalidHomeFolder", LocalResourceFile);
                        }
                    }

                    //Validate Portal Alias
                    if (!string.IsNullOrEmpty(strPortalAlias))
                    {
                        PortalAliasInfo portalAlias = PortalAliasController.GetPortalAliasLookup(strPortalAlias.ToLower());
                        if (portalAlias != null)
                        {
                            message = Localization.GetString("DuplicatePortalAlias", LocalResourceFile);
                        }
                    }

                    //Create Portal
                    if (String.IsNullOrEmpty(message))
                    {
                        //Attempt to create the portal
                        UserInfo adminUser = new UserInfo();
                        int      intPortalId;
                        try
                        {
                            if (useCurrent.Checked)
                            {
                                adminUser   = UserInfo;
                                intPortalId = objPortalController.CreatePortal(txtPortalName.Text,
                                                                               adminUser.UserID,
                                                                               txtDescription.Text,
                                                                               txtKeyWords.Text,
                                                                               template,
                                                                               homeDir,
                                                                               strPortalAlias,
                                                                               strServerPath,
                                                                               strChildPath,
                                                                               blnChild);
                            }
                            else
                            {
                                adminUser = new UserInfo
                                {
                                    FirstName   = txtFirstName.Text,
                                    LastName    = txtLastName.Text,
                                    Username    = txtUsername.Text,
                                    DisplayName = txtFirstName.Text + " " + txtLastName.Text,
                                    Email       = txtEmail.Text,
                                    IsSuperUser = false,
                                    Membership  =
                                    {
                                        Approved         = true,
                                        Password         = txtPassword.Text,
                                        PasswordQuestion = txtQuestion.Text,
                                        PasswordAnswer   = txtAnswer.Text
                                    },
                                    Profile =
                                    {
                                        FirstName = txtFirstName.Text,
                                        LastName  = txtLastName.Text
                                    }
                                };

                                intPortalId = objPortalController.CreatePortal(txtPortalName.Text,
                                                                               adminUser,
                                                                               txtDescription.Text,
                                                                               txtKeyWords.Text,
                                                                               template,
                                                                               homeDir,
                                                                               strPortalAlias,
                                                                               strServerPath,
                                                                               strChildPath,
                                                                               blnChild);
                            }
                        }
                        catch (Exception ex)
                        {
                            intPortalId = Null.NullInteger;
                            message     = ex.Message;
                        }
                        if (intPortalId != -1)
                        {
                            //Create a Portal Settings object for the new Portal
                            PortalInfo objPortal   = objPortalController.GetPortal(intPortalId);
                            var        newSettings = new PortalSettings {
                                PortalAlias = new PortalAliasInfo {
                                    HTTPAlias = strPortalAlias
                                }, PortalId = intPortalId, DefaultLanguage = objPortal.DefaultLanguage
                            };
                            string webUrl = Globals.AddHTTP(strPortalAlias);
                            try
                            {
                                if (!Globals.IsHostTab(PortalSettings.ActiveTab.TabID))
                                {
                                    message = Mail.SendMail(PortalSettings.Email,
                                                            txtEmail.Text,
                                                            PortalSettings.Email + ";" + Host.HostEmail,
                                                            Localization.GetSystemMessage(newSettings, "EMAIL_PORTAL_SIGNUP_SUBJECT", adminUser),
                                                            Localization.GetSystemMessage(newSettings, "EMAIL_PORTAL_SIGNUP_BODY", adminUser),
                                                            "",
                                                            "",
                                                            "",
                                                            "",
                                                            "",
                                                            "");
                                }
                                else
                                {
                                    message = Mail.SendMail(Host.HostEmail,
                                                            txtEmail.Text,
                                                            Host.HostEmail,
                                                            Localization.GetSystemMessage(newSettings, "EMAIL_PORTAL_SIGNUP_SUBJECT", adminUser),
                                                            Localization.GetSystemMessage(newSettings, "EMAIL_PORTAL_SIGNUP_BODY", adminUser),
                                                            "",
                                                            "",
                                                            "",
                                                            "",
                                                            "",
                                                            "");
                                }
                            }
                            catch (Exception exc)
                            {
                                Logger.Error(exc);

                                closePopUpStr = (PortalSettings.EnablePopUps) ? "onclick=\"return " + UrlUtils.ClosePopUp(true, webUrl, true) + "\"" : "";
                                message       = string.Format(Localization.GetString("UnknownSendMail.Error", LocalResourceFile), webUrl, closePopUpStr);
                            }
                            var objEventLog = new EventLogController();
                            objEventLog.AddLog(objPortalController.GetPortal(intPortalId), PortalSettings, UserId, "", EventLogController.EventLogType.PORTAL_CREATED);

                            // mark default language as published if content localization is enabled
                            bool ContentLocalizationEnabled = PortalController.GetPortalSettingAsBoolean("ContentLocalizationEnabled", PortalId, false);
                            if (ContentLocalizationEnabled)
                            {
                                LocaleController lc = new LocaleController();
                                lc.PublishLanguage(intPortalId, objPortal.DefaultLanguage, true);
                            }

                            //Redirect to this new site
                            if (message == Null.NullString)
                            {
                                webUrl = (PortalSettings.EnablePopUps) ? UrlUtils.ClosePopUp(true, webUrl, false) : webUrl;
                                Response.Redirect(webUrl, true);
                            }
                            else
                            {
                                closePopUpStr = (PortalSettings.EnablePopUps) ? "onclick=\"return " + UrlUtils.ClosePopUp(true, webUrl, true) + "\"" : "";
                                message       = string.Format(Localization.GetString("SendMail.Error", LocalResourceFile), message, webUrl, closePopUpStr);
                                messageType   = ModuleMessage.ModuleMessageType.YellowWarning;
                            }
                        }
                    }
                    UI.Skins.Skin.AddModuleMessage(this, "", message, messageType);
                }
                catch (Exception exc) //Module failed to load
                {
                    Exceptions.ProcessModuleLoadException(this, exc);
                }
            }
        }
        protected virtual void SaveAliasesGrid(object source, CommandEventArgs e)
        {
            string childPath = string.Empty;
            string message   = string.Empty;

            //Get the index of the row to save
            int index = Grid.EditItemIndex;

            var portalAlias = Aliases[index];
            var ctlAlias    = Grid.Items[index].Cells[1].FindControl("txtHTTPAlias") as TextBox;

            bool isPrimary = GetIsPrimary(index);

            string strAlias = String.Empty;

            if (ctlAlias != null)
            {
                strAlias = ctlAlias.Text.Trim();
            }

            if (string.IsNullOrEmpty(strAlias))
            {
                message = Localization.GetString("InvalidAlias", LocalResourceFile);
            }
            else
            {
                if (strAlias.IndexOf("://", StringComparison.Ordinal) != -1)
                {
                    strAlias = strAlias.Remove(0, strAlias.IndexOf("://", StringComparison.Ordinal) + 3);
                }
                if (strAlias.IndexOf("\\\\", StringComparison.Ordinal) != -1)
                {
                    strAlias = strAlias.Remove(0, strAlias.IndexOf("\\\\", StringComparison.Ordinal) + 2);
                }

                //Validate Alias, this needs to be done with lowercase, downstream we only check with lowercase variables
                if (!PortalAliasController.ValidateAlias(strAlias.ToLowerInvariant(), false))
                {
                    message = Localization.GetString("InvalidAlias", LocalResourceFile);
                }
            }

            if (string.IsNullOrEmpty(message) && AddMode)
            {
                var aliases = PortalAliasController.Instance.GetPortalAliases();
                if (aliases.Contains(strAlias))
                {
                    message = Localization.GetString("DuplicateAlias", LocalResourceFile);
                }
            }

            if (string.IsNullOrEmpty(message))
            {
                portalAlias.HTTPAlias = strAlias;
                portalAlias.IsPrimary = isPrimary;

                var item = Grid.Items[index];
                var cultureCodeDropDown = item.Controls[2].FindControl("cultureCodeDropDown") as DnnComboBox;
                if (cultureCodeDropDown != null)
                {
                    portalAlias.CultureCode = cultureCodeDropDown.SelectedValue;
                }

                GetPortalAliasProperties(index, portalAlias);

                if (AddMode)
                {
                    PortalAliasController.Instance.AddPortalAlias(portalAlias);
                }
                else
                {
                    PortalAliasController.Instance.UpdatePortalAlias(portalAlias);
                }

                //Reset Edit Index
                ErrorLabel.Visible = false;
                Grid.EditItemIndex = -1;
                _Aliases           = null;
            }
            else
            {
                ErrorLabel.Text    = message;
                ErrorLabel.Visible = true;
            }

            BindAliases();
        }
        protected void SaveAlias(object source, CommandEventArgs e)
        {
            var    controller = new PortalAliasController();
            bool   isChild    = false;
            string childPath  = string.Empty;
            string message    = string.Empty;

            //Get the index of the row to save
            int index = dgPortalAlias.EditItemIndex;

            var portalAlias = (PortalAliasInfo)Aliases[index];
            var ctlAlias    = (TextBox)dgPortalAlias.Items[index].Cells[1].FindControl("txtHTTPAlias");
            var chkChild    = (CheckBox)dgPortalAlias.Items[index].Cells[2].FindControl("chkChild");

            string strAlias = ctlAlias.Text.Trim();

            if (string.IsNullOrEmpty(strAlias))
            {
                message = Localization.GetString("InvalidAlias", LocalResourceFile);
            }
            else
            {
                if (strAlias.IndexOf("://") != -1)
                {
                    strAlias = strAlias.Remove(0, strAlias.IndexOf("://") + 3);
                }
                if (strAlias.IndexOf("\\\\") != -1)
                {
                    strAlias = strAlias.Remove(0, strAlias.IndexOf("\\\\") + 2);
                }

                isChild = (chkChild != null && chkChild.Checked);

                //Validate Alias
                if (!PortalAliasController.ValidateAlias(strAlias, false))
                {
                    message = Localization.GetString("InvalidAlias", LocalResourceFile);
                }

                //Validate Child Folder Name
                if (isChild)
                {
                    childPath = strAlias.Substring(strAlias.LastIndexOf("/") + 1);
                    if (!PortalAliasController.ValidateAlias(childPath, true))
                    {
                        message = Localization.GetString("InvalidAlias", LocalResourceFile);
                    }
                }
            }

            if (string.IsNullOrEmpty(message) && isChild)
            {
                //Attempt to create child folder
                string childPhysicalPath = Server.MapPath(childPath);

                if (Directory.Exists(childPhysicalPath))
                {
                    message = Localization.GetString("ChildExists", LocalResourceFile);
                }
                else
                {
                    message = PortalController.CreateChildPortalFolder(childPhysicalPath);
                }
            }

            if (string.IsNullOrEmpty(message))
            {
                portalAlias.HTTPAlias = strAlias;
                if (AddMode)
                {
                    controller.AddPortalAlias(portalAlias);
                }
                else
                {
                    controller.UpdatePortalAliasInfo(portalAlias);
                }

                //Reset Edit Index
                lblError.Visible            = false;
                dgPortalAlias.EditItemIndex = -1;
                _Aliases = null;
            }
            else
            {
                lblError.Text    = message;
                lblError.Visible = true;
            }

            BindAliases();
        }