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;
}