From: Frank Louwers Date: Thu, 10 Sep 2020 11:31:04 +0000 (+0200) Subject: Add youtube and duckduckgo X-Git-Tag: rec-4.5.0-alpha0~10^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a27f3758e18da6cd44c4c83592b243857ec221fd;p=thirdparty%2Fpdns.git Add youtube and duckduckgo --- diff --git a/pdns/recursordist/examples/safesearch.lua b/pdns/recursordist/examples/safesearch.lua index 2eaa61bc87..a5f3468884 100644 --- a/pdns/recursordist/examples/safesearch.lua +++ b/pdns/recursordist/examples/safesearch.lua @@ -1,5 +1,5 @@ --[[ - Both Google and Bing offer ways to enforce the use of their 'safesearch' or 'strict' functionality + Google, Youtube, Bing and DuckDuckGo offer ways to enforce the use of their 'safesearch' or 'strict' functionality for some or all of your users. This script provides a 'handleSafeSearch' function that implements enforced safe search for Google and Bing. @@ -11,6 +11,10 @@ For Bing, only 'www.bing.com' is relevant. + For Youtube: https://support.google.com/a/answer/6214622?hl=en - option 1. Note that they offer both a very strict search, and a moderate. Usually, moderate is a good balance. If you want really strict, change the youtubedomains values to 11 instead of 1. + + For DuckDuckGo: https://help.duckduckgo.com/duckduckgo-help-pages/features/safe-search/ (bottom) + There is a comment below in preresolve where you could insert code to determine if a particular user should be filtered or not ]]-- @@ -22,24 +26,52 @@ do googledomains["ipv6"..v]=2 -- this too - change to 1 to get v4 instead of NXDOMAIN end +youtubedomains={} +youtubedomains['www.youtube.com'] = 1 +youtubedomains['m.youtube.com'] = 1 +youtubedomains['youtubei.googleapis.com'] = 1 +youtubedomains['youtube.googleapis.com'] = 1 +youtubedomains['www.youtube-nocookie.com'] = 1 function handleSafeSearch(dq) local name = dq.qname:toStringNoDot():lower(); - local status = googledomains[name] - if( status == 1) then + local statusg = googledomains[name] + local statusyt = youtubedomains[name] + + if( statusg == 1) then dq:addAnswer(pdns.CNAME, "forcesafesearch.google.com") dq.rcode=0 dq.followupFunction="followCNAMERecords" return true - elseif( status == 2) then + + elseif( statusyt == 1) then + dq:addAnswer(pdns.CNAME, "restrictmoderate.youtube.com") + dq.rcode=0 + dq.followupFunction="followCNAMERecords" + return true + + elseif( statusyt == 11) then + dq:addAnswer(pdns.CNAME, "restrict.youtube.com") + dq.rcode=0 + dq.followupFunction="followCNAMERecords" + return true + + elseif( statusg == 2) then dq.rcode=pdns.NXDOMAIN -- inserting actual SOA record is a nice touch but requires figuring out country code return true + elseif(name=="www.bing.com") then dq:addAnswer(pdns.CNAME, "strict.bing.com") dq.rcode=0 dq.followupFunction="followCNAMERecords" return true + + elseif(name=="duckduckgo.com") then + dq:addAnswer(pdns.CNAME, "safe.duckduckgo.com") + dq.rcode=0 + dq.followupFunction="followCNAMERecords" + return true end return false