about.html: Better UPC sponsorship link
[girocco/ztw.git] / cgi / pwproj.cgi
blob299159fa87313e42764af0d997b4b7f4cbf89be1
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib qw(/home/repo/repomgr/cgi);
9 use Git::RepoCGI;
12 sub genpwd {
13 # FLUFFY!
14 substr(crypt(rand, rand), 2);
18 my $repo = Git::RepoCGI->new('Forgotten Project Password');
19 my $cgi = $repo->cgi;
21 my $name = $cgi->param('name');
23 unless (defined $name) {
24 print "<p>I need the project name as an argument.</p>\n";
25 exit;
28 if (!valid_proj_name($name)) {
29 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
30 exit;
33 if (!Git::RepoCGI::Project::does_exist($name)) {
34 print "<p>Sorry but this project does not exist. Now, how did you <em>get</em> here?!</p>\n";
35 exit;
38 if (!Git::RepoCGI::Project::available($name)) {
39 print "<p>Sorry but your project has not finished mirroring yet. If it takes inordinate amount of time, please tell the administrator.</p>\n";
40 exit;
43 my $proj = Git::RepoCGI::Project->load($name);
44 $proj or die "not found project $name, that's really weird!";
46 my $mail = $proj->{email};
48 if ($cgi->param('y0')) {
49 # submitted
51 my $newpwd = genpwd();
53 open (M, '|-', 'mail', '-s', '[repo.or.cz] New password for project '.$name, $mail) or die "Cannot spawn mail: $!";
54 print M <<EOT;
55 Hello,
57 somebody asked for the password for project $name to be reset. Since you are
58 the project admin, you get to know the new password:
60 $newpwd
62 In case you didn't request the password to be reset, we apologize. Nevertheless,
63 you have to use the reset password now (possibly to change it back).
65 Quick-link to the edit project page:
67 http://repo.or.cz/m/editproj.cgi?name=$name
69 Have fun!
70 EOT
71 close M or die "mail $mail for $name died? $!";
73 $proj->update_password($newpwd);
75 print "<p>Project password has been reset. Have a nice day.</p>\n";
76 exit;
79 print <<EOT;
80 <p>You are trying to make me reset password for project $name. I'll send the new
81 password to the project admin &lt;$mail&gt;.</p>
82 <form method="post">
83 <input type="hidden" name="name" value="$name" />
84 <p><input type="submit" name="y0" value="Reset Password" /></p>
85 </form>
86 EOT