File: //scripts.20110531.215904.25158/addpop
#!/usr/bin/perl
# cpanel - addpop Copyright(c) 2010 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
BEGIN { unshift @INC, '/usr/local/cpanel'; }
use strict;
use Cpanel::SafetyBits;
use Cpanel::AcctUtils;
my ( $email, $pass, $quota ) = @ARGV;
if ( !$email ) {
print 'Please enter the pop account to add (ex. bob@sally.com)? ';
chomp( $email = <STDIN> );
}
if ( !$pass ) {
print 'Please enter a password for this pop account? ';
chomp( $pass = <STDIN> );
}
# We do not want to prompt for quota as it could break 3rdparty calls to it by adding an unexpected prompt
# if(!defined $quota) {
# print 'Please enter a quota (in MB) for this account. (zero means unlimited) ';
# chomp( $quota = <STDIN> );
# }
$quota = abs(int($quota));
# Prevent large quota settings, courier doesn't like over 2GB quotas (FB29218)
if ( $quota >= 2048 ) {
$quota = 0;
print "The given quota is 2048 MB or greater so the setting will be set to 'unlimited'.\n";
}
my ( $user, $domain ) = split( /\@/, $email );
my $owner = Cpanel::AcctUtils::getdomainowner( $domain, { 'default' => '' } );
if ( !$owner ) {
die "Cannot find the owner of $domain, try rebuilding /etc/userdomains first with /scripts/updateuserdomains";
}
my ( $uid, $gid ) = ( getpwnam($owner) )[ 2, 3 ];
Cpanel::SafetyBits::setuids( $uid, $gid );
$ENV{'REMOTE_USER'} = $owner;
system '/usr/local/cpanel/cpanel-email', 'addpop', $user, $pass, $quota, $domain;
if ($? != 0) {
die "\nEmail account creation failed ($?)\n";
}
my $quota_text;
if($quota == 0) {
$quota_text = 'unlimited';
}
else {
$quota_text = "$quota MB";
}
print "Created $email with password $pass with a quota of $quota_text for user $owner\n";