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

update info for blocked domains #162

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.3
3.0.2
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
FROM internetee/ruby:3.0.2

RUN apt-get update -y > /dev/null
RUN apt-get install whois -y > /dev/null
RUN mkdir -p /opt/webapps/app/tmp/pids
# RUN apt-get update -y > /dev/null
# RUN apt-get install whois -y > /dev/null
WORKDIR /opt/webapps/app

RUN mkdir -p /opt/webapps/app/tmp/pids
RUN touch /opt/webapps/app/tmp/pids/.keep

COPY Gemfile Gemfile.lock ./
RUN gem install bundler && bundle install --jobs 20 --retry 5

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ group :development do
end

group :development, :test do
gem 'minitest'
gem 'minitest', '~> 5.16.3' # Обновлено до последней версии
gem 'simplecov', '0.17.1', require: false # CC last supported v0.17
end
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ DEPENDENCIES
dotenv
eventmachine (~> 1.2.7)
mina (~> 1.2.4)
minitest
minitest (~> 5.16.3)
pg (~> 1.4.0)
pry (~> 0.14.1)
rubocop
simplecov (= 0.17.1)
simpleidn (~> 0.2.1)

BUNDLED WITH
2.2.17
2.5.22
77 changes: 59 additions & 18 deletions lib/whois_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,67 @@ def connection

def receive_data(data)
connection
begin
ip = Socket.unpack_sockaddr_in(get_peername)
rescue StandardError::TypeError => e
logger.error("uncaught #{e} exception while handling connection: #{e.message}")
close_connection
end
ip = get_client_ip
return if ip.nil?

validator = UnicodeValidator.new(data)
invalid_data = !validator.valid?
name = sanitize_domain_name(data)
return if name.nil?

process_whois_request(name, ip, data)
close_connection_after_writing
end

private

if invalid_data
def get_client_ip
Socket.unpack_sockaddr_in(get_peername)
rescue StandardError::TypeError => e
logger.error("uncaught #{e} exception while handling connection: #{e.message}")
close_connection
nil
end

def sanitize_domain_name(data)
validator = UnicodeValidator.new(data)
if !validator.valid?
logger.info "#{ip}: requested domain name is not in utf-8"
send_data(invalid_encoding_msg)
close_connection_after_writing
return
return nil
end

name = data.strip
name = name.downcase
name = SimpleIDN.to_unicode(name)
SimpleIDN.to_unicode(data.strip.downcase)
end

def process_whois_request(name, ip, original_data)
if special_ee_domain?(name)
handle_special_ee_domain(name, ip, original_data)
else
handle_regular_domain(name, ip, original_data)
end
end

def special_ee_domain?(name)
%w[pri.ee fie.ee med.ee com.ee].include?(name)
end

def handle_special_ee_domain(name, ip, original_data)
logger.info "#{ip}: requested: #{original_data} [searched by: #{name}; Special .ee second-level domain]"
send_data special_ee_domain_msg(name)
end

def handle_regular_domain(name, ip, original_data)
whois_record = WhoisRecord.find_by(name: name)

if whois_record
logger.info "#{ip}: requested: #{data} [searched by: #{name}; Record found with id: #{whois_record.try(:id)}]"
logger.info "#{ip}: requested: #{original_data} [searched by: #{name}; Record found with id: #{whois_record.try(:id)}]"
send_data whois_record.unix_body
else
logger.info "#{ip}: requested: #{data} [searched by: #{name}; No record found]"
logger.info "#{ip}: requested: #{original_data} [searched by: #{name}; No record found]"
provide_data_body(name)
end
close_connection_after_writing
end

private

def provide_data_body(domain_name)
return send_data(no_entries_msg) if domain_valid_format?(domain_name)

Expand Down Expand Up @@ -107,6 +134,20 @@ def footer_msg
"\n\nEstonia .ee Top Level Domain WHOIS server\n" \
"More information at http://internet.ee\n"
end

def special_ee_domain_msg(domain)
<<~MSG
Estonia .ee Top Level Domain WHOIS server

Domain:
name: #{domain}
status: Blocked

Estonia .ee Top Level Domain WHOIS server
More information at http://internet.ee

MSG
end
end

EventMachine.run do
Expand Down
2 changes: 2 additions & 0 deletions log/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*
*/
!.gitignore
tmp/pids/
.DS_Store
15 changes: 15 additions & 0 deletions test/models/whois_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,19 @@ def test_disputed_record_is_inactive_if_unregistered
assert !@whois_record.active?
end

def test_special_ee_second_level_domains
special_domains = %w[pri.ee fie.ee med.ee com.ee]
special_domains.each do |domain|
@whois_record = WhoisRecord.new(name: domain, json: { name: domain, status: ['Blocked'] })

output = @whois_record.unix_body

assert_match(/Estonia .ee Top Level Domain WHOIS server/, output)
assert_match(/Domain:/, output)
assert_match(/name:\s+#{domain}/, output)
assert_match(/status:\s+Blocked/, output)
assert_match(/More information at http:\/\/internet\.ee/, output)
end
end

end
3 changes: 0 additions & 3 deletions tmp/pids/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions tmp/pids/whois_server.pid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Loading