| 1 | ############################################################################## | ||
| 2 | # The Faq-O-Matic is Copyright 1997 by Jon Howell, all rights reserved. # | ||
| 3 | # # | ||
| 4 | # This program is free software; you can redistribute it and/or # | ||
| 5 | # modify it under the terms of the GNU General Public License # | ||
| 6 | # as published by the Free Software Foundation; either version 2 # | ||
| 7 | # of the License, or (at your option) any later version. # | ||
| 8 | # # | ||
| 9 | # This program is distributed in the hope that it will be useful, # | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
| 12 | # GNU General Public License for more details. # | ||
| 13 | # # | ||
| 14 | # You should have received a copy of the GNU General Public License # | ||
| 15 | # along with this program; if not, write to the Free Software # | ||
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.# | ||
| 17 | # # | ||
| 18 | # Jon Howell can be contacted at: # | ||
| 19 | # 6211 Sudikoff Lab, Dartmouth College # | ||
| 20 | # Hanover, NH 03755-3510 # | ||
| 21 | # jonh@cs.dartmouth.edu # | ||
| 22 | # # | ||
| 23 | # An electronic copy of the GPL is available at: # | ||
| 24 | # http://www.gnu.org/copyleft/gpl.html # | ||
| 25 | # # | ||
| 26 | ############################################################################## | ||
| 27 | |||
| 28 | use strict; | ||
| 29 | |||
| 30 | package FAQ::OMatic::submitPass; | ||
| 31 | |||
| 32 | use CGI; | ||
| 33 | use FAQ::OMatic::Item; | ||
| 34 | use FAQ::OMatic; | ||
| 35 | use FAQ::OMatic::Auth; | ||
| 36 | use FAQ::OMatic::I18N; | ||
| 37 | |||
| 38 | |||
| 39 | sub main { | ||
| 40 | my $cgi = FAQ::OMatic::dispatch::cgi(); | ||
| 41 | |||
| 42 | my $params = FAQ::OMatic::getParams($cgi); | ||
| 43 | |||
| 44 | if ($params->{'_fromChangePass'} or $params->{'_badSecret'}) { | ||
| 45 | # this is the user coming from changePass; send the secret | ||
| 46 | # in email, and put up a page explaining what to do. | ||
| 47 | my $id = $params->{'_id'} || ''; | ||
| 48 | if (not FAQ::OMatic::validEmail($id)) { | ||
| 49 | FAQ::OMatic::gripe('error', gettext("An email address must look like 'name\@some.domain'.") | ||
| 50 | ."\n" | ||
| 51 | .gettexta("If yours (%0) does and I keep rejecting it, please mail the administrator of this FAQ at %1 and tell him or her what's happening.", | ||
| 52 | $id, $FAQ::OMatic::Config::adminEmail)); | ||
| 53 | } | ||
| 54 | my $pass = $params->{'_pass'} || ''; | ||
| 55 | # THANKS to Mark Shaw <mshaw@dal.asp.ti.com> for catching this | ||
| 56 | # potential uninitialized value error. | ||
| 57 | if (not ($pass =~ m/^\S*$/)) { | ||
| 58 | FAQ::OMatic::gripe('error', gettext("Your password may not contain spaces or carriage returns.")); | ||
| 59 | } | ||
| 60 | |||
| 61 | # put the secret in the IDfile, but don't put in the new | ||
| 62 | # Only create a secret if user is coming straight from changePass. | ||
| 63 | # Don't create ANOTHER secret if this is just the user | ||
| 64 | # looping back around after entering a bad secret. | ||
| 65 | if ($params->{'_fromChangePass'}) { | ||
| 66 | my $secret = FAQ::OMatic::Entropy::gatherRandomString(); | ||
| 67 | my $restart = $params->{'_restart'} || | ||
| 68 | FAQ::OMatic::makeAref('faq', {}, 'url', 0, 'blastAll'); | ||
| 69 | # keep passwords out of the GET request fired up | ||
| 70 | # when restarting after an authentication. | ||
| 71 | # THANKS to | ||
| 72 | # Cream-puff Casper Milquetoast <doughnut@doughnut.net> | ||
| 73 | # for reporting this issue. | ||
| 74 | my $saveurl = FAQ::OMatic::makeAref($restart, | ||
| 75 | {'auth'=>'','pass'=>'','id'=>'', | ||
| 76 | '_id'=>'', '_pass'=>''}, | ||
| 77 | 'url', 'saveTransients'); | ||
| 78 | |||
| 79 | # password yet, or we'll have circumvented the whole secret | ||
| 80 | # thing. | ||
| 81 | my ($idf,$passf,$secretf,$saveurlf,$oldwaitpassf,@rest)=FAQ::OMatic::Auth::readIDfile($id); | ||
| 82 | if ((not defined $passf) | ||
| 83 | or (not defined $idf) | ||
| 84 | or ($idf ne $id)) { | ||
| 85 | $passf = '__INVALID__'; | ||
| 86 | } | ||
| 87 | my $cryptwaitpass = FAQ::OMatic::Auth::cryptPass($pass); | ||
| 88 | # we'll store the crypted version to install later | ||
| 89 | |||
| 90 | FAQ::OMatic::Auth::writeIDfile($id,$passf,$secret,$saveurl,$cryptwaitpass,@rest); | ||
| 91 | |||
| 92 | # mail the user the secret url | ||
| 93 | my $secreturl = FAQ::OMatic::makeAref('submitPass', | ||
| 94 | { '_id'=>$id, | ||
| 95 | '_secret'=>$secret }, | ||
| 96 | 'url', 0, 'blastAll'); | ||
| 97 | my $subj = gettext("Your Faq-O-Matic authentication secret"); | ||
| 98 | my $mesg = gettext("To validate your Faq-O-Matic password, you may either enter this secret into the Validation form:")."\n\n"; | ||
| 99 | $mesg .= gettext("Secret:")." ".$secret."\n\n"; | ||
| 100 | $mesg .= gettext("Or access the following URL. Be careful when you copy and paste the URL that the line-break doesn't cut the URL short."); | ||
| 101 | $mesg .= "\n\n$secreturl\n\n".gettext("Thank you for using Faq-O-Matic.")."\n\n"; | ||
| 102 | $mesg .= gettexta("(Note: if you did not sign up to use the Faq-O-Matic, someone else has attempted to log in using your name. Do not access the URL above; it will validate the password that user has supplied. Instead, send mail to %0 and I will look into the matter.)", $FAQ::OMatic::Config::adminEmail ); | ||
| 103 | |||
| 104 | if (FAQ::OMatic::sendEmail($id, $subj, $mesg)) { | ||
| 105 | FAQ::OMatic::gripe('error', | ||
| 106 | gettexta("I couldn't mail the authentication secret to \"%0\" and I'm not sure why.", $id)); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | # now tell the user what's going on | ||
| 111 | my $rt = ''; | ||
| 112 | |||
| 113 | $rt .= FAQ::OMatic::pageHeader($params); | ||
| 114 | |||
| 115 | if ($params->{'_badSecret'}) { | ||
| 116 | $rt .= gettext("The secret you entered is not correct.")."\n"; | ||
| 117 | $rt .= | ||
| 118 | gettext("Did you copy and paste the secret or the URL completely?") | ||
| 119 | ."\n<p>\n"; | ||
| 120 | } | ||
| 121 | else { | ||
| 122 | $rt .= gettexta("I sent email to you at \"%0\". It should arrive soon, containing a URL.", | ||
| 123 | $id) | ||
| 124 | ."\n<p>\n"; | ||
| 125 | } | ||
| 126 | $rt.= gettext("Either open the URL directly, or paste the secret into the form below and click Validate.") | ||
| 127 | ."\n<p>\n" | ||
| 128 | .gettext("Thank you for taking the time to sign up.") | ||
| 129 | ."\n"; | ||
| 130 | |||
| 131 | $rt.= FAQ::OMatic::makeAref('submitPass', | ||
| 132 | { '_id'=>$id, | ||
| 133 | '_pass'=>$pass }, | ||
| 134 | 'POST', 0, 'blastAll'); | ||
| 135 | #$rt.="<form action=\"submitPass\" method=POST>\n"; | ||
| 136 | $rt.= gettext("Secret:")." \n"; | ||
| 137 | $rt.= "<input type=text name=\"_secret\" value=\"\" size=36>\n"; | ||
| 138 | $rt.= "<p><input type=submit name=\"_submit\" value=\"".gettext("Validate")."\">\n"; | ||
| 139 | $rt.= "</form>\n"; | ||
| 140 | |||
| 141 | $rt .= FAQ::OMatic::pageFooter($params); | ||
| 142 | print $rt; | ||
| 143 | } else { | ||
| 144 | # this is the user presenting his secret received via email | ||
| 145 | my $id = $params->{'_id'}; | ||
| 146 | my $secret = $params->{'_secret'}; | ||
| 147 | my ($idf,$passf,$secretf,$saveurl,$cryptwaitpassf,@rest) | ||
| 148 | = FAQ::OMatic::Auth::readIDfile($id); | ||
| 149 | if (not defined($idf) | ||
| 150 | or not ($idf eq $id) | ||
| 151 | or not ($secret eq $secretf)) { | ||
| 152 | # if we get the wrong secret, send the user back | ||
| 153 | # around to the page with the Validate button (the top case | ||
| 154 | # in this file) to give them another chance to enter the secret. | ||
| 155 | my $url = FAQ::OMatic::makeAref('submitPass', | ||
| 156 | { '_badSecret'=>1, '_id'=>$id }, 'url'); | ||
| 157 | FAQ::OMatic::redirect($cgi, $url); | ||
| 158 | } | ||
| 159 | |||
| 160 | # no secret necessary anymore | ||
| 161 | FAQ::OMatic::Auth::writeIDfile($idf, $cryptwaitpassf); | ||
| 162 | # generate a cookie. We know it's you by your secret, but | ||
| 163 | # we don't have your (uncrypted) password to let you go through the | ||
| 164 | # normal password check. So we'll just create a cookie right now. | ||
| 165 | my $newauth = "&auth=".FAQ::OMatic::Auth::newCookie($idf); | ||
| 166 | FAQ::OMatic::redirect($cgi, $saveurl.$newauth); | ||
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 170 | 1; | ||
| 171 | |||
| 172 | |||
| 173 | |||
| 174 | |||
| 175 |