}
-- Implements Google Safe Search
-local function safesearch_google(state, query)
- local qname = kres.dname2str(query.sname)
+local function safesearch_google(response)
+ return function(state, query)
+ local qname = kres.dname2str(query.sname)
- -- Check if we need to handle this
- if not qname:match("^google%.") and not qname:match("^www%.google%.") then
- return policy.PASS
- end
+ -- Check if we need to handle this
+ if not qname:match("^google%.") and not qname:match("^www%.google%.") then
+ return policy.PASS
+ end
- -- Check if the TLD is any of the valid Google TLDs
- for i, tld in ipairs(GOOGLE_TLDS) do
- if qname == string.format("google.%s.", tld)
- or qname == string.format("www.google.%s.", tld) then
- return policy.ANSWER({
- [kres.type.CNAME] = {
- rdata = kres.str2dname("forcesafesearch.google.com."),
- ttl = 60
- }
- })
+ -- Check if the TLD is any of the valid Google TLDs
+ for i, tld in ipairs(GOOGLE_TLDS) do
+ if qname == string.format("google.%s.", tld)
+ or qname == string.format("www.google.%s.", tld) then
+ return response
+ end
end
end
end
return
end
+ -- Helper to respond with a CNAME
+ local function response(name)
+ return policy.ANSWER({
+ [kres.type.CNAME] = {
+ rdata = kres.str2dname(name),
+ ttl = 60,
+ }
+ })
+ end
+
-- Enable Googe Safe Search
- policy.add(safesearch_google)
+ policy.add(safesearch_google(response("forcesafesearch.google.com")))
+
+ -- Enable Bing Strict Search
+ policy.add(
+ policy.domains(
+ response("strict.bing.com"),
+ { "bing.com", "www.bing.com" }
+ )
+ )
+
+ -- Enable DuckDuckGo Safe Search
+ policy.add(
+ policy.domains(
+ response("safe.duckduckgo.com"),
+ { "duckduckgo.com", "www.duckduckgo.com" }
+ )
+ )
+
+ -- Enable Yandex Family Search
+ policy.add(
+ policy.domains(
+ response("familysearch.yandex.com"),
+ { "yandex.com", "www.yandex.com" }
+ )
+ )
+ policy.add(
+ policy.domains(
+ response("familysearch.yandex.ru"),
+ { "yandex.ru", "www.yandex.ru" }
+ )
+ )
end
-- Loads the Forwarding Rules