I wrote this script to automatically create email pop accounts for a certain domain from a list. It makes a backup from the original file and adds it to the file.
Passwords are created and crypted. A CSV file containing the emailadresses and plaintext passwords is also created. This can be emailed to the customer.
How to:
- Create a file called: poptmp.txt
- Put all the names of the pop accounts in here. Each name on a new line (ie joe.doe). These can be Upper or lowercase. The script converts it to lowsercase.
Script:
#!/usr/bin/perl
#
# poptool.pl
# Create pop accounts from list
#
#
$popnames = "poptmp.txt";
# Change DOMAIN.COM to users domain name
$domain = "DOMAIN.COM";
#change to dir of this script
$scriptdir = "/home/USER/script";
# This file contains the addresses and plaintext passwords in csv format.
$pop_passwd_text = "$scriptdir/pop_password.csv";
# Don't change. This is the location for the pop account file
$pop_passwd_file = "/etc/virtual/$domain/passwd";
# make backup old password file
system "/bin/cp /etc/virtual/$domain/passwd /etc/virtual/$domain/passwd.old";
#open names file
open(IDFILE, "$popnames");
@idfile = <IDFILE>;
close(IDFILE);
foreach $idfile (@idfile) {
chomp $idfile;
$idfile = lc $idfile;
# generate password
$returnvalue = &generate_random_password(6);
$VAR{pass} = "$returnvalue";
$VAR{salt} = "ab";
$VAR{pass} = crypt($VAR{pass}, $VAR{salt});
# Write email and passwords to file
open (PASS, ">>$pop_passwd_text") || die "Error $pop_passwd_text\n";
print PASS "$idfile\@$domain;$returnvalue;\n";
close PASS;
open (PASS, ">>$pop_passwd_file");
print PASS "$idfile:$VAR{pass}\n";
close PASS;
print "$idfile\@$domain:$VAR{pass}\n";
}
sub generate_random_password
{
my $passwordsize = shift;
my @alphanumeric = ('a'..'z', 'A'..'Z', 0..9);
my $randpassword = join '',
map $alphanumeric[rand @alphanumeric], 0..$passwordsize;
return $randpassword;
}
# end poptool script
Passwords are created and crypted. A CSV file containing the emailadresses and plaintext passwords is also created. This can be emailed to the customer.
How to:
- Create a file called: poptmp.txt
- Put all the names of the pop accounts in here. Each name on a new line (ie joe.doe). These can be Upper or lowercase. The script converts it to lowsercase.
Script:
#!/usr/bin/perl
#
# poptool.pl
# Create pop accounts from list
#
#
$popnames = "poptmp.txt";
# Change DOMAIN.COM to users domain name
$domain = "DOMAIN.COM";
#change to dir of this script
$scriptdir = "/home/USER/script";
# This file contains the addresses and plaintext passwords in csv format.
$pop_passwd_text = "$scriptdir/pop_password.csv";
# Don't change. This is the location for the pop account file
$pop_passwd_file = "/etc/virtual/$domain/passwd";
# make backup old password file
system "/bin/cp /etc/virtual/$domain/passwd /etc/virtual/$domain/passwd.old";
#open names file
open(IDFILE, "$popnames");
@idfile = <IDFILE>;
close(IDFILE);
foreach $idfile (@idfile) {
chomp $idfile;
$idfile = lc $idfile;
# generate password
$returnvalue = &generate_random_password(6);
$VAR{pass} = "$returnvalue";
$VAR{salt} = "ab";
$VAR{pass} = crypt($VAR{pass}, $VAR{salt});
# Write email and passwords to file
open (PASS, ">>$pop_passwd_text") || die "Error $pop_passwd_text\n";
print PASS "$idfile\@$domain;$returnvalue;\n";
close PASS;
open (PASS, ">>$pop_passwd_file");
print PASS "$idfile:$VAR{pass}\n";
close PASS;
print "$idfile\@$domain:$VAR{pass}\n";
}
sub generate_random_password
{
my $passwordsize = shift;
my @alphanumeric = ('a'..'z', 'A'..'Z', 0..9);
my $randpassword = join '',
map $alphanumeric[rand @alphanumeric], 0..$passwordsize;
return $randpassword;
}
# end poptool script