lib/neetob/cli/cloudflare/verify_spf.rb in neetob-0.5.5 vs lib/neetob/cli/cloudflare/verify_spf.rb in neetob-0.5.6
- old
+ new
@@ -20,19 +20,34 @@
url = create_url(zone_id, "dns_records")
response = get(url)
raise(StandardError, "No DNS records found") if response[:result].empty?
- spf_txt_records = response[:result].filter { |dns| dns[:type] == "TXT" && dns[:content].start_with?("v=spf1") }
+ spf_txt_records = response[:result].filter { |dns|
+ dns[:type] == "TXT" &&
+ (dns[:content].start_with?("v=spf1") || dns[:content].start_with?("\"v=spf1"))
+ }
if spf_txt_records.count > 1
ui.error("More than one TXT record found for SPF")
+ elsif spf_txt_records.count == 0
+ ui.success("No TXT record for SPF present")
else
ui.success("Only one TXT record for SPF present")
end
spf_txt_records.each_with_index do |dns, index|
ui.info("SPF TXT #{index + 1}: #{dns[:content]}")
+ end
+
+ if spf_txt_records.count == 1
+ unique_spf_txt_record = spf_txt_records.first
+
+ if unique_spf_txt_record[:content].end_with?("-all") || unique_spf_txt_record[:content].end_with?("-all\"")
+ ui.success("SPF TXT record is set to hard fail for SPF compliance")
+ else
+ ui.error("SPF TXT record is not set to hard fail for SPF compliance")
+ end
end
end
end
end
end