clone.sh/update.sh: add --force to git fast-import
[girocco.git] / cgi / pwproj.cgi
blobf0a4f97b0a495ccc21de3dd407caafc28aadb99f
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib ".";
9 use Girocco::CGI;
10 use Girocco::Config;
11 use Girocco::Project;
12 use Girocco::Util;
15 sub genpwd {
16 # FLUFFY!
17 substr(crypt(rand, rand), 2);
21 my $gcgi = Girocco::CGI->new('Forgotten Project Password');
22 my $cgi = $gcgi->cgi;
24 my $name = $cgi->param('name');
26 unless (defined $name) {
27 print "<p>I need the project name as an argument.</p>\n";
28 exit;
31 if (!Girocco::Project::does_exist($name,1) && !Girocco::Project::valid_name($name)) {
32 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
33 exit;
36 if (!Girocco::Project::does_exist($name,1)) {
37 print "<p>Sorry but this project does not exist. Now, how did you <em>get</em> here?!</p>\n";
38 exit;
41 my $proj = Girocco::Project->load($name);
42 $proj or die "not found project $name, that's really weird!";
43 my $escname = $name;
44 $escname =~ s/[+]/%2B/g;
46 my $mail = $proj->{email};
48 my $y0 = $cgi->param('y0') || '';
49 if ($y0 eq 'Reset Password' && $cgi->request_method eq 'POST') {
50 # submitted
52 my $newpwd = genpwd();
54 defined(my $MAIL = mailer_pipe '-s', "[$Girocco::Config::name] New password for project $name", $mail)
55 or die "Cannot spawn mailer: $!";
56 print $MAIL <<EOT;
57 Hello,
59 Somebody asked for the password for project $name to be reset. Since you are
60 the project admin, you get to know the new password:
62 $newpwd
64 In case you did not request the password to be reset, we apologize. Nevertheless,
65 you have to use the reset password now (possibly to change it back).
67 Quick-link to the edit project page:
69 $Girocco::Config::webadmurl/editproj.cgi?name=$escname
71 Have fun!
72 EOT
73 close $MAIL or die "mail $mail for $name died? $!";
75 $proj->update_password($newpwd);
77 print "<p>Project password has been reset. Have a nice day.</p>\n";
78 exit;
81 print <<EOT;
82 <p>You are trying to make me reset password for project $name. I will send the new
83 password to the project admin &lt;$mail&gt;.</p>
84 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/pwproj.cgi">
85 <input type="hidden" name="name" value="$name" />
86 <p><input type="submit" name="y0" value="Reset Password" /></p>
87 </form>
88 EOT