How to update SPF for all cPanel accounts?

The /usr/local/cpanel/Cpanel/SPF.pm file handles the SPF installation script that runs "/usr/local/cpanel/bin/spf_installer username" and is also
used in cPanel > Email Authentication area for setting the IP for the SPF record.

First, make a backup of the file:

cp /usr/local/cpanel/Cpanel/SPF.pm /usr/local/cpanel/Cpanel/SPF.pm.bak

Now revise the lines that have this:

my $mainip = Cpanel::DIp::getmainserverip();

To have this instead:

my $mainip = '192.12.12.12';

This will then use the hard-coded IP when installing the SPF records. This will occur for all parked, addon, and subdomains on the account for the SPF
installation. Whenever the user in cPanel > Email Authentication area enables SPF records, the hard-coded IP will be used.

Please note that the code entry occurs thrice in the file, so you would need to revise all the entries. If you only revise the initial entry, only
the main domain will be changed to that new hard-coded IP, while parked, addon, and subdomains will not be.

You may also want to put that file into the exclude list for cPanel so it does not get overwritten on cPanel updates:

echo "/usr/local/cpanel/Cpanel/SPF.pm" >> /etc/cpanelsync.exclude

Script to update SPF for all accounts

=================================================================
#!/bin/bash
IFS="$"
cd /var/named
/bin/ls -- /var/cpanel/users | grep -v
"root\|system\|passwd\|cpanel\|nobody\|mysql\|\`\|\-\|\." | while read
CPUSER; do
echo "Installing SPF for '${CPUSER}'";
/usr/local/cpanel/bin/spf_installer "${CPUSER}" > /dev/null
done

No comments:

Post a Comment