diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..dbfb8da Binary files /dev/null and b/.DS_Store differ diff --git a/.ruby-version b/.ruby-version index 711ee4f..d9c62ed 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.3 \ No newline at end of file +3.0.2 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 030805e..f77412e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Gemfile b/Gemfile index 98ffae3..06bcf4d 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 2054bd9..de1a47c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -73,7 +73,7 @@ DEPENDENCIES dotenv eventmachine (~> 1.2.7) mina (~> 1.2.4) - minitest + minitest (~> 5.16.3) pg (~> 1.4.0) pry (~> 0.14.1) rubocop @@ -81,4 +81,4 @@ DEPENDENCIES simpleidn (~> 0.2.1) BUNDLED WITH - 2.2.17 + 2.5.22 diff --git a/lib/whois_server.rb b/lib/whois_server.rb index 5375d6b..c276fd9 100644 --- a/lib/whois_server.rb +++ b/lib/whois_server.rb @@ -53,17 +53,23 @@ def receive_data(data) return end - name = data.strip - name = name.downcase + name = data.strip.downcase name = SimpleIDN.to_unicode(name) - 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)}]" - send_data whois_record.unix_body + + # Add special handling for .ee second-level domains + if %w[pri.ee fie.ee med.ee com.ee].include?(name) + logger.info "#{ip}: requested: #{data} [searched by: #{name}; Special .ee second-level domain]" + send_data special_ee_domain_msg(name) else - logger.info "#{ip}: requested: #{data} [searched by: #{name}; No record found]" - provide_data_body(name) + 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)}]" + send_data whois_record.unix_body + else + logger.info "#{ip}: requested: #{data} [searched by: #{name}; No record found]" + provide_data_body(name) + end end close_connection_after_writing end @@ -107,6 +113,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 diff --git a/log/.gitignore b/log/.gitignore index 94548af..903df8e 100644 --- a/log/.gitignore +++ b/log/.gitignore @@ -1,3 +1,5 @@ * */ !.gitignore +tmp/pids/ +.DS_Store \ No newline at end of file diff --git a/test/models/whois_record_test.rb b/test/models/whois_record_test.rb index c88f93a..80aa629 100644 --- a/test/models/whois_record_test.rb +++ b/test/models/whois_record_test.rb @@ -107,4 +107,25 @@ 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'] }) + + expected_output = <<~OUTPUT + 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 + + OUTPUT + + assert_equal expected_output, @whois_record.unix_body + end + end + end diff --git a/tmp/pids/.gitignore b/tmp/pids/.gitignore deleted file mode 100644 index 94548af..0000000 --- a/tmp/pids/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -* -*/ -!.gitignore diff --git a/tmp/pids/whois_server.pid b/tmp/pids/whois_server.pid new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tmp/pids/whois_server.pid @@ -0,0 +1 @@ +1