taskd: Listen on $chroot/etc/taskd.socket, change protocol to allow multiple commands
[girocco/susan.git] / cgi / pwproj.cgi
blobc53ba9ab827bdc380c96b1aa530b1ddd7a7c22fc
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::valid_name($name)) {
32 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
33 exit;
36 if (!Girocco::Project::does_exist($name)) {
37 print "<p>Sorry but this project does not exist. Now, how did you <em>get</em> here?!</p>\n";
38 exit;
41 if (!Girocco::Project::available($name)) {
42 print "<p>Sorry but your project has not finished mirroring yet. If it takes inordinate amount of time, please tell the administrator.</p>\n";
43 exit;
46 my $proj = Girocco::Project->load($name);
47 $proj or die "not found project $name, that's really weird!";
49 my $mail = $proj->{email};
51 if ($cgi->param('y0')) {
52 # submitted
54 my $newpwd = genpwd();
56 open (M, '|-', 'mail', '-s', "[$Girocco::Config::name] New password for project $name", $mail) or die "Cannot spawn mail: $!";
57 print M <<EOT;
58 Hello,
60 somebody asked for the password for project $name to be reset. Since you are
61 the project admin, you get to know the new password:
63 $newpwd
65 In case you did not request the password to be reset, we apologize. Nevertheless,
66 you have to use the reset password now (possibly to change it back).
68 Quick-link to the edit project page:
70 $Girocco::Config::webadmurl/editproj.cgi?name=$name
72 Have fun!
73 EOT
74 close M or die "mail $mail for $name died? $!";
76 $proj->update_password($newpwd);
78 print "<p>Project password has been reset. Have a nice day.</p>\n";
79 exit;
82 print <<EOT;
83 <p>You are trying to make me reset password for project $name. I will send the new
84 password to the project admin &lt;$mail&gt;.</p>
85 <form method="post">
86 <input type="hidden" name="name" value="$name" />
87 <p><input type="submit" name="y0" value="Reset Password" /></p>
88 </form>
89 EOT