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/grabemails
#!/usr/bin/perl

print <<'EOM';
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!! This script is deprecated and will be removed in future builds !!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

EOM
sleep 5;

chomp($hostname = `hostname`);
open(PASSWD,"/etc/passwd");
while(<PASSWD>) {
	s/\n//g;
	($user,undef,undef,undef,undef,$homedir,undef) = split(/:/,$_,7);
	if (-e "/var/cpanel/users/$user" && ! -e "$homedir/.contactemail") {
		$domain = getdomain($user);
		$email = '';
		open(VA,"/etc/valiases/${domain}");
		while(<VA>) {
			if(/^\*: (\S+)/) {
				$email = $1;
			}
		}
		close(VA);
		$email =~ s/\n//g;
		if ($email =~ /\@.*\./ || $email =~ /^\w+$/) {
			if ($email =~ /^\w+$/) {
				$email .= '@' . $hostname;
			}
			if ($pid = fork()) {
				#parent	
			} else {
				setuids($user);			
				open(CA,">$homedir/.contactemail");
				print CA "$email";
				close(CA);
				safe_chmod(0600,$user,"$homedir/.contactemail");
				exit;
			}
			waitpid($pid,0);
		}
		
	}
}
close(PASSWD);
#.contactemail

   sub getdomain {
      $user = $_[0];
      open(CPU,"/var/cpanel/users/$user");
      while(<CPU>) {
         s/\n//g;
         if (/^DNS=(\S+)/) {
            close(CPU);
            return $1;
         }
      }
      close(CPU);
      return "";
   }

sub setuids {
   my($user) = $_[0];
   my($uid,$gid);
   (undef,undef,$uid,$gid) = getpwnam($user);
   if ( ! ($( = int($gid)) ) {
         print "error setting gid\n";
         exit;
         }

         if ( ! ($) = "$gid $gid") ) {
      print "error setting gid\n";
      exit;
   }
   if (! (($> = $uid) && ($< = $uid)) ) {
      die "error setting uid ($uid) [$user]\n";
   }
   return $uid;
}