Example #1
0
        public ActionResult EditPage(string id)
        {
            if (id == null)
            {
                return(RedirectToAction("ViewPage"));
            }
            SqlAccess.SqlAccess     sa   = new SqlAccess.SqlAccess();
            wwBuildInfo.wwBuildInfo wwbi = new wwBuildInfo.wwBuildInfo();
            string fixNameCaps           = sa.FixNameCaps(id);

            if (fixNameCaps == "")
            {
                return(RedirectToAction("ViewPage"));
            }
            ViewData["PageName"] = ((fixNameCaps == "") ? id : fixNameCaps);
            //ViewData["CustomHtml"] = "<div class='ui label'>Testing html \" ` ` \" chars</div>";
            string[] pageContents = sa.GetPageByName(id);
            for (int i = 0; i < 4; i++)
            {
                pageContents[i] = pageContents[i].Replace("\n", "").Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("\r", "\\r");
            }
            ViewData["HtmlEdit"] = pageContents[0];
            ViewData["CssEdit"]  = pageContents[1];
            ViewData["JsEdit"]   = pageContents[2];
            ViewData["HeadEdit"] = pageContents[3];
            try
            {
                ViewData["ShowUndraftButton"] = (ViewData["PageName"].ToString().Substring(0, 6) == "Draft|") ? "true" : "false";
            }
            catch (Exception ex)
            {
                ViewData["ShowUndraftButton"] = "false";
            }
            ViewData["VersionNumber"] = wwbi.GetVersion();
            ViewData["SoftwareName"]  = wwbi.GetName();
            ViewData["SiteName"]      = getSiteSettings()["SiteName"];
            if (_signInManager.IsSignedIn(User))
            {
                return(View());
            }
            else
            {
                return(RedirectToAction("ViewPage", "Page"));
            }
        }
Example #2
0
        public ActionResult ViewPage(string id)
        {
            if (id == null)
            {
                //return RedirectToAction("Index", "Home");
                id = "Index";
            }

            SqlAccess.SqlAccess     sa   = new SqlAccess.SqlAccess();
            wwBuildInfo.wwBuildInfo wwbi = new wwBuildInfo.wwBuildInfo();
            //ViewData["CustomHtml"] = "<div class='ui label'>Testing html \" ` ` \" chars</div>";
            string[]      pageData        = sa.GetPageByName(id);
            string        pageContents    = pageData[0];
            string        fixNameCaps     = sa.FixNameCaps(id);
            List <string> authCredentials = new List <string>();

            ViewData["PageName"] = ((fixNameCaps == "") ? id : fixNameCaps);
            if (pageContents == "")
            {
                ViewData["CustomHtml"] = @"<div class=""ui negative message"">
  <div class=""header"">
404 Error
  </div>
  <p>Either this page is empty or it does not exist. 
</p></div>";
                ViewData["ErrorShown"] = true;
            }
            else
            {
                ViewData["CustomHtml"] = applySyntaxRules(pageContents, ViewData["PageName"].ToString());
                Dictionary <string, object> authProcessedText =
                    applyAuthenticationRules(ViewData["CustomHtml"].ToString());
                ViewData["CustomHtml"] = (string)authProcessedText["outText"];
                authCredentials        = (List <string>)authProcessedText["authCredentials"];
            }
            string newHtml = ViewData["CustomHtml"].ToString().Replace("{{HIDENAVBAR}}\r\n", "");

            if (newHtml != ViewData["CustomHtml"].ToString())
            {
                ViewData["ShowNavbar"] = false;
                ViewData["CustomHtml"] = newHtml;
            }
            else
            {
                ViewData["ShowNavbar"] = true;
            }
            newHtml = ViewData["CustomHtml"].ToString().Replace("{{NOMARGIN}}\r\n", "");
            if (newHtml != ViewData["CustomHtml"].ToString())
            {
                ViewData["NoMargin"]   = true;
                ViewData["CustomHtml"] = newHtml;
            }
            else
            {
                ViewData["NoMargin"] = false;
            }
            ViewData["CustomCss"]     = pageData[1];
            ViewData["CustomJs"]      = pageData[2];
            ViewData["CustomHead"]    = pageData[3];
            ViewData["VersionNumber"] = wwbi.GetVersion();
            ViewData["SoftwareName"]  = wwbi.GetName();
            ViewData["SiteName"]      = getSiteSettings()["SiteName"];
            if (_userManager.Users.ToList().Count < 1)
            {
                return(RedirectToPage("/Account/Register", new { area = "Identity" }));
            }

            bool credentialMatches = true;

            if (authCredentials.Count > 0)
            {
                credentialMatches = false;
                var req  = HttpContext.Request;
                var auth = req.Headers["Authorization"];
                if (!string.IsNullOrEmpty(auth))
                {
                    var cred = ASCIIEncoding.ASCII.GetString(Convert.FromBase64String(auth.ToString().Substring(6))).Split(':');
                    var user = new { Name = cred[0], Pass = cred[1] };
                    foreach (string credentialPair in authCredentials)
                    {
                        var credentialList = credentialPair.Split("|");
                        if (user.Name == credentialList[0] && user.Pass == credentialList[1])
                        {
                            credentialMatches = true;
                            break; // Don't keep going through the credential list
                        }
                    }
                }
            }
            try
            {
                if (!credentialMatches)
                {
                    HttpContext.Response.Headers.Add("WWW-Authenticate", "Basic realm=\"This page is protected, please enter the username and password specific to the page.\"");
                    return(new UnauthorizedResult());
                }
                if ((!_signInManager.IsSignedIn(User)) && (ViewData["PageName"].ToString().Substring(0, 6) == "Draft|"))
                {
                    return(RedirectToAction("ViewPage", "Page", new { id = "Index" }));
                }
                return(View());
            }
            catch (Exception ex)
            {
                // Sometimes the string isn't long enough to be substringed
                return(View());
            }
        }