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: //scripts.20110531.215904.25158/stage2fpmail
#!/usr/bin/perl


$reseller = $ARGV[0];

print "Searching for domains without mail extensions...(pass 2)...\n";

	if (! -e "/usr/local/frontpage/version5.0"){
		$fpv = 4;
	}

@files = (glob('/usr/local/frontpage/*.cnf'));


foreach $file (@files) {
	$file =~ /([\w\-\.]+):80.cnf/i;
	my $domain = $1;
	my $good = 0;
        my $hassender = 0;
	my $dumpold = 0;
	open FILE, "$file" || next;
	while (<FILE>) {
		$line = $_;
		if ($line =~ /Sendmail/i && $line =~ /MailSender/i) {
			print "Dumping Old settings\n";
			$dumpold = 1;
		}
		if ($fpv == 4) {
			if ($line =~ /Sendmail/i) {	
				$good = 1;
			}
			if ($line =~ /MailSender/i) {	
				$hassender = 1;
			}
		} else {
			if ($line =~ /MailSender/i) {	
				$hassender = 1;
			}
			if ($line =~ /Sendmail/i) {
				$good = 1;
				$hassender = 1;
				if ($line =~ /\%r/ || $dumpold) {
					print "Processing File $file\n";
					close(FILE);
					open(R,"$file");
					@RF=<R>;
					close(R);
					foreach (@RF) {
						if (!/sendmail/i 
							&& !/mailsender/i
							&& !/smtp/i &&
							!/^$/) { 
						$rl .= $_;;  }

					}
					if ($fpv == 4){
						$rl .= "SendmailCommand:/usr/sbin/sendmail %r\n";
					} else {
						$rl .= "SendmailCommand:/usr/sbin/sendmail\n";
					}
					$rl .= "MailSender:webmaster\@${domain}\n";
					$rl .= "SMTPHost:127.0.0.1\n";
					open(RTLM,">$file") || die "Unable to open $file\n";;
					print RTLM $rl;
					close(RTLM);
					$good = 1;
					last;
				}
			}
		}
	}
	close FILE;
	if (!$good) {
		print "Adding Sendmail to $file\n";
		push @add, $file;
	}
	if (!$hassender) {
		print "Adding Sender to $file\n";
		push @addsender, $file;
	}
}

foreach $file (@add) {
	$file =~ /([\w\-\.]+):80.cnf/i;
	my $domain = $1;
	my $owner = "";
	$domain =~ s/^www\.//;
	my $user = getdomainowner($domain);
	if (!$user) {
#		next;
	}
	open CP, "/var/cpanel/users/$user" || next;
	while (<CP>) {
		chomp;
		if (s/^OWNER=//) {
			close CP;
			$owner = $_;
		}
	}
	close CP;
	if ($reseller ne "" && $reseller ne "root") {
		if ($reseller ne $owner) {
			next;
		}
	}

	open FP, ">>$file" || next;
	print FP "SMTPHost:127.0.0.1\n";
	if ($fpv == 4){
		print FP "SendmailCommand:/usr/sbin/sendmail %r\n";
	} else {
		print FP "SendmailCommand:/usr/sbin/sendmail\n";
	}
	close FP;
	print "Added FP Mail for $domain ($user)\n";
}


foreach $file (@addsender) {
	$file =~ /([\w\-\.]+):80.cnf/i;
	my $domain = $1;
	my $owner = "";
	$domain =~ s/^www\.//;
	open FP, ">>$file" || next;
	print FP "MailSender:webmaster\@${domain}\n";
	close FP;
	print "Added FP Mail Sender for $domain ($user)\n";
}

print "\nAll Domains now have frontpage mail enabled!\n";

exit;

sub getdomainowner {
   my $domain = $_[0];
   my $name = "";
   open UD, "/etc/userdomains" || return "";
   while (<UD>) {
      chomp;
      my ($ndomain,$nname) = split(/\:/, $_, 2);
      $ndomain =~ s/\s//g;
      $nname =~ s/\s//g;
      if ($ndomain eq $domain) {
         $name = $nname;
         last;
      }
   }
   close UD;
   if ($name eq "") { return "" }
   if ($name eq "root") { return "" }
   return $name;
}