Exemple #1
0
        public static void FixReferralSpam(string path)
        {
            string bad                = ConfigurationManager.AppSettings["badWords"];
            long   badWordsCount      = 0;
            long   totalBadWordsCount = 0;

            DirectoryInfo info = new DirectoryInfo("../../");

            ReferralBlackListFactory.AddBlacklist(new MovableTypeBlacklist(), Path.Combine(info.FullName, "blacklist.txt"));

            if (bad != null && bad.Length > 0)
            {
                ReferralBlackListFactory.AddBlacklist(new ReferralUrlBlacklist(), bad);
            }

            string ourNamespace = "urn:newtelligence-com:dasblog:runtime:data";

            foreach (string file in Directory.GetFiles(path, "*.dayfeedback.xml"))
            {
                badWordsCount = 0;
                NameTable           nt        = new NameTable();
                object              permaLink = nt.Add("PermaLink");
                XmlNamespaceManager ns        = new XmlNamespaceManager(nt);
                ns.AddNamespace("def", ourNamespace);
                XmlDocument x = new XmlDocument(nt);
                try
                {
                    x.Load(file);
                }
                catch (XmlException ex)
                {
                    WriteLine(String.Format("ERROR: Malformed Xml in file: {0}", file));
                    WriteLine(ex.ToString());
                    Console.WriteLine("Press ENTER to continue...");
                    Console.ReadLine();
                }

                XmlNodeList nodes = x.SelectNodes("/def:DayExtra/def:Trackings/def:Tracking", ns);
                Console.WriteLine("Found {0} trackings/referrals in {1}", nodes.Count, file);
                for (int i = 0; i < nodes.Count; i++)
                {
                    XmlNode node          = nodes[i];
                    XmlNode permaLinkNode = node[(string)permaLink];
                    if (permaLinkNode != null && IsBadNode(permaLinkNode.InnerText))
                    {
                        badWordsCount++;
                        totalBadWordsCount++;
                        node.ParentNode.RemoveChild(node);
                    }
                }
                if (badWordsCount > 0)
                {
                    x.Save(file);
                }
                WriteLine(String.Format("Found {0} bad words in {1}...", badWordsCount, Path.GetFileName(file)));
            }
        }
        protected void buttonSave_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                // There were validation errors, save client states.
                CleanGravatar();
                CleanAutoExpire();
                CleanHtmlComments();
                CleanGeoRss();
                return;
            }

            SharedBasePage requestPage = Page as SharedBasePage;
            SiteConfig     siteConfig  = requestPage.SiteConfig;

            siteConfig.Contact             = textContact.Text;
            siteConfig.Copyright           = textCopyright.Text;
            siteConfig.FrontPageCategory   = textFrontPageCategory.Text;
            siteConfig.FrontPageDayCount   = int.Parse(textFrontPageDayCount.Text);
            siteConfig.FrontPageEntryCount = int.Parse(textFrontPageEntryCount.Text);
            siteConfig.EntriesPerPage      = int.Parse(textEntriesPerPage.Text);
            try
            {
                siteConfig.ContentLookaheadDays = int.Parse(textContentLookaheadDays.Text);
            }
            catch (FormatException)
            {
                siteConfig.ContentLookaheadDays = 0;
            }
            siteConfig.RssDayCount               = int.Parse(textMainMaxDaysInRss.Text);
            siteConfig.RssMainEntryCount         = int.Parse(textMainMaxEntriesInRss.Text);
            siteConfig.RssEntryCount             = int.Parse(textOtherMaxEntriesInRss.Text);
            siteConfig.AlwaysIncludeContentInRSS = checkAlwaysIncludeContentInRSS.Checked;
            siteConfig.EnableRssItemFooters      = checkEnableRSSItemFooter.Checked;
            siteConfig.RssItemFooter             = textRSSItemFooter.Text;
            siteConfig.RSSEndPointRewrite        = txtRSSEndPointRewrite.Text;
            siteConfig.EnablePop3        = checkPop3Enabled.Checked;
            siteConfig.Pop3Interval      = int.Parse(textPop3Interval.Text);
            siteConfig.Pop3Server        = textPop3Server.Text;
            siteConfig.Pop3SubjectPrefix = textPop3SubjectPrefix.Text;
            siteConfig.Pop3Username      = textPop3Username.Text;
            if (textPop3Password.Text.Length > 0 &&
                textPop3Password.Text != passwordPlaceHolder)
            {
                siteConfig.Pop3Password = textPop3Password.Text;
            }
            siteConfig.Pop3DeleteAllMessages = mailDeletionAll.Checked;
            siteConfig.Pop3LogIgnoredEmails  = logIgnoredEmails.Checked;
            siteConfig.EnableXSSUpstream     = checkXssEnabled.Checked;
            siteConfig.XSSUpstreamEndpoint   = textXssEndpoint.Text;
            siteConfig.XSSUpstreamInterval   = int.Parse(textXssInterval.Text);
            if (textXssPassword.Text.Length > 0 &&
                textXssPassword.Text != passwordPlaceHolder)
            {
                siteConfig.XSSUpstreamPassword = textXssPassword.Text;
            }
            siteConfig.XSSUpstreamUsername = textXssUsername.Text;
            siteConfig.XSSRSSFilename      = textXssRssFilename.Text;

            siteConfig.Root                                   = textRoot.Text;
            siteConfig.SmtpServer                             = textSmtpServer.Text;
            siteConfig.SmtpPort                               = int.Parse(textSmtpPort.Text);
            siteConfig.UseSSLForSMTP                          = checkUseSSLForSMTP.Checked;
            siteConfig.NotificationEMailAddress               = textNotificationEmailAddress.Text;
            siteConfig.SendCommentsByEmail                    = checkComments.Checked;
            siteConfig.EnableCoComment                        = checkEnableCoComment.Checked;
            siteConfig.SendPingbacksByEmail                   = checkPingbacks.Checked;
            siteConfig.SendReferralsByEmail                   = checkReferrals.Checked;
            siteConfig.SendTrackbacksByEmail                  = checkTrackbacks.Checked;
            siteConfig.SendPostsByEmail                       = checkPosts.Checked;
            siteConfig.EnableAutoPingback                     = checkEnableAutoPingback.Checked;
            siteConfig.EnableBloggerApi                       = checkEnableBloggerApi.Checked;
            siteConfig.EnableComments                         = checkEnableComments.Checked;
            siteConfig.EnableCommentApi                       = checkEnableCommentApi.Checked;
            siteConfig.ShowCommentsWhenViewingEntry           = checkShowCommentsWhenViewingEntry.Checked;
            siteConfig.EnableConfigEditService                = checkEnableConfigEditService.Checked;
            siteConfig.EnableEditService                      = checkEnableEditService.Checked;
            siteConfig.EnableAutoSave                         = checkEnableAutoSave.Checked;
            siteConfig.EnableTrackbackService                 = checkEnableTrackbackService.Checked;
            siteConfig.EnablePingbackService                  = checkEnablePingbackService.Checked;
            siteConfig.EnableClickThrough                     = checkEnableClickThrough.Checked;
            siteConfig.EnableAggregatorBugging                = checkEnableAggregatorBugging.Checked;
            siteConfig.Subtitle                               = textSubtitle.Text;
            siteConfig.Title                                  = textTitle.Text;
            siteConfig.ShowCommentCount                       = checkShowCommentCounters.Checked;
            siteConfig.Pop3InlineAttachedPictures             = checkPop3InlineAttachedPictures.Checked;
            siteConfig.Pop3InlinedAttachedPicturesThumbHeight = int.Parse(textPop3AttachedPicturesPictureThumbnailHeight.Text);
            siteConfig.ShowItemDescriptionInAggregatedViews   = checkShowItemDescriptionInAggregatedViews.Checked;
            siteConfig.EnableStartPageCaching                 = checkEnableStartPageCaching.Checked;
            siteConfig.EnableBlogrollDescription              = checkEnableBlogrollDescription.Checked;
            siteConfig.EnableUrlRewriting                     = checkEnableUrlRewriting.Checked;
            siteConfig.DisplayTimeZoneIndex                   = Convert.ToInt32(listTimeZones.SelectedValue);
            siteConfig.AdjustDisplayTimeZone                  = !checkUseUTC.Checked;
            siteConfig.EntryTitleAsLink                       = checkEntryTitleAsLink.Checked;
            siteConfig.EnableCrossposts                       = checkEnableCrosspost.Checked;
            if (textPassword.Text.Length > 0 &&
                textPassword.Text != passwordPlaceHolder)
            {
                SiteSecurity.SetPassword(requestPage.User.Identity.Name, textPassword.Text);
            }
            siteConfig.CategoryAllEntries = checkCategoryAllEntries.Checked;
            requestPage.UserTheme         = siteConfig.Theme = listThemes.SelectedValue;

            siteConfig.ReferralUrlBlackList       = textReferralBlacklist.Text.TrimEnd(';');
            siteConfig.EnableReferralUrlBlackList = checkReferralUrlBlacklist.Checked;
            siteConfig.EnableCaptcha = checkCaptchaEnabled.Checked;
            siteConfig.EnableReferralUrlBlackList404s = checkReferralBlacklist404s.Checked;
            siteConfig.ChannelImageUrl            = textRSSChannelImage.Text;
            siteConfig.EnableTitlePermaLink       = checkEnableTitlePermaLink.Checked;
            siteConfig.EnableTitlePermaLinkUnique = checkEnableTitlePermaLinkUnique.Checked;
            siteConfig.EnableTitlePermaLinkSpaces = checkEnableTitlePermaLinkSpaces.Checked;
            siteConfig.EncryptLoginPassword       = checkEnableEncryptLoginPassword.Checked;
            siteConfig.EnableSmtpAuthentication   = checkEnableSmtpAuthentication.Checked;
            siteConfig.SmtpUserName = textSmtpUsername.Text;
            if (textSmtpPassword.Text.Length > 0 &&
                textSmtpPassword.Text != passwordPlaceHolder)
            {
                siteConfig.SmtpPassword = textSmtpPassword.Text;
            }
            siteConfig.RssLanguage           = textRssLanguage.Text;
            siteConfig.EnableSearchHighlight = checkEnableSearchHighlight.Checked;
            siteConfig.EnableEntryReferrals  = checkEnableEntryReferral.Checked;

            siteConfig.FeedBurnerName = textFeedBurnerName.Text.Trim();
            siteConfig.UseFeedSchemeForSyndication = checkUseFeedScheme.Checked;
            siteConfig.LogBlockedReferrals         = checkLogBlockedReferrals.Checked;
            siteConfig.EnableSpamBlockingService   = checkSpamBlockingEnabled.Checked;
            siteConfig.SpamBlockingServiceApiKey   = textSpamBlockingApiKey.Text;
            siteConfig.EnableSpamModeration        = (optionSpamHandling.SelectedValue != SPAM_OPTION_DELETE);
            siteConfig.EnableCommentDays           = checkEnableCommentDays.Checked;
            siteConfig.HtmlTidyContent             = checkAttemptToHtmlTidyContent.Checked;
            siteConfig.ResolveCommenterIP          = checkResolveCommenterIP.Checked;

            siteConfig.TitlePermalinkSpaceReplacement = dropDownTitlePermalinkReplacementCharacter.SelectedValue;

            if (checkEnableCommentDays.Checked)
            {
                try
                {
                    int days = Convert.ToInt32(textDaysCommentsAllowed.Text);
                    if (days > 0)
                    {
                        siteConfig.DaysCommentsAllowed = days;
                    }
                }
                catch (FormatException)
                {
                    siteConfig.DaysCommentsAllowed = 60;
                }
            }
            else
            {
                siteConfig.DaysCommentsAllowed = 60;
            }

            // comments approval
            siteConfig.CommentsRequireApproval = checkCommentsRequireApproval.Checked;

            // removed the ability to edit the html tags, which are allowed for now
            foreach (ListItem li in checkBoxListAllowedTags.Items)
            {
                ValidTag tag = siteConfig.AllowedTags[li.Value];
                if (tag != null)
                {
                    tag.IsAllowed = li.Selected;
                }
            }

            // comments allow html
            siteConfig.CommentsAllowHtml = checkAllowHtml.Checked;

            // comments allow Gravatar and alt path
            GravatarPopulateConfig();

            // supress email address display
            siteConfig.SupressEmailAddressDisplay = checkDisableEmailDisplay.Checked;

            // enable daily report email
            siteConfig.EnableDailyReportEmail = checkDailyReport.Checked;

            PingServiceCollection savePingServices = new PingServiceCollection();

            foreach (PingService pingService in PingServiceCollection)
            {
                if (checkBoxListPingServices.Items.FindByValue(pingService.Endpoint).Selected)
                {
                    savePingServices.Add(pingService);
                }
            }

            siteConfig.PingServices     = savePingServices;
            siteConfig.EntryEditControl = drpEntryEditControl.SelectedValue;

            // GeoRSS stuff.
            siteConfig.EnableGeoRss = checkEnableGeoRss.Checked;
            if (checkEnableGeoRss.Checked)
            {
                siteConfig.EnableDefaultLatLongForNonGeoCodedPosts = checkEnableDefaultLatLongForNonGeoCodedPosts.Checked;
                if (checkEnableDefaultLatLongForNonGeoCodedPosts.Checked)
                {
                    double latitude;
                    if (double.TryParse(textDefaultLatitude.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out latitude))
                    {
                        siteConfig.DefaultLatitude = latitude;
                    }

                    double longitude;
                    if (double.TryParse(textDefaultLongitude.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out longitude))
                    {
                        siteConfig.DefaultLongitude = longitude;
                    }
                }

                siteConfig.EnableGoogleMaps = checkEnableGoogleMaps.Checked;
                if (checkEnableGoogleMaps.Checked)
                {
                    siteConfig.GoogleMapsApiKey = textGoogleMapsApi.Text;
                }
            }

            // open id stuff
            siteConfig.AllowOpenIdAdmin        = chkAllowOpenIdAdmin.Checked;
            siteConfig.AllowOpenIdComments     = chkAllowOpenIdCommenter.Checked;
            siteConfig.BypassSpamOpenIdComment = chkBypassSpamOpenIdCommenter.Checked;

            siteConfig.AMPPagesEnabled = checkAmpEnabled.Checked;

            SiteConfig.Save(siteConfig);

            SeoMetaTags smt = new SeoMetaTags().GetMetaTags();

            smt.MetaDescription = txtMetaDescription.Text;
            smt.MetaKeywords    = txtMetaKeywords.Text;
            smt.TwitterCard     = txtTwitterCard.Text;
            smt.TwitterSite     = txtTwitterSite.Text;
            smt.TwitterCreator  = txtTwitterCreator.Text;
            smt.TwitterImage    = txtTwitterImage.Text;
            smt.FaceBookAdmins  = txtFaceBookAdmins.Text;
            smt.FaceBookAppID   = txtFaceBookAppID.Text;

            SeoMetaTags.Save(smt);

            if (siteConfig.EnableReferralUrlBlackList && siteConfig.ReferralUrlBlackList.Length != 0)
            {
                ReferralBlackListFactory.AddBlacklist(new ReferralUrlBlacklist(), siteConfig.ReferralUrlBlackList);
            }
            else
            {
                ReferralBlackListFactory.RemoveBlacklist(typeof(ReferralUrlBlacklist));
            }

            requestPage.Redirect(Page.Request.Url.AbsoluteUri);
        }
        protected void Application_Start(Object sender, EventArgs e)
        {
            //We clear out the Cache on App Restart...
            CacheFactory.GetCache().Clear();

            ILoggingDataService loggingService = null;

            loggingService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
            loggingService.AddEvent(new EventDataItem(EventCodes.ApplicationStartup, "", ""));

            SiteConfig siteConfig = SiteConfig.GetSiteConfig(SiteConfig.GetConfigFilePathFromCurrentContext());

            //if (siteConfig.EnableReportMailer)
            {
                reportMailer = new ReportMailer(
                    SiteConfig.GetConfigFilePathFromCurrentContext(),
                    SiteConfig.GetContentPathFromCurrentContext(),
                    SiteConfig.GetLogPathFromCurrentContext()
                    );

                reportMailerThread              = new Thread(new ThreadStart(reportMailer.Run));
                reportMailerThread.Name         = "ReportMailer";
                reportMailerThread.IsBackground = true;
                reportMailerThread.Start();
            }

            if (siteConfig.EnablePop3)
            {
                mailToWeblog = new MailToWeblog(
                    SiteConfig.GetConfigFilePathFromCurrentContext(),
                    SiteConfig.GetContentPathFromCurrentContext(),
                    SiteConfig.GetBinariesPathFromCurrentContext(),
                    SiteConfig.GetLogPathFromCurrentContext(),
                    new Uri(new Uri(SiteConfig.GetSiteConfig().Root), SiteConfig.GetSiteConfig().BinariesDirRelative)
                    );

                mailToWeblogThread              = new Thread(new ThreadStart(mailToWeblog.Run));
                mailToWeblogThread.Name         = "MailToWeblog";
                mailToWeblogThread.IsBackground = true;
                mailToWeblogThread.Start();
            }

            if (siteConfig.EnableXSSUpstream)
            {
                xssUpstreamer = new XSSUpstreamer(
                    SiteConfig.GetConfigFilePathFromCurrentContext(),
                    SiteConfig.GetContentPathFromCurrentContext(),
                    SiteConfig.GetLogPathFromCurrentContext()
                    );

                xssUpstreamerThread              = new Thread(new ThreadStart(xssUpstreamer.Run));
                xssUpstreamerThread.Name         = "XSSUpstreamer";
                xssUpstreamerThread.IsBackground = true;
                xssUpstreamerThread.Start();
            }

            /*
             * if (siteConfig.EnableMovableTypeBlackList)
             * {
             *      ReferralBlackListFactory.AddBlacklist(new MovableTypeBlacklist(), Path.Combine(SiteConfig.GetConfigPathFromCurrentContext(), "blacklist.txt"));
             * }
             */

            if (siteConfig.EnableReferralUrlBlackList && siteConfig.ReferralUrlBlackList.Length != 0)
            {
                ReferralBlackListFactory.AddBlacklist(new ReferralUrlBlacklist(), siteConfig.ReferralUrlBlackList);
            }
        }