-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added utility to change user passwords
- Loading branch information
Showing
4 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
|
||
use FindBin '$Bin'; | ||
use lib "$Bin/../lib"; | ||
use GBrowse::ConfigData; | ||
use Bio::Graphics::Browser2; | ||
use Bio::Graphics::Browser2::UserDB; | ||
use Getopt::Long; | ||
|
||
my @ORIGINAL_ARGV = @ARGV; | ||
|
||
use constant USAGE => <<END; | ||
Usage: $0 user [pass] | ||
Changes the password for the indicated user. | ||
If no password is provided on the command line, then | ||
a new random password will be chosen. | ||
This script uses the "user_account_db" option in the currently | ||
installed GBrowse.conf configuration file to find | ||
the appropriate accounts database. | ||
END | ||
|
||
my $wwwuser = GBrowse::ConfigData->config('wwwuser'); | ||
my $uid = (getpwnam($wwwuser))[2]; | ||
unless ($uid == $<) { | ||
print STDERR "Not running as $wwwuser. Trying to use sudo to remedy. You may be asked for your login password.\n"; | ||
my @args = ('sudo','-u',$wwwuser,$0, @ORIGINAL_ARGV); | ||
exec @args; | ||
exit 0; | ||
} | ||
|
||
my $globals = Bio::Graphics::Browser2->open_globals or die "Couldn't open GBrowse.conf"; | ||
my $userdb = Bio::Graphics::Browser2::UserDB->new($globals); | ||
|
||
my $name = shift or die "Please provide a username. Run $0 --help for help\n"; | ||
my $pass = shift || get_random_password(); | ||
|
||
my $uid = $userdb->userid_from_username($name); | ||
$uid || die "unknown user: $name\n"; | ||
|
||
$userdb->set_password($uid,$pass); | ||
warn "Account \"$name\": password successfully set to $pass.\n"; | ||
|
||
exit 0; | ||
|
||
sub get_random_password { | ||
my $p = ''; | ||
my @a = ('a'..'z','A'..'Z',0..9); | ||
for (1..10) { | ||
$p .= $a[rand @a]; | ||
} | ||
return $p; | ||
} | ||
|
||
__END__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters