protected void cvCaptcha_ServerValidate(object source, ServerValidateEventArgs args) { if (!Settings.GetDisableCaptchaControl(Tools.DetectCurrentWiki())) { args.IsValid = txtCaptcha.Text == SessionFacade.GetCaptcha(); } else { args.IsValid = true; } }
/// <summary> /// Loads the security configuration. /// </summary> /// <param name="wiki">The wiki.</param> private void LoadSecurityConfig(string currentWiki) { chkAllowUsersToRegister.Checked = Settings.UsersCanRegister(currentWiki); PopulateAccountActivationMode(Settings.GetAccountActivationMode(currentWiki)); PopulateDefaultGroups(Settings.GetUsersGroup(currentWiki), Settings.GetAdministratorsGroup(currentWiki), Settings.GetAnonymousGroup(currentWiki)); chkEnableCaptchaControl.Checked = !Settings.GetDisableCaptchaControl(currentWiki); chkPreventConcurrentEditing.Checked = Settings.GetDisableConcurrentEditing(currentWiki); switch (Settings.GetModerationMode(currentWiki)) { case ChangeModerationMode.None: rdoNoModeration.Checked = true; break; case ChangeModerationMode.RequirePageViewingPermissions: rdoRequirePageViewingPermissions.Checked = true; break; case ChangeModerationMode.RequirePageEditingPermissions: rdoRequirePageEditingPermissions.Checked = true; break; } txtExtensionsAllowed.Text = string.Join(", ", Settings.GetAllowedFileTypes(currentWiki)); lstFileDownloadCountFilterMode.SelectedIndex = -1; switch (Settings.GetFileDownloadCountFilterMode(currentWiki)) { case FileDownloadCountFilterMode.CountAll: lstFileDownloadCountFilterMode.SelectedIndex = 0; txtFileDownloadCountFilter.Enabled = false; break; case FileDownloadCountFilterMode.CountSpecifiedExtensions: lstFileDownloadCountFilterMode.SelectedIndex = 1; txtFileDownloadCountFilter.Enabled = true; txtFileDownloadCountFilter.Text = string.Join(", ", Settings.GetFileDownloadCountFilter(currentWiki)); break; case FileDownloadCountFilterMode.ExcludeSpecifiedExtensions: txtFileDownloadCountFilter.Text = string.Join(", ", Settings.GetFileDownloadCountFilter(currentWiki)); txtFileDownloadCountFilter.Enabled = true; lstFileDownloadCountFilterMode.SelectedIndex = 2; break; default: throw new NotSupportedException(); } chkAllowScriptTags.Checked = Settings.GetScriptTagsAllowed(currentWiki); txtIpHostFilter.Text = Settings.GetIpHostFilter(currentWiki); }
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(); } }
protected void Page_Load(object sender, EventArgs e) { currentWiki = DetectWiki(); if (SessionFacade.LoginKey != null) { UrlTools.Redirect("Profile.aspx"); return; } // Test whether the default Users Provider is read-only IUsersStorageProviderV40 p = Collectors.CollectorsBox.UsersProviderCollector.GetProvider(GlobalSettings.DefaultUsersProvider, currentWiki); if (p.UserAccountsReadOnly) { Log.LogEntry("Default Users Provider (" + p.Information.Name + ") is read-only, aborting Account Creation", EntryType.Warning, Log.SystemUsername, currentWiki); UrlTools.Redirect(UrlTools.BuildUrl(currentWiki, "Error.aspx")); } PrintRegisterNotice(); Page.Title = Properties.Messages.RegisterTitle + " - " + Settings.GetWikiTitle(currentWiki); if (!Settings.UsersCanRegister(currentWiki)) { UrlTools.Redirect(UrlTools.BuildUrl(currentWiki, "AccessDenied.aspx")); } switch (Settings.GetAccountActivationMode(currentWiki)) { case AccountActivationMode.Email: lblAccountActivationMode.Text = Properties.Messages.ActivationEmail; break; case AccountActivationMode.Administrator: lblAccountActivationMode.Text = Properties.Messages.ActivationAdmin; break; case AccountActivationMode.Auto: lblAccountActivationMode.Text = Properties.Messages.ActivationAuto; break; } if (Settings.GetDisableCaptchaControl(currentWiki)) { lblCaptcha.Visible = false; captcha.Visible = false; } if (!Page.IsPostBack) { rxvUserName.ValidationExpression = GlobalSettings.UsernameRegex; rxvDisplayName.ValidationExpression = GlobalSettings.DisplayNameRegex; rxvEmail1.ValidationExpression = GlobalSettings.EmailRegex; rxvPassword1.ValidationExpression = GlobalSettings.PasswordRegex; } if (Page.IsPostBack) { // Preserve password value (a bit insecure but much more usable) txtPassword1.Attributes.Add("value", txtPassword1.Text); txtPassword2.Attributes.Add("value", txtPassword2.Text); } }
protected void Page_Load(object sender, EventArgs e) { currentWiki = DetectWiki(); Page.Title = Properties.Messages.PostTitle + " - " + Settings.GetWikiTitle(currentWiki); if (Request["Page"] == null) { UrlTools.RedirectHome(currentWiki); } page = Pages.FindPage(currentWiki, Request["Page"]); if (page == null) { UrlTools.RedirectHome(currentWiki); } editor.CurrentPage = page; if (page.Provider.ReadOnly) { UrlTools.Redirect(UrlTools.BuildUrl(currentWiki, page.FullName, GlobalSettings.PageExtension)); } if (!Page.IsPostBack) { lblTitle.Text += " - " + FormattingPipeline.PrepareTitle(currentWiki, page.Title, false, FormattingContext.MessageBody, page.FullName); } // Verify permissions and setup captcha AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki)); bool canPostMessage = authChecker.CheckActionForPage(page.FullName, Actions.ForPages.PostDiscussion, SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames(currentWiki)); if (!canPostMessage) { UrlTools.Redirect(UrlTools.BuildUrl(currentWiki, Tools.UrlEncode(page.FullName), GlobalSettings.PageExtension)); } captcha.Visible = SessionFacade.LoginKey == null && !Settings.GetDisableCaptchaControl(currentWiki); if (Page.IsPostBack) { return; } editor.SetContent("", Settings.GetUseVisualEditorAsDefault(currentWiki)); string username = Request.UserHostAddress; if (SessionFacade.LoginKey != null) { username = SessionFacade.CurrentUsername; } bool edit = Request["Edit"] != null; if (!edit) { if (Request["Parent"] != null) { try { int.Parse(Request["Parent"]); } catch { UrlTools.RedirectHome(currentWiki); } Message[] messages = Pages.GetPageMessages(page); Message parent = Pages.FindMessage(messages, int.Parse(Request["Parent"])); if (parent != null) { txtSubject.Text = (!parent.Subject.ToLowerInvariant().StartsWith("re:") ? "Re: " : "") + parent.Subject; } } } else { try { int.Parse(Request["Edit"]); } catch { UrlTools.RedirectHome(currentWiki); } Message[] messages = Pages.GetPageMessages(page); Message msg = Pages.FindMessage(messages, int.Parse(Request["Edit"])); if (msg != null) { txtSubject.Text = msg.Subject; editor.SetContent(msg.Body, Settings.GetUseVisualEditorAsDefault(currentWiki)); } else { throw new Exception("Message not found (" + page.FullName + "." + Request["Edit"] + ")."); } } }