Beispiel #1
0
        protected void Application_Error(object sender, EventArgs e)
        {
            // Retrieve last error and log it, redirecting to Error.aspx (avoiding infinite loops)

            Exception ex = Server.GetLastError( );

            HttpException httpEx = ex as HttpException;

            if (httpEx != null)
            {
                // Try to redirect an inexistent .aspx page to a probably existing .ashx page
                if (httpEx.GetHttpCode( ) == 404)
                {
                    string page = Path.GetFileNameWithoutExtension(Request.PhysicalPath);
                    UrlTools.Redirect(page + Settings.PageExtension);
                    return;
                }
            }

            LogError(ex);
            string url = "";

            try
            {
                url = Tools.GetCurrentUrlFixed( );
            }
            catch { }
            EmailTools.NotifyError(ex, url);
            Session["LastError"] = Server.GetLastError( );
            if (!Request.PhysicalPath.ToLowerInvariant( ).Contains("error.aspx"))
            {
                UrlTools.Redirect("Error.aspx");
            }
        }
Beispiel #2
0
 /// <summary>
 /// Redirects to the login page if needed.
 /// </summary>
 public static void RedirectToLoginIfNeeded()
 {
     if (SessionFacade.LoginKey == null)
     {
         UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
     }
 }
        protected void btnAutoWikiUrl_Click(object sender, EventArgs e)
        {
            string url = Tools.GetCurrentUrlFixed();

            // Assume the URL contains AdminConfig.aspx
            url             = url.Substring(0, url.ToLowerInvariant().IndexOf("adminconfig.aspx"));
            txtMainUrl.Text = url;
        }
Beispiel #4
0
 /// <summary>
 /// Logs an error.
 /// </summary>
 /// <param name="ex">The error.</param>
 private void LogError(Exception ex)
 {
     //if(ex.InnerException != null) ex = ex.InnerException;
     try {
         ScrewTurn.Wiki.Log.LogEntry(Tools.GetCurrentUrlFixed() + "\n" +
                                     ex.Source + " thrown " + ex.GetType().FullName + "\n" + ex.Message + "\n" + ex.StackTrace,
                                     ScrewTurn.Wiki.PluginFramework.EntryType.Error, ScrewTurn.Wiki.Log.SystemUsername);
     }
     catch { }
 }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            currentWiki = DetectWiki();

            Page.Title = Properties.Messages.UserTitle + " - " + Settings.GetWikiTitle(currentWiki);

            currentUsername = Request["User"];
            if (string.IsNullOrEmpty(currentUsername))
            {
                currentUsername = Request["Username"];
            }
            if (string.IsNullOrEmpty(currentUsername))
            {
                UrlTools.Redirect("Default.aspx");
            }

            if (currentUsername == "admin")
            {
                currentUser = Users.GetGlobalAdministratorAccount();
            }
            else
            {
                currentUser = Users.FindUser(currentWiki, currentUsername);
            }

            if (currentUser == null)
            {
                UrlTools.Redirect("Default.aspx");
            }

            if (!Page.IsPostBack)
            {
                lblTitle.Text = lblTitle.Text.Replace("##NAME##", Users.GetDisplayName(currentUser));

                txtSubject.Text = Request["Subject"];
                if (txtSubject.Text != "" && SessionFacade.LoginKey == null)
                {
                    UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
                }
            }

            if (SessionFacade.LoginKey == null)
            {
                pnlMessage.Visible = false;
            }
            else
            {
                pnlMessage.Visible = true;
            }

            DisplayGravatar();

            DisplayRecentActivity();
        }
Beispiel #6
0
        /// <summary>
        /// Verifies read permissions for the current user, redirecting to the appropriate page if no valid permissions are found.
        /// </summary>
        public static void VerifyReadPermissionsForCurrentNamespace()
        {
            var currentUsername = SessionFacade.GetCurrentUsername();
            var currentGroups   = SessionFacade.GetCurrentGroupNames();

            var canViewNamespace = AuthChecker.CheckActionForNamespace(
                Tools.DetectCurrentNamespaceInfo(), Actions.ForNamespaces.ReadPages,
                currentUsername, currentGroups);

            if (!canViewNamespace)
            {
                if (SessionFacade.CurrentUsername == null)
                {
                    UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
                }
                else
                {
                    UrlTools.Redirect("AccessDenied.aspx");
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Verifies read permissions for the current user, redirecting to the appropriate page if no valid permissions are found.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        public static void VerifyReadPermissionsForCurrentNamespace(string wiki)
        {
            string currentUsername = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames(wiki);

            AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(wiki));

            bool canViewNamespace = authChecker.CheckActionForNamespace(
                Tools.DetectCurrentNamespaceInfo(), Actions.ForNamespaces.ReadPages,
                currentUsername, currentGroups);

            if (!canViewNamespace)
            {
                if (SessionFacade.CurrentUsername == null)
                {
                    UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
                }
                else
                {
                    UrlTools.Redirect("AccessDenied.aspx");
                }
            }
        }
Beispiel #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            currentWiki = DetectWiki();

            Page.Title = Properties.Messages.EditTitle + " - " + Settings.GetWikiTitle(currentWiki);

            lblEditNotice.Text = Formatter.FormatPhase3(currentWiki, Formatter.Format(currentWiki, Settings.GetProvider(currentWiki).GetMetaDataItem(
                                                                                          MetaDataItem.EditNotice, DetectNamespace()), false, FormattingContext.Other, null), FormattingContext.Other, null);

            // Prepare page unload warning
            string ua = Request.UserAgent;

            if (!string.IsNullOrEmpty(ua))
            {
                ua = ua.ToLowerInvariant();
                StringBuilder sbua = new StringBuilder(50);
                sbua.Append(@"<script type=""text/javascript"">");
                sbua.Append("\r\n<!--\r\n");
                if (ua.Contains("gecko"))
                {
                    // Mozilla
                    sbua.Append("addEventListener('beforeunload', __UnloadPage, true);");
                }
                else
                {
                    // IE
                    sbua.Append("window.attachEvent('onbeforeunload', __UnloadPage);");
                }
                sbua.Append("\r\n// -->\r\n");
                sbua.Append("</script>");
                lblUnloadPage.Text = sbua.ToString();
            }

            if (!Page.IsPostBack)
            {
                PopulateCategories(new CategoryInfo[0]);

                if (Settings.GetAutoGeneratePageNames(currentWiki))
                {
                    pnlPageName.Visible   = false;
                    pnlManualName.Visible = true;
                }
            }

            // Load requested page, if any
            if (Request["Page"] != null || Page.IsPostBack)
            {
                string name = null;
                if (Request["Page"] != null)
                {
                    name = Request["Page"];
                }
                else
                {
                    name = txtName.Text;
                }

                currentPage = Pages.FindPage(currentWiki, name);

                // If page already exists, load the content and disable page name,
                // otherwise pre-fill page name
                if (currentPage != null)
                {
                    keepAlive.CurrentPage = currentPage.FullName;

                    // Look for a draft
                    PageContent draftContent = Pages.GetDraft(currentPage);

                    if (draftContent == null)
                    {
                        draftContent = currentPage;
                    }
                    else
                    {
                        isDraft = true;
                    }

                    // Set current page for editor and attachment manager
                    editor.CurrentPage            = currentPage;
                    attachmentManager.CurrentPage = currentPage;

                    if (!int.TryParse(Request["Section"], out currentSection))
                    {
                        currentSection = -1;
                    }

                    // Fill data, if not posted back
                    if (!Page.IsPostBack)
                    {
                        // Set keywords, description
                        SetKeywords(draftContent.Keywords);
                        txtDescription.Text = draftContent.Description;

                        txtName.Text          = NameTools.GetLocalName(currentPage.FullName);
                        txtName.Enabled       = false;
                        pnlPageName.Visible   = false;
                        pnlManualName.Visible = false;

                        PopulateCategories(Pages.GetCategoriesForPage(currentPage));

                        txtTitle.Text = draftContent.Title;

                        // Manage section, if appropriate (disable if draft)
                        if (!isDraft && currentSection != -1)
                        {
                            int    startIndex, len;
                            string dummy = "";
                            ExtractSection(draftContent.Content, currentSection, out startIndex, out len, out dummy);
                            editor.SetContent(draftContent.Content.Substring(startIndex, len), Settings.GetUseVisualEditorAsDefault(currentWiki));
                        }
                        else
                        {
                            // Select default editor view (WikiMarkup or Visual) and populate content
                            editor.SetContent(draftContent.Content, Settings.GetUseVisualEditorAsDefault(currentWiki));
                        }
                    }
                }
                else
                {
                    // Pre-fill name, if not posted back
                    if (!Page.IsPostBack)
                    {
                        // Set both name and title, as the NAME was provided from the query-string and must be preserved
                        pnlPageName.Visible   = true;
                        pnlManualName.Visible = false;
                        txtName.Text          = NameTools.GetLocalName(name);
                        txtTitle.Text         = txtName.Text;
                        editor.SetContent(LoadTemplateIfAppropriate(), Settings.GetUseVisualEditorAsDefault(currentWiki));
                    }
                }
            }
            else
            {
                if (!Page.IsPostBack)
                {
                    chkMinorChange.Visible = false;
                    chkSaveAsDraft.Visible = false;

                    editor.SetContent(LoadTemplateIfAppropriate(), Settings.GetUseVisualEditorAsDefault(currentWiki));
                }
            }

            // Here is centralized all permissions-checking code
            DetectPermissions();

            // Verify the following permissions:
            // - if new page, check for page creation perms
            // - else, check for editing perms
            //    - full edit or edit with approval
            // - categories management
            // - attachment manager
            // - CAPTCHA if enabled and user is anonymous
            // ---> recheck every time an action is performed

            if (currentPage == null)
            {
                // Check permissions for creating new pages
                if (!canCreateNewPages)
                {
                    if (SessionFacade.LoginKey == null)
                    {
                        UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
                    }
                    else
                    {
                        UrlTools.Redirect("AccessDenied.aspx");
                    }
                }
            }
            else
            {
                // Check permissions for editing current page
                if (!canEdit && !canEditWithApproval)
                {
                    if (SessionFacade.LoginKey == null)
                    {
                        UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
                    }
                    else
                    {
                        UrlTools.Redirect("AccessDenied.aspx");
                    }
                }
            }

            if (!canEdit && canEditWithApproval)
            {
                // Hard-wire status of draft and minor change checkboxes
                chkMinorChange.Enabled = false;
                chkSaveAsDraft.Enabled = false;
                chkSaveAsDraft.Checked = true;
            }

            // Setup categories
            lstCategories.Enabled       = canManagePageCategories;
            pnlCategoryCreation.Visible = canCreateNewCategories;

            // Setup attachment manager (require at least download permissions)
            attachmentManager.Visible = canDownloadAttachments;

            // CAPTCHA
            pnlCaptcha.Visible = SessionFacade.LoginKey == null && !Settings.GetDisableCaptchaControl(currentWiki);
            captcha.Visible    = pnlCaptcha.Visible;

            // Moderation notice
            pnlApprovalRequired.Visible = !canEdit && canEditWithApproval;

            // Check and manage editing collisions
            ManageEditingCollisions();

            if (!Page.IsPostBack)
            {
                ManageTemplatesDisplay();

                // Display draft status
                ManageDraft();
            }
        }
Beispiel #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            discussMode  = Request["Discuss"] != null;
            viewCodeMode = Request["Code"] != null && !discussMode;
            if (!Settings.EnableViewPageCodeFeature)
            {
                viewCodeMode = false;
            }

            currentPage = DetectPageInfo(true);

            VerifyAndPerformRedirects();

            // The following actions are verified:
            // - View content (redirect to AccessDenied)
            // - Edit or Edit with Approval (for button display)
            // - Any Administrative activity (Rollback/Admin/Perms) (for button display)
            // - Download attachments (for button display - download permissions are also checked in GetFile)
            // - View discussion (for button display in content mode)
            // - Post discussion (for button display in discuss mode)

            string currentUsername = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames();

            bool canView             = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.ReadPage, currentUsername, currentGroups);
            bool canEdit             = false;
            bool canEditWithApproval = false;

            Pages.CanEditPage(currentPage, currentUsername, currentGroups, out canEdit, out canEditWithApproval);
            if (canEditWithApproval && canEdit)
            {
                canEditWithApproval = false;
            }
            bool canDownloadAttachments = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.DownloadAttachments, currentUsername, currentGroups);
            bool canSetPerms            = AuthChecker.CheckActionForGlobals(Actions.ForGlobals.ManagePermissions, currentUsername, currentGroups);
            bool canAdmin            = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.ManagePage, currentUsername, currentGroups);
            bool canViewDiscussion   = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.ReadDiscussion, currentUsername, currentGroups);
            bool canPostDiscussion   = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.PostDiscussion, currentUsername, currentGroups);
            bool canManageDiscussion = AuthChecker.CheckActionForPage(currentPage, Actions.ForPages.ManageDiscussion, currentUsername, currentGroups);

            if (!canView)
            {
                if (SessionFacade.LoginKey == null)
                {
                    UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
                }
                else
                {
                    UrlTools.Redirect(UrlTools.BuildUrl("AccessDenied.aspx"));
                }
            }
            attachmentViewer.Visible = canDownloadAttachments;

            attachmentViewer.PageInfo = currentPage;
            currentContent            = Content.GetPageContent(currentPage, true);

            pnlPageInfo.Visible = Settings.EnablePageInfoDiv;

            SetupTitles();

            SetupToolbarLinks(canEdit || canEditWithApproval, canViewDiscussion, canPostDiscussion, canDownloadAttachments, canAdmin, canAdmin, canSetPerms);

            SetupLabels();
            SetupPrintAndRssLinks();
            SetupMetaInformation();
            VerifyAndPerformPageRedirection();
            SetupRedirectionSource();
            SetupNavigationPaths();
            SetupAdjacentPages();

            SessionFacade.Breadcrumbs.AddPage(currentPage);
            SetupBreadcrumbsTrail();

            SetupDoubleClickHandler();

            SetupEmailNotification();

            SetupPageContent(canPostDiscussion, canManageDiscussion);

            if (currentPage != null)
            {
                Literal canonical = new Literal();
                canonical.Text = Tools.GetCanonicalUrlTag(Request.Url.ToString(), currentPage, Pages.FindNamespace(NameTools.GetNamespace(currentPage.FullName)));
                Page.Header.Controls.Add(canonical);
            }
        }