#!/bin/bash

# Locate directory of DNS zone files
if [ -d "/var/named/run-root/var/" ]; then
        DNS_ZONE_DIR="/var/named/run-root/var/"
        echo "DNS zone files located in $DNS_Zone_DIR"
else
        if [ -d "/var/named/chroot/var/" ]; then
                DNS_ZONE_DIR="/var/named/chroot/var/"
                echo "DNS zone files located in $DNS_Zone_DIR"
        else
                echo "Can't find directory for DNS zones files"
                exit;
        fi
fi

# Change Plesk default SPF to include secureserver.net
for i in $(ls "$DNS_ZONE_DIR" | cut -d" " -f1 | grep -v 'localhost.rev\|named.root\|run\|PROTO.localhost.rev\|make-localhost\|managed-keys.bind\|managed-keys.bind.jnl\|.in-addr.arpa'); do
  plesk bin dns --del $i -txt 'v=spf1 +a +mx -all' && plesk bin dns --add $i -txt 'v=spf1 +a +mx include:secureserver.net -all'
  plesk bin dns --del $i -txt 'v=spf1 +a +mx ~all' && plesk bin dns --add $i -txt 'v=spf1 +a +mx include:secureserver.net ~all'
  plesk bin dns --del $i -txt 'v=spf1 +a +mx +all' && plesk bin dns --add $i -txt 'v=spf1 +a +mx include:secureserver.net +all'
  plesk bin dns --del $i -txt 'v=spf1 a +mx -all' && plesk bin dns --add $i -txt 'v=spf1 +a +mx include:secureserver.net -all'
  plesk bin dns --del $i -txt 'v=spf1 a +mx ~all' && plesk bin dns --add $i -txt 'v=spf1 +a +mx include:secureserver.net ~all'
  plesk bin dns --del $i -txt 'v=spf1 a +mx +all' && plesk bin dns --add $i -txt 'v=spf1 +a +mx include:secureserver.net +all'
  plesk bin dns --del $i -txt 'v=spf1 +a mx -all' && plesk bin dns --add $i -txt 'v=spf1 +a +mx include:secureserver.net -all'
  plesk bin dns --del $i -txt 'v=spf1 +a mx ~all' && plesk bin dns --add $i -txt 'v=spf1 +a +mx include:secureserver.net ~all'
  plesk bin dns --del $i -txt 'v=spf1 +a mx +all' && plesk bin dns --add $i -txt 'v=spf1 +a +mx include:secureserver.net +all'
  plesk bin dns --del $i -txt 'v=spf1 a mx -all' && plesk bin dns --add $i -txt 'v=spf1 +a +mx include:secureserver.net -all'
  plesk bin dns --del $i -txt 'v=spf1 a mx ~all' && plesk bin dns --add $i -txt 'v=spf1 +a +mx include:secureserver.net ~all'
  plesk bin dns --del $i -txt 'v=spf1 a mx +all' && plesk bin dns --add $i -txt 'v=spf1 +a +mx include:secureserver.net +all'
done