private void toolStripMenuItem2_Click(object sender, EventArgs e) { var linq = blockLogs.Where( (log) => { Uri uri = new Uri(log.url); return(!mainPolicy.isWhitelistedHost(uri.Host) && mainPolicy.isContentAllowed(uri.PathAndQuery, BlockPhraseScope.URL, out _)); } ); refreshLogs(linq); }
public void regexContext() { FilterPolicy filter = new FilterPolicy() { BlockedPhrases = new List <PhraseFilter>() { new PhraseFilter() { Type = BlockPhraseType.REGEX, Phrase = "la[tp]ex", Scope = BlockPhraseScope.ANY // just block it - Very bad term! }, new PhraseFilter() { Type = BlockPhraseType.REGEX, Phrase = "^(?=.*search)(?!.*google\\.com).*\\/search.*[\\?&]q\\=", Scope = BlockPhraseScope.URL, } }, AllowedDomains = new List <DomainPolicy>() { new DomainPolicy() { DomainBlocked = false, DomainFormat = ".google.com", Type = AllowDomainType.SUBDOMAINS } } }; string reason = ""; areFalse(filter.isContentAllowed("translateX: -50%", BlockPhraseScope.BODY, out reason)); areTrue(filter.isWhitelistedURL(new Uri( "https://www.google.com/search?q=normal%20search&oq=normal%20search&aqs=chrome..69i57.2865j0j1&sourceid=chrome&ie=UTF-8&safe=active") , out reason)); Console.Write(reason); }
public void newBlockFeatures() { var epAllowList = new List <EPPolicy>(); FilterPolicy filter = new FilterPolicy() { BlockedPhrases = new List <PhraseFilter>() { new PhraseFilter() { Type = BlockPhraseType.WORDCONTAINING, Phrase = "ssearch", Scope = BlockPhraseScope.URL // only search url will blocked }, new PhraseFilter() { Type = BlockPhraseType.EXACTWORD, Phrase = "veryHTMLTerm", Scope = BlockPhraseScope.BODY // like html }, new PhraseFilter() { Type = BlockPhraseType.WORDCONTAINING, Phrase = "veryBadTerm", Scope = BlockPhraseScope.ANY // just block it - Very bad term! }, }, AllowedDomains = new List <DomainPolicy>() { new DomainPolicy() { DomainBlocked = true, DomainFormat = "777.com", Type = AllowDomainType.SUBDOMAINS }, new DomainPolicy() { DomainBlocked = false, DomainFormat = "666.com", Type = AllowDomainType.SUBDOMAINS, AllowEP = epAllowList, BlockEP = new List <EPPolicy>() { new EPPolicy() { EpFormat = "\\/search(\\/{0,1})", Type = AllowEPType.REGEX } } } } }; string totalReason = ""; string reason = ""; // blocked by url\any but not body scope areFalse(filter.isWhitelistedURL("a.666.com", "/ssearch", out reason)); totalReason += reason + '\n'; areFalse(filter.isWhitelistedURL("a.666.com", "/ok?q=veryBadTerm", out reason)); totalReason += reason + '\n'; areTrue(filter.isWhitelistedURL("a.666.com", "/ok?q=veryHTMLTerm", out reason)); totalReason += "<Allowed>\n"; areFalse(filter.isContentAllowed("<veryHTMLTerm>", BlockPhraseScope.BODY, out reason)); totalReason += reason + '\n'; areTrue(filter.isContentAllowed("<ssearch>", BlockPhraseScope.BODY, out reason)); totalReason += "<Allowed>\n"; areFalse(filter.isContentAllowed("<veryBadTerm>", BlockPhraseScope.BODY, out reason)); totalReason += reason + '\n'; areTrue(filter.isContentAllowed("<veryHTMLTerm>", BlockPhraseScope.URL, out reason)); totalReason += "<Allowed>\n"; areFalse(filter.isContentAllowed("<ssearch>", BlockPhraseScope.URL, out reason)); totalReason += reason + '\n'; areFalse(filter.isContentAllowed("<veryBadTerm>", BlockPhraseScope.URL, out reason)); totalReason += reason + '\n'; areFalse(filter.isContentAllowed("<veryHTMLTerm>", BlockPhraseScope.ANY, out reason)); totalReason += reason + '\n'; areFalse(filter.isContentAllowed("<ssearch>", BlockPhraseScope.ANY, out reason)); totalReason += reason + '\n'; areFalse(filter.isContentAllowed("<veryBadTerm>", BlockPhraseScope.ANY, out reason)); totalReason += reason + '\n'; // Blocked 777 by "DomainBlocked" areFalse(filter.isWhitelistedURL("a.777.com", "/some-ep", out reason)); totalReason += reason + '\n'; // Allowed EP in 666 by default areTrue(filter.isWhitelistedURL("a.666.com", "/some-ep", out reason)); totalReason += "<Allowed>\n"; // Blocked EP in 666 by blocke EP areFalse(filter.isWhitelistedURL("a.666.com", "/some-ep/search/", out reason)); totalReason += reason + '\n'; areFalse(filter.isWhitelistedURL("a.666.com", "/some-ep/search", out reason)); totalReason += reason + '\n'; areFalse(filter.isWhitelistedURL("a.666.com", "/search/gggg", out reason)); totalReason += reason + '\n'; epAllowList.Add(new EPPolicy() { EpFormat = "/img", Type = AllowEPType.STARTWITH }); // Blocked EP in 66 when not default - no t in whitelist areFalse(filter.isWhitelistedURL("a.666.com", "/some-ep", out reason)); totalReason += reason + '\n'; // Allowed EP in 66 when w.l. and not blocked by ep areTrue(filter.isWhitelistedURL("a.666.com", "/img?a=b&b=c", out reason)); totalReason += "<Allowed>\n"; // Blocked EP in 66 when w.l. and blocked by ep areFalse(filter.isWhitelistedURL("a.666.com", "/img/search?a=b&b=c", out reason)); totalReason += reason; Console.Write(totalReason); }
public void isWhitelistedEPTest() { string reason_throwaway = ""; IHTTPFilter filter = new FilterPolicy() { BlockedPhrases = new List <PhraseFilter>() { new PhraseFilter() { Type = BlockPhraseType.WORDCONTAINING, Phrase = "bad", Scope = BlockPhraseScope.ANY }, new PhraseFilter() { Type = BlockPhraseType.REGEX, Phrase = "wor[dk]", Scope = BlockPhraseScope.ANY } } , AllowedDomains = new List <DomainPolicy>() { new DomainPolicy() { DomainBlocked = false, DomainFormat = "e.com", Type = AllowDomainType.EXACT, AllowEP = new List <EPPolicy>() { new EPPolicy() { Type = AllowEPType.STARTWITH, EpFormat = "/i-am-whitelisted" } } } } }; string ep1 = "/search?q=verybadword"; string ep2 = "/i-am-whitelisted"; string ep3 = "/i-am-whitelisted/badword"; // any ep except bad phrases: areTrue(filter.isWhitelistedEP(new DomainPolicy() { DomainBlocked = false, DomainFormat = "", Type = AllowDomainType.EXACT, AllowEP = new List <EPPolicy>() }, ep1, out reason_throwaway)); areFalse(filter.isContentAllowed(ep1, BlockPhraseScope.URL, out reason_throwaway)); // only ep that are whitelisted var domain1 = ((FilterPolicy)filter).AllowedDomains[0]; areTrue(filter.isWhitelistedEP(domain1, ep2, out reason_throwaway)); areFalse(filter.isWhitelistedEP(domain1, "/not-whitelisted", out reason_throwaway)); areTrue(filter.isWhitelistedEP(domain1, ep2 + "/work", out reason_throwaway)); areFalse(filter.isContentAllowed(ep2 + "/work", BlockPhraseScope.URL, out reason_throwaway)); areFalse(filter.isWhitelistedURL(new Uri("http://e.com" + ep2 + "/work"), out reason_throwaway)); // does both checks areFalse(filter.isContentAllowed(ep3, BlockPhraseScope.URL, out reason_throwaway)); areFalse(filter.isWhitelistedURL(new Uri("http://e.com" + ep3), out reason_throwaway)); // does both checks areFalse(filter.isWhitelistedEP(null, "", out reason_throwaway)); }