editproj: improve mirror and password handling
[girocco/ztw.git] / cgi / pwproj.cgi
blob93cb7813f78c7bba34dc8f501dfb8df12e669393
1 #!/usr/bin/perl
2 # (c) Zachary T Welch <zw@superlucidity.net>
3 # (c) Petr Baudis <pasky@suse.cz>
4 # GPLv2
6 use strict;
7 use warnings;
9 use lib qw(/home/repo/repomgr/cgi);
10 use Git::RepoCGI;
12 my $repo = Git::RepoCGI->new('Forgotten Project Password');
13 my $name = $repo->sparam('name');
14 my $proj = $repo->load_project($name);
16 my $mail = $proj->{email};
18 if ($repo->sparam('y0')) {
19 # submitted
20 my $newpwd = genpwd();
22 # TODO: get hard-coded domain name from a config file
23 my $domain = 'repo.or.cz';
24 my $subject = "[$domain] New password for project $name";
25 open (M, '|-', 'mail', '-s', $subject, $mail)
26 or $repo->bye("Cannot spawn mail: $!");
27 print M <<EOT;
28 Hello,
30 Somebody requested the password for project '$name.git' to be reset.
32 This address has been listed as the contact address for the project,
33 so you are receiving the new password:
35 $newpwd
37 If you did not request the password to be reset, then we apologize.
38 In any event, you must now use this new password to change the settings
39 for the '$name.git' project.
41 If you would like to change your project password again, you can use
42 this quick link to edit the project page:
44 Quick-link to the edit project page:
46 http://repo.or.cz/m/editproj.cgi?name=$name
48 Have fun!
49 EOT
50 close M or $repo->bye("Sending mail to $mail for $name failed: $!");
52 $proj->update_password($newpwd);
54 print "<p>Project password has been reset. Have a nice day.</p>\n";
55 exit;
58 print <<EOT;
59 <p>If you have forgotten the admin password for the '$name' project,
60 it can be reset to a random string that will be mailed to the listed
61 contact e-mail address:&nbsp;<tt>&lt;$mail&gt;</tt>.</p>
62 <form method="post">
63 <input type="hidden" name="name" value="$name" />
64 <p><input type="submit" name="y0" value="Reset Password" /></p>
65 </form>
66 EOT