示例#1
0
        void WebEvents_OnLoadRequestedPath(HandleFlag handled)
        {
            requestedPage = null;
            if (handled.Handled)
            {
                return;
            }
            PageEntry page = Pages.FromPath(SprocketPath.Value);

            if (page == null)
            {
                return;
            }
            requestedPage = page;
            if (Values.PagePreProcessors.ContainsKey(page.PageCode))
            {
                foreach (PagePreprocessorHandler method in Values.PagePreProcessors[page.PageCode])
                {
                    method(page);
                }
            }
            if (OnBeforeRenderPage != null)
            {
                OnBeforeRenderPage(page);
            }
            string txt = page.Render();

            Response.ContentType = page.ContentType;
            Response.Write(txt);
            handled.Set();
        }
 void Instance_OnBeforeLoadExistingFile(HandleFlag handled)
 {
     if (SprocketPath.Value.ToLower() == "datastore/clientspace.id")             // deny access
     {
         handled.Set();
     }
 }
示例#3
0
        void TestBox_OnAdminRequest(AdminInterface admin, string sprocketPath, string[] pathSections, HandleFlag handled)
        {
            //admin.AddMainMenuLink(new AdminMenuLink("Test Box", WebUtility.MakePath("admin/testbox"), 1000));
            if (sprocketPath != "admin/testbox") return;
            handled.Set();
            admin.AddInterfaceScript(new RankedString(ResourceLoader.LoadTextResource(typeof(AjaxForm).Assembly, "Sprocket.Web.Controls.AjaxForm.js"), 0));
            admin.AddHeadSection(new RankedString(CSS, 0));
            admin.ContentHeading = "Test Box";
            admin.AddContentSection(new RankedString("blah", -1000));

            AjaxFormFieldBlock b = new AjaxFormFieldBlock("UserDetails", "Main User Details");
            b.Add(new AjaxFormStandardField(
                "Username",
                "Username",
                "<input type=\"text\" id=\"Username\" />",
                null,
                "function(value) { return value.length == 0 ? 'Please enter a username' : false }",
                true, 1));
            b.Add(new AjaxFormStandardField("First Name", "FirstName", "<input type=\"text\" />", null, "", true, 0));

            AjaxFormFieldBlock b2 = new AjaxFormFieldBlock("RandomCrap", "Random Crap");
            b2.Add(new AjaxFormField("stuff", null, null, -1));

            AjaxFormFieldBlockList bl = new AjaxFormFieldBlockList();
            bl.Add(b);
            bl.Add(b2);

            admin.AddContentSection(new RankedString(bl, 1001));
        }
示例#4
0
        void WebEvents_OnLoadRequestedPath(HandleFlag handled)
        {
            if (!IntegrationEnabled)
            {
                return;
            }

            switch (SprocketPath.Value)
            {
            case "paypal-ipn-process":
            {
                PayPalTransactionResponse resp = InstantPaymentNotification.Authenticate();
                if (OnInstantPaymentNotification != null && resp != null)
                {
                    OnInstantPaymentNotification(resp);
                }
            }

            break;

            case "paypal-trans-return":
            {
                PayPalTransactionResponse resp = TransactionReturn();
                if (OnTransactionResponse != null && resp != null)
                {
                    OnTransactionResponse(resp);
                }
            }
            break;

            default:
                return;
            }
            handled.Set();
        }
示例#5
0
        void WebEvents_OnLoadRequestedPath(HandleFlag handled)
        {
            if (handled.Handled)
            {
                return;
            }
            if (!WebAuthentication.IsLoggedIn)
            {
                return;
            }
            if (!WebAuthentication.VerifyAccess(PermissionType.ModifyPages))
            {
                return;
            }

            if (SprocketPath.Sections.Length >= 4 && SprocketPath.Sections[0] == "admin")
            {
                switch (SprocketPath.Sections[1])
                {
                case "pages":
                    switch (SprocketPath.Sections[2])
                    {
                    case "delete":
                    {
                        long id;
                        if (long.TryParse(SprocketPath.Sections[3], out id))
                        {
                            Page page = ContentManager.Instance.DataProvider.SelectPage(id);
                            if (page != null)
                            {
                                Result r = page.SaveRevision("** Page deleted.", page.RevisionInformation.Draft, page.RevisionInformation.Hidden, true);
                                if (!r.Succeeded)
                                {
                                    Response.Write("Unable to delete page:<br/>" + r.Message);
                                    Response.End();
                                    return;
                                }
                            }
                        }
                    }
                        WebUtility.Redirect("admin/pages");
                        break;

                    case "imgthumb":
                    {
                        long id;
                        if (long.TryParse(SprocketPath.Sections[3], out id))
                        {
                            SizingOptions options = new SizingOptions(60, 45, SizingOptions.Display.Constrain, id);
                            FileManager.FileManager.Instance.TransmitImage(options);
                        }
                    }
                    break;
                    }
                    break;
                }
            }
        }
 void WebEvents_OnLoadRequestedPath(HandleFlag handled)
 {
     if (handled.Handled) return;
     if (SprocketPath.Sections.Length == 2 && SprocketPath.Sections[0] == "cmsimage" && SprocketPath.Value.EndsWith(".jpg"))
     {
         FileManager.FileManager.Instance.TransmitRequestedImage();
         handled.Set();
     }
 }
示例#7
0
 void WebEvents_OnBeginHttpRequest(HandleFlag handled)
 {
     RequestSpeedExpression.Set();
     Values.PageStack.Clear();
     if (IsDefinitionsXmlOutOfDate)
     {
         Values.Templates = null;
         Values.Pages     = null;
     }
 }
		void OnBeginHttpRequest(HandleFlag handled)
		{
			if (handled.Handled)
				return;

			if (IsAjaxRequest)
			{
				handled.Set();
				ProcessRequest(HttpContext.Current);
			}
		}
示例#9
0
 void AdminHandler_OnLoadAdminPage(AdminInterface admin, PageEntry page, HandleFlag handled)
 {
     if (WebAuthentication.VerifyAccess(PermissionType.ModifyPages))
     {
         admin.AddMainMenuLink(new AdminMenuLink("Pages and Content", WebUtility.MakeFullPath("admin/pages"), ObjectRank.Normal, "pages_and_content"));
     }
     if (WebAuthentication.VerifyAccess(PermissionType.ModifyTemplates))
     {
         admin.AddMainMenuLink(new AdminMenuLink("Page Templates", WebUtility.MakeFullPath("admin/templates"), ObjectRank.Normal, "page_templates"));
     }
 }
示例#10
0
 void Instance_OnLoadRequestedPath(HandleFlag handled)
 {
     if (SprocketPath.Sections.Length >= 2)
     {
         if (SprocketPath.Sections[0] == "datastore" && SprocketPath.Sections[1] == "databases")
         {
             HttpContext.Current.Response.Write("access denied.");
             HttpContext.Current.Response.End();
         }
     }
 }
示例#11
0
        void WebEvents_OnPathNotFound(HandleFlag handled)
        {
            Page page = DataProvider.SelectPageBySprocketPath(SprocketPath.Value);

            if (page == null)
            {
                return;
            }
            Response.ContentType = page.ContentType;
            Response.Write(page.Render());
            handled.Set();
        }
示例#12
0
        void WebEvents_OnLoadRequestedPath(HandleFlag handled)
        {
            if (handled.Handled)
            {
                return;
            }
            if (SprocketPath.Sections[0] == "admin")
            {
                if (!WebAuthentication.IsLoggedIn)
                {
                    HttpContext.Current.Response.Write("Access Denied.");
                    handled.Set();
                    return;
                }
                switch (SprocketPath.Value)
                {
                case "admin":
                {
                    string html = WebUtility.CacheTextFile("resources/admin/frames/admin-iframes.htm");
                    //string html = ResourceLoader.LoadTextResource("Sprocket.Web.CMS.Admin.admin-iframes.htm");
                    SprocketScript scr = new SprocketScript(html, "Admin Frames", "Admin Frames");
                    HttpContext.Current.Response.Write(scr.Execute());
                }
                break;

                case "admin/overlay":
                    RenderOverlayPage();
                    break;

                case "admin/frames":
                {
                    string html = WebUtility.CacheTextFile("resources/admin/frames/admin-frames.htm");
                    //string html = ResourceLoader.LoadTextResource("Sprocket.Web.CMS.Admin.admin-frames.htm");
                    SprocketScript scr = new SprocketScript(html, "Admin Overlay Frame", "Admin Overlay Frame");
                    HttpContext.Current.Response.Write(scr.Execute());
                }
                break;

                case "admin/addressbar":
                {
                    string html = WebUtility.CacheTextFile("resources/admin/frames/admin-address-bar.htm");
                    //string html = ResourceLoader.LoadTextResource("Sprocket.Web.CMS.Admin.admin-address-bar.htm");
                    SprocketScript scr = new SprocketScript(html, "Admin Overlay Frame", "Admin Overlay Frame");
                    HttpContext.Current.Response.Write(scr.Execute());
                }
                break;

                default:
                    return;
                }
                handled.Set();
            }
        }
示例#13
0
 void WebEvents_OnLoadRequestedPath(HandleFlag handled)
 {
     if (handled.Handled)
     {
         return;
     }
     if (SprocketPath.Sections.Length == 2 && SprocketPath.Sections[0] == "cmsimage" && SprocketPath.Value.EndsWith(".jpg"))
     {
         FileManager.FileManager.Instance.TransmitRequestedImage();
         handled.Set();
     }
 }
示例#14
0
        void WebEvents_OnLoadRequestedPath(HandleFlag handled)
        {
            if (handled.Handled) return;
            if (SprocketPath.Sections[0] == "admin")
            {
                if (!WebAuthentication.IsLoggedIn)
                {
                    HttpContext.Current.Response.Write("Access Denied.");
                    handled.Set();
                    return;
                }
                switch (SprocketPath.Value)
                {
                    case "admin":
                        {
                            string html = WebUtility.CacheTextFile("resources/admin/frames/admin-iframes.htm");
                            //string html = ResourceLoader.LoadTextResource("Sprocket.Web.CMS.Admin.admin-iframes.htm");
                            SprocketScript scr = new SprocketScript(html, "Admin Frames", "Admin Frames");
                            HttpContext.Current.Response.Write(scr.Execute());
                        }
                        break;

                    case "admin/overlay":
                        RenderOverlayPage();
                        break;

                    case "admin/frames":
                        {
                            string html = WebUtility.CacheTextFile("resources/admin/frames/admin-frames.htm");
                            //string html = ResourceLoader.LoadTextResource("Sprocket.Web.CMS.Admin.admin-frames.htm");
                            SprocketScript scr = new SprocketScript(html, "Admin Overlay Frame", "Admin Overlay Frame");
                            HttpContext.Current.Response.Write(scr.Execute());
                        }
                        break;

                    case "admin/addressbar":
                        {
                            string html = WebUtility.CacheTextFile("resources/admin/frames/admin-address-bar.htm");
                            //string html = ResourceLoader.LoadTextResource("Sprocket.Web.CMS.Admin.admin-address-bar.htm");
                            SprocketScript scr = new SprocketScript(html, "Admin Overlay Frame", "Admin Overlay Frame");
                            HttpContext.Current.Response.Write(scr.Execute());
                        }
                        break;

                    default:
                        return;
                }
                handled.Set();
            }
        }
示例#15
0
 void WebEvents_OnBeginHttpRequest(HandleFlag handled)
 {
     if (IsAdminRequest && !AjaxRequestHandler.IsAjaxRequest)
     {
         foreach (XmlSourceFileDependent file in definitionsFiles)
         {
             if (file.HasFileChanged)
             {
                 definitionsFiles = new List <XmlSourceFileDependent>();
                 LoadDefinitionFiles();
                 break;
             }
         }
     }
 }
        void OnBeginHttpRequest(HttpApplication appInst, HandleFlag handled)
        {
            HttpApplicationState app = HttpContext.Current.Application;

            app.Lock();
            if (app["Sprocket_PGREQ_XmlCache_Count"] == null)
            {
                app["Sprocket_PGREQ_XmlCache_Count"] = 1;
            }
            else
            {
                app["Sprocket_PGREQ_XmlCache_Count"] = (int)app["Sprocket_PGREQ_XmlCache_Count"] + 1;
            }
            app.UnLock();
        }
示例#17
0
 void ContentCache_OnLoadRequestedPath(HandleFlag handled)
 {
     if (File.Exists(SprocketPath.Physical))
     {
         return;                 // the cache never deals with paths that directly map to actual physical files
     }
     //DateTime dt = DateTime.Now;
     if (Transmit(SprocketPath.Value))
     {
         HttpContext.Current.Response.End();
         handled.Set();
     }
     //TimeSpan ts = DateTime.Now - dt;
     //LogFile.Append("writetimes.txt", ts.ToString() + " - " + SprocketPath.Value);
 }
示例#18
0
        void OnAdminRequest(AdminInterface admin, HandleFlag handled)
        {
            // build the "current user" block
            User   user  = User.Select(SecurityProvider.ClientSpaceID, WebAuthentication.Instance.CurrentUsername);
            string block = "<div id=\"currentuser-block\">"
                           + "You are currently logged in as <b>{0}</b>."
                           + "</div>";

            admin.AddLeftColumnSection(new RankedString(
                                           string.Format(block, (user.FirstName + " " + user.Surname).Trim()), -100));

            admin.WebsiteName = CurrentClientSpace.Name;

            if (!SecurityProvider.CurrentUser.HasPermission(PermissionType.UserAdministrator))
            {
                return;
            }

            admin.AddMainMenuLink(new AdminMenuLink("Users and Roles", WebUtility.MakeFullPath("admin/security"), 0));

            // build the security interface if it has been requested
            if (SprocketPath.Value.StartsWith("admin/security"))
            {
                handled.Set();

                int defaultMaxFilterMatches;
                try { defaultMaxFilterMatches = int.Parse(SprocketSettings.GetValue("WebSecurityDefaultUserFilterMatches")); }
                catch { defaultMaxFilterMatches = 50; }

                admin.AddInterfaceScript(WebControlScript.TabStrip);
                admin.AddInterfaceScript(WebControlScript.Fader);
                admin.AddInterfaceScript(WebControlScript.AjaxForm);
                string scr = ResourceLoader.LoadTextResource("Sprocket.Security.CMS.security.js")
                             .Replace("50,//{defaultMaxFilterMatches}", defaultMaxFilterMatches.ToString() + ",")
                             .Replace("if(true)//{ifUserCanAccessRoleManagement}",
                                      SecurityProvider.CurrentUser.HasPermission(PermissionType.RoleAdministrator) ? "" : "if(false)");
                admin.AddInterfaceScript(new RankedString(scr, 0));
                admin.AddBodyOnLoadScript(new RankedString("SecurityInterface.Run()", 0));

                admin.ContentHeading = "Users and Roles";

                string html = "<div id=\"user-admin-container\"></div>";

                admin.AddContentSection(new RankedString(html, 0));
                admin.AddHeadSection(new RankedString("<link rel=\"stylesheet\" type=\"text/css\" href=\""
                                                      + WebUtility.MakeFullPath("resources/admin/security.css") + "\" />", 0));
            }
        }
		void Instance_OnLoadRequestedPath(HandleFlag handled)
		{
			if (handled.Handled) return;
			if (SprocketPath.Value == "$dbsetup")
			{
				Result result = DatabaseManager.DatabaseEngine.Initialise();
				if (result.Succeeded)
				{
					HttpContext.Current.Response.Write("<p>Database setup completed.</p>");
					if (Completed != null)
						Completed();
				}
				else
					HttpContext.Current.Response.Write("<h2>Unable to Initialise Database</h2><p>" + result.Message + "</p>");
				handled.Set();
			}
		}
示例#20
0
        void OnAdminRequest(AdminInterface admin, string sprocketPath, string[] pathSections, HandleFlag handled)
        {
            // build the "current user" block
            User user = User.Select(SecurityProvider.ClientSpaceID, WebAuthentication.Instance.CurrentUsername);
            string block = "<div id=\"currentuser-block\">"
                         + "You are currently logged in as <b>{0}</b>."
                         + "</div>";
            admin.AddLeftColumnSection(new RankedString(
                string.Format(block, (user.FirstName + " " + user.Surname).Trim()), -100));

            admin.WebsiteName = CurrentClientSpace.Name;

            if (!SecurityProvider.CurrentUser.HasPermission(PermissionType.UserAdministrator))
                return;

            admin.AddMainMenuLink(new AdminMenuLink("Users and Roles", WebUtility.MakeFullPath("admin/security"), 0));

            // build the security interface if it has been requested
            if (sprocketPath.StartsWith("admin/security"))
            {
                handled.Set();

                int defaultMaxFilterMatches;
                try { defaultMaxFilterMatches = int.Parse(SprocketSettings.GetValue("WebSecurityDefaultUserFilterMatches")); }
                catch { defaultMaxFilterMatches = 50; }

                admin.AddInterfaceScript(WebControlScript.TabStrip);
                admin.AddInterfaceScript(WebControlScript.Fader);
                admin.AddInterfaceScript(WebControlScript.AjaxForm);
                string scr = ResourceLoader.LoadTextResource("Sprocket.Security.CMS.security.js")
                    .Replace("50,//{defaultMaxFilterMatches}", defaultMaxFilterMatches.ToString() + ",")
                    .Replace("if(true)//{ifUserCanAccessRoleManagement}",
                        SecurityProvider.CurrentUser.HasPermission(PermissionType.RoleAdministrator) ? "" : "if(false)");
                admin.AddInterfaceScript(new RankedString(scr, 0));
                admin.AddBodyOnLoadScript(new RankedString("SecurityInterface.Run()", 0));

                admin.ContentHeading = "Users and Roles";

                string html = "<div id=\"user-admin-container\"></div>";

                admin.AddContentSection(new RankedString(html, 0));
                admin.AddHeadSection(new RankedString("<link rel=\"stylesheet\" type=\"text/css\" href=\""
                    + WebUtility.MakeFullPath("resources/admin/security.css") + "\" />", 0));
            }
        }
        void OnAdminRequest(AdminInterface admin, string sprocketPath, string[] pathSections, HandleFlag handled)
        {
            admin.AddMainMenuLink(new AdminMenuLink("Website Pages", WebUtility.MakeFullPath("admin/pages"), 0));

            if(handled.Handled) return;

            switch (sprocketPath)
            {
                case "admin/pages":
                    admin.ContentHeading = "Website Page List";
                    admin.AddContentSection(new RankedString(GetPageList(), 0));
                    break;

                default:
                    return;
            }

            handled.Set();
        }
示例#22
0
        void OnLoadRequestedPath(HttpApplication app, string path, string[] pathSections, HandleFlag handled)
        {
            if (path != "test")
                return;
            handled.Set();

            HttpContext c = HttpContext.Current;
            c.Response.Write("QS Keys:<br/>");
            for (int i = 0; i < c.Request.QueryString.Count; i++)
                HttpContext.Current.Response.Write(c.Request.QueryString.GetKey(i) + " = " + c.Request.QueryString[i] + "<br/>");

            c.Response.Write("QS Form:<br/>");
            for (int i = 0; i < c.Request.QueryString.Count; i++)
                HttpContext.Current.Response.Write(c.Request.Form.GetKey(i) + " = " + c.Request.Form[i] + "<br/>");

            string html = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + WebUtility.BasePath;
            HttpContext.Current.Response.Write(html);
            //string scripts = ((WebClientScripts)SystemCore.Instance["WebClientScripts"]).BuildScriptTags();
            //HttpContext.Current.Response.Write(scripts + html.Replace(Environment.NewLine, "<br />"));
        }
示例#23
0
        void WebsiteAdmin_OnAdminRequest(AdminInterface admin, HandleFlag handled)
        {
            if (SprocketPath.Sections[0] != "admin")
            {
                return;
            }

            switch (SprocketPath.Value)
            {
            case "admin/dbsetup":
                Result result = DatabaseManager.DatabaseEngine.Initialise();
                if (result.Succeeded)
                {
                    admin.AddContentSection(new RankedString("<p style=\"color:green\" class=\"standalone-message\">Database setup completed.</p>", 1));
                }
                else
                {
                    admin.AddContentSection(new RankedString("<strong style=\"color:red\" class=\"standalone-message\">Unable to Initialise Database</strong><p>" + result.Message + "</p>", 1));
                }
                break;

            case "admin/clearcache":
                ContentCache.ClearCache();
                admin.AddContentSection(new RankedString("<p style=\"color:green\" class=\"standalone-message\">The cache has been cleared.</p>", 1));
                break;

            case "admin":
                break;

            default:
                return;
            }

            admin.ContentHeading = "Current Overview";
            admin.AddContentSection(new RankedString("<div class=\"standalone-message\">" +
                                                     "<a href=\"" + WebUtility.BasePath + "admin/dbsetup\">Run database setup</a> | " +
                                                     "<a href=\"" + WebUtility.BasePath + "admin/clearcache\">Clear page cache</a>" +
                                                     "</div>", 0));
            handled.Set();
        }
示例#24
0
        void Instance_OnLoadRequestedPath(HandleFlag handled)
        {
            if (handled.Handled) return;
            if (SprocketPath.Value == "$dbsetup")
            {
                Result result = DatabaseManager.DatabaseEngine.Initialise();
                if (result.Succeeded)
                {
                    HttpContext.Current.Response.Write("<p>Database setup completed.</p>");
                    if (Completed != null)
                        Completed();
                    WebUtility.Redirect("admin");
                }
                else
                {
                    HttpContext.Current.Response.Write("<h2>Unable to Initialise Database</h2><p>" + result.Message.Replace(Environment.NewLine,"<br/>") + "</p>");
                    HttpContext.Current.Response.End();
                }

                handled.Set();
            }
        }
示例#25
0
        void WebEvents_OnPathNotFound(HandleFlag handled)
        {
            #region Map missing referenced files (e.g. images and css) to the same location as the content file

            //if (!SprocketPath.Value.Contains("."))
            //{
            //    HttpContext.Current.Response.Write(ResourceLoader.LoadTextResource("Sprocket.Web.CMS.Content.404.htm"));
            //    handled.Set();
            //    return;
            //}
            string urlpath;
            if (SprocketPath.Sections.Length == 1)
            {
                urlpath = "";
            }
            else
            {
                urlpath = SprocketPath.Value.Substring(0, SprocketPath.Value.Length - SprocketPath.Sections[SprocketPath.Sections.Length - 1].Length - 1);
            }

            PageEntry page = Pages.FromPath(urlpath);
            if (page == null)
            {
                return;
            }
            string newurl = page.ContentFile;
            newurl = WebUtility.BasePath + newurl.Substring(0, newurl.LastIndexOf('/') + 1) + SprocketPath.Sections[SprocketPath.Sections.Length - 1];
            if (!File.Exists(HttpContext.Current.Server.MapPath(newurl)))
            {
                return;
            }
            HttpContext.Current.Response.TransmitFile(HttpContext.Current.Server.MapPath(newurl));
            handled.Set();

            #endregion
        }
		void WebEvents_OnLoadRequestedPath(HandleFlag handled)
		{
			requestedPage = null;
			if (handled.Handled) return;
			PageEntry page = Pages.FromPath(SprocketPath.Value);
			if (page == null)
				return;
			requestedPage = page;
			if (OnBeforeRenderPage != null)
				OnBeforeRenderPage(page);
			string txt = page.Render();
			Response.ContentType = page.ContentType;
			Response.Write(txt);
			handled.Set();
		}
		void WebsiteAdmin_OnAdminRequest(AdminInterface admin, HandleFlag handled)
		{
			if (SprocketPath.Sections[0] != "admin") return;

			switch (SprocketPath.Value)
			{
				case "admin/dbsetup":
					Result result = DatabaseManager.DatabaseEngine.Initialise();
					if (result.Succeeded)
						admin.AddContentSection(new RankedString("<p style=\"color:green\" class=\"standalone-message\">Database setup completed.</p>", 1));
					else
						admin.AddContentSection(new RankedString("<strong style=\"color:red\" class=\"standalone-message\">Unable to Initialise Database</strong><p>" + result.Message + "</p>", 1));
					break;

				case "admin/clearcache":
					ContentCache.ClearCache();
					admin.AddContentSection(new RankedString("<p style=\"color:green\" class=\"standalone-message\">The cache has been cleared.</p>", 1));
					break;

				case "admin":
					break;

				default:
					return;
			}

			admin.ContentHeading = "Current Overview";
			admin.AddContentSection(new RankedString("<div class=\"standalone-message\">" +
				"<a href=\"" + WebUtility.BasePath + "admin/dbsetup\">Run database setup</a> | " +
				"<a href=\"" + WebUtility.BasePath + "admin/clearcache\">Clear page cache</a>" +
				"</div>", 0));
			handled.Set();
		}
        void OnAdminRequest(AdminInterface admin, string sprocketPath, string[] pathSections, HandleFlag handled)
        {
            admin.AddMainMenuLink(new AdminMenuLink("Website Pages", WebUtility.MakeFullPath("admin/pages"), 0));

            if (handled.Handled)
            {
                return;
            }

            switch (sprocketPath)
            {
            case "admin/pages":
                admin.ContentHeading = "Website Page List";
                admin.AddContentSection(new RankedString(GetPageList(), 0));
                break;

            default:
                return;
            }

            handled.Set();
        }
示例#29
0
        /// <summary>
        /// This is the very first point where Sprocket interrupts the ASP.Net HTTP pipeline
        /// and allows itself to start handling requests. Note that this is way before the 
        /// standard ASP.Net page framework would kick in. At this point state information like
        /// cookies and sessions have not yet been loaded.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void FireBeginRequest(object sender, EventArgs e)
        {
            if (!AjaxRequestHandler.IsAjaxRequest)
            {
                // The SprocketPath refers to the bit after the application base path and before the
                // querystring, minus any leading and trailing forward-slashes. (/) For example if the
                // full URL is "http://www.sprocketcms.com/myapp/admin/users/?edit" and the subdirectory
                // "myapp" is a virtual directory (IIS application) then the SprocketPath would be
                // "admin/users".
                string sprocketPath = null;
                string appPath = HttpContext.Current.Request.Path.ToLower();

                // check to see if there's a trailing slash and if there isn't, redirect to stick a trailing
                // slash onto the path. This is to keep pathing consistent because otherwise relative paths
                // (such as to images and css files) aren't pathed as expected. We DON'T do this if a form
                // has been posted however, because otherwise we lose the contents of the posted form. It is
                // assumed that if you forget to post to a path with a trailing slash, that once you finish
                // processing the form that you'll redirect off to a secondary page anyway, which means
                // sticking a slash on the end of this URL is unnecessary anyway.
                if (!appPath.EndsWith("/") && !appPath.Contains(".") && HttpContext.Current.Request.Form.Count == 0)
                {
                    HttpContext.Current.Response.Redirect(appPath + "/");
                    HttpContext.Current.Response.End();
                    return;
                }

                // changes (e.g.) "http://www.sprocketcms.com/myapp/admin/users/?edit" into "admin/users"
                SprocketPath.Parse(HttpContext.Current.Request.Url);
                //sprocketPath = appPath.Remove(0, HttpContext.Current.Request.ApplicationPath.Length).Trim('/');
                //SprocketPath.Value = sprocketPath;
                //SprocketPath.Sections = SprocketPath.Value.Split('/');
            }
            HandleFlag handled = new HandleFlag();

            if(OnBeginHttpRequest != null)
                OnBeginHttpRequest(handled);

            if (handled.Handled)
            {
                HttpContext.Current.Response.End();
                return;
            }

            // The SprocketSettings module is one of the modules that handles the OnBeginHttpRequest
            // event. It lets each module check for any .config file errors (or other settings errors)
            // and report them back here. If we get to this point and at least one module has reported
            // a settings error, we show Sprocket's critical error page which has a nice list of
            // error messages that the user can try to rectify.
            if (SprocketSettings.Errors.HasCriticalError)
            {
                ShowErrorPage();
                return;
            }
        }
示例#30
0
 void Instance_OnBeforeLoadExistingFile(HandleFlag handled)
 {
     if (SprocketPath.Value.ToLower() == "datastore/clientspace.id") // deny access
         handled.Set();
 }
示例#31
0
        void OnBeginHttpRequest(HandleFlag handled)
        {
            if (handled.Handled)
                return;

            if (HttpContext.Current.Request.Path.EndsWith("module-hierarchy-diagram.gif"))
            {
                handled.Set();

                int levels = 0; // the depth of the dependency hierarchy
                int pos = 0; // the number of horizontal positions that this level contains for the bordered boxes
                int maxpos = 1; // the highest box position for the current row
                Dictionary<string, int> modulePositions = new Dictionary<string, int>(); // store which horizontal position each module should have its box drawn in
                Dictionary<int, int> levelCounts = new Dictionary<int, int>(); // specify how many box positions are on each depth level
                foreach (RegisteredModule m in Core.Instance.ModuleRegistry)
                {
                    if (m.Importance > levels) // if we've hit the next depth level in the heirarchy
                    {
                        levels++; // set the number of the level we're now working at
                        pos = 1; // specify that we're at horizontal position #1 on the image
                    }
                    else
                    {
                        pos++;
                        maxpos = maxpos < pos ? pos : maxpos;
                    }
                    modulePositions[m.Namespace] = pos;
                    levelCounts[levels] = pos;
                }

                int rectWidth = 110;
                int rectHeight = 50;
                int heightGap = 25;
                int widthGap = 15;
                int lineGap = 10;
                int bmpWidth = maxpos * rectWidth + (maxpos - 1) * widthGap + 11;
                //  bmpHeight = top/bottom margins + combined height of boxes + the gaps between the levels
                int bmpHeight = (heightGap * 2) + (rectHeight * (levels + 1)) + (levels * heightGap) + 1;

                Bitmap bmp = new Bitmap(bmpWidth, bmpHeight);
                Graphics gfx = Graphics.FromImage(bmp);
                Pen pen = new Pen(Color.FromArgb(200, 200, 200), 1);
                Brush whiteBrush = new SolidBrush(Color.White);
                Brush greyBrush = new SolidBrush(Color.WhiteSmoke);
                Brush blackBrush = new SolidBrush(Color.Black);
                Brush redBrush = new SolidBrush(Color.Red);
                Font font = new Font("Verdana", 7, FontStyle.Bold);

                gfx.FillRectangle(whiteBrush, 0, 0, bmpWidth, bmpHeight);
                gfx.SmoothingMode = SmoothingMode.HighQuality;

                // draw rectangles
                foreach (RegisteredModule m in Core.Instance.ModuleRegistry)
                {
                    Brush brush = new SolidBrush(dllColors[new FileInfo(m.Module.GetType().Assembly.Location).Name]);
                    Rectangle rect = GetModuleRect(m, rectWidth, rectHeight, widthGap, heightGap, modulePositions[m.Namespace], levels, levelCounts[m.Importance], bmpWidth);
                    gfx.FillRectangle(brush, rect);
                    gfx.DrawRectangle(pen, rect);
                }

                // draw lines
                foreach (RegisteredModule m in Core.Instance.ModuleRegistry)
                {
                    Rectangle rect = GetModuleRect(m, rectWidth, rectHeight, widthGap, heightGap, modulePositions[m.Namespace], levels, levelCounts[m.Importance], bmpWidth);

                    ModuleDependencyAttribute[] atts = (ModuleDependencyAttribute[])Attribute.GetCustomAttributes(m.Module.GetType(), typeof(ModuleDependencyAttribute), true);
                    int attnum = 0;
                    foreach (ModuleDependencyAttribute att in atts)
                    {
                        attnum++;
                        RegisteredModule dm = Core.Modules.ModuleRegistry[att.ModuleType.FullName];
                        int xmodstart = (rectWidth / 2) - ((atts.Length - 1) * lineGap) / 2 + ((attnum - 1) * lineGap);
                        int xmodend = Math.Max(bmpWidth / 2 - (levelCounts[dm.Importance] * rectWidth + (levelCounts[dm.Importance] - 1) * widthGap) / 2, 0);
                        int level = dm.Importance + 1;
                        int dmxpos = modulePositions[dm.Namespace];
                        Point start = new Point(rect.X + xmodstart, rect.Y);
                        Point end = new Point(xmodend + (dmxpos - 1) * rectWidth + (dmxpos - 1) * widthGap + rectWidth / 2,
                            heightGap + level * rectHeight + (level - 1) * heightGap);
                        Color color;
                        switch (attnum % 7)
                        {
                            case 0: color = Color.Red; break;
                            case 1: color = Color.Silver; break;
                            case 2: color = Color.Blue; break;
                            case 3: color = Color.Violet; break;
                            case 4: color = Color.Orange; break;
                            case 5: color = Color.DarkCyan; break;
                            default: color = Color.SlateBlue; break;
                        }
                        gfx.DrawLine(new Pen(color), start, end);
                        gfx.FillEllipse(new SolidBrush(color), start.X - 2, start.Y - 2, 5, 5);
                        gfx.FillRectangle(new SolidBrush(Color.FromArgb(200, 200, 200)), end.X - 2, end.Y - 2, 5, 5);
                    }
                }

                // write words
                StringFormat fmt = new StringFormat();
                fmt.Alignment = StringAlignment.Center;
                fmt.LineAlignment = StringAlignment.Center;
                fmt.Trimming = StringTrimming.Character;
                foreach (RegisteredModule m in Core.Instance.ModuleRegistry)
                {
                    Rectangle rect = GetModuleRect(m, rectWidth, rectHeight, widthGap, heightGap, modulePositions[m.Namespace],
                        levels, levelCounts[m.Importance], bmpWidth);
                    Rectangle wordsrect = new Rectangle(rect.X + 3, rect.Y + 3, rect.Width - 6, rect.Height - 6);
                    Brush bgbrush = new SolidBrush(Color.FromArgb(200, dllColors[new FileInfo(m.Module.GetType().Assembly.Location).Name]));
                    gfx.FillRectangle(bgbrush, wordsrect);
                    gfx.DrawString(m.Title, font, blackBrush, wordsrect, fmt);
                }

                ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
                ImageCodecInfo encoder = null;
                for (int i = 0; i < encoders.Length; i++)
                    if (encoders[i].MimeType == "image/jpeg")
                    {
                        encoder = encoders[i];
                        break;
                    }
                if (encoder == null)
                    throw new SprocketException("Can't create a image because no JPEG encoder exists.");
                EncoderParameters prms = new EncoderParameters(1);
                prms.Param[0] = new EncoderParameter(Encoder.Quality, 200L);

                bmp.Save(HttpContext.Current.Response.OutputStream, encoder, prms);
                HttpContext.Current.Response.ContentType = "image/jpg";
            }
        }
 void OnPathNotFound(HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled)
 {
     if (!sprocketPath.Contains(".")) return;
     string urlpath;
     if (pathSections.Length == 1)
         urlpath = "";
     else
         urlpath = sprocketPath.Substring(0, sprocketPath.Length - pathSections[pathSections.Length - 1].Length - 1);
     XmlElement node = (XmlElement)PagesXml.SelectSingleNode("//Page[@Path='" + urlpath + "']");
     if (node == null) return;
     string newurl = "resources/content/" + node.GetAttribute("ContentFile");
     newurl = WebUtility.BasePath + newurl.Substring(0, newurl.LastIndexOf('/') + 1) + pathSections[pathSections.Length - 1];
     if (!File.Exists(HttpContext.Current.Server.MapPath(newurl)))
         return;
     HttpContext.Current.Response.TransmitFile(HttpContext.Current.Server.MapPath(newurl));
     handled.Set();
 }
示例#33
0
        void OnLoadRequestedPath(HandleFlag handled)
        {
            switch (SprocketPath.Value)
            {
            case "test":
                Response.Write("<form method=\"post\" action=\""
                               + WebUtility.BasePath + "test/upload/\" enctype=\"multipart/form-data\">"
                               + "<input type=\"file\" size=\"40\" name=\"thefile\" /> <input type=\"submit\" value=\"upload\" />"
                               + "</form>"
                               );
                break;

            case "test/upload":
                HttpPostedFile posted = HttpContext.Current.Request.Files[0];
                SprocketFile   file   = new SprocketFile(Security.SecurityProvider.ClientSpaceID, posted, "Test Image", "A test image.");
                FileManager.DataLayer.Store(file);
                WebUtility.Redirect("test/show/?" + file.SprocketFileID);
                break;

            case "test/show":
                long          id      = long.Parse(WebUtility.RawQueryString);
                SizingOptions options = new SizingOptions(320, 180, 10, Color.Black, Color.CadetBlue, 2, SizingOptions.Display.Letterbox, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(200, 200, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.Display.Letterbox, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(200, 200, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.Display.Stretch, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 200, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.Display.Letterbox, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 100, 10, Color.White, Color.FromArgb(240, 240, 240), 1, SizingOptions.Display.Letterbox, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Top, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Top, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Bottom, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Bottom, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Center, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Center, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Left, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Left, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Right, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Right, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.Display.Center, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.Display.Center, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                options = new SizingOptions(400, 300, 10, Color.Black, Color.CadetBlue, 0, 10, id);
                Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" align=\"top\" /> ");
                break;

            default:
                if (SprocketPath.Value.EndsWith(".jpg") && SprocketPath.Value.StartsWith("test/image/"))
                {
                    FileManager.Instance.TransmitRequestedImage();
                    break;
                }
                return;
            }
            handled.Set();
        }
示例#34
0
 void Instance_OnLoadRequestedPath(HandleFlag handled)
 {
     if(SprocketPath.Sections.Length >= 2)
         if (SprocketPath.Sections[0] == "datastore" && SprocketPath.Sections[1] == "databases")
         {
             HttpContext.Current.Response.Write("access denied.");
             HttpContext.Current.Response.End();
         }
 }
		void WebEvents_OnBeginHttpRequest(HandleFlag handled)
		{
			RequestSpeedExpression.Set();
			Values.PageStack.Clear();
			if (IsDefinitionsXmlOutOfDate)
			{
				Values.Templates = null;
				Values.Pages = null;
			}
		}
示例#36
0
 void Instance_OnLoadRequestedPath(HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled)
 {
     if (handled.Handled)
     {
         return;
     }
     if (sprocketPath == "$dbsetup")
     {
         DatabaseManager.Instance.ExecuteAllDataScripts(Database.Main.DatabaseEngine);
         HttpContext.Current.Response.Write("<p>Database setup completed.</p>");
         handled.Set();
     }
 }
		void WebEvents_OnBeforeLoadExistingFile(HandleFlag handled)
		{
			if (!SprocketPath.Value.EndsWith(".js")) return;
			FileInfo file = new FileInfo(SprocketPath.Physical);
			HttpContext.Current.Response.Cache.SetLastModified(file.LastWriteTime);
			HttpContext.Current.Response.Cache.SetMaxAge(new TimeSpan(24, 0, 0));
			if (!CompressJavaScript) return;
			bool rewrite = false;
			if (!ContentCache.IsContentCached(SprocketPath.Value))
				rewrite = true;
			else if (!compressedJSFiles.ContainsKey(file.FullName))
				rewrite = true;
			else if (compressedJSFiles[file.FullName] != file.LastWriteTime)
				rewrite = true;
			HttpContext.Current.Response.ContentType = "text/javascript";
			if (rewrite)
			{
				try
				{
					using (StreamReader reader = file.OpenText())
					{
						string s = JavaScriptCondenser.Condense(reader.ReadToEnd());
						HttpContext.Current.Response.Write(s);
						ContentCache.CacheContent(SprocketPath.Value, s);
						reader.Close();
						compressedJSFiles[file.FullName] = file.LastWriteTime;
					}
				}
				catch
				{
					return; // if an error occurs, let the system serve up the file normally
				}
			}
			else
				HttpContext.Current.Response.Write(ContentCache.ReadCache(SprocketPath.Value));
			handled.Set();
		}
示例#38
0
        void OnLoadRequestedPath(HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled)
        {
            if (handled.Handled)
            {
                return;
            }
            if (sprocketPath.StartsWith("datastore/filemanager/"))
            {                   // deny access if the directory is accessed directly
                handled.Set();
                return;
            }
            SprocketFile file = LoadCacheSprocketFile(sprocketPath);

            if (file == null)
            {
                return;
            }
            if (!File.Exists(file.PhysicalPath))
            {
                throw new SprocketException("A file has been requested that is handled by the FileManager. "
                                            + "The file has a record in the database but the accompanying file is missing. The ID for "
                                            + "the file is " + file.SprocketFileID + " and the Sprocket path is " + file.SprocketPath + ".");
            }
            handled.Set();
            if (OnBeforeSprocketFileServed != null)
            {
                Result result = new Result();
                OnBeforeSprocketFileServed(file, result);                 // allow other modules to deny access to the file
                if (!result.Succeeded)
                {
                    return;
                }
            }
            if (OnSprocketFileServed != null)
            {
                OnSprocketFileServed(file);
            }
            HttpContext.Current.Response.TransmitFile(file.PhysicalPath);
            HttpContext.Current.Response.ContentType = file.ContentType;
        }
示例#39
0
 void WebsiteAdmin_OnAdminRequest(AdminInterface admin, string sprocketPath, string[] pathSections, HandleFlag handled)
 {
     if (sprocketPath != "admin")
     {
         return;
     }
     admin.ContentHeading = "Current Overview";
     admin.AddContentSection(new RankedString("<div class=\"standalone-message\">Overview information under construction.</div>", 0));
     handled.Set();
 }
示例#40
0
        void WebEvents_OnLoadRequestedPath(HandleFlag handled)
        {
            if (handled.Handled)
            {
                return;
            }
            if (!IsAdminRequest)
            {
                return;
            }

            PageEntry page = pages.FromPath(SprocketPath.Value);

            if (page == null)
            {
                return;
            }

            KeyValuePair <string, object>[] vars;
            if (!SprocketPath.StartsWith("admin", "login"))
            {
                if (!WebAuthentication.VerifyAccess(PermissionType.AccessAdminArea))
                {
                    WebUtility.Redirect("admin/login");
                    return;
                }

                AdminInterface   admin   = new AdminInterface();
                WebClientScripts scripts = WebClientScripts.Instance;
                admin.AddMainMenuLink(new AdminMenuLink("Website Home", WebUtility.MakeFullPath(""), ObjectRank.Last, "website_home"));
                admin.AddMainMenuLink(new AdminMenuLink("Overview", WebUtility.MakeFullPath("admin"), ObjectRank.First, "website_overview"));
                admin.AddMainMenuLink(new AdminMenuLink("Log Out", WebUtility.MakeFullPath("admin/logout"), ObjectRank.Last, "log_out"));

                admin.AddFooterLink(new AdminMenuLink("Log Out", WebUtility.MakeFullPath("admin/logout"), ObjectRank.Early));
                admin.AddFooterLink(new AdminMenuLink("&copy; 2005-" + DateTime.UtcNow.Year + " " + SprocketSettings.GetValue("WebsiteName"), "", ObjectRank.Late));
                admin.AddFooterLink(new AdminMenuLink("Powered by Sprocket", "http://www.sprocketcms.com", ObjectRank.Last));
                admin.AddHeadSection(new AdminSection(scripts.BuildStandardScriptsBlock(), ObjectRank.Late));
                admin.WebsiteName = GetWebsiteName();

                if (OnLoadAdminPage != null)
                {
                    OnLoadAdminPage(admin, page, handled);
                    if (handled.Handled)
                    {
                        return;
                    }
                }

                vars = admin.GetScriptVariables();
            }
            else
            {
                vars    = new KeyValuePair <string, object> [1];
                vars[0] = new KeyValuePair <string, object>("_admin_websitename", GetWebsiteName());
            }

            ContentManager.RequestedPage = page;
            if (pagePreProcessors.ContainsKey(page.PageCode))
            {
                foreach (PagePreprocessorHandler method in pagePreProcessors[page.PageCode])
                {
                    method(page);
                }
            }
            string txt = page.Render(vars);

            Response.ContentType = page.ContentType;
            Response.Write(txt);
            handled.Set();
        }
示例#41
0
        void OnLoadRequestedPath(HttpApplication app, string path, string[] pathSections, HandleFlag handled)
        {
            if (pathSections.Length == 0)
            {
                return;
            }
            if (pathSections[0] != "admin")
            {
                return;
            }
            bool   processed = false;
            string lastchunk = pathSections[pathSections.Length - 1];

            switch (lastchunk)
            {
            case "admin.css":
                HttpContext.Current.Response.TransmitFile("~/resources/admin/admin.css");
                HttpContext.Current.Response.ContentType = "text/css";
                processed = true;
                break;

            default:
                WebAuthentication auth     = WebAuthentication.Instance;
                HttpResponse      Response = HttpContext.Current.Response;
                HttpServerUtility Server   = HttpContext.Current.Server;
                switch (path)
                {
                case "admin/login":
                    ShowLoginScreen();
                    processed = true;
                    break;

                case "admin/logout":
                    auth.ClearAuthenticationCookie();
                    Response.Redirect(WebUtility.MakeFullPath("admin/login"));
                    processed = true;
                    break;

                case "admin/login/process":
                    if (auth.ProcessLoginForm("SprocketUsername", "SprocketPassword", "SprocketPreserveLogin"))
                    {
                        Response.Redirect(WebUtility.MakeFullPath("admin"));
                    }
                    else
                    {
                        ShowLoginScreen("Invalid Username and/or Password.");
                    }
                    processed = true;
                    break;

                default:
                    if (!auth.IsLoggedIn)
                    {
                        GotoLoginScreen();
                        processed = true;
                    }
                    else if (OnCMSAdminAuthenticationSuccess != null)
                    {
                        Result result = new Result();
                        OnCMSAdminAuthenticationSuccess(auth.CurrentUsername, result);
                        if (!result.Succeeded)
                        {
                            ShowLoginScreen(result.Message);
                            processed = true;
                        }
                    }
                    break;
                }
                break;
            }
            if (processed)
            {
                handled.Set();
                return;
            }

            if (OnAdminRequest != null)
            {
                AdminInterface admin = new AdminInterface();
                OnAdminRequest(admin, path, pathSections, handled);
                if (handled.Handled)
                {
                    WebClientScripts scripts = WebClientScripts.Instance;
                    admin.AddMainMenuLink(new AdminMenuLink("Current Overview", WebUtility.MakeFullPath("admin"), -100));
                    admin.AddMainMenuLink(new AdminMenuLink("Log Out", WebUtility.MakeFullPath("admin/logout"), 100));
                    admin.AddFooterLink(new AdminMenuLink("&copy; 2005-" + DateTime.Now.Year + " " + SprocketSettings.GetValue("WebsiteName"), "", 100));
                    string powered = SprocketSettings.GetValue("ShowPoweredBySprocket");
                    if (powered != null)
                    {
                        if (StringUtilities.MatchesAny(powered.ToLower(), "true", "yes"))
                        {
                            admin.AddFooterLink(new AdminMenuLink("Powered by Sprocket", "http://www.sprocketcms.com", 1000));
                        }
                    }
                    admin.AddHeadSection(new RankedString(scripts.BuildStandardScriptsBlock(), 1));
                    HttpContext.Current.Response.Write(admin.Render(path));
                }
            }
        }
示例#42
0
        /// <summary>
        /// Sprocket calls this method in response to ASP.Net's AcquireRequestState event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void FireAcquireRequestState(object sender, EventArgs e)
        {
            if (OnRequestStateLoaded != null) // as always, let the other modules know where we are...
                OnRequestStateLoaded((HttpApplication)sender);

            HttpContext pg = HttpContext.Current;

            // The SprocketPath refers to the bit after the application base path and before the
            // querystring, minus any leading and trailing forward-slashes. (/) For example if the
            // full URL is "http://www.sprocketcms.com/myapp/admin/users/?edit" and the subdirectory
            // "myapp" is a virtual directory (IIS application) then the SprocketPath would be
            // "admin/users".
            string sprocketPath = null;
            string appPath = pg.Request.Path.ToLower();

            // check to see if there's a trailing slash and if there isn't, redirect to stick a trailing
            // slash onto the path. This is to keep pathing consistent because otherwise relative paths
            // (such as to images and css files) aren't pathed as expected. We DON'T do this if a form
            // has been posted however, because otherwise we lose the contents of the posted form. It is
            // assumed that if you forget to post to a path with a trailing slash, that once you finish
            // processing the form that you'll redirect off to a secondary page anyway, which means
            // sticking a slash on the end of this URL is unnecessary anyway.
            if (!appPath.EndsWith("/") && !appPath.Contains(".") && HttpContext.Current.Request.Form.Count == 0)
            {
                pg.Response.Redirect(appPath + "/");
                pg.Response.End();
                return;
            }

            // changes (e.g.) "http://www.sprocketcms.com/myapp/admin/users/?edit" into "admin/users"
            sprocketPath = appPath.Remove(0, pg.Request.ApplicationPath.Length).Trim('/');

            // split up the path sections to make things even easier for request event handlers
            string[] pathSections = sprocketPath.Split('/');

            // this is our flag so that request event handlers can let us know if they handled this request.
            HandleFlag flag = new HandleFlag();

            if (OnLoadRequestedPath != null)
            {
                OnLoadRequestedPath((HttpApplication)sender, sprocketPath, pathSections, flag);
                if (flag.Handled)
                {
                    // stop the browser from caching the page
                    // HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

                    // if one of the modules handled the request event, then we can stop
                    // doing stuff now. The OnEndRequest event will still be called though.
                    pg.Response.End();
                    return;
                }
            }

            // if we've reached this point and none of our modules have volunteered to handle
            // the request, we can check to see if the requested path actually exists (gasp!)
            // and if so, serve up that file! This is handy if we insist on using the Standard
            // ASP.Net Page framework (yuck) or want to serve up other things like plain html
            // files.
            if (!flag.Handled && File.Exists(pg.Request.PhysicalPath))
            {
                // here we provide a last chance opportunity to alter the response before the
                // file is served.
                if (OnBeforeLoadExistingFile != null)
                {
                    OnBeforeLoadExistingFile((HttpApplication)sender, sprocketPath, pathSections, flag);
                    if (flag.Handled)
                    {
                        pg.Response.End();
                        return;
                    }
                }
                HttpContext.Current.RewritePath(pg.Request.Path);
                return;
            }

            // at this point we know that no file matching the exists, so we can check to see
            // if a directory of the specified name exists. If it does, we can see if there are
            // any default pages inside the folder that should execute. This requires the a key
            // to be configured for appSettings in the Web.config file:
            // <add key="DefaultPageFilenames" value="default.aspx,default.asp,default.htm,index.htm" />
            if (Directory.Exists(pg.Request.PhysicalPath))
            {
                string dpgstr = SprocketSettings.GetValue("DefaultPageFilenames");
                if (dpgstr != null)
                {
                    string[] pgarr = dpgstr.Split(',');
                    foreach (string pgname in pgarr)
                    {
                        string pgpath = "/" + pg.Request.Path.Trim('/') + "/" + pgname;
                        string physpath = pg.Request.PhysicalPath + "\\" + pgname;
                        if (File.Exists(physpath))
                        {
                            HttpContext.Current.Response.Redirect(pgpath);
                            return;
                        }
                    }
                }
            }

            // if we've reached this point and still havent found anything that wants to handle
            // the current request, we offer up a final chance to respond to this fact...
            if(OnPathNotFound != null)
            {
                OnPathNotFound((HttpApplication)sender, sprocketPath, pathSections, flag);
                if (flag.Handled)
                {
                    pg.Response.End();
                    return;
                }
            }

            // if we got this far, sorry folks, but you're about to get a boring ASP.Net 404 page.
        }
示例#43
0
 void OnLoadRequestedPath(HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled)
 {
     if (handled.Handled) return;
     if (sprocketPath.StartsWith("datastore/filemanager/"))
     {	// deny access if the directory is accessed directly
         handled.Set();
         return;
     }
     SprocketFile file = LoadCacheSprocketFile(sprocketPath);
     if (file == null) return;
     if (!File.Exists(file.PhysicalPath))
         throw new SprocketException("A file has been requested that is handled by the FileManager. "
             + "The file has a record in the database but the accompanying file is missing. The ID for "
             + "the file is " + file.SprocketFileID + " and the Sprocket path is " + file.SprocketPath + ".");
     handled.Set();
     if (OnBeforeSprocketFileServed != null)
     {
         Result result = new Result();
         OnBeforeSprocketFileServed(file, result); // allow other modules to deny access to the file
         if (!result.Succeeded) return;
     }
     if (OnSprocketFileServed != null)
         OnSprocketFileServed(file);
     HttpContext.Current.Response.TransmitFile(file.PhysicalPath);
     HttpContext.Current.Response.ContentType = file.ContentType;
 }
示例#44
0
        void WebEvents_OnLoadRequestedPath(System.Web.HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled)
        {
            if (!IntegrationEnabled)
            {
                return;
            }

            switch (sprocketPath)
            {
            case "paypal-ipn-process":
                using (PayPalTransactionResponse resp = InstantPaymentNotification.Authenticate())
                {
                    if (OnInstantPaymentNotification != null && resp != null)
                    {
                        OnInstantPaymentNotification(resp);
                    }
                }

                break;

            case "paypal-trans-return":
                using (PayPalTransactionResponse resp = TransactionReturn())
                {
                    if (OnTransactionResponse != null && resp != null)
                    {
                        OnTransactionResponse(resp);
                    }
                }
                break;

            default:
                return;
            }
            handled.Set();
        }
示例#45
0
        void OnLoadRequestedPath(HandleFlag handled)
        {
            if (SprocketPath.Value != "sysinfo")
                return;
            handled.Set();
            string html = ResourceLoader.LoadTextResource("Sprocket.Web.html.sysinfo.htm");
            HttpResponse Response = HttpContext.Current.Response;
            string modules = "<tr>" +
                "<th nowrap=\"true\">Assembly</th>" +
                "<th nowrap=\"true\">Module Namespace</th>" +
                "<th nowrap=\"true\">Module Name</th>" +
                "<th>Description</th>" +
                "</tr>";
            bool alt = false;
            List<ISprocketModule> bydll = new List<ISprocketModule>();
            int colorNum = -1;
            foreach (RegisteredModule module in Core.Instance.ModuleRegistry)
            {
                string asmname = new FileInfo(module.Module.GetType().Assembly.Location).Name;
                if (!dllColors.ContainsKey(asmname))
                {
                    colorNum++;
                    if (colorNum >= colors.Length)
                        colorNum = 0;
                    dllColors.Add(asmname, colors[colorNum]);
                }
                bydll.Add(module.Module);
            }

            bydll.Sort(delegate(ISprocketModule x, ISprocketModule y)
            {
                string ax = new FileInfo(x.GetType().Assembly.Location).Name;
                string ay = new FileInfo(y.GetType().Assembly.Location).Name;
                int z = string.Compare(ax, ay, true);
                if (z != 0) return z;
                return string.Compare(x.GetType().FullName, y.GetType().FullName, true);
            });

            string oldf = "";
            bool altf = true;
            bool newdllrow = true;
            foreach (ISprocketModule module in bydll)
            {
                string newf = new FileInfo(module.GetType().Assembly.Location).Name;
                string filename;
                if (oldf != newf)
                {
                    filename = newf;
                    oldf = newf;
                    altf = !altf;
                    newdllrow = true;
                }
                else
                {
                    filename = "&nbsp;";
                    newdllrow = false;
                }
                RegisteredModule m = Core.Instance[module];

                modules += string.Format(
                    "<tr class=\"row-{0}{2}\">" +
                    "<td valign=\"top\" class=\"assembly-{1}\">" + filename + "</td>" +
                    "<td valign=\"top\" class=\"module-code-{0}\"><strong>" + m.Namespace + "</strong></td>" +
                    "<td valign=\"top\" nowrap=\"true\" class=\"module-title-{0}\">" + m.Title + "</td>" +
                    "<td valign=\"top\">" + m.Description + "</td>" +
                    "</tr>",
                    alt ? "alt2" : "alt1",
                    altf ? "alt2" : "alt1",
                    newdllrow ? " newdllrow" : "");
                alt = !alt;
            }

            html = html.Replace("{modules}", modules);
            Response.Write(html);
        }
示例#46
0
 void WebsiteAdmin_OnAdminRequest(AdminInterface admin, string sprocketPath, string[] pathSections, HandleFlag handled)
 {
     if (sprocketPath != "admin") return;
     admin.ContentHeading = "Current Overview";
     admin.AddContentSection(new RankedString("<div class=\"standalone-message\">Overview information under construction.</div>", 0));
     handled.Set();
 }
示例#47
0
        void WebEvents_OnLoadRequestedPath(System.Web.HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled)
        {
            if (!IntegrationEnabled)
            {
                return;
            }

            switch (sprocketPath)
            {
            case "paypal-ipn-process":
                break;

            case "paypal-trans-return":
                TransactionReturn();
                break;

            default:
                return;
            }
            handled.Set();
        }
示例#48
0
        void WebEvents_OnLoadRequestedPath(HandleFlag handled)
        {
            if (handled.Handled) return;
            switch (SprocketPath.Value)
            {
                case "activate/fix":
                    {
                        bool failed = false;
                        if (!WebAuthentication.IsLoggedIn)
                            failed = true;
                        else if(!WebAuthentication.VerifyAccess(PermissionType.AdministrativeAccess))
                            failed = true;
                        if (failed)
                        {
                            HttpContext.Current.Response.Write("<html><body><p>Access denied. Administrative access required.</p></body></html>");
                            handled.Set();
                            return;
                        }
                        else
                        {
                            try
                            {
                                int k;
                                using (TransactionScope scope = new TransactionScope())
                                {
                                    DatabaseManager.DatabaseEngine.GetConnection();
                                    List<User> users = SecurityProvider.DataLayer.FilterUsers(null, null, null, null, null, null, false, out k);
                                    foreach (User user in users)
                                        SecurityProvider.RequestUserActivation(user.UserID, user.Email);
                                    scope.Complete();
                                }
                                HttpContext.Current.Response.Write("<html><body><p>" + k + " activation requests created.</p></body></html>");
                                handled.Set();
                                return;
                            }
                            finally
                            {
                                DatabaseManager.DatabaseEngine.ReleaseConnection();
                            }
                        }
                    }

                default:
                    switch (SprocketPath.Sections[0])
                    {
                        case "_captcha":
                            RenderCAPTCHAImage();
                            break;

                        case "activate":
                            if (SprocketPath.Sections.Length == 2)
                            {
                                string activationCode = SprocketPath.Sections[1];
                                long userID;
                                Result r = SecurityProvider.DataLayer.ActivateUser(activationCode, out userID);
                                if (r.Succeeded)
                                {
                                    User user = null;
                                    if (WebAuthentication.IsLoggedIn)
                                        if (SecurityProvider.CurrentUser.UserID == userID)
                                        {
                                            user = SecurityProvider.CurrentUser;
                                            user.Activated = true;
                                        }
                                    if (user == null)
                                        user = SecurityProvider.DataLayer.SelectUser(userID);

                                    if (OnUserActivated != null)
                                        OnUserActivated(user, handled);
                                    if (!handled.Handled)
                                    {
                                        HttpContext.Current.Response.Write("<html><body><p>The user has been successfully activated.</p></body></html>");
                                        handled.Set();
                                    }
                                }
                                else
                                {
                                    if (OnUserActivationError != null)
                                        OnUserActivationError(r, handled);
                                    if (!handled.Handled)
                                    {
                                        HttpContext.Current.Response.Write("<html><body><p>" + r.Message + "</p></body></html>");
                                        handled.Set();
                                    }
                                }
                            }
                            break;
                    }
                    break;
            }
        }
示例#49
0
        /// <summary>
        /// This is the very first point where Sprocket interrupts the ASP.Net HTTP pipeline
        /// and allows itself to start handling requests. Note that this is way before the 
        /// standard ASP.Net page framework would kick in. At this point state information like
        /// cookies and sessions have not yet been loaded.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void FireBeginRequest(object sender, EventArgs e)
        {
            HandleFlag handled = new HandleFlag();

            if(OnBeginHttpRequest != null)
                OnBeginHttpRequest((HttpApplication)sender, handled);

            if (handled.Handled)
            {
                HttpContext.Current.Response.End();
                return;
            }

            // The SprocketSettings module is one of the modules that handles the OnBeginHttpRequest
            // event. It lets each module check for any .config file errors (or other settings errors)
            // and report them back here. If we get to this point and at least one module has reported
            // a settings error, we show Sprocket's critical error page which has a nice list of
            // error messages that the user can try to rectify.
            if (((SprocketSettings)SystemCore.Instance["SprocketSettings"]).ErrorList.HasCriticalError)
            {
                ShowErrorPage();
                return;
            }
        }
示例#50
0
        /// <summary>
        /// Sprocket calls this method in response to ASP.Net's AcquireRequestState event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void FireAcquireRequestState(object sender, EventArgs e)
        {
            if (OnRequestStateLoaded != null) // as always, let the other modules know where we are...
                OnRequestStateLoaded();

            if (HttpContext.Current.Request.Form.Count > 0)
            {
                foreach (FormPostAction action in formPostActions)
                {
                    if (action.PostFromPath != null)
                        if (action.PostFromPath != SprocketPath.ExtractSprocketPath(HttpContext.Current.Request.UrlReferrer.ToString()))
                            continue;

                    if (action.PostToPath != null)
                        if (action.PostToPath.ToLower() != SprocketPath.Value)
                            continue;

                    if (action.FieldName != null)
                    {
                        string s = HttpContext.Current.Request.Form[action.FieldName];
                        if (s == null)
                            continue;
                        if (action.FieldValue != null)
                            if (s != action.FieldValue)
                                continue;
                    }

                    action.PostHandler();
                }
            }

            // this is our flag so that request event handlers can let us know if they handled this request.
            HandleFlag flag = new HandleFlag();

            if (OnLoadRequestedPath != null)
            {
                OnLoadRequestedPath(flag);
                if (flag.Handled)
                {
                    // stop the browser from caching the page
                    // HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

                    if (OnRequestedPathProcessed != null)
                        OnRequestedPathProcessed();

                    // if one of the modules handled the request event, then we can stop
                    // doing stuff now. The OnEndRequest event will still be called though.
                    HttpContext.Current.Response.End();
                    return;
                }
            }

            // if we've reached this point and none of our modules have volunteered to handle
            // the request, we can check to see if the requested path actually exists (gasp!)
            // and if so, serve up that file! This is handy if we insist on using the Standard
            // ASP.Net Page framework (yuck) or want to serve up other things like plain html
            // files.
            if (!flag.Handled && File.Exists(HttpContext.Current.Request.PhysicalPath))
            {
                // here we provide a last chance opportunity to alter the response before the
                // file is served.
                if (OnBeforeLoadExistingFile != null)
                {
                    OnBeforeLoadExistingFile(flag);
                    if (flag.Handled)
                    {
                        HttpContext.Current.Response.End();
                        return;
                    }
                }
                HttpContext.Current.RewritePath(HttpContext.Current.Request.Path);
                return;
            }

            // at this point we know that no file matching the exists, so we can check to see
            // if a directory of the specified name exists. If it does, we can see if there are
            // any default pages inside the folder that should execute. This requires the a key
            // to be configured for appSettings in the Web.config file:
            // <add key="DefaultPageFilenames" value="default.aspx,default.asp,default.htm,index.htm" />
            if (Directory.Exists(HttpContext.Current.Request.PhysicalPath))
            {
                string dpgstr = SprocketSettings.GetValue("DefaultPageFilenames");
                if (dpgstr != null)
                {
                    string[] pgarr = dpgstr.Split(',');
                    foreach (string pgname in pgarr)
                    {
                        string pgpath = "/" + HttpContext.Current.Request.Path.Trim('/') + "/" + pgname;
                        string physpath = HttpContext.Current.Request.PhysicalPath + "\\" + pgname;
                        if (File.Exists(physpath))
                        {
                            HttpContext.Current.Response.Redirect(pgpath);
                            return;
                        }
                    }
                }
            }

            // if we've reached this point and still havent found anything that wants to handle
            // the current request, we offer up a final chance to respond to this fact...
            if(OnPathNotFound != null)
            {
                OnPathNotFound(flag);
                if (flag.Handled)
                {
                    if (OnRequestedPathProcessed != null)
                        OnRequestedPathProcessed();
                    HttpContext.Current.Response.End();
                    return;
                }
            }

            // if we got this far, sorry folks, but you're about to get a boring ASP.Net 404 page.
        }
		void ContentCache_OnLoadRequestedPath(HandleFlag handled)
		{
			if (handled.Handled)
				return;
			else if (SprocketPath.Value == "$clear-cache")
			{
				if (OnCacheClearanceRequested != null)
				{
					Result r = new Result();
					OnCacheClearanceRequested(r);
					if (!r.Succeeded)
					{
						HttpContext.Current.Response.Write(r.Message);
						handled.Set();
						return;
					}
				}
				ClearCache();
				HttpContext.Current.Response.Write("The cache has been cleared.");
				handled.Set();
			}
			else if (SprocketPath.Value == "datastore\\content-cache" || SprocketPath.Value.StartsWith("datastore\\content-cache\\"))
			{
				handled.Set();
				HttpContext.Current.Response.Write("Access denied.");
			}
		}
        void OnPathNotFound(HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled)
        {
            if (handled.Handled)
            {
                return;
            }
            if (!sprocketPath.Contains("."))
            {
                return;
            }
            string urlpath;

            if (pathSections.Length == 1)
            {
                urlpath = "";
            }
            else
            {
                urlpath = sprocketPath.Substring(0, sprocketPath.Length - pathSections[pathSections.Length - 1].Length - 1);
            }
            XmlElement node = (XmlElement)PagesXml.SelectSingleNode("//Page[@Path='" + urlpath + "']");

            if (node == null)
            {
                return;
            }
            string newurl = "resources/content/" + node.GetAttribute("ContentFile");

            newurl = WebUtility.BasePath + newurl.Substring(0, newurl.LastIndexOf('/') + 1) + pathSections[pathSections.Length - 1];
            if (!File.Exists(HttpContext.Current.Server.MapPath(newurl)))
            {
                return;
            }
            string file = HttpContext.Current.Server.MapPath(newurl);

            switch (new FileInfo(file).Extension)
            {
            case ".jpg":
                HttpContext.Current.Response.ContentType = "image/jpg";
                break;

            case ".gif":
                HttpContext.Current.Response.ContentType = "image/gif";
                break;

            case ".png":
                HttpContext.Current.Response.ContentType = "image/png";
                break;
            }
            HttpContext.Current.Response.TransmitFile(file);
            handled.Set();
        }
示例#53
0
        void OnLoadRequestedPath(HttpApplication app, string path, string[] pathSections, HandleFlag handled)
        {
            if (pathSections.Length == 0) return;
            if (pathSections[0] != "admin") return;
            bool processed = false;
            string lastchunk = pathSections[pathSections.Length - 1];

            switch(lastchunk)
            {
                case "admin.css":
                    HttpContext.Current.Response.TransmitFile("~/resources/admin/admin.css");
                    HttpContext.Current.Response.ContentType = "text/css";
                    processed = true;
                    break;

                default:
                    WebAuthentication auth = (WebAuthentication)SystemCore.Instance["WebAuthentication"];
                    HttpResponse Response = HttpContext.Current.Response;
                    HttpServerUtility Server = HttpContext.Current.Server;
                    switch (path)
                    {
                        case "admin/login":
                            ShowLoginScreen();
                            processed = true;
                            break;

                        case "admin/logout":
                            auth.ClearAuthenticationCookie();
                            Response.Redirect(WebUtility.MakeFullPath("admin/login"));
                            processed = true;
                            break;

                        case "admin/login/process":
                            if (auth.ProcessLoginForm("SprocketUsername", "SprocketPassword", "SprocketPreserveLogin"))
                                Response.Redirect(WebUtility.MakeFullPath("admin"));
                            else
                                ShowLoginScreen("Invalid Username and/or Password.");
                            processed = true;
                            break;

                        default:
                            if (!auth.IsLoggedIn)
                            {
                                GotoLoginScreen();
                                processed = true;
                            }
                            else if (OnCMSAdminAuthenticationSuccess != null)
                            {
                                Result result = new Result();
                                OnCMSAdminAuthenticationSuccess(auth.CurrentUsername, result);
                                if (!result.Succeeded)
                                {
                                    ShowLoginScreen(result.Message);
                                    processed = true;
                                }
                            }
                            break;
                    }
                    break;
            }
            if (processed)
            {
                handled.Set();
                return;
            }

            if (OnAdminRequest != null)
            {
                AdminInterface admin = new AdminInterface();
                OnAdminRequest(admin, path, pathSections, handled);
                if (handled.Handled)
                {
                    WebClientScripts scripts = (WebClientScripts)SystemCore.Instance["WebClientScripts"];
                    admin.AddMainMenuLink(new AdminMenuLink("Current Overview", WebUtility.MakeFullPath("admin"), -100));
                    admin.AddMainMenuLink(new AdminMenuLink("Log Out", WebUtility.MakeFullPath("admin/logout"), 100));
                    admin.AddFooterLink(new AdminMenuLink("&copy; 2005-" + DateTime.Now.Year + " " + SprocketSettings.GetValue("WebsiteName"), "", 100));
                    string powered = SprocketSettings.GetValue("ShowPoweredBySprocket");
                    if(powered != null)
                        if(Utilities.MatchesAny(powered.ToLower(), "true", "yes"))
                            admin.AddFooterLink(new AdminMenuLink("Powered by Sprocket", "http://www.sprocketcms.com", 1000));
                    admin.AddHeadSection(new RankedString(scripts.BuildScriptTags(), 1));
                    HttpContext.Current.Response.Write(admin.Render(path));
                }
            }
        }
        void OnLoadRequestedPath(HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled)
        {
            if (handled.Handled)
            {
                return;
            }

            if (!File.Exists(WebUtility.MapPath(PageRegistry.XmlFilePath)))
            {
                return;
            }

            switch (sprocketPath)
            {
            case "$reset":
                PageRegistry.UpdateValues();
                TemplateRegistry.Reload();
                ListRegistry.Reload();
                OutputFormatRegistry.Reload();
                GeneralRegistry.Reload();
                ContentCache.ClearCache();
                WebUtility.Redirect("");
                break;

            default:
                PageRegistry.CheckDate();

                PageEntry page = PageRegistry.Pages.FromPath(sprocketPath);
                if (page == null)
                {
                    return;
                }
                if (OnBeforeRenderPage != null)
                {
                    OnBeforeRenderPage(page, sprocketPath, pathSections);
                }
                string output = page.Render();
                if (output == null)
                {
                    return;
                }
                Response.Write(output);
                break;
            }

            handled.Set();
        }
示例#55
0
 void ContentCache_OnLoadRequestedPath(System.Web.HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled)
 {
     if (handled.Handled)
         return;
     else if (sprocketPath == "$clear-cache")
     {
         if (OnCacheClearanceRequested != null)
         {
             Result r = new Result();
             OnCacheClearanceRequested(r);
             if (!r.Succeeded)
             {
                 HttpContext.Current.Response.Write(r.Message);
                 handled.Set();
                 return;
             }
         }
         ClearCache();
         HttpContext.Current.Response.Write("The cache has been cleared.");
         handled.Set();
     }
     else if (sprocketPath == "datastore\\content-cache" || sprocketPath.StartsWith("datastore\\content-cache\\"))
     {
         handled.Set();
         HttpContext.Current.Response.Write("Access denied.");
     }
 }
		void WebEvents_OnPathNotFound(HandleFlag handled)
		{
			#region Map missing referenced files (e.g. images and css) to the same location as the content file

			if (!SprocketPath.Value.Contains("."))
			{
				HttpContext.Current.Response.Write(ResourceLoader.LoadTextResource("Sprocket.Web.CMS.Content.404.htm"));
				handled.Set();
				return;
			}
			string urlpath;
			if (SprocketPath.Sections.Length == 1)
				urlpath = "";
			else
				urlpath = SprocketPath.Value.Substring(0, SprocketPath.Value.Length - SprocketPath.Sections[SprocketPath.Sections.Length - 1].Length - 1);

			PageEntry page = Pages.FromPath(urlpath);
			if (page == null) return;
			string newurl = page.ContentFile;
			newurl = WebUtility.BasePath + newurl.Substring(0, newurl.LastIndexOf('/') + 1) + SprocketPath.Sections[SprocketPath.Sections.Length - 1];
			if (!File.Exists(HttpContext.Current.Server.MapPath(newurl)))
				return;
			HttpContext.Current.Response.TransmitFile(HttpContext.Current.Server.MapPath(newurl));
			handled.Set();

			#endregion
		}
示例#57
0
        void OnLoadRequestedPath(HandleFlag handled)
        {
            switch (SprocketPath.Value)
            {
                case "test":
                    Response.Write("<form method=\"post\" action=\""
                        + WebUtility.BasePath + "test/upload/\" enctype=\"multipart/form-data\">"
                        + "<input type=\"file\" size=\"40\" name=\"thefile\" /> <input type=\"submit\" value=\"upload\" />"
                        + "</form>"
                        );
                    break;

                case "test/upload":
                    HttpPostedFile posted = HttpContext.Current.Request.Files[0];
                    SprocketFile file = new SprocketFile(Security.SecurityProvider.ClientSpaceID, posted, "Test Image", "A test image.");
                    FileManager.DataLayer.Store(file);
                    WebUtility.Redirect("test/show/?" + file.SprocketFileID);
                    break;

                case "test/show":
                    long id = long.Parse(WebUtility.RawQueryString);
                    SizingOptions options = new SizingOptions(320, 180, 10, Color.Black, Color.CadetBlue, 2, SizingOptions.Display.Letterbox, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(200, 200, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.Display.Letterbox, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(200, 200, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.Display.Stretch, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 200, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.Display.Letterbox, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 100, 10, Color.White, Color.FromArgb(240, 240, 240), 1, SizingOptions.Display.Letterbox, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Top, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Top, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Bottom, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Bottom, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Center, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Center, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Left, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Left, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.CropAnchor.Right, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.CropAnchor.Right, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 100, 0, Color.Black, Color.CadetBlue, 0, SizingOptions.Display.Center, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(100, 100, 15, Color.Black, Color.Red, 5, SizingOptions.Display.Center, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" /> ");

                    options = new SizingOptions(400, 300, 10, Color.Black, Color.CadetBlue, 0, 10, id);
                    Response.Write("<img src=\"" + WebUtility.BasePath + "test/image/" + options.Filename + "?nocache\" hspace=\"5\" vspace=\"5\" align=\"top\" /> ");
                    break;

                default:
                    if (SprocketPath.Value.EndsWith(".jpg") && SprocketPath.Value.StartsWith("test/image/"))
                    {
                        FileManager.Instance.TransmitRequestedImage();
                        break;
                    }
                    return;
            }
            handled.Set();
        }
示例#58
0
        void WebEvents_OnLoadRequestedPath(HandleFlag handled)
        {
            if (handled.Handled)
            {
                return;
            }
            switch (SprocketPath.Value)
            {
            case "activate/fix":
            {
                bool failed = false;
                if (!WebAuthentication.IsLoggedIn)
                {
                    failed = true;
                }
                else if (!SecurityProvider.CurrentUser.HasPermission(PermissionType.AdministrativeAccess))
                {
                    failed = true;
                }
                if (failed)
                {
                    HttpContext.Current.Response.Write("<html><body><p>Access denied. Administrative access required.</p></body></html>");
                    handled.Set();
                    return;
                }
                else
                {
                    try
                    {
                        int k;
                        using (TransactionScope scope = new TransactionScope())
                        {
                            DatabaseManager.DatabaseEngine.GetConnection();
                            List <User> users = SecurityProvider.DataLayer.FilterUsers(null, null, null, null, null, null, false, out k);
                            foreach (User user in users)
                            {
                                SecurityProvider.RequestUserActivation(user.UserID, user.Email);
                            }
                            scope.Complete();
                        }
                        HttpContext.Current.Response.Write("<html><body><p>" + k + " activation requests created.</p></body></html>");
                        handled.Set();
                        return;
                    }
                    finally
                    {
                        DatabaseManager.DatabaseEngine.ReleaseConnection();
                    }
                }
            }

            default:
                switch (SprocketPath.Sections[0])
                {
                case "_captcha":
                    RenderCAPTCHAImage();
                    break;

                case "activate":
                    if (SprocketPath.Sections.Length == 2)
                    {
                        string activationCode = SprocketPath.Sections[1];
                        long   userID;
                        Result r = SecurityProvider.DataLayer.ActivateUser(activationCode, out userID);
                        if (r.Succeeded)
                        {
                            User user = null;
                            if (WebAuthentication.IsLoggedIn)
                            {
                                if (SecurityProvider.CurrentUser.UserID == userID)
                                {
                                    user           = SecurityProvider.CurrentUser;
                                    user.Activated = true;
                                }
                            }
                            if (user == null)
                            {
                                user = SecurityProvider.DataLayer.SelectUser(userID);
                            }

                            if (OnUserActivated != null)
                            {
                                OnUserActivated(user, handled);
                            }
                            if (!handled.Handled)
                            {
                                HttpContext.Current.Response.Write("<html><body><p>The user has been successfully activated.</p></body></html>");
                                handled.Set();
                            }
                        }
                        else
                        {
                            if (OnUserActivationError != null)
                            {
                                OnUserActivationError(r, handled);
                            }
                            if (!handled.Handled)
                            {
                                HttpContext.Current.Response.Write("<html><body><p>" + r.Message + "</p></body></html>");
                                handled.Set();
                            }
                        }
                    }
                    break;
                }
                break;
            }
        }
示例#59
0
 void Instance_OnLoadRequestedPath(System.Web.HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled)
 {
     if (sprocketPath == "scripttest")
     {
         string         html   = Sprocket.Utility.ResourceLoader.LoadTextResource("Sprocket.Web.CMS.SprocketScript.test.htm");
         SprocketScript script = new SprocketScript(html);
         HttpContext.Current.Response.ContentType = "text/html";
         script.Execute(HttpContext.Current.Response.OutputStream);
         //string test = script.Execute();
         //HttpContext.Current.Response.Write(test);
         handled.Set();
     }
 }
示例#60
0
 internal static extern bool SetHandleInformation(SafeHandle handle,
                                                  HandleFlag dwMask,
                                                  HandleFlag dwFlags);