Adding verifications on TTL and subdomain values.
This commit is contained in:
parent
5c735a2055
commit
147d4df0fa
@ -7,6 +7,9 @@ class DNSManager::Storage::Zone
|
|||||||
property domain : String
|
property domain : String
|
||||||
property resources = [] of DNSManager::Storage::Zone::ResourceRecord
|
property resources = [] of DNSManager::Storage::Zone::ResourceRecord
|
||||||
|
|
||||||
|
# We don't want to accept less than 30 seconds TTL.
|
||||||
|
class_property ttl_limit_min = 30
|
||||||
|
|
||||||
def initialize(@domain)
|
def initialize(@domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -69,7 +72,9 @@ class DNSManager::Storage::Zone
|
|||||||
errors << "invalid subdomain: #{@name}"
|
errors << "invalid subdomain: #{@name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: impose a limit on the TTL
|
if @ttl < Zone.ttl_limit_min
|
||||||
|
errors << "invalid ttl: #{@ttl}, shouldn't be less than #{Zone.ttl_limit_min}"
|
||||||
|
end
|
||||||
|
|
||||||
unless Zone.is_ipv4_address_valid? @target
|
unless Zone.is_ipv4_address_valid? @target
|
||||||
errors << "target not valid ipv4: #{@target}"
|
errors << "target not valid ipv4: #{@target}"
|
||||||
@ -78,6 +83,7 @@ class DNSManager::Storage::Zone
|
|||||||
errors
|
errors
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class AAAA < ResourceRecord
|
class AAAA < ResourceRecord
|
||||||
def get_errors : Array(Error)
|
def get_errors : Array(Error)
|
||||||
errors = [] of Error
|
errors = [] of Error
|
||||||
@ -86,7 +92,9 @@ class DNSManager::Storage::Zone
|
|||||||
errors << "invalid subdomain: #{@name}"
|
errors << "invalid subdomain: #{@name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: impose a limit on the TTL
|
if @ttl < Zone.ttl_limit_min
|
||||||
|
errors << "invalid ttl: #{@ttl}, shouldn't be less than #{Zone.ttl_limit_min}"
|
||||||
|
end
|
||||||
|
|
||||||
unless Zone.is_ipv6_address_valid? @target
|
unless Zone.is_ipv6_address_valid? @target
|
||||||
errors << "target not valid ipv6: #{@target}"
|
errors << "target not valid ipv6: #{@target}"
|
||||||
@ -95,13 +103,71 @@ class DNSManager::Storage::Zone
|
|||||||
errors
|
errors
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class TXT < ResourceRecord
|
class TXT < ResourceRecord
|
||||||
|
def get_errors : Array(Error)
|
||||||
|
errors = [] of Error
|
||||||
|
|
||||||
|
unless Zone.is_subdomain_valid? @name
|
||||||
|
errors << "invalid subdomain: #{@name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @ttl < Zone.ttl_limit_min
|
||||||
|
errors << "invalid ttl: #{@ttl}, shouldn't be less than #{Zone.ttl_limit_min}"
|
||||||
|
end
|
||||||
|
|
||||||
|
errors
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class PTR < ResourceRecord
|
class PTR < ResourceRecord
|
||||||
|
def get_errors : Array(Error)
|
||||||
|
errors = [] of Error
|
||||||
|
|
||||||
|
unless Zone.is_domain_valid? @target
|
||||||
|
errors << "invalid subdomain: #{@target}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @ttl < Zone.ttl_limit_min
|
||||||
|
errors << "invalid ttl: #{@ttl}, shouldn't be less than #{Zone.ttl_limit_min}"
|
||||||
|
end
|
||||||
|
errors
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class NS < ResourceRecord
|
class NS < ResourceRecord
|
||||||
|
def get_errors : Array(Error)
|
||||||
|
errors = [] of Error
|
||||||
|
|
||||||
|
unless Zone.is_subdomain_valid? @name
|
||||||
|
errors << "invalid subdomain: #{@name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @ttl < Zone.ttl_limit_min
|
||||||
|
errors << "invalid ttl: #{@ttl}, shouldn't be less than #{Zone.ttl_limit_min}"
|
||||||
|
end
|
||||||
|
|
||||||
|
errors
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class CNAME < ResourceRecord
|
class CNAME < ResourceRecord
|
||||||
|
def get_errors : Array(Error)
|
||||||
|
errors = [] of Error
|
||||||
|
|
||||||
|
unless Zone.is_subdomain_valid? @name
|
||||||
|
errors << "invalid subdomain: #{@name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
if @ttl < Zone.ttl_limit_min
|
||||||
|
errors << "invalid ttl: #{@ttl}, shouldn't be less than #{Zone.ttl_limit_min}"
|
||||||
|
end
|
||||||
|
|
||||||
|
unless Zone.is_subdomain_valid? @target
|
||||||
|
errors << "invalid target: #{@target}"
|
||||||
|
end
|
||||||
|
errors
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class MX < ResourceRecord
|
class MX < ResourceRecord
|
||||||
@ -109,6 +175,24 @@ class DNSManager::Storage::Zone
|
|||||||
def initialize(@name, @ttl, @target, @priority = 10)
|
def initialize(@name, @ttl, @target, @priority = 10)
|
||||||
@rrtype = "mx"
|
@rrtype = "mx"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_errors : Array(Error)
|
||||||
|
errors = [] of Error
|
||||||
|
|
||||||
|
unless Zone.is_subdomain_valid? @name
|
||||||
|
errors << "invalid subdomain: #{@name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
if @ttl < Zone.ttl_limit_min
|
||||||
|
errors << "invalid ttl: #{@ttl}, shouldn't be less than #{Zone.ttl_limit_min}"
|
||||||
|
end
|
||||||
|
|
||||||
|
unless Zone.is_domain_valid? @target
|
||||||
|
errors << "invalid target (domain): #{@target}"
|
||||||
|
end
|
||||||
|
|
||||||
|
errors
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class SRV < ResourceRecord
|
class SRV < ResourceRecord
|
||||||
@ -128,7 +212,7 @@ class DNSManager::Storage::Zone
|
|||||||
def get_errors? : Array(Error)
|
def get_errors? : Array(Error)
|
||||||
errors = [] of Error
|
errors = [] of Error
|
||||||
unless Zone.is_domain_valid? @domain
|
unless Zone.is_domain_valid? @domain
|
||||||
errors << "invalid domain"
|
errors << "invalid domain #{@domain}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@resources.each do |r|
|
@resources.each do |r|
|
||||||
|
Loading…
Reference in New Issue
Block a user