6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/models/staypuft/deployment/ip_check.rb', line 6
def check_ip_or_hostname(record, attribute, value)
begin
ip_addr = IPAddr.new(value)
ip_range = ip_addr.to_range
if ip_range.begin == ip_range.end
true
else
record.errors.add attribute, NOT_RANGE_MSG
false
end
rescue
if /(?=^.{1,254}$)(^(((?!-)[a-zA-Z0-9-]{1,63}(?<!-))|((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63})$)/ =~ value
true
else
record.errors.add attribute, INVALID_IP_OR_FQDN_MSG
false
end
end
end
|