Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F905167
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
Fri, Aug 29, 9:40 PM
Size
511 B
Mime Type
text/x-ruby
Expires
Sun, Aug 31, 9:40 PM (6 h, 23 m)
Engine
blob
Format
Raw Data
Handle
252522
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