Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F907021
record.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
Sat, Aug 30, 12:37 PM
Size
1 KB
Mime Type
text/x-ruby
Expires
Mon, Sep 1, 12:37 PM (1 d, 1 h)
Engine
blob
Format
Raw Data
Handle
253767
Attached To
rWEBDNS WebDNS (edet4)
record.rb
View Options
require
'ipaddr'
class
Record
<
ActiveRecord
::
Base
belongs_to
:domain
def
self
.
record_types
[
'SOA'
,
'NS'
,
'CNAME'
,
'A'
,
'AAAA'
,
'MX'
,
'TXT'
,
'SPF'
,
'SRV'
,
'SSHFP'
,
'PTR'
,
]
end
validates
:name
,
presence
:
true
validates
:type
,
inclusion
:
{
in
:
record_types
}
before_validation
:guess_reverse_name
before_validation
:set_name
after_save
:update_zone_serial
after_destroy
:update_zone_serial
def
short
return
''
if
name
==
domain
.
name
return
''
if
name
.
blank?
File
.
basename
(
name
,
".
#{
domain
.
name
}
"
)
end
def
supports_prio?
false
end
# Create record specific urls for all record types
#
# Overrides default rails STI
def
self
.
model_name
return
super
if
self
==
Record
Record
.
model_name
end
def
to_dns
[
name
,
'IN'
,
type
,
supports_prio?
?
prio
:
nil
,
content
].
compact
.
join
(
' '
)
end
private
# Hooks
def
guess_reverse_name
return
if
not
type
==
'PTR'
return
if
not
domain
.
reverse?
return
if
name
.
blank?
reverse
=
IPAddr
.
new
(
name
)
.
reverse
self
.
name
=
reverse
if
reverse
.
end_with?
(
domain
.
name
)
rescue
IPAddr
::
InvalidAddressError
# rubycop:disable HandleExceptions
end
# Powerdns expects full domain names
def
set_name
self
.
name
=
domain
.
name
if
name
.
blank?
self
.
name
=
"
#{
name
}
.
#{
domain
.
name
}
"
if
not
name
.
end_with?
(
domain
.
name
)
end
def
update_zone_serial
# SOA records handle serial themselves
return
true
if
type
==
'SOA'
domain
.
soa
.
bump_serial!
end
end
Event Timeline
Log In to Comment