For what it's worth I've changed the code a bit to reflect yahoo in case anybody has a need for it. Thanks again for the great script!
Code:
#!/usr/local/bin/perl
#WHMADDON:yahooforwardfinder:Yahoo Forwarder Finder
##----------------------------------------------------
## Version 1.0
##
## Usage:
##
## 1) Copy to "/usr/local/cpanel/whostmgr/docroot/cgi/" directory.
## 2) Rename to "addon_yahooforwarderfinder.cgi".
## 3) Chown to root:root.
## 4) Chmod to 755.
## 5) Log into WHM as user with root privs and click the link
## called "AOL Forwarder Finder" under the Add-ons section.
##----------------------------------------------------
BEGIN {
push(@INC,'/usr/local/cpanel','/usr/local/cpanel/Cpanel');
push(@INC,"/usr/local/cpanel/whostmgr/docroot/cgi");
}
use whmlib;
#--------------------------------
my $delimiter = "::";
#--------------------------------
print "Content-type: text/html\r\n\r\n";
defheader("Yahoo Finder");
#-------------------------------------
if (!$ACL{all}) {
print "<p>Sorry, but this function may only be run by the server administrator.</p>";
exit();
}
#-------------------------------------
# Start main work.
&printscriptinfo;
my @yahooforwarders;
my @print;
chdir("/etc/valiases");
@yahooforwarders = `grep -i \@yahoo. *`;
if (! @yahooforwarders) {
print "<p>There were no \@yahoo forwarders found. Lucky!</p>";
exit();
}
foreach my $line (@yahooforwarders) {
my $owner;
my $realdomain;
my $reseller;
my @yahoos;
my @yahooaddresses;
my ($domain, $forwarder, $addresses) = split(/:/, $line);
$owner = `/scripts/whoowns $domain`;
$realdomain = &domainname($owner);
$reseller = &findreseller($owner);
@yahooaddresses = split(/,/, $addresses);
my @yahoos;
foreach (@yahooaddresses) {
$_ = &trim($_);
if ($_ =~ /yahoo.com/i) {
push(@yahoos, $_);
}
}
if ($forwarder eq "*") {
$forwarder = "default address";
}
foreach(@yahoos) {
push(@print, $reseller . $delimiter . $realdomain . $delimiter . $domain . $delimiter . $forwarder . $delimiter . $_ . "\n<br />");
}
}
# Print results.
@print = sort { $a cmp $b } @print;
foreach(@print) {
print($_);
}
## Subroutines
sub trim {
my $string = shift(@_);
$string =~ s/\s//g;
return $string;
}
sub domainname {
my $user;
my $domain;
$user = $_[0];
open(CPU,"/var/cpanel/users/" . $user);
while(<CPU>) {
if (/^DNS=(\S+)/) {
$domain = $1;
}
}
close(CPU);
return $domain;
}
sub findreseller {
my $user;
my $reseller;
$user = $_[0];
open(CPU,"/var/cpanel/users/" . $user);
while(<CPU>) {
if (/^OWNER=(\S+)/) {
$reseller = $1;
}
}
close(CPU);
#if ($reseller ne "root") {
return &domainname($reseller);
#}
#else {
# return "NOT RESOLD";
#}
}
sub printscriptinfo {
print "<p>This script shows a list of all email forwarders on the server that are set up to forward email to Yahoo.</p><p><b>[reseller's domain]</b> = The reseller who owns the [cpanel domain].<br /><b>[cpanel domain]</b> = The main cpanel domain where the forwarder is located.<br /><b>[forwarder domain]</b> = The actual domain for the forwarder. (ie: It might be an add-on or parked domain.)<br /><b>[forwarder address]</b> = The actual email address that is doing the forwarding.<br /><b>[yahoo address]</b> = The destination/target email address.</p>";
print "<p>[reseller's domain] " . $delimiter . " [cpanel domain] " . $delimiter . " [forwarder domain] " . $delimiter . " [forwarder address] " . $delimiter . " [yahoo address]</p>";
}