Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure settings that must be IP's are IP's and not hostnames #53

Merged
merged 1 commit into from Apr 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions hooks/lib/provisioning_wizard.rb
Expand Up @@ -357,8 +357,8 @@ def validate_base_url
def validate_ntp_host
if @ntp_host.nil? || @ntp_host.empty?
'NTP sync host must be specified'
elsif !(valid_ip?(@ntp_host))
'NTP sync host - Invalid IP address'
elsif !(valid_hostname?(@ntp_host)) && !(valid_hostname?(@ntp_host))
'NTP sync host - Invalid Hostname or IP address'
end
end

Expand Down Expand Up @@ -448,9 +448,13 @@ def fix_interface_name(facter_name)
end

def valid_ip?(ip)
(!!(ip =~ Resolv::IPv4::Regex)) ||
(!!(ip =~ Resolv::IPv6::Regex)) ||
(ip =~ /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/)
ip =~ /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/
end

def valid_hostname?(hostname)
(!!(hostname =~ Resolv::IPv4::Regex)) ||
(!!(hostname =~ Resolv::IPv6::Regex)) ||
(hostname =~ /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/)
end

# NOTE(jistr): currently we only have tzinfo for ruby193 scl and
Expand Down