Esempio n. 1
0
 public static bool ContentContainsBannedDomain(string subverse, string contentToEvaluate)
 {
     if (!String.IsNullOrEmpty(contentToEvaluate))
     {
         Subverse s = null;
         if (!String.IsNullOrEmpty(subverse))
         {
             s = DataCache.Subverse.Retrieve(subverse);
         }
         if (s == null || (s != null && !s.ExcludeSitewideBans))
         {
             List <string> domains = new List <string>();
             ProcessMatches(Regex.Matches(contentToEvaluate, CONSTANTS.PROTOCOL_LESS_LINK_REGEX, RegexOptions.IgnoreCase), domains);
             if (domains.Count > 0)
             {
                 bool hasBannedDomainLinks = BanningUtility.IsDomainBanned(domains.ToArray());
                 if (hasBannedDomainLinks)
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Esempio n. 2
0
 public static bool ContentContainsBannedDomain(string subverse, string contentToEvaluate)
 {
     if (!String.IsNullOrEmpty(contentToEvaluate))
     {
         Subverse s = null;
         if (!String.IsNullOrEmpty(subverse))
         {
             s = DataCache.Subverse.Retrieve(subverse);
         }
         if (s == null || (s != null && !s.ExcludeSitewideBans))
         {
             MatchCollection matches = Regex.Matches(contentToEvaluate, CONSTANTS.HTTP_LINK_REGEX, RegexOptions.IgnoreCase);
             List <string>   domains = new List <string>();
             foreach (Match match in matches)
             {
                 string domain = match.Groups["domain"].Value.ToLower();
                 if (!String.IsNullOrWhiteSpace(domain) && !domains.Contains(domain))
                 {
                     domains.Add(domain);
                 }
             }
             if (domains.Count > 0)
             {
                 bool hasBannedDomainLinks = BanningUtility.IsDomainBanned(domains.ToArray());
                 if (hasBannedDomainLinks)
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Esempio n. 3
0
 public static bool ContentContainsBannedDomain(string subverse, string comment)
 {
     if (!String.IsNullOrEmpty(comment))
     {
         var s = DataCache.Subverse.Retrieve(subverse);
         if (s == null || (s != null && !s.ExcludeSitewideBans))
         {
             MatchCollection matches = Regex.Matches(comment, CONSTANTS.HTTP_LINK_REGEX, RegexOptions.IgnoreCase);
             List <string>   domains = new List <string>();
             foreach (Match match in matches)
             {
                 string   domain = match.Groups["domain"].Value;
                 string[] parts  = domain.Split('.');
                 if (parts.Length > 2)
                 {
                     domain = String.Format("{0}.{1}", parts[parts.Length - 2], parts[parts.Length - 1]);
                 }
                 domains.Add(domain);
             }
             if (domains.Count > 0)
             {
                 bool hasBannedDomainLinks = BanningUtility.IsDomainBanned(domains.ToArray());
                 if (hasBannedDomainLinks)
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Esempio n. 4
0
        // add new submission
        public static async Task <string> AddNewSubmission(Submission submissionModel, Subverse targetSubverse, string userName)
        {
            using (var db = new voatEntities())
            {
                // LINK TYPE SUBMISSION
                if (submissionModel.Type == 2)
                {
                    // strip unicode if title contains unicode
                    if (ContainsUnicode(submissionModel.LinkDescription))
                    {
                        submissionModel.LinkDescription = StripUnicode(submissionModel.LinkDescription);
                    }

                    // reject if title is whitespace or < than 5 characters
                    if (submissionModel.LinkDescription.Length < 5 || String.IsNullOrWhiteSpace(submissionModel.LinkDescription))
                    {
                        return("The title may not be less than 5 characters.");
                    }

                    // make sure the input URI is valid
                    if (!UrlUtility.IsUriValid(submissionModel.Content))
                    {
                        // ABORT
                        return("The URI you are trying to submit is invalid.");
                    }

                    // check if target subvere allows submissions from globally banned hostnames
                    if (!targetSubverse.ExcludeSitewideBans)
                    {
                        // check if hostname is banned before accepting submission
                        var domain = UrlUtility.GetDomainFromUri(submissionModel.Content);
                        if (BanningUtility.IsDomainBanned(domain))
                        {
                            // ABORT
                            return("The domain you are trying to submit is banned.");
                        }
                    }

                    // check if user has reached daily crossposting quota
                    if (UserHelper.DailyCrossPostingQuotaUsed(userName, submissionModel.Content))
                    {
                        // ABORT
                        return("You have reached your daily crossposting quota for this URL.");
                    }

                    // check if target subverse has thumbnails setting enabled before generating a thumbnail
                    if (targetSubverse.IsThumbnailEnabled)
                    {
                        // try to generate and assign a thumbnail to submission model
                        submissionModel.Thumbnail = await ThumbGenerator.ThumbnailFromSubmissionModel(submissionModel);
                    }

                    // flag the submission as anonymized if it was submitted to a subverse with active anonymized_mode
                    submissionModel.IsAnonymized = targetSubverse.IsAnonymized;
                    submissionModel.UserName     = userName;
                    submissionModel.Subverse     = targetSubverse.Name;
                    submissionModel.UpCount      = 1;
                    db.Submissions.Add(submissionModel);

                    await db.SaveChangesAsync();
                }
                else
                // MESSAGE TYPE SUBMISSION
                {
                    // strip unicode if submission contains unicode
                    if (ContainsUnicode(submissionModel.Title))
                    {
                        submissionModel.Title = StripUnicode(submissionModel.Title);
                    }

                    // reject if title is whitespace or less than 5 characters
                    if (submissionModel.Title.Length < 5 || String.IsNullOrWhiteSpace(submissionModel.Title))
                    {
                        return("Sorry, submission title may not be less than 5 characters.");
                    }

                    // grab server timestamp and modify submission timestamp to have posting time instead of "started writing submission" time
                    submissionModel.IsAnonymized = targetSubverse.IsAnonymized;
                    submissionModel.UserName     = userName;
                    submissionModel.Subverse     = targetSubverse.Name;
                    submissionModel.CreationDate = DateTime.Now;
                    submissionModel.UpCount      = 1;
                    db.Submissions.Add(submissionModel);

                    if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPreSave))
                    {
                        submissionModel.Content = ContentProcessor.Instance.Process(submissionModel.Content, ProcessingStage.InboundPreSave, submissionModel);
                    }

                    await db.SaveChangesAsync();

                    if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPostSave))
                    {
                        ContentProcessor.Instance.Process(submissionModel.Content, ProcessingStage.InboundPostSave, submissionModel);
                    }
                }
            }

            // null is returned if no errors were raised
            return(null);
        }