Example #1
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, EventArgs e)
        {
            // Get portalID from querystring
            if (Request.Params["portalID"] != null)
            {
                currentPortalID = Int32.Parse(Request.Params["portalID"]);
            }

            if (currentPortalID != -1)
            {
                // Remove cache for reload settings
                if (!Page.IsPostBack)
                {
                    CurrentCache.Remove(Key.PortalSettings());
                }

                // Obtain PortalSettings of this Portal
                PortalSettings currentPortalSettings = PortalSettings.GetPortalSettings(currentPortalID);

                // If this is the first visit to the page, populate the site data
                if (!Page.IsPostBack)
                {
                    PortalIDField.Text = currentPortalID.ToString();
                    TitleField.Text    = currentPortalSettings.PortalName;
                    AliasField.Text    = currentPortalSettings.PortalAlias;
                    PathField.Text     = currentPortalSettings.PortalPath;
                }
                EditTable.DataSource =
                    new SortedList(
                        PortalSettings.GetPortalCustomSettings(currentPortalSettings.PortalID,
                                                               PortalSettings.GetPortalBaseSettings(null)));
                EditTable.DataBind();
                EditTable.ObjectID = currentPortalID;
            }
        }
        protected void AddModuleToPane_Click(object sender, EventArgs e)
        {
            // All new modules go to the end of the content pane
            var m = new ModuleItem();

            m.Title       = this.moduleTitle.Text;
            m.ModuleDefID = Int32.Parse(this.moduleType.SelectedItem.Value);
            m.Order       = 999;

            // save to database
            var mod = new ModulesDB();

            // Change by [email protected]
            // Date: 6/2/2003
            // Original:             m.ID = _mod.AddModule(tabID, m.Order, "ContentPane", m.Title, m.ModuleDefID, 0, "Admins", "All Users", "Admins", "Admins", "Admins", false);
            // Changed by Mario Endara <*****@*****.**> (2004/11/09)
            // The new module inherits security from Pages module (current ModuleID)
            // so who can edit the tab properties/content can edit the module properties/content (except view that remains =)
            m.ID = mod.AddModule(
                this.PageID,
                m.Order,
                this.paneLocation.SelectedItem.Value,
                m.Title,
                m.ModuleDefID,
                0,
                PortalSecurity.GetEditPermissions(this.ModuleID),
                this.viewPermissions.SelectedItem.Value,
                PortalSecurity.GetAddPermissions(this.ModuleID),
                PortalSecurity.GetDeletePermissions(this.ModuleID),
                PortalSecurity.GetPropertiesPermissions(this.ModuleID),
                PortalSecurity.GetMoveModulePermissions(this.ModuleID),
                PortalSecurity.GetDeleteModulePermissions(this.ModuleID),
                false,
                PortalSecurity.GetPublishPermissions(this.ModuleID),
                false,
                false,
                false);

            // End Change [email protected]

            // reload the portalSettings from the database
            this.Context.Items["PortalSettings"] = PortalSettings.GetPortalSettings(this.PageID, this.PortalSettings.PortalAlias);
            this.PortalSettings = (PortalSettings)this.Context.Items["PortalSettings"];

            // reorder the modules in the content pane
            var modules = this.GetModules("ContentPane");

            this.OrderModules(modules);

            // resave the order
            foreach (ModuleItem item in modules)
            {
                mod.UpdateModuleOrder(item.ID, item.Order, "ContentPane");
            }

            // Redirect to the same page to pick up changes
            this.Response.Redirect(this.AppendModuleID(this.Request.RawUrl, m.ID));
        }
        /// <summary>
        /// The RightLeft_Click server event handler on this page is
        ///   used to move a portal module between layout panes on
        ///   the tab page
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="T:System.Web.UI.ImageClickEventArgs"/> instance containing the event data.
        /// </param>
        /// <remarks>
        /// </remarks>
        protected void RightLeft_Click(object sender, ImageClickEventArgs e)
        {
            var sourcePane = ((ImageButton)sender).Attributes["sourcepane"];
            var targetPane = ((ImageButton)sender).Attributes["targetpane"];
            var sourceBox  = (ListBox)this.Page.FindControl(sourcePane);

            if (sourceBox == null)
            {
                sourceBox = (ListBox)this.Page.Master.FindControl("Content").FindControl(sourcePane);
            }

            var targetBox = (ListBox)this.Page.FindControl(targetPane);

            if (targetBox == null)
            {
                targetBox = (ListBox)this.Page.Master.FindControl("Content").FindControl(targetPane);
            }

            if (sourceBox.SelectedIndex != -1)
            {
                // get source arraylist
                var sourceList = this.GetModules(sourcePane);

                // get a reference to the module to move
                // and assign a high order number to send it to the end of the target list
                var m = (ModuleItem)sourceList[sourceBox.SelectedIndex];

                if (PortalSecurity.IsInRoles(PortalSecurity.GetMoveModulePermissions(m.ID)))
                {
                    // add it to the database
                    var admin = new ModulesDB();
                    admin.UpdateModuleOrder(m.ID, 99, targetPane);

                    // delete it from the source list
                    sourceList.RemoveAt(sourceBox.SelectedIndex);

                    // reload the portalSettings from the database
                    HttpContext.Current.Items["PortalSettings"] = PortalSettings.GetPortalSettings(
                        this.PageID, this.PortalSettings.PortalAlias);
                    this.PortalSettings = (PortalSettings)this.Context.Items["PortalSettings"];

                    // reorder the modules in the source pane
                    sourceList = this.GetModules(sourcePane);
                    this.OrderModules(sourceList);

                    // resave the order
                    foreach (ModuleItem item in sourceList)
                    {
                        admin.UpdateModuleOrder(item.ID, item.Order, sourcePane);
                    }

                    // reorder the modules in the target pane
                    var targetList = this.GetModules(targetPane);
                    this.OrderModules(targetList);

                    // resave the order
                    foreach (ModuleItem item in targetList)
                    {
                        admin.UpdateModuleOrder(item.ID, item.Order, targetPane);
                    }

                    // Redirect to the same page to pick up changes
                    this.Response.Redirect(this.AppendModuleID(this.Request.RawUrl, m.ID));
                }
                else
                {
                    this.msgError.Visible = true;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Handles the BeginRequest event of the AppleseedApplication control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data.
        /// </param>
        protected void AppleseedApplication_BeginRequest(object sender, EventArgs e)
        {
            string Addwww = System.Configuration.ConfigurationManager.AppSettings.Get("AddWwwToRequest");

            if (Addwww != null && Addwww.Equals("true"))
            {
                if (!Request.IsSecureConnection)
                {
                    if (!Request.Url.AbsoluteUri.ToLower().Contains("www"))
                    {
                        var newUrl = Request.Url.AbsoluteUri.Replace("http://", "http://www.");
                        Response.Redirect(newUrl, true);
                    }
                }
            }

            /*Send a signal to allow custom js registration (not enabled yet)*/
            Bus.Send(new JSRegisterDescriptor()
            {
                Scripts = new List <string>()
            });

            var contextReader = new Reader(new WebContextReader());
            var context       = contextReader.Current;

            var currentUrl = context.Request.Path.ToLower();

            if (Debugger.IsAttached && currentUrl.Contains("trace.axd"))
            {
                return;
            }

            context.Trace.Warn("Application_BeginRequest :: " + currentUrl);
            if (Portal.PageID > 0)
            {
                var physicalPath = context.Server.MapPath(currentUrl.Substring(currentUrl.LastIndexOf("/") + 1));

                if (!File.Exists(physicalPath))
                {
                    // Rewrites the path
                    context.RewritePath("~/default.aspx?" + context.Request.ServerVariables["QUERY_STRING"]);
                }
            }
            else
            {
                var pname = currentUrl.Substring(currentUrl.LastIndexOf("/") + 1);

                // if the request was not caused by an MS Ajax Client script invoking a WS.
                if (!currentUrl.ToLower().EndsWith(".asmx/js"))
                {
                    if (!String.IsNullOrEmpty(pname) && pname.Length > 5)
                    {
                        pname = pname.Substring(0, pname.Length - 5);
                    }

                    if (Regex.IsMatch(pname, @"^\d+$"))
                    {
                        context.RewritePath(
                            string.Format(
                                "~/default.aspx?pageid={0}{1}", pname, context.Request.ServerVariables["QUERY_STRING"]));
                    }
                }
            }

            // 1st Check: is it a dangerously malformed request?
            #region
            // Important patch http://support.microsoft.com/?kbid=887459
            if (context.Request.Path.IndexOf('\\') >= 0 ||
                Path.GetFullPath(context.Request.PhysicalPath) != context.Request.PhysicalPath)
            {
                throw new AppleseedRedirect(LogLevel.Warn, HttpStatusCode.NotFound, "Malformed request", null);
            }

            #endregion

            // 2nd Check: is the AllPortals Lock switched on?
            // let the user through if client IP address is in LockExceptions list, otherwise throw...
            #region
            if (Config.LockAllPortals)
            {
                var rawUrl       = context.Request.RawUrl.ToLower(CultureInfo.InvariantCulture);
                var lockRedirect = Config.LockRedirect;
                if (!rawUrl.EndsWith(lockRedirect))
                {
                    // construct IPList
                    var lockKeyHolders = Config.LockKeyHolders.Split(new[] { ';' });
                    var ipList         = new IPList();
                    foreach (var lockKeyHolder in lockKeyHolders)
                    {
                        if (lockKeyHolder.IndexOf("-") > -1)
                        {
                            ipList.AddRange(
                                lockKeyHolder.Substring(0, lockKeyHolder.IndexOf("-")),
                                lockKeyHolder.Substring(lockKeyHolder.IndexOf("-") + 1));
                        }
                        else
                        {
                            ipList.Add(lockKeyHolder);
                        }
                    }

                    // check if requestor's IP address is in allowed list
                    if (!ipList.CheckNumber(context.Request.UserHostAddress))
                    {
                        throw new PortalsLockedException();
                    }
                }
            }
            #endregion

            // 3rd Check: is database/code version correct?
            var requestUri      = context.Request.Url;
            var requestPath     = requestUri.AbsolutePath.ToLower(CultureInfo.InvariantCulture);
            var returnToRequest = CheckAndUpdateDB(context, requestPath);


            if (returnToRequest)
            {
                return;
            }

            PortalSettings portalSettings = null;

            var pageId       = Portal.PageID;        // Get PageID from QueryString
            var portalAlias  = Portal.UniqueID;      // Get requested alias from querystring, cookies or hostname
            var defaultAlias = Config.DefaultPortal; // get default portal from config

            try {
                portalSettings = PortalSettings.GetPortalSettings(pageId, portalAlias);
            } catch (DatabaseUnreachableException dexc) {
                // If no database, must update
                ErrorHandler.Publish(LogLevel.Error, dexc);
                using (var s = new Services()) {
                    s.RunDBUpdate(Config.ConnectionString);
                }

                portalSettings = PortalSettings.GetPortalSettings(pageId, portalAlias);
            }

            if (portalSettings == null || (portalSettings != null && portalSettings.PortalAlias == null))
            {
                portalSettings = PortalSettings.GetPortalSettings(pageId, defaultAlias);
            }
            //if (portalSettings.PortalAlias == null) {
            //    // critical error - neither requested alias nor default alias could be found in DB
            //    throw new AppleseedRedirect(
            //        Config.NoPortalErrorRedirect,
            //        LogLevel.Fatal,
            //        Config.NoPortalErrorResponse,
            //        "Unable to load any portal - redirecting request to ErrorNoPortal page.",
            //        null);
            //}


            Membership.Provider.ApplicationName     = portalSettings.PortalAlias;
            ProfileManager.Provider.ApplicationName = portalSettings.PortalAlias;
            Roles.ApplicationName = portalSettings.PortalAlias;

            // Portal Settings has passed the test so add it to Context
            context.Items.Add("PortalSettings", portalSettings);
            context.Items.Add("PortalID", portalSettings.PortalID); // jes1111


            var smartErrorRedirect = Config.SmartErrorRedirect;
            if (smartErrorRedirect.StartsWith("~/"))
            {
                smartErrorRedirect = smartErrorRedirect.TrimStart(new[] { '~' });
            }

            if (requestPath.EndsWith(smartErrorRedirect.ToLower(CultureInfo.InvariantCulture)))
            {
                return; // this is SmartError page... so continue
            }

            // WLF: This was backwards before so it would always set refreshSite true because the cookie was changed before it was checked.
            // WLF: REVIEW: This whole section needs a code review.
            // Try to get alias from cookie to determine if alias has been changed
            var refreshSite       = false;
            var portalAliasCookie = context.Request.Cookies["PortalAlias"];
            if (portalAliasCookie != null && portalAliasCookie.Value.ToLower() != Portal.UniqueID)
            {
                refreshSite = true; // Portal has changed since last page request
            }

            if (portalSettings != null)
            {
                portalAliasCookie = new HttpCookie("PortalAlias")
                {
                    Path = "/", Value = portalSettings.PortalAlias
                };
                if (context.Response.Cookies["PortalAlias"] == null)
                {
                    context.Response.Cookies.Add(portalAliasCookie);
                }
                else
                {
                    context.Response.Cookies.Set(portalAliasCookie);
                }
            }

            // if switching portals then clean parameters [TipTopWeb]
            // Must be the last instruction in this method
            var refreshedCookie = context.Request.Cookies["refreshed"];

            // 5/7/2006 Ed Daniel
            // Added hack for Http 302 by extending condition below to check for more than 3 cookies
            if (refreshSite && context.Request.Cookies.Keys.Count > 3)
            {
                // Sign out and force the browser to refresh only once to avoid any dead-lock
                if (refreshedCookie == null || refreshedCookie.Value == "false")
                {
                    var rawUrl             = context.Request.RawUrl;
                    var newRefreshedCookie = new HttpCookie("refreshed", "true")
                    {
                        Path    = "/",
                        Expires = DateTime.Now.AddMinutes(1)
                    };
                    if (refreshedCookie == null)
                    {
                        context.Response.Cookies.Add(newRefreshedCookie);
                    }
                    else
                    {
                        context.Response.Cookies.Set(newRefreshedCookie);
                    }

                    var msg =
                        string.Format(
                            "User logged out on global.asax line 423. Values -> refreshsite: {0}, context.Request.Cookies.Keys.count: {1}, rawurl: {2}",
                            refreshSite,
                            context.Request.Cookies.Keys.Count,
                            rawUrl);

                    ErrorHandler.Publish(
                        LogLevel.Warn,
                        msg);

                    // sign-out, if refreshed parameter on the command line we will not call it again
                    PortalSecurity.SignOut(rawUrl, false);
                }
            }

            // invalidate cookie, so the page can be refreshed when needed
            refreshedCookie = context.Request.Cookies["refreshed"];
            if (refreshedCookie != null && context.Request.Cookies.Keys.Count > 3)
            {
                var newRefreshedCookie = new HttpCookie("refreshed", "false")
                {
                    Path    = "/",
                    Expires = DateTime.Now.AddMinutes(1)
                };
                context.Response.Cookies.Set(newRefreshedCookie);
            }

            // This is done in order to allow the sitemap to reference a page that is outside this website.
            var targetPage = this.Request.Params["sitemapTargetPage"];
            if (!string.IsNullOrEmpty(targetPage))
            {
                int mvcPageId;
                if (int.TryParse(targetPage, out mvcPageId))
                {
                    var url = HttpUrlBuilder.BuildUrl(mvcPageId);
                    this.Response.Redirect(url);
                }
            }
        }