#!/usr/local/bin/perl # Linked to from the forgotten password email BEGIN { push(@INC, "."); }; use WebminCore; $no_acl_check++; $trust_unknown_referers = 1; &init_config(); &ReadParse(); $gconfig{'forgot_pass'} || &error($text{'forgot_ecannot'}); my $forgot_password_link_dir = "$config_directory/forgot-password"; my $forgot_timeout = 10; &error_setup($text{'forgot_err'}); # Check that the random ID is valid $in{'id'} =~ /^[a-f0-9]+$/i || &error($text{'forgot_eid'}); my %link; &read_file("$forgot_password_link_dir/$in{'id'}", \%link) || &error($text{'forgot_eid2'}); time() - $link{'time'} > 60*$forgot_timeout && &error(&text('forgot_etime', $forgot_timeout)); # Get the Webmin user &foreign_require("acl"); my ($wuser) = grep { $_->{'name'} eq $link{'user'} } &acl::list_users(); $wuser || &error(&text('forgot_euser2', "".&html_escape($link{'user'})."")); &ui_print_header(undef, $text{'forgot_title'}, "", undef, undef, 1, 1); if (defined($in{'newpass'})) { # Validate the password $in{'newpass'} =~ /\S/ || &error($text{'forgot_enewpass'}); my $perr = &acl::check_password_restrictions( $wuser->{'name'}, $in{'newpass'}); $perr && &error(&text('forgot_equality', $perr)); # Actually update the password if (&foreign_check("virtual-server")) { # Is this a Virtualmin domain owner? &foreign_require("virtual-server"); $d = &virtual_server::get_domain_by("user", $link{'user'}, "parent", ""); } if ($d) { # Update in Virtualmin } elsif ($wuser->{'pass'} eq 'x') { # Update in Users and Groups } else { # Update in Webmin print &text('forgot_wdoing', "".&html_escape($link{'user'}).""),"
\n"; $wuser->{'pass'} = &acl::encrypt_password($in{'newpass'}); &acl::modify_user($wuser->{'name'}, $wuser); &reload_miniserv(); print $text{'forgot_done'},"

\n"; } print &text('forgot_retry', '/'),"

\n"; &unlink_file("$forgot_password_link_dir/$in{'id'}"); } else { # Show password selection form print "

\n"; print &ui_form_start("forgot.cgi", "post"); print &ui_hidden("id", $in{'id'}); print "",&text('forgot_newpass', "".&html_escape($link{'user'}).""),"\n", &ui_textbox("newpass", undef, 30),"

\n"; print &ui_form_end([ [ undef, $text{'forgot_passok'} ] ]); print "

\n"; } &ui_print_footer();