From f6fe63bde6d329d4522de1078dc8627cc0b02a01 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Fri, 18 Oct 2024 11:54:31 +0300 Subject: [PATCH] update info for blocked domains --- .DS_Store | Bin 0 -> 8196 bytes .ruby-version | 2 +- Dockerfile | 9 +++++--- Gemfile | 2 +- Gemfile.lock | 4 ++-- lib/whois_server.rb | 38 +++++++++++++++++++++++-------- log/.gitignore | 2 ++ test/models/whois_record_test.rb | 21 +++++++++++++++++ tmp/pids/.gitignore | 3 --- tmp/pids/whois_server.pid | 1 + 10 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 .DS_Store delete mode 100644 tmp/pids/.gitignore create mode 100644 tmp/pids/whois_server.pid diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..dbfb8da1f6a2f3522e81407363326026a883b8fa GIT binary patch literal 8196 zcmeHMyNVP+6g{;w>Vgl}WZAG4!A#gcXqPb(Om;tDc4l-|n6U?UH?P#p9}vt%W5L+S zO#BN!z{J2)RkxeI)!my2GT<%fIzydXb#5KHySP07+|lLY5I6v^%PZjCO?Evk@ZsvT z9T|B*bexaX^6+?Gtv8)W8!!jV0dv3{FbB+mZE=8Sc4)f;=YC?XHwVmt|I&f*ekgba zECqeS`08L6O90}S!?E%AUid*Q1WQ4mkPMqkQ;BJ+lM=(F=^QU4t`zhM({wl~KAb2! zsZd;0=lVqqhbt3WZw{CPT?az#KE@*~@e&uRe!uqHx4CsSnaozzjAMM%{I56PzdqLd z;!1vV*7`PZ=Pjq=My-o8Tw~n3wYL8#+G>q#=e;pH4`1g|;T2x+ z9$4x;_Py*kT7pDYt`A|34Z2{=daLu++=}bKq|saO27G /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