void WebEvents_OnLoadRequestedPath(HandleFlag handled)
		{
			if (handled.Handled) return;
			if (SprocketPath.Sections[0] == "admin")
			{
				if (!WebAuthentication.Instance.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();
			}
		}
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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();
     }
 }
		void OnBeginHttpRequest(HandleFlag handled)
		{
			if (handled.Handled)
				return;

			if (IsAjaxRequest)
			{
				handled.Set();
				ProcessRequest(HttpContext.Current);
			}
		}
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
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 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();
        }
		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();
			}
		}
        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();
        }
Ejemplo n.º 10
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 />"));
        }
Ejemplo n.º 11
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();
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
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();
            }
        }
        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();
        }
Ejemplo n.º 15
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
        }
Ejemplo n.º 16
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";
            }
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
 void Instance_OnBeforeLoadExistingFile(HandleFlag handled)
 {
     if (SprocketPath.Value.ToLower() == "datastore/clientspace.id") // deny access
         handled.Set();
 }
Ejemplo n.º 19
0
 void Instance_OnBeforeLoadExistingFile(System.Web.HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled)
 {
     if (sprocketPath.ToLower() == "datastore/clientspace.id") // deny access
         handled.Set();
 }
Ejemplo n.º 20
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();
        }
		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
		}
Ejemplo n.º 22
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 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.");
			}
		}
Ejemplo n.º 24
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 OnLoadRequestedPath(HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled)
        {
            if (handled.Handled) 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();
        }
Ejemplo n.º 26
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;
            }
        }
		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();
		}
Ejemplo n.º 28
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);
 }
Ejemplo n.º 29
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));
                }
            }
        }
Ejemplo n.º 30
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();
        }
Ejemplo n.º 31
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.");
     }
 }
Ejemplo n.º 32
0
        void OnBeginHttpRequest(HttpApplication app, HandleFlag handled)
        {
            if (handled.Handled)
                return;

            if (app.Context.Request.Path.EndsWith(".ajax"))
            {
                handled.Set();
                ProcessRequest(HttpContext.Current);
            }
        }
 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();
 }
Ejemplo n.º 34
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();
 }
		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();
		}
Ejemplo n.º 36
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;
            }
        }
Ejemplo n.º 37
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));
                }
            }
        }
		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();
		}
Ejemplo n.º 39
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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 41
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;
 }