Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google-safe-search-example #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

henri
Copy link

@henri henri commented Jun 9, 2021

Example added for forced Google safe search using DNS.

@henri
Copy link
Author

henri commented Jun 10, 2021

Sorted those soft-tabs :)


# build google force safe search ruls for rubyDNS

google_domains = `curl https://www.google.com/supported_domains 2>> /dev/null | sed "s/^.//g"`.split("\n")
Copy link
Member

@ioquatix ioquatix Jun 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be improved.

require 'async'
require 'async/http/internet'

google_domains = Sync do
	internet = Async::HTTP::Internet.new
	response = internet.get("https://www.google.com/supported_domains")
	
	response.read.split(/\n/)
ensure
	response&.close
end

IN = Resolv::DNS::Resource::IN

# Start the RubyDNS server
RubyDNS::run_server(INTERFACES) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domains = Regexp.union(google_domains)

# Start the RubyDNS server
RubyDNS::run_server(INTERFACES) do
	@logger.debug!
	
	match(domains, IN::A) do |transaction|
		transaction.respond!(Name.create('forcesafesearch.google.com'), resource_class: IN::CNAME)
	end
	
	otherwise do |transaction|
		transaction.passthrough!(UPSTREAM)
	end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need to tweak domains but this should avoid having to generate a script/server.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domains = /#{Regexp.union(google_domains)}\z/

maybe sufficient.

@logger.debug!

#match google.com
match(/^google.com$/, IN::A) do |transaction|
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to preserve sub-domains such as admin.google.com, docs.google.com etc.

It may be necessary to do an exact match. Maybe Google handles this? Probably better to only override the specific top level domains for the force safe search?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like the idea you suggested if that can work. Even if it is just matching the exact domains within an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants