MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //proc/self/root/scripts.20110531.215904.25158/mailtroubleshoot
#!/usr/bin/perl

use IPC::Open2;

die "Please use mail troubleshooter Version 2.0 in WHM.";

$email = $ARGV[0];
$islocal = $ARGV[1];
$hostname = `/bin/hostname`;

$inhost = 0;
open(LD,"/etc/localdomains");
while(<LD>) {
	if (/^$hostname$/) {
		$inhost =1;
	}
}
close(LD);


if (!$inhost) {
	print "Found one major problem, $hostname is not in /etc/localdomains\n";
	open(LD,">>/etc/localdomains");
	print LD "$hostname\n";
	close(LD);
	print "It was added and checks continue .... \n";
}


if (($email eq "" || $islocal eq "") && (! -t STDIN)) { die "Not enough args" };

print "Welcome to the mail troubleshooter (C) 2000-2004 cPanel, Inc.\n\n";
if ($email eq "") {
print "Please enter the email address that you are having a problem with\n";
print "------->";
	chomp($email = <STDIN>);
}
if ($islocal eq "") {
print "Is this address residing on this machine?\n";
print "------->";
	chomp($islocal = <STDIN>);
}
if ($islocal =~ /^n/i) { $islocal = 0; } else { $islocal = 1; }

print "Alright, I'll check on $email for you please give me a second.....\n\n";
$problem = findprob($email);

if ($problem =~ /^badmode (\S+)/) {
	print "Found a problem, fixing permissions on $1\n";
	chmod (0660,$1);
}
if ($problem eq "unroutable" && $islocal == 1) {
	(undef,$domain) = split(/\@/,$email);
	print "Found a problem, adding $domain to /etc/localdomains\n";
	open(LD,">>/etc/localdomains");
	print LD "$domain\n";
	close(LD);
}
if ($problem eq "unroutable" && $islocal == 0) {
	print "Found a problem, mail cannot be routed to an external server\n";
	print "Either the domain is local and you answered otherwise\n";
	print "or their is a problem with the remote mail server if it\n";
	print "even has a dns entry\n";
}
if ($problem eq "nosticky") {
	print "Permissions problems on /var/spool/mail, fixing\n";
	system("/scripts/mailperm");
}
if ($problem eq "badmode") {
	print "Permissions problems, fixing\n";
	system("/scripts/mailperm");
}
if ($problem eq "") {
	print "Sorry, I couldn't find a problem.. maybe I just don't know about\n";
	print "the problem you are having or there is no problem\n";
}


sub findprob {
	open2(\*RDRFH, \*WTRFH,"/bin/mail -v $email 2>&1");
	print WTRFH "This is a test message automatically sent by the mailer daemon\n";
	print WTRFH "Please delete it at your convience\n";
	print WTRFH "\n.\n";
	print WTRFH "\0";
	close(WTRFH);
	while (<RDRFH>) {
		if (/unrouteable mail domain/) {
			return "unroutable";
		}
		if (/relay through/) {
			return "unroutable";
		}
		if (/mail loops back to me/) {
			die "FATAL! SENDMAIL IS INSTALLED!!!!! Please contact the sysadmin ASAP";
		}
		if (/mailbox (\S+) has wrong mode/) {
			return "badmode $1";
		}
#		if (/creating lock file hitching post/) {
#			return "nosticky";
#		}
#		if (/file mode.*should not contain/) {
#			return "badmode";
#		}
	}
}