Commit 2e37faa7 authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 353995: Make checksetup able to reset a user's password

Patch By Max Kanat-Alexander <mkanat@bugzilla.org> (module owner) a=mkanat
parent c031e0bf
...@@ -307,27 +307,9 @@ sub create_admin { ...@@ -307,27 +307,9 @@ sub create_admin {
chomp($full_name); chomp($full_name);
} }
while (!$password) { if (!$password) {
# trap a few interrupts so we can fix the echo if we get aborted. $password = _prompt_for_password(
local $SIG{HUP} = \&_create_admin_exit; get_text('install_admin_get_password'));
local $SIG{INT} = \&_create_admin_exit;
local $SIG{QUIT} = \&_create_admin_exit;
local $SIG{TERM} = \&_create_admin_exit;
system("stty","-echo") unless ON_WINDOWS; # disable input echoing
print get_text('install_admin_get_password') . ' ';
$password = <STDIN>;
chomp $password;
print "\n", get_text('install_admin_get_password2') . ' ';
my $pass2 = <STDIN>;
chomp $pass2;
eval { validate_password($password, $pass2); };
if ($@) {
print "\n$@\n";
undef $password;
}
system("stty","echo") unless ON_WINDOWS;
} }
my $admin = Bugzilla::User->create({ login_name => $login, my $admin = Bugzilla::User->create({ login_name => $login,
...@@ -370,13 +352,52 @@ sub make_admin { ...@@ -370,13 +352,52 @@ sub make_admin {
print "\n", get_text('install_admin_created', { user => $user }), "\n"; print "\n", get_text('install_admin_created', { user => $user }), "\n";
} }
# This is just in case we get interrupted while getting the admin's password. sub _prompt_for_password {
sub _create_admin_exit { my $prompt = shift;
my $password;
while (!$password) {
# trap a few interrupts so we can fix the echo if we get aborted.
local $SIG{HUP} = \&_password_prompt_exit;
local $SIG{INT} = \&_password_prompt_exit;
local $SIG{QUIT} = \&_password_prompt_exit;
local $SIG{TERM} = \&_password_prompt_exit;
system("stty","-echo") unless ON_WINDOWS; # disable input echoing
print $prompt, ' ';
$password = <STDIN>;
chomp $password;
print "\n", get_text('install_confirm_password'), ' ';
my $pass2 = <STDIN>;
chomp $pass2;
eval { validate_password($password, $pass2); };
if ($@) {
print "\n$@\n";
undef $password;
}
system("stty","echo") unless ON_WINDOWS;
}
return $password;
}
# This is just in case we get interrupted while getting a password.
sub _password_prompt_exit {
# re-enable input echoing # re-enable input echoing
system("stty","echo") unless ON_WINDOWS; system("stty","echo") unless ON_WINDOWS;
exit 1; exit 1;
} }
sub reset_password {
my $login = shift;
my $user = Bugzilla::User->check($login);
my $prompt = "\n" . get_text('install_reset_password', { user => $user });
my $password = _prompt_for_password($prompt);
$user->set_password($password);
$user->update();
print "\n", get_text('install_reset_password_done'), "\n";
}
1; 1;
__END__ __END__
......
...@@ -66,7 +66,8 @@ $ENV{'HTTP_ACCEPT_LANGUAGE'} ||= setlocale(LC_CTYPE); ...@@ -66,7 +66,8 @@ $ENV{'HTTP_ACCEPT_LANGUAGE'} ||= setlocale(LC_CTYPE);
my %switch; my %switch;
GetOptions(\%switch, 'help|h|?', 'check-modules', 'no-templates|t', GetOptions(\%switch, 'help|h|?', 'check-modules', 'no-templates|t',
'verbose|v|no-silent', 'make-admin=s'); 'verbose|v|no-silent', 'make-admin=s',
'reset-password=s');
# Print the help message if that switch was selected. # Print the help message if that switch was selected.
pod2usage({-verbose => 1, -exitval => 1}) if $switch{'help'}; pod2usage({-verbose => 1, -exitval => 1}) if $switch{'help'};
...@@ -212,6 +213,9 @@ Bugzilla::Install::update_settings(); ...@@ -212,6 +213,9 @@ Bugzilla::Install::update_settings();
Bugzilla::Install::make_admin($switch{'make-admin'}) if $switch{'make-admin'}; Bugzilla::Install::make_admin($switch{'make-admin'}) if $switch{'make-admin'};
Bugzilla::Install::create_admin(); Bugzilla::Install::create_admin();
Bugzilla::Install::reset_password($switch{'reset-password'})
if $switch{'reset-password'};
########################################################################### ###########################################################################
# Create default Product and Classification # Create default Product and Classification
########################################################################### ###########################################################################
...@@ -240,6 +244,7 @@ checksetup.pl - A do-it-all upgrade and installation script for Bugzilla. ...@@ -240,6 +244,7 @@ checksetup.pl - A do-it-all upgrade and installation script for Bugzilla.
./checksetup.pl [--help|--check-modules] ./checksetup.pl [--help|--check-modules]
./checksetup.pl [SCRIPT [--verbose]] [--no-templates|-t] ./checksetup.pl [SCRIPT [--verbose]] [--no-templates|-t]
[--make-admin=user@domain.com] [--make-admin=user@domain.com]
[--reset-password=user@domain.com]
=head1 OPTIONS =head1 OPTIONS
...@@ -267,6 +272,11 @@ Makes the specified user into a Bugzilla administrator. This is ...@@ -267,6 +272,11 @@ Makes the specified user into a Bugzilla administrator. This is
in case you accidentally lock yourself out of the Bugzilla administrative in case you accidentally lock yourself out of the Bugzilla administrative
interface. interface.
=item B<--reset-password>=user@domain.com
Resets the specified user's password. checksetup.pl will prompt you to
enter a new password for the user.
=item B<--no-templates> (B<-t>) =item B<--no-templates> (B<-t>)
Don't compile the templates at all. Existing compiled templates will Don't compile the templates at all. Existing compiled templates will
......
...@@ -356,9 +356,6 @@ ...@@ -356,9 +356,6 @@
[% ELSIF message_tag == "install_admin_get_password" %] [% ELSIF message_tag == "install_admin_get_password" %]
Enter a password for the administrator account: Enter a password for the administrator account:
[% ELSIF message_tag == "install_admin_get_password2" %]
Please retype the password to verify:
[% ELSIF message_tag == "install_admin_created" %] [% ELSIF message_tag == "install_admin_created" %]
[% user.login FILTER html %] is now set up as an administrator. [% user.login FILTER html %] is now set up as an administrator.
...@@ -376,6 +373,9 @@ ...@@ -376,6 +373,9 @@
[% ELSIF message_tag == "install_column_rename" %] [% ELSIF message_tag == "install_column_rename" %]
Renaming column '[% old FILTER html %]' to '[% new FILTER html %]'... Renaming column '[% old FILTER html %]' to '[% new FILTER html %]'...
[% ELSIF message_tag == "install_confirm_password" %]
Please retype the password to verify:
[% ELSIF message_tag == "install_default_classification" %] [% ELSIF message_tag == "install_default_classification" %]
Creating default classification '[% name FILTER html %]'... Creating default classification '[% name FILTER html %]'...
...@@ -406,6 +406,12 @@ ...@@ -406,6 +406,12 @@
account) to ensure it is set up as you wish - this includes account) to ensure it is set up as you wish - this includes
setting the 'urlbase' option to the correct URL. setting the 'urlbase' option to the correct URL.
[% ELSIF message_tag == "install_reset_password" %]
Enter a new password for [% user.login FILTER html %]:
[% ELSIF message_tag == "install_reset_password_done" %]
New password set.
[% ELSIF message_tag == "install_webservergroup_empty" %] [% ELSIF message_tag == "install_webservergroup_empty" %]
**************************************************************************** ****************************************************************************
WARNING! You have not entered a value for the "webservergroup" parameter WARNING! You have not entered a value for the "webservergroup" parameter
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment