blib/script/gbrowse_change_passwd.pl untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 9 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 71 CC 1 SCAR 6.9
CC
1
Cov
0%
get_random_password
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 use strict;
4  
5 use FindBin '$Bin';
6 use lib "$Bin/../lib";
7 use GBrowse::ConfigData;
8 use Bio::Graphics::Browser2;
9 use Bio::Graphics::Browser2::UserDB;
10 use Getopt::Long;
11  
12 my @ORIGINAL_ARGV = @ARGV;
13  
14 use constant USAGE => <<END;
15 Usage: $0 user [pass]
16  
17 Changes the password for the indicated user.
18 If no password is provided on the command line, then
19 a new random password will be chosen.
20  
21 This script uses the "user_account_db" option in the currently
22 installed GBrowse.conf configuration file to find
23 the appropriate accounts database.
24 END
25 ;
26 if ($ARGV[0] =~ /^--?h/) {
27 die USAGE;
28 }
29  
30 my $wwwuser = GBrowse::ConfigData->config('wwwuser');
31 my $uid = (getpwnam($wwwuser))[2];
32 unless ($uid == $<) {
33 print STDERR "Not running as $wwwuser. Trying to use sudo to remedy. You may be asked for your login password.\n";
34 my @args = ('sudo','-u',$wwwuser,$0, @ORIGINAL_ARGV);
35 exec @args;
36 exit 0;
37 }
38  
39 my $globals = Bio::Graphics::Browser2->open_globals or die "Couldn't open GBrowse.conf";
40 my $userdb = Bio::Graphics::Browser2::UserDB->new($globals);
41  
42 my $name = shift or die "Please provide a username. Run $0 --help for help\n";
43 my $pass = shift || get_random_password();
44  
45 my $uid = $userdb->userid_from_username($name);
46 $uid || die "unknown user: $name\n";
47  
48 $userdb->set_password($uid,$pass);
49 warn "Account \"$name\": password successfully set to $pass.\n";
50  
51 exit 0;
52  
53 sub get_random_password {
54 my $p = '';
55 my @a = ('a'..'z','A'..'Z',0..9);
56 for (1..10) {
57 $p .= $a[rand @a];
58 }
59 return $p;
60 }
61  
62 __END__