WIP: SPF, to_s + to_bind9.

master
Philippe Pittoli 2024-02-29 04:51:40 +01:00
parent faacccda15
commit 98d0c3c28a
1 changed files with 58 additions and 5 deletions

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