-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# 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") | ||
|
||
google_domains.each do | dom | | ||
|
||
puts "" | ||
puts "#match #{dom}" | ||
puts "match(/^#{dom}$/, IN::A) do |transaction|" | ||
puts " transaction.respond!(Name.create('forcesafesearch.google.com'), resource_class: IN::CNAME)" | ||
puts "end" | ||
puts "match(/^www.#{dom}$/, IN::A) do |transaction|" | ||
puts " transaction.respond!(Name.create('forcesafesearch.google.com'), resource_class: IN::CNAME)" | ||
puts "end" | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env ruby | ||
require 'rubydns' | ||
|
||
INTERFACES = [ | ||
[:udp, "0.0.0.0", 5300], | ||
[:tcp, "0.0.0.0", 5300], | ||
] | ||
|
||
# Use upstream DNS for name resolution. | ||
UPSTREAM = RubyDNS::Resolver.new([ | ||
[:udp, "8.8.8.8", 53], | ||
[:tcp, "8.8.8.8", 53] | ||
]) | ||
|
||
$R = Resolv::DNS.new | ||
Name = Resolv::DNS::Name | ||
IN = Resolv::DNS::Resource::IN | ||
|
||
# Start the RubyDNS server | ||
RubyDNS::run_server(INTERFACES) do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might need to tweak There was a problem hiding this comment. Choose a reason for hiding this commentThe 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| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
transaction.respond!(Name.create('forcesafesearch.google.com'), resource_class: IN::CNAME) | ||
end | ||
match(/^www.google.com$/, IN::A) do |transaction| | ||
transaction.respond!(Name.create('forcesafesearch.google.com'), resource_class: IN::CNAME) | ||
end | ||
|
||
otherwise do |transaction| | ||
transaction.passthrough!(UPSTREAM) | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be improved.