Author Topic: How to create multiple users accounts?  (Read 6877 times)

andre

  • Zen Apprentice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
How to create multiple users accounts?
« on: January 14, 2008, 12:14:50 pm »
I study in a school and i have 800 students and 100 teachers and i want do this more possible  as soon i can, we have a pc with ebox 0.10 and we want to create multiple users accounts in a quick way. Thanks

Javier Amor Garcia

  • Zentyal Staff
  • Zen Hero
  • *****
  • Posts: 1225
  • Karma: +12/-0
    • View Profile
Re: How to create multiple users accounts?
« Reply #1 on: January 17, 2008, 10:29:57 am »
The way to do that is to create a small script to read a file which your users data and then call the eBox's method to add users.

In the FAQ you can find a more detailed explanation: http://trac.ebox-platform.com/wiki/Document/HowTo/ImportUsersInBulk

Cheers,
  Javier

patcunha

  • Zen Apprentice
  • *
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: How to create multiple users accounts?
« Reply #2 on: January 28, 2008, 12:54:14 pm »
What if I want to be able to put the users in a group when I'm creating them?
What changes do I have to make in the script so that it will put the user in its group?
Must i create groups previously?

sixstone

  • Zentyal Staff
  • Zen Hero
  • *****
  • Posts: 1417
  • Karma: +26/-0
    • View Profile
    • Sixstone's blog
Re: How to create multiple users accounts?
« Reply #3 on: January 28, 2008, 07:55:44 pm »
It's easy the modification, I post it here in order to help more people. There are several posibilities, I propose the one which add another field which is the group where the user is going to be added, but there are more for sure. This solution only applies where the user belongs to zero/one group. The file structure is the following where jblow belongs to a group called 'blowers' and jdoe belongs to no group:

Code: [Select]
jblow,Joe Blow,jblowspassword,blowers,
jdoe,Jane Doe,jdoespassword,

I change the final lines from first loop starts till the end of the script:

Code: [Select]
while(my $line = <$USERS>) {
   chomp ($line);
   my $user;
   my ($username,$fullname,$password, $group) = split(',',$line);
   $user->{'user'} = $username;
   $user->{'fullname'} = $fullname;
   $user->{'password'} = $password;
   $usersModules->addUser($user, 0);
   if ( defined( $group ) )
      unless ( $usersModule->groupExists($group) ) {
          $usersModule->addGroup($group, '', 0);
      }
      $usersModule->addUserToGroup($username, $group);
   }
}

WARNING! I haven't checked but I think it is alright :). ;)

Hope this helps
My secret is my silence...

ispa

  • Zen Apprentice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: How to create multiple users accounts?
« Reply #4 on: February 18, 2008, 12:18:56 pm »
I created the  CSV files with the Data of the user and also the file bulkusers. I have a few doubts :
- how do i run the file with the script?
- how do I send the files fto the server?
- how do I give root permission?

Javier Amor Garcia

  • Zentyal Staff
  • Zen Hero
  • *****
  • Posts: 1225
  • Karma: +12/-0
    • View Profile
Re: How to create multiple users accounts?
« Reply #5 on: February 18, 2008, 12:30:18 pm »
Quote
- how do i run the file with the script?
The script is fairly primitive and it expects a file called 'users' to be in the same directory, it will oepn and read this file.

Quote
how do I send the files fto the server?
Easier way it is to use the 'scp' command. (type 'man scp' in your linux box to get help about this command)

Quote
how do I give root permission?
Just run the file logged as root

ispa

  • Zen Apprentice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: How to create multiple users accounts?
« Reply #6 on: February 19, 2008, 12:55:36 pm »
I ran the script and got this:
Code: [Select]
debian:~# perl bulkusers
Global symbol "$usersModules" requires explicit package name at bulkusers line 21.
syntax error at bulkusers line 23, near ")
      unless"
syntax error at bulkusers line 27, near "}"
Execution of bulkusers aborted due to compilation errors.
my bulkusers file looks like this:
Code: [Select]
#!/usr/bin/perl

use strict;
use warnings;

use EBox;
use EBox::Global;

EBox::init();
my $usersModule = EBox::Global->modInstance('users');

my @users = ();
open(my $USERS,"users");
while(my $line = <$USERS>) {
   chomp ($line);
   my $user;
   my ($username,$fullname,$password, $group) = split(',',$line);
   $user->{'user'} = $username;
   $user->{'fullname'} = $fullname;
   $user->{'password'} = $password;
   $usersModules->addUser($user, 0);
   if ( defined( $group ) )
      unless ( $usersModule->groupExists($group) ) {
          $usersModule->addGroup($group, '', 0);
      }
      $usersModule->addUserToGroup($username, $group);
   }
}
close($USERS);

foreach my $user (@users) {
   $usersModule->addUser($user, 0);
}

1;

and my users file looks like this:
Code: [Select]
7a01,7a01,7495,7a

7a02,7a02,1599,7a

7a03,7a03,3804,7a

7a04,7a04,6495,7a

7a05,7a05,3385,7a

7a06,7a06,8899,7a

7a07,7a07,3433,7a

7a08,7a08,9915,7a

7a09,7a09,1223,7a

7a10,7a10,8480,7a

7a11,7a11,3533,7a

7a12,7a12,9031,7a

7a13,7a13,2403,7a

7a14,7a14,9051,7a

7a15,7a15,6969,7a

sixstone

  • Zentyal Staff
  • Zen Hero
  • *****
  • Posts: 1417
  • Karma: +26/-0
    • View Profile
    • Sixstone's blog
Re: How to create multiple users accounts?
« Reply #7 on: February 19, 2008, 01:14:55 pm »
The correct code script is as follows:

Code: [Select]
#!/usr/bin/perl

use strict;
use warnings;

use EBox;
use EBox::Global;

EBox::init();
my $usersModule = EBox::Global->modInstance('users');

my @users = ();
open(my $USERS,"users");
while(my $line = <$USERS>) {
   chomp ($line);
   my $user;
   my ($username,$fullname,$password, $group) = split(',',$line);
   $user->{'user'} = $username;
   $user->{'fullname'} = $fullname;
   $user->{'password'} = $password;
   $usersModule->addUser($user, 0);
   if ( defined( $group ) ) {
       unless ( $usersModule->groupExists($group) ) {
           $usersModule->addGroup($group, '', 0);
       }
       $usersModule->addUserToGroup($username, $group);
   }
}
close($USERS);

foreach my $user (@users) {
   $usersModule->addUser($user, 0);
}

1;

Regarding to the "users" file, you miss the trailing comma as

Code: [Select]
7a12,7a12,9031,7a,
My secret is my silence...

patcunha

  • Zen Apprentice
  • *
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: How to create multiple users accounts?
« Reply #8 on: February 22, 2008, 11:23:29 am »
It worked!!! ;)

heru

  • Zen Apprentice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: How to create multiple users accounts?
« Reply #9 on: February 24, 2009, 04:08:50 am »
hallo
im newbie in eBOX n i just installed ebox on my computer
how to edit this script so we can create email address to each user


TQ

Javier Amor Garcia

  • Zentyal Staff
  • Zen Hero
  • *****
  • Posts: 1225
  • Karma: +12/-0
    • View Profile
Re: How to create multiple users accounts?
« Reply #10 on: February 24, 2009, 02:28:42 pm »
First, enable the mail module, create the virtual domain for the addresses and save changes.

I think that this version of the script should work:
Code: [Select]
#!/usr/bin/perl

use strict;
use warnings;

use EBox;
use EBox::Global;
use EBox::MailUserLdap;

my $vdomain = 'example.com';

EBox::init();
my $usersModule = EBox::Global->modInstance('users');

my $mailUsers =  EBox::MailUserLdap->new();

my @users = ();
open(my $USERS,"users");
while(my $line = <$USERS>) {
   chomp ($line);
   my $user;
   my ($username,$fullname,$password, $group) = split(',',$line);
   $user->{'user'} = $username;
   $user->{'fullname'} = $fullname;
   $user->{'password'} = $password;
   $usersModule->addUser($user, 0);
   if ( defined( $group ) ) {
       unless ( $usersModule->groupExists($group) ) {
           $usersModule->addGroup($group, '', 0);
       }
       $usersModule->addUserToGroup($username, $group);
   }
}
close($USERS);

foreach my $user (@users) {
   my $username = $user->{user};
   $mailUsers->setUserAccount($username, $username, $vdomain);
   
}

1;
You must edit the variable vdomain to use your own vdomain, all users will have addresses in the form username@vdomain

* Last EDIT: I have removed a wrong line
« Last Edit: February 25, 2009, 09:37:04 am by Javier Amor Garcia »

heru

  • Zen Apprentice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: How to create multiple users accounts?
« Reply #11 on: March 16, 2009, 04:59:07 am »
thanks for this script, but this script does not create email for my user, so i edit this script n its succes

tq bro

Code: [Select]
#!/usr/bin/perl

use strict;
use warnings;

use EBox;
use EBox::Global;
use EBox::MailUserLdap;

my $vdomain = 'example.com';

EBox::init();
my $usersModule = EBox::Global->modInstance('users');

my $mailUsers =  EBox::MailUserLdap->new();

my @users = ();
open(my $USERS,"users");
while(my $line = <$USERS>) {
   chomp ($line);
   my $user;
   my ($username,$fullname,$password, $group) = split(',',$line);
   $user->{'user'} = $username;
   $user->{'fullname'} = $fullname;
   $user->{'password'} = $password;
   $usersModule->addUser($user, 0);
   if ( defined( $group ) ) {
       unless ( $usersModule->groupExists($group) ) {
           $usersModule->addGroup($group, '', 0);
       }
       $usersModule->addUserToGroup($username, $group);
   }
   $mailUsers->setUserAccount($username, $username, $vdomain);
}
close($USERS);

1;
« Last Edit: March 18, 2009, 03:43:11 am by heru »

bccs

  • Zen Apprentice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
ImportUsersInBulk
« Reply #12 on: August 17, 2009, 04:56:30 pm »
I have tried http://trac.ebox-platform.com/wiki/Document/HowTo/ImportUsersInBulk to import users using eBox 1.3.3 and it doesn't work. 

I get the error message: readline() on closed filehandle $USERS at /root/bulkusers line 14

Doesn't eBox 1.3.3 work differently than 1.2?

Javier Amor Garcia

  • Zentyal Staff
  • Zen Hero
  • *****
  • Posts: 1225
  • Karma: +12/-0
    • View Profile
Re: How to create multiple users accounts?
« Reply #13 on: August 18, 2009, 09:21:20 am »
This 'readline' error is not from eBox but for Perl's i/o api. Probably you havent a  filename called 'users' or you havent read permissions in this file
« Last Edit: August 18, 2009, 09:27:59 am by Javier Amor Garcia »

bccs

  • Zen Apprentice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: How to create multiple users accounts?
« Reply #14 on: August 20, 2009, 04:25:20 pm »
I ran bulkusers in /root when I got that last error message because that is what I thought the HOWTO http://trac.ebox-platform.com/wiki/Document/HowTo/ImportUsersInBulk told me to do.  However, when I moved bulkusers and users to /tmp it ran fine.  Following the posts here I tried to assign groups to my users as well. When I run the following code, I get the following error: user name newuser does not exist. 

users file contains just this one line: newuser,New,User,password,students,

Code: [Select]
#!/usr/bin/perl

use strict;
use warnings;

use EBox;
use EBox::Global;

EBox::init();
my $usersModule = EBox::Global->modInstance('users');

my @users = ();
open(my $USERS,"users") or die "Error opening 'users' file: $!";
while(my $line = <$USERS>) {
   chomp ($line);
   my $user;
   my ($username,$givenname,$surname,$password, $group) = split(',',$line);
   $user->{'user'} = $username;
   $user->{'givenname'} = $givenname;
   $user->{'surname'} = $surname;
   $user->{'password'} = $password;
   push(@users,$user);
   if ( defined( $group ) ) {
       unless ( $usersModule->groupExists($group) ) {
           $usersModule->addGroup($group, '', 0);
       }
       $usersModule->addUserToGroup($username, $group);
   }
}
close($USERS);

foreach my $user (@users) {
   $usersModule->addUser($user, 0);
}

1;