WIP: SPF, to_s + to_bind9.

This commit is contained in:
Philippe Pittoli 2024-02-29 04:51:40 +01:00
parent faacccda15
commit 98d0c3c28a

View File

@ -260,6 +260,22 @@ class DNSManager::Storage::Zone
# baguette.netlib.re. 3600 IN TXT "v=spf1 a mx ip4:<IP> a:mail.baguette.netlib.re ~all"
class SPF < ResourceRecord
def qualifier_to_char(qualifier : Qualifier) : Char
case qualifier
when .pass?
'+'
when .none?
'?'
when .soft_fail?
'~'
# when .hard_fail?
else '-'
end
end
def qualifier_to_string(qualifier : Qualifier) : String
"#{qualifier_to_char qualifier}all"
end
# SPF mechanisms are about policy, which comes with the form of a single character:
# - '?' means no policy (neutral),
# - '+' means PASS result. Default behavior for any mechanism except `all`.
@ -309,6 +325,10 @@ class DNSManager::Storage::Zone
errors = [] of Error
errors
end
def to_s
"#{@t}=#{v}"
end
end
class Mechanism
@ -333,7 +353,7 @@ class DNSManager::Storage::Zone
# TODO
def get_errors : Array(Error)
errors = [] of Error
case @q
case @t
when Mechanism::Type::A
when Mechanism::Type::IP4
when Mechanism::Type::IP6
@ -344,6 +364,10 @@ class DNSManager::Storage::Zone
end
errors
end
def to_s
"#{qualifier_to_char @q}#{@t}=#{v}"
end
end
property v : String = "spf1"
@ -363,11 +387,11 @@ class DNSManager::Storage::Zone
errors = [] of Error
unless Zone.is_subdomain_valid? @name
errors << "CNAME invalid subdomain: #{@name}"
errors << "SPF invalid subdomain: #{@name}"
end
if @ttl < Zone.ttl_limit_min
errors << "CNAME invalid ttl: #{@ttl}, shouldn't be less than #{Zone.ttl_limit_min}"
errors << "SPF invalid ttl: #{@ttl}, shouldn't be less than #{Zone.ttl_limit_min}"
end
@mechanisms.each do |m|
@ -388,11 +412,40 @@ class DNSManager::Storage::Zone
end
def to_s(io : IO)
io << "TODO"
io << "(#{ "%4d" % @rrid }) "
io << "#{ "%30s" % @name} #{ "%6d" % @ttl} IN SPF "
io << '"'
@mechanisms.each do |m|
io << m
io << ' '
end
if mod = @modifiers
mod.each do |m|
io << m
io << ' '
end
end
io << qualifier_to_string @q
io << '"'
io << "\n"
end
def to_bind9(io : IO)
io << "TODO"
io << "#{@name} #{@ttl} IN TXT "
io << '"'
@mechanisms.each do |m|
io << m
io << ' '
end
if mod = @modifiers
mod.each do |m|
io << m
io << ' '
end
end
io << qualifier_to_string @q
io << '"'
io << "\n"
end
end