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

📄 sendmail2vpopmail.pl

📁 相当优秀的 UNIX 进程管理工具
💻 PL
📖 第 1 页 / 共 2 页
字号:
print ("Number of aliases processed:\t\t\t\t", $countalias,"\n");print ("Number of aliases from alias file processed:\t\t",@donealias + 1,"\n");print ("Number of forwards processed:\t\t\t\t",$countforward,"\n");print ("Number of forwards from alias file processed:\t\t",$countaliasforward,"\n");$dbh->disconnect();#processalias()sub processalias { #now we could stop processing if the user is created already#but god(root?) knows if alias is aliased to itself  foreach $line2 (@MYALIASFILE) {    @values3=split(/:/,$line2);    if( ( ! ($line2 =~ /^#/) ) && $_[0] ne "PROCESS_WHOLE_ALIAS_FILE") {      $aliasname=$values3[0];      $aliasname=~ s/^\s+|\s+$//g;      if ($sysuname eq $aliasname) {        push(@donealias,$aliasname);        @aliastgt=split(/,/,$values3[1]);        foreach $line3 (@aliastgt) {          $line3=~ s/^\s+|\s+$//g;          if( $line3 =~ /@/) {            $countaliasforward+=1;            if($DEBUG >= 10) {              print("Creating forward for user $virtuname\@$domain to $line3 \n");            }            $sth = $dbh->prepare("SELECT pw_dir FROM  vpopmail  where pw_name='postmaster'  and pw_domain='$domain'");            $sth->execute;            while (my $ref = $sth->fetchrow_arrayref) {              $mdir= $$ref[0];            }            $sth->finish;            #fix the aliases with . inside to :            $virtuname1=$virtuname;            $virtuname1=~ s/(.+)\.(.+)/$1\:$2/g;            $virtuname1=lc($virtuname);            open(OUTFILE, ">$mdir/../.qmail-$virtuname1");            print OUTFILE "&$line3";            close (OUTFILE);            } else {            if($DEBUG >= 20) {              print("Creating $line3 which is aliased from the alias $sysuname in virtusertable \n");              &createvpopmailuser($line3);            }          }        }      }    }  }  }#createaliasforward()sub createaliasforward {  #do not create an alias for the user we already created  if ($virtuname ne $sysuname) {    if ($sysuname =~ /error:/ ) {      if($DEBUG >= 20) {        print("We do not create aliases for error messages at $domain to $sysuname\n");      }    } else {      if ($virtuname eq "") {        if($DEBUG >= 20) {          print("Changing default email address to catchall account for $domain $sysuname\@$domain\n");        }        $virtuname=default;      }      #figure out if this is a forward or alias      if($sysuname =~ /@/) {        $countforward+=1;        if($DEBUG >= 10) {          print("Creating forward for user $virtuname\@$domain to $sysuname \n");        }        $sth = $dbh->prepare("SELECT pw_dir FROM  vpopmail  where pw_name='postmaster'  and pw_domain='$domain'");        $sth->execute;        while (my $ref = $sth->fetchrow_arrayref) {          $mdir= $$ref[0];        }	$sth->finish;        #fix the aliases with . inside to :        $virtuname1=$virtuname;        $virtuname1=~ s/(.+)\.(.+)/$1\:$2/g;        $virtuname1=lc($virtuname);        open(OUTFILE, ">$mdir/../.qmail-$virtuname1");        print OUTFILE "&$sysuname";        close (OUTFILE);      } else {        $countalias+=1;        if($DEBUG >= 10) {          print("Creating Alias for User $virtuname\@$domain to $sysuname\@$domain \n");        }        $sth = $dbh->prepare("SELECT pw_dir FROM  vpopmail  where pw_name='postmaster'  and pw_domain='$domain'");        $sth->execute;        while (my $ref = $sth->fetchrow_arrayref) {          $mdir= $$ref[0];        }	$sth->finish;        #fix the aliases with . inside to :        $virtuname1=$virtuname;        $virtuname1=~ s/(.+)\.(.+)/$1\:$2/g;        $virtuname1=lc($virtuname);        open(OUTFILE, ">$mdir/../.qmail-$virtuname1");        $sth = $dbh->prepare("SELECT pw_dir FROM  vpopmail  where pw_name='$sysuname'  and pw_domain='$domain'");        $sth->execute;        while (my $ref = $sth->fetchrow_arrayref) {          $mdir= $$ref[0];        }	$sth->finish;        print OUTFILE "$mdir/Maildir/\n";        close (OUTFILE);      }    }  }}#createvpopmailuser($username)sub createvpopmailuser {$notalias=0;  foreach $line1 (@MYPASSFILE) {    $domaindone=0;    $userdone=1;    @values2=split(/:/,$line1);    if( ( ! ($line1 =~ /^#/) ) && $_[0] eq "PROCESS_WHOLE_PASSWORD_FILE") {      $sysuname=$values2[0];      $syspass=$values2[1];      $sysuid=$values2[2];      if ($SPOOL eq 0) {        $SYSDIR=$values2[8];      }      $userdone=0;    }    if( ( ! ($line1 =~ /^#/) ) && $_[0] eq $values2[0]) {      $sysuname=$values2[0];      $syspass=$values2[1];      $sysuid=$values2[2];      if ($SPOOL eq 0) {        $SYSDIR=$values2[8];      }      $userdone=0;    }    if ( ($values2[2] < $MINUID || $values2[2] > $MAXUID) && $userdone eq 0) {      if ($DEBUG >= 10 && $userdone eq 0) {        print("Skipping creation of users UID less than $MINUID or more than $MAXUID\n");        print("Please process virtual accounts pointing to system account $sysuname manually\n");        sleep($SLEEPTIME);      }      $userdone=1;    }    #detect if we already processed some stuff...    foreach $elem (@donedom) {      if($elem eq $domain) {        $domaindone=1;      }    }    if($DUPLICATE eq 0) {      #if the username has @ then its forward...      foreach $elem (@doneuser) {        if($elem eq $sysuname || $sysuname =~ /@/ ) {          $userdone=1;        }      }    } else {      foreach $elem (@doneuser1) {        if($elem eq $sysuname || $sysuname =~ /@/ ) {          $userdone=1;        }      }    }    if ($DEBUG >= 20 && $userdone eq 0) {      print("System Username:UID:Password:Home/Spool Directory: $sysuname:$sysuid:$syspass:$SYSDIR \n");      sleep($SLEEPTIME);    }    #if we are creating a user for this domain first time.    if ($domaindone ne 1) {      print("Creating domain $domain and user(s)\n");      `$VPOPMAILHOMEDIR/bin/vadddomain  $domain  $POSTMASTERPASSWORD`;      $sth = $dbh->prepare("SELECT pw_dir FROM  vpopmail  where pw_name='postmaster'  and pw_domain='$domain'");      $sth->execute;      while (my $ref = $sth->fetchrow_arrayref) {        $mdir= $$ref[0];      }      $sth->finish;      open(OUTFILE, ">$mdir/../.qmailadmin-limits");      print OUTFILE "maxpopaccounts: $DEFAULTDOMUSERLIMIT\n";      print OUTFILE "maxaliases: $DEFAULTALIASLIMIT\n";      print OUTFILE "maxforwards: $DEFAULTFORWARDSLIMIT\n";      print OUTFILE "maxautoresponders: $DEFAULTAUTORESPONDERLIMIT\n";      print OUTFILE "maxmailinglists: $DEFAULTMAILLISTLIMIT\n";      print OUTFILE "default_quota: $DEFAULTDOMQUOTA\n";      close (OUTFILE);      push(@donedom,$domain);    }    #if we didnt create this user yet, somewhere else, sometime ago.    if ($userdone ne 1) {      #statistics :)      $countvpopuser+=1;      if ($SYSTEMQUOTA eq 1) {        $arg = Quota::getqcarg($SYSDIR);        ($block_curr, $block_soft, $block_hard, $block_timelimit,            $inode_curr, $inode_soft, $inode_hard, $inode_timelimit) =            Quota::query($arg,$sysuid);      } else {        $block_hard="";      }      if($block_hard ne "") {        if ($block_hard < $MINQUOTA) {          $block_hard=$MINQUOTA        }        $QUOTA="$block_hard" ."000S";        if($DEBUG >= 10) {          print("Creating User $sysuname\@$domain with quota $QUOTA \n");        }        `$VPOPMAILHOMEDIR/bin/vadduser -q $QUOTA  $sysuname\@$domain  $sysuname`;        } else {        if ($DEFAULTQUOTA ne 0) {          if($DEBUG >= 10) {            print("Creating User $sysuname\@$domain with default quota $DEFAULTQUOTA \n");          }          `$VPOPMAILHOMEDIR/bin/vadduser -q $DEFAULTQUOTA  $sysuname\@$domain  $sysuname`;        } else {          if($DEBUG >= 10) {            print("Creating User $sysuname\@$domain without quota \n");          }          `$VPOPMAILHOMEDIR/bin/vadduser $sysuname\@$domain  $sysuname`;        }      }      #update the vpopmail pasword with the system password      $dbh->do("UPDATE vpopmail SET pw_passwd='$syspass'  where pw_name='$sysuname' and pw_domain='$domain'");      $sth = $dbh->prepare("SELECT pw_dir FROM  vpopmail  where pw_name='$sysuname'  and pw_domain='$domain'");      $sth->execute;      while (my $ref = $sth->fetchrow_arrayref) {        $mdir= $$ref[0];      }      $sth->finish;      #copymails to user Maildir converting...      $MAILBOXDIR="$SYSDIR/$INBOX";      if ($DEBUG >= 20) {        print("User mail file $MAILBOXDIR \n");        sleep($SLEEPTIME);      }      if ( -e "$MAILBOXDIR" ) { # if user has any mail in spool        open(MAILSPOOL, "<$MAILBOXDIR") || next;        $i = time;        if($DEBUG >= 10) {          print("Copying and converting $sysuname mail to $mdir \n");        }        while(<MAILSPOOL>) {          if (/^From /) {            $filename = sprintf("%s/Maildir/new/%d.$$.mbox",$mdir, $i);            open(MBOX, ">$filename") || die("Unable to create new message");;            $i++;            next;          } #if ends          s/^>From /From /;          print MBOX || die ("Unable to write to new message");        } #while mailspool ends        close(MAILSPOOL);        close(MBOX);      } # if -e $MAILBOXDIR ends      push(@doneuser,$sysuname);      if ($DUPLICATE ne 0 && $domain eq $DEFAULTDOMAIN) {        push(@doneuser1,$sysuname);      }      if ($domain eq $DEFAULTDOMAIN) {        #for statistics        $countdefaultdomain+=1;      }     }  }}

⌨️ 快捷键说明

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