request-password.pl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/perl -wT
  2. # cord@debian.org
  3. use lib "/var/list/reaper/lib";
  4. use strict;
  5. use CGI qw/:standard/;
  6. use CGI::Carp qw(fatalsToBrowser);
  7. use MIME::Lite;
  8. my $userfile='/etc/postfix/debian';
  9. my $passwd='/org/lists.debian.org/cgi-bin/review/.htpasswd';
  10. my $bounce_addr = "cord\@liszt.debian.org";
  11. my $logfile = '/org/lists.debian.org/spam-log/pw-reminder.log';
  12. $ENV{'PATH'} = '';
  13. print header;
  14. open (HEADER, "/org/lists.debian.org/html/header.in") or
  15. die ("$0: can't open /org/lists.debian.org/html/header.in: $!\n");
  16. while (<HEADER>) {
  17. s/u_TITLE_u/Request a Password for Listarchive Review/;
  18. print;
  19. }
  20. close (HEADER);
  21. print h2('Request A Password for Listarchive Review');
  22. print "<hr noshade width=\"100%\" size=\"1\">\n";
  23. print p("Only Debian Developer are allowed to review the Listarchive. Please
  24. enter your Debian userid, and press 'Submit', and a new generated
  25. password will be send to your Debian-Mailadress.");
  26. print p("This user/pass-method is a temporary solution, when we have a
  27. solution for authorizing against a central DB, we will switch over.");
  28. print start_form;
  29. print p("Your Debian UserId:", textfield('uid'), "\@debian.org");
  30. print submit('Request Password');
  31. print end_form;
  32. if (param()) {
  33. if (param('uid') =~ m#^(\w+)$#) {
  34. my $uid = $1;
  35. open(DD, $userfile) or die ("$0: can't open $userfile for reading: $!\n");
  36. my $line;
  37. my $found = 0;
  38. foreach $line (<DD>) {
  39. $line = (split(' ', $line))[0];
  40. if ($line eq "$uid\@debian.org") {
  41. $found = 1;
  42. }
  43. }
  44. close (DD);
  45. if (-e $logfile) {
  46. open (LOG, $logfile) or die ("$0: can't open $logfile for reading\n");
  47. my ($time, $ip, $user);
  48. foreach (<LOG>) {
  49. ($time, $ip, $user) = split(m#\s+#, $_);
  50. next if (time()-3600 > $time);
  51. next if ($user ne $uid);
  52. $found = -1;
  53. }
  54. }
  55. if ($found == 1) {
  56. my $pw=`/usr/bin/pwgen 8 1`;
  57. $pw =~ m#^([\w\d]+)$#;
  58. my $password = $1;
  59. system('/usr/bin/htpasswd', '-b', $passwd, $uid, $password);
  60. my $msg = MIME::Lite->new (
  61. From => "Debian Listmaster Team <listmaster\@lists.debian.org>",
  62. To => "$uid\@debian.org",
  63. Subject => "$uid\@debian.org Password for Debian Listarchive Review",
  64. Type => "text/plain",
  65. "X-Loop:" => "liszt-password-resetter",
  66. "Precedence:" => "junk",
  67. "Reply-To:" => "listmaster\@lists.debian.org",
  68. "Errors-To:" => "listmaster\@lists.debian.org",
  69. "Datestamp" => 0,
  70. Data => "Thank you for participating in the Debian Listarchive Review.
  71. Now you can go to https://lists.debian.org/cgi-bin/review/review1.pl and
  72. start reviewing.
  73. When you are asked for Authorisation please enter:
  74. user: $uid
  75. pass: $password
  76. Sincerely,
  77. The Listmaster Team
  78. --
  79. http://lists.debian.org
  80. ");
  81. $msg->send or die "$0: you DON'T have mail!: $!\n";
  82. print p("New password send out");
  83. open(LOG, '>>', $logfile) or die ("$0: can't open $logfile for writing: $!\n");
  84. print LOG time . " $ENV{'REMOTE_ADDR'} $uid\n";
  85. close LOG;
  86. } elsif ($found == 0) {
  87. print p("FAIL: user unknown");
  88. } elsif ($found == -1) {
  89. print p("FAIL: already requested a password in the last hour");
  90. } else {
  91. print p("FAIL: this shouldn't happen");
  92. }
  93. } else {
  94. print p("FAIL: invalid characters");
  95. }
  96. }
  97. open (FOOTER, "/org/lists.debian.org/html/footer.in") or
  98. die ("$0: can't open /org/lists.debian.org/html/footer.in: $!\n");
  99. while (<FOOTER>) {
  100. print;
  101. }
  102. close (FOOTER);