I have some hosting accounts where I park / point quite many domains, it’s very annoying to always set up the email domain forwards. I think the domain forward is what most people want as default, however WHM/cPanel doesn’t do that.
I had a look through the scripts and modified one to do this for all parked domain if there is no forwarding set up yet.
Depending on your needs you can change it to run just for one account (set $user instead of looping through /var/cpanel/users). If you often add domains and don’t want to run the script manually just put it in a cron job.
Here the script:
#!/usr/bin/perl
my(%PDLIST);
opendir(CPU,"/var/cpanel/users");
@CPUS=readdir(CPU);
closedir(CPU);
foreach my $user (@CPUS) {
my $dns;
my @PD;
if (-f "/var/cpanel/users/$user") {
open(CP,"/var/cpanel/users/$user");
while(<CP>
if (/^DNS=(\S+)/) { $dns=$1; }
elsif (/^DNS\d+=(\S+)/) { push(@PD,$1); }
}
close(CP);
foreach my $pd (@PD) {
my $issub = 0;
if ($pd =~ /\.${dns}$/) {$issub=1;}
foreach my $pdtest (@PD) {
next if ($pdtest eq $pd);
if ($pd =~ /\.${pdtest}$/) { $issub=1; }
}
if (!$issub) {
$PDLIST{$dns}{$pd} = 1;
next if $pd eq $dns;
#print $pd . "\t->\t" . $dns . "\n";
if (-s "/etc/vdomainaliases/$pd" > 0) {
print $pd . "\t->\t" . $dns . " exists\n";
} else {
print $pd . "\t->\t" . $dns . " no entry\n";
system("echo \"$pd: $dns\" > /etc/vdomainaliases/$pd");
#last;
}
}
}
}
}