Script to massively insert users into Kolab?

Diego M. Vadell dvadell at linuxclusters.com.ar
Thu Aug 28 04:08:00 CEST 2008


On Monday 25 August 2008 16:59:13 Richard Bos wrote:
> Op Monday 25 August 2008 08:41:07 schreef Alessio Cecchi:
> > >     Is there any script to automatically create users in a Kolab
> > > server? I'm migrating from cyrus to Kolab and I was going to do it (
> > > with WWW-Mechanize to fill the forms in /admin/ ) but I thought I
> > > should better don't reinvent the wheel and ask if anyone already did
> > > such a thing.
> >
> > Hi,
> >
> > I used several times with success this script:
> >
> > http://wiki.kolab.org/index.php/Csvtoldap.pl
>
> But does this script not bypass all the checks that are build into the
> kolab frontend?  Wouldn't it be better if there is a hook in kolab, that
> can be used to insert user data and that checks that the data is correct?

Hi,
   I tried csvtoldap.pl but, being a newbie with ldap, I couldn't help feeling 
a little unconfortable because of this little test I did:

* I made a test user through the web interface
* dumped that user through slapcat and compared it with the ldif that 
csvtoldap.pl outputs:
* they look different!

So I made the script with WWW-Mechanize and I got about 300 users done in a 
couple of minutes. It goes a little like this (it's pretty rough though, but 
I hope it could help someone)

----------------
#!/kolab/bin/perl
use WWW::Mechanize;

my $csv_file = shift;

my $fields = {
    'username' => "manager",
    'password' => "XXXXXXXXX",
};

# Log In
my $mech = WWW::Mechanize->new( autocheck => 1 );
$mech->get( 'https://localhost/admin/' );

$mech->submit_form(fields => $fields);
      die unless $mech->success;

my $link = "https://localhost/admin/user/user.php?action=create";
$mech->get($link);

# Get the users list
open (CSV,"$csv_file");
while ($line = <CSV>) {
    chomp $line;
    my ($name, $sn, $pass, $login) = split (";", $line);
    add_user( $name, $sn, $pass, $login );
}

# Add user sub
sub add_user {
    my ($name, $sn, $pass, $login) = @_;

    print "Adding: $name / $sn / $pass / $login \n";
    my $fields = {
        'givenname' => $name,
        'sn' => $sn,
        'user_mail' => $login,
        'password_0' => $pass,
        'password_1' => $pass,
    };

    $mech->form_number(1);
    $mech->submit_form(with_fields => $fields, button => 'submit_user');
          die unless $mech->success;
}
------------------

 -- Diego




More information about the users mailing list