From 1a928445c9d4abc22d54b3ae1d9f95a7937354a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Wed, 25 Mar 2020 09:57:02 +0200 Subject: [PATCH 1/2] Return Policy error if domain entry in wrong format --- lib/whois_server.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/whois_server.rb b/lib/whois_server.rb index 98093af..18428c4 100644 --- a/lib/whois_server.rb +++ b/lib/whois_server.rb @@ -54,13 +54,27 @@ def receive_data(data) send_data whois_record.unix_body else logger.info "#{ip}: requested: #{data} [searched by: #{name}; No record found]" - send_data no_entries_msg + send_data(domain_valid_format?(name) ? no_entries_msg : policy_error_msg) end close_connection_after_writing end private + def domain_valid_format?(name) + domain_name_regexp = /\A[a-z0-9\-\u00E4\u00F5\u00F6\u00FC\u0161\u017E]{2,61}\. + ([a-z0-9\-\u00E4\u00F5\u00F6\u00FC\u0161\u017E]{2,61}\.)?[a-z0-9]{1,61}\z/x + + formatted_domain_name = name.strip.downcase + nil != (formatted_domain_name =~ domain_name_regexp) + + + end + + def policy_error_msg + "\nPolicy error" + footer_msg + end + def no_entries_msg "\nDomain not found" + footer_msg end From 9aa1c29ea4171a9f11896f68aa301961f63786db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 26 Mar 2020 07:37:37 +0200 Subject: [PATCH 2/2] Fix code styling issues --- lib/whois_server.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/whois_server.rb b/lib/whois_server.rb index 18428c4..89c7c60 100644 --- a/lib/whois_server.rb +++ b/lib/whois_server.rb @@ -54,21 +54,25 @@ def receive_data(data) send_data whois_record.unix_body else logger.info "#{ip}: requested: #{data} [searched by: #{name}; No record found]" - send_data(domain_valid_format?(name) ? no_entries_msg : policy_error_msg) + provide_data_body(name) end close_connection_after_writing end private - def domain_valid_format?(name) + def provide_data_body(domain_name) + return send_data(no_entries_msg) if domain_valid_format?(domain_name) + + send_data(policy_error_msg) + end + + def domain_valid_format?(domain_name) domain_name_regexp = /\A[a-z0-9\-\u00E4\u00F5\u00F6\u00FC\u0161\u017E]{2,61}\. ([a-z0-9\-\u00E4\u00F5\u00F6\u00FC\u0161\u017E]{2,61}\.)?[a-z0-9]{1,61}\z/x - formatted_domain_name = name.strip.downcase + formatted_domain_name = domain_name.strip.downcase nil != (formatted_domain_name =~ domain_name_regexp) - - end def policy_error_msg