I inherited an excellent script that works wonderfully.Thank you Joe Balsama!
I have replaced the site specifics with generic server.domain.com cyrususer and 
password
I use this script to add and delete user mailboxes.
It queries the server for the user via NIS ypmatch.

I shall paste it here as I do not know if the list takes attachments?

mailboxes

#!/usr/bin/perl

my $list = '';
my $arg = '';
my $username = '';
my $command = '';

$login_info =
  "eval cyradm connect cyr_conn servername.domain.com\n" .
  "eval cyr_conn authenticate -pwcommand {{\n" .
  "       set hostname \"servername.domain.com\"\n" .
  "       set adminid \"cyrususer\"\n" .
  "       set adminpw \"password\"\n" .
  "       list \$adminid \$adminpw\n" .
  "       }}\n\n";

$usage =
  "\nmailboxes [ADD|DEL] [-f FILE] [-u USERNAME]\n" .
  "creates new mailboxes on server.domain.com\n";

unless (@ARGV) {die "$usage\n"; }
unless (( $ARGV[0] eq 'ADD' ) || ( $ARGV[0] eq 'DEL' )) {die "$usage\n"; }

my $command = $ARGV[0];
shift;

while (<@ARGV>)
{
        if ($ARGV[0] eq '-f')
        {
          $list = "1";
          open LIST, @ARGV[1] || die "Can't open LIST\n$usage";
          shift;
          shift;
        }
        if ($ARGV[0] eq '-u')
        {
          $username = @ARGV[1] || die "No username provided\n$usage";
          $arg = "1";
          shift;
          shift;
        }
}


if (( $list eq '1' ) && ( $command eq 'ADD' ))
{
  while (<LIST>) 
  {
        if ( -f "make.cyr.boxes" ) { unlink "make.cyr.boxes"; }
        umask 0077;
        open CMDS, ">>make.cyr.boxes" || die "Can't open CMDS for writing\n";
        print CMDS $login_info;
        $user = $_;
        chomp $user;
        $user =~ s/^(\w+):.+$/$1/;
        if ( system("ypmatch $user passwd") eq '0' ) 
        {
           # (^ if uid actually exists)
           print CMDS "puts \"\\ncreate inbox for user " . $user . "\\n\"\n";
           print CMDS "cyr_conn createmailbox user." . $user . "\n";
           print CMDS "puts \"\\nset quota for " . $user . " 8000k\\n\"\n";
           print CMDS "cyr_conn setquota user." . $user . " storage 8000\n";
           close CMDS;
           system ("/usr/local/sbin/cyradm", "-file", "make.cyr.boxes");
        } else {
           print "$user: No such user\n";
        }
   }
   close LIST;
} elsif (( $list eq '1' ) && ( $command eq 'DEL' )) {
        die "\$list = $list  :  Cannot $command from a file (too unsafe)\n$usage";
}

if ($arg) 
        {
        if ( -f "make.cyr.boxes" ) { unlink "make.cyr.boxes"; }
        umask 0077;
        open CMDS, ">>make.cyr.boxes" || die "Can't open CMDS for writing\n";
        print CMDS $login_info;
        $user = $username;
        chomp $user;
        $user =~ s/^(\w+):.+$/$1/;
        if ( system("ypmatch $user passwd") eq '0' ) 
        {
           # (^ if uid actually exists)
           if ( $command eq 'ADD' )
           {    
                print CMDS "puts \"\\ncreate inbox for user " . $user . "\\n\"\n";
                print CMDS "cyr_conn createmailbox user." . $user . "\n";
                print CMDS "puts \"\\nset quota for " . $user . " 8000k\\n\"\n";
                print CMDS "cyr_conn setquota user." . $user . " storage 8000\n";
           } elsif ( $command eq 'DEL' ) {
                print CMDS "puts \"\\ndelete inbox for user " . $user . "\\n\"\n";
                print CMDS "cyr_conn setaclmailbox user." . $user . " cyrus all\n";
                print CMDS "cyr_conn deletemailbox user." . $user . "\n";
           } else { 
                die "Invalid command: $command\n"; 
           }
        
        close CMDS;
           system ("/usr/local/sbin/cyradm", "-file", "make.cyr.boxes");
        } else {
           print "$user: No such user\n";
        }
}

exit;

-----Original Message-----
From:   Daniel Schwager [SMTP:[EMAIL PROTECTED]]
Sent:   Thursday, October 04, 2001 2:02 AM
To:     Vincent Stoessel
Cc:     [EMAIL PROTECTED]
Subject:        Re: perl script for adding users

Vincent Stoessel wrote:
>
> Anyone have a sample perl script for adding new users for
> cyrus?

.. and anyone habe a sample perl script for changing user-permissions
   recursive ??

regards

Danny

--
------------------------------------------------------------
DT Netsolution GmbH -  Talaeckerstr. 30 -  D-70437 Stuttgart
Tel: +49-711-5505915-0               Fax: +49-711-5505915-12
WEB: http://www.dtnet.de/           email: [EMAIL PROTECTED]

Reply via email to