# frozen_string_literal: true module Neetob class CLI module MonthlyAudit module InstancesAndAddons module Cloudflare class DnsEntryHasProxyStatus < CLI::Base DOMAINS_TO_IGNORE_AUDIT_RESULT_FOR = [ "neeto.com", "bigbinary.com", "neetorecord.com", ] def initialize super() end def run ui.success "### 3.2.2. Checking whether DNS entry has proxy status" domains_data = [["Domain", "DNS proxy status", "Audit Passed"]] ui.info("\n", print_to_audit_log: false) last_dns_proxy_status = nil Neetob::CLI::Cloudflare::Base::ZONE_IDS.keys.select { |domain| domain.to_s.include?(".com") }.map do |domain| ui.info("Checking proxy status for DNS entries for #{domain}", print_to_audit_log: false) domain = domain.to_s proxiable_records = Neetob::CLI::Cloudflare::DnsProxyStatus.new(domain).run record_to_check = proxiable_records.select { |record| record[:name] == "*.#{domain}" }.first if record_to_check.nil? audit_passed = DOMAINS_TO_IGNORE_AUDIT_RESULT_FOR.include?(domain.to_s) ? "Ignored" : "No" domains_data << [domain, "No * records found", audit_passed] else is_wildcard_subdomain_proxied = record_to_check[:proxied] audit_passed = DOMAINS_TO_IGNORE_AUDIT_RESULT_FOR.include?(domain.to_s) ? "Ignored" : (is_wildcard_subdomain_proxied ? "Yes" : "No") proxy_status = is_wildcard_subdomain_proxied ? "on" : "off" dns_proxy_status = "* record has proxying turned #{proxy_status}" same_as_last_dns_proxy_status = dns_proxy_status == last_dns_proxy_status last_dns_proxy_status = dns_proxy_status if same_as_last_dns_proxy_status dns_proxy_status = "''" end domains_data << [domain, dns_proxy_status, audit_passed] end end ui.print_table(domains_data) end end end end end end end