]> git.evergreen-ils.org Git - Evergreen.git/blob - OpenSRF/bin/jabber_users_create
fixed a problem in utils where I was using a va_list after calling va_end on the...
[Evergreen.git] / OpenSRF / bin / jabber_users_create
1 #!/usr/bin/perl -w
2
3 # Pulls the jabber users from the oils/jabber config files
4 # and populates the mysql db for the jabber server with the users
5
6 use DBI;
7 use strict;
8 use OpenILS::Utils::Config qw( /pines/conf/oils.conf );
9 my $config = OpenILS::Utils::Config->current;
10
11 if( @ARGV < 2 ) {
12         print "usage: perl jcreate.pl dbhost dbuser dbpass\n";
13         exit;
14 }
15
16
17 my $host = $ARGV[0];
18 my $user        = $ARGV[1];
19 my $pass = $ARGV[2];
20
21 my $connection = DBI->connect( "DBI:mysql:jabberd2:$host", $user, $pass )
22         or die "Cannot connect to db: $! \n";
23
24 my $jpass = $config->transport->auth->password;
25 my $realm = $config->transport->server->primary;
26
27 # Delete all users
28 my $clean = "delete from authreg;";
29 my $sth = $connection->prepare( $clean );
30 $sth->execute();
31
32 my @users = keys %{$config->transport->users};
33
34 # Grab each user from the config and push them into mysql
35 for my $user (@users) {
36         if( ! $user or $user eq "__id" or $user eq "__sub") { next; }
37         print "Inserting $user:  ";
38
39         my $sql = "insert into authreg (username, realm, password) values " .
40                 "('$user', '$realm', '$jpass');";
41
42         print "[$sql]\n"; 
43
44         $sth = $connection->prepare( $sql );
45         $sth->execute();
46
47 }
48
49 $sth->finish();
50