⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendmail2vpopmail.pl

📁 相当优秀的 UNIX 进程管理工具
💻 PL
📖 第 1 页 / 共 2 页
字号:
#!/usr/bin/perl# USE AT YOUR OWN RISK!!! Sendmail2Vpopmail.pl v0.0.4  Date:21.07.2003## v0.0.2	* Fixed the bug in chmod/chown not working and default forwards#                 limit not assigned.# v0.0.3	* Fixed the bug of creating aliases/forwards with . inside# v0.0.4	* Fixed the bug of creating aliases/forwards with capital letters## This script "should" convert sendmail users including users from virtusertable# files to vpopmail. It only works for vpopmail installations which DOES NOT# utilize LARGE_SITE. Although it would be trivial to include large site support.# Script also can read the system quota limits for the directory where the mail# of users is located and transfer it to vpopmail system## FEATURES## * Supports converting system quotas# * Supports setting a minimum quota for users with or without quota# * Supports setting a default quota if system quota is not used#   or if a user doesnt have system quota# * Supports virtusertable file# * Supports setting QmailAdmin and vQadmin limits# * Supports system traditional system mail spool directory or#   if the mail is stored in user directory.# * Supports processing of password file for a default domain name#   for the users which do not exist in virtusertable# * Suports creating aliases or forwards from virtusertable file for#   users whouse virtual username is not same with system username# * Supports putting all users to default domain without processing#   virtusertable file# * Supports creating duplicate accounts in default domain for the #   users already processed in virtusertable file# * Supports processing of alias file# * Works with DES or MD5 passwords on FreeBSD## TODO## * Script could log its actions...# * LARGE_SITE support...# * Script could support aliases file better...# * Cleaning variables!## BUGS## * There is no simple way to know (at least for me) the domain's directory#   path in vpopmail system. This script is just assuming that since postmaster#   is the first account to be created, it must be in the domain's first#   level. Then extracts one directory and finds the domain directory.# * If a username is aliased to aliased alias then this wont work.#   If somebody knows how to fix this then please contact me!# * Too many variables used...# * If a username is under multiple virtual domains, then it wont be#   created for the other domains. (unless duplicate is selected?)## NOTES## * Be sure that the quotas are enabled if you mount your users directory#   with NFS or similar. I did this mistake and no quotas were processed!# * Be sure that you disable debugging sleep times to 0 otherwise it will#   take long long time to process all your users.# # For any comments or if you add new features, please contact with me.# Evren Yurtesen <yurtesen@ispro.net.tr>## I have tested this script on a FreeBSD system with about 10000 users with# quotas and the mail files stored on user directories. The rest is untested!# So if you have any experiences please write!#there is no doubt these modules MUST be installed in your system! :)use DBI;use Quota;# debuglevel: increase the number for more and more messages# currently only 0-10-20 levels exist$DEBUG=0;#waiting time after a debug message$SLEEPTIME=1;#system alias file#if an empty file is given then it will be ignored#(/dev/null would suffice perhaps)#it is needed if you have been using alias file in#conjunction with virtusertable file. For example#if you have this in your virtusertable file#abc@abc.com                    abc#and in your alias file#abc:   abc1,abc2,abc3$ALIASFILE="/etc/aliases";#$ALIASFILE="/dev/null";#system virtusertable file#if an empty file is given then all users in password file #will be added to defaultdomain (/dev/null would suffice)$VIRTFILE="virtusertable";#$VIRTFILE="/dev/null";#do you want to create all users in password file, also in the#default domain? even if they were previously created because#they exist in virtusertable file? if set to 1 then duplicates#will be created$DUPLICATE=0;#FreeBSD password file (might work for Linux shadow?)a$PASSFILE="/etc/master.passwd";#do you want to use system quota? if enabled then the script#will find the hard limit of the user.#the inode limit is not processed!#to disable, set to 0$SYSTEMQUOTA=1;#default quota for all moved users (in bytes) or if SYSTEMQUOTA#is set, then this effects the users who doesnt have quota if#DEFAULTQUOTA is set to 0 then the users wont have quota if#SYSTEMQUOTA is also disabled. If SYSTEMQUOTA is enabled then the#users who doesnt have system quotas will not have quota$DEFAULTQUOTA="10000000S";#well considering the hard drive technology is advancing quite fast,#you might want to increase the minimum quota for your users.#lets say if they have a quota of 6000kbyte then you can increase#it to 10000kbyte if MINQUOTA is set to 10000.#if the user has 12000kbyte then it wont effect anything#if set to 0 then it wont have effect (obviously)#if you are not checking SYSTEMQUOTA then MINQUOTA does not have#any effect$MINQUOTA="10000";#minimum and maximum userid's while processing the password file#this is required so that you wont process root account etc.#accidentally and make an email address with root password!#it wouldnt be nice :p$MINUID=100;$MAXUID=60000;#VPOPMAIL USER/GROUP$VPOPMAILUSER="vpopmail";$VPOPMAILGROUP="vchkpw";#default domain limits for qmailadmin etc. will have this quotas etc.#a value of 0 disables that functionality.$DEFAULTDOMUSERLIMIT="20";$DEFAULTALIASLIMIT="100";$DEFAULTFORWARDSLIMIT="5";$DEFAULTAUTORESPONDERLIMIT="0";$DEFAULTMAILLISTLIMIT="0";$DEFAULTDOMQUOTA="10000000S";#are you using spool directory 0 or user homedirs 1 to store mail?$SPOOL=0;#system mail spool directory (do not set it if user inboxes are in their homedirs)!#$SYSDIR="/var/spool/mail";#inbox file (set it to location of inbox of user inside his directory if user inboxes#are in their homedirs);#$INBOX=$sysuname; #sets the user INBOX name to his username$INBOX="mail/INBOX";#the default vpopmail directory#the domains directory and bin directory must be inside!$VPOPMAILHOMEDIR="/usr/local/vpopmail";#default domain for users which are not in virtusertable#if set to "none" only users in virtusertable is processed.#be aware that it is not possible to process a single domain#excluding the users in virtusertable file without processing#the virtusertable file$DEFAULTDOMAIN="mydomain.net";#default postmaster password for all domains$POSTMASTERPASSWORD="mypassword";#sql settings$SQL_DATABASE="vpopmail";$SQL_SERVER="localhost";$SQL_USERNAME="vpopmail";$SQL_PASSWORD="mypassword";#configuration ends here-----------------------------------------------#open virtusertable fileopen(MYVIRTFILE,"< $VIRTFILE") or die "I could not open $VIRTFILE exiting ....";#open password file and put into an array, since we will use this MANY timesopen(MYPASSFILEH,"< $PASSFILE") or die "I could not open $PASSFILE exiting ....";@MYPASSFILE=<MYPASSFILEH>;close (MYPASSFILE);#open alias file and put into an array, since we will use this MANY times   open(MYALIASFILEH,"< $ALIASFILE") or die "I could not open $ALIASFILE exiting ....";@MYALIASFILE=<MYALIASFILEH>;close (MYALIASFILEH);#connect to database...$dbh = DBI->connect("DBI:mysql:$SQL_DATABASE:$SQL_SERVER","$SQL_USERNAME","$SQL_PASSWORD")    or die "I could not connect $SQL_DATABASE at $SQL_SERVER with $SQL_USERNAME identified by $SQL_PASSWORD";#reset some variables, just to be sure :)$countalias=0;$countdefaultdomain=0;$countforward=0;$countuser=0;$domaindone=0;$userdone=0;$samevirtsys=0;#Go through the virtusertable filewhile( $line=<MYVIRTFILE> ) {  chomp($line);  #just skip the lines which doesnt have any meaning for us...  if ($line =~ /@/ && ! ($line =~ /^#/ ) ) {    #parse the virtusertable and find virtusername, virtuserdomain, systemusername    @values=split(/[\ \t]+/,$line);    $values[0] =~ s/^\s+|\s+$//g;    $values[1] =~ s/^\s+|\s+$//g;    @values1=split(/@/,$values[0]);    #put virtuser values to variables    $virtuname=$values1[0];    $domain=$values1[1];    $sysuname=$values[1];    #detect if we already processed some stuff in a previous run...    foreach $elem (@donedom) {      if($elem eq $domain) {        $domaindone=1;      }    }    foreach $elem (@doneuser) {      if($elem eq $sysuname) {        $userdone=1;      }    }    #do not do anything for stuff we wont need    if ( $sysuname =~ /error:/ || $virtuname eq "") {      if($DEBUG >= 20) {        print("Not searching default user password for domain $domain. Simply needless... \n");        sleep($SLEEPTIME);      }    } else {      &createvpopmailuser($sysuname);      &processalias;      &createaliasforward;    }  }}close (MYVIRTFILE);#process the default domainprint("\n\nProcessing default domain $DEFAULTDOMAIN \n");print("It might take a while. You can monitor your SQL \n");print("database or vpopmail domains directory to see \n");print("what is going on \n\n\n");$domain=$DEFAULTDOMAIN;&createvpopmailuser("PROCESS_WHOLE_PASSWORD_FILE");print ("Setting user/group owners and access rights\n");`chown -R $VPOPMAILUSER:$VPOPMAILGROUP $VPOPMAILHOMEDIR/domains`;`chmod -R go-rwx $VPOPMAILHOMEDIR/domains`;print ("Number of domains processed:\t\t\t\t",$#donedom + 1,"\n");print ("Number of virtusers processed:\t\t\t\t",$#doneuser + 1,"\n");print ("Number of system users processed:\t\t\t",$#doneuser + 1 + $countvpopuser,"\n");if ($DUPLICATE ne 0) {  print ("Number of default domain users processed:\t\t",@doneuser1 + 1,"\n");} else {  print ("Number of default domain users processed:\t\t",$countdefaultdomain,"\n");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -