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 30, 2024
1 parent c30c3f3 commit 5160543
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 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,10 @@ def ask_questions
show_parameters
return false unless agree("\nProceed? (Y/N): ")

if is_hostname?(message_server_host)
return false unless hostname_fqdn?(message_server_host)
end

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

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

def is_hostname?(host)
require "resolv"

return !(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 5160543

Please sign in to comment.