Skip to content

Commit

Permalink
messaging hostname fqdn validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nasark committed Jan 31, 2024
1 parent c30c3f3 commit 84b0063
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/manageiq/appliance_console/message_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def ask_questions
show_parameters
return false unless agree("\nProceed? (Y/N): ")

return false if hostname?(message_server_host) && !hostname_fqdn?(message_server_host)

return false unless host_reachable?(message_server_host, "Message Server Host:")

true
Expand Down Expand Up @@ -177,6 +179,21 @@ def file_contains?(path, content)
true
end

def hostname?(host)
host !~ IP_REGEXP
end

def hostname_fqdn?(host)
require "socket"

fqdn = Addrinfo.getaddrinfo(Socket.gethostname, nil).first.getnameinfo.first
unless host == fqdn
return false
end

true
end

def host_reachable?(host, what)
require 'net/ping'
say("Checking connectivity to #{host} ... ")
Expand Down

0 comments on commit 84b0063

Please sign in to comment.