Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F2571734
ipv6_validator.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jun 10, 9:02 PM
Size
511 B
Mime Type
text/x-ruby
Expires
Fri, Jun 12, 9:02 PM (1 d, 20 h)
Engine
blob
Format
Raw Data
Handle
393927
Attached To
rWEBDNS WebDNS (edet4)
ipv6_validator.rb
View Options
require
'ipaddr'
require
'socket'
class
Ipv6Validator
<
ActiveModel
::
EachValidator
def
valid_v6?
(
addr
)
return
false
if
addr
[
'/'
]
# IPAddr accepts addr/mask format
return
false
if
addr
[
'['
]
return
false
if
addr
[
']'
]
IPAddr
.
new
(
addr
,
Socket
::
AF_INET6
)
true
rescue
IPAddr
::
AddressFamilyError
,
IPAddr
::
InvalidAddressError
false
end
def
validate_each
(
record
,
attribute
,
value
)
return
if
valid_v6?
(
value
)
record
.
errors
[
attribute
]
<<
'is not a valid IPv6 address'
end
end
Event Timeline
Log In to Comment