| 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::authenticate; | ||
| 31 | |||
| 32 | use CGI; | ||
| 33 | use FAQ::OMatic::Item; | ||
| 34 | use FAQ::OMatic; | ||
| 35 | use FAQ::OMatic::Auth; | ||
| 36 | use FAQ::OMatic::HelpMod; | ||
| 37 | use FAQ::OMatic::I18N; | ||
| 38 | |||
| 39 | sub main { | ||
| 40 | my $cgi = FAQ::OMatic::dispatch::cgi(); | ||
| 41 | my $params = FAQ::OMatic::getParams($cgi); | ||
| 42 | |||
| 43 | my $rt = FAQ::OMatic::pageHeader($params, ['help', 'faq']); | ||
| 44 | |||
| 45 | my $what = $params->{'_restart'}; | ||
| 46 | my $whoIsAllowed = FAQ::OMatic::Auth::authError($params->{'_reason'}, | ||
| 47 | $params->{'file'}); | ||
| 48 | |||
| 49 | # Give them the option of setting up a new password | ||
| 50 | # Creating a login is the same thing | ||
| 51 | my $newPassButton .= FAQ::OMatic::button( | ||
| 52 | FAQ::OMatic::makeAref('changePass', | ||
| 53 | {'_pass_pass' => '', | ||
| 54 | '_pass_id' => '' }, '', 'saveTransients'), | ||
| 55 | gettext("Set a New Password")); | ||
| 56 | my $newLoginButton .= FAQ::OMatic::button( | ||
| 57 | FAQ::OMatic::makeAref('changePass', | ||
| 58 | {'_pass_pass' => '', | ||
| 59 | '_pass_id' => '' }, '', 'saveTransients'), | ||
| 60 | gettext("Create a New Login")); | ||
| 61 | |||
| 62 | if ($params->{'badPass'}) { | ||
| 63 | $rt.=gettext("That password is invalid. If you've forgotten your old password, you can")." $newPassButton.\n"; | ||
| 64 | |||
| 65 | delete $params->{'badPass'}; | ||
| 66 | # We had to use a nontransient param because the func that sets | ||
| 67 | # the badPass flag (FAQ::OMatic::AuthLocal::authenticate()) doesn't directly | ||
| 68 | # generate a URL, and of course stuffing a transient param | ||
| 69 | # into the param list won't make it to the URL. | ||
| 70 | # | ||
| 71 | # You're probably worried the param could live on too long (I was). | ||
| 72 | # Say you fill in the authentication dialog with a bad password. | ||
| 73 | # You get a badPass param, but say the script checking your | ||
| 74 | # authentication decides to accept the 'anonymous' $aq==1 | ||
| 75 | # authentication that results. But wait -- the reason you were | ||
| 76 | # asked to authenticate in the first place was that your previous | ||
| 77 | # auth wasn't good enough for that script. And aq=1 is certainly | ||
| 78 | # no better. | ||
| 79 | } else { | ||
| 80 | if ($what eq 'addItem') { | ||
| 81 | $rt.=gettexta("New items can only be added by %0.",$whoIsAllowed); | ||
| 82 | } elsif ($what eq 'addPart') { | ||
| 83 | $rt.=gettexta("New text parts can only be added by %0.",$whoIsAllowed); | ||
| 84 | } elsif ($what eq 'delPart') { | ||
| 85 | $rt.=gettexta("Text parts can only be removed by %0.",$whoIsAllowed); | ||
| 86 | } elsif ($what eq 'editPart' or $what eq 'submitPart') { | ||
| 87 | my $xreason = $params->{'_xreason'} || ''; | ||
| 88 | if ($xreason eq 'useHTML') { | ||
| 89 | $rt.=gettexta("This part contains raw HTML. To avoid pages with invalid HTML, the moderator has specified that only %0 can edit HTML parts. If you are %0 you may authenticate yourself with this form.",$whoIsAllowed); | ||
| 90 | } elsif ($params->{'_insertpart'}) { | ||
| 91 | $rt.=gettexta("Text parts can only be added by %0.",$whoIsAllowed); | ||
| 92 | } else { | ||
| 93 | $rt.=gettexta("Text parts can only be edited by %0.",$whoIsAllowed); | ||
| 94 | } | ||
| 95 | } elsif ($what eq 'editItem' or $what eq 'submitItem') { | ||
| 96 | $rt.=gettexta("The title and options for this item can only be edited by %0.",$whoIsAllowed); | ||
| 97 | } elsif ($what eq 'editModOptions' or $what eq 'submitModOptions') { | ||
| 98 | $rt.=gettexta("The moderator options can only be edited by %0.",$whoIsAllowed); | ||
| 99 | } elsif ($what eq 'moveItem' or $what eq 'submitMove') { | ||
| 100 | if ($whoIsAllowed =~ m/moderator/) { | ||
| 101 | $rt.=gettext("This item can only be moved by someone who can edit both the source and destination parent items."); | ||
| 102 | } else { | ||
| 103 | $rt.=gettexta("This item can only be moved by %0.",$whoIsAllowed); | ||
| 104 | } | ||
| 105 | } elsif ($what eq 'selectBag' | ||
| 106 | or $what eq 'editBag' | ||
| 107 | or $what eq 'submitBag') { | ||
| 108 | my $xreason = $params->{'_xreason'} || ''; | ||
| 109 | if ($xreason eq 'replace') { | ||
| 110 | $rt.=gettexta("Existing bags can only be replaced by %0.",$whoIsAllowed); | ||
| 111 | } else { | ||
| 112 | $rt.=gettexta("Bags can only be posted by %0.",$whoIsAllowed); | ||
| 113 | } | ||
| 114 | } elsif ($what eq 'install') { | ||
| 115 | $rt.=gettexta("The FAQ-O-Matic can only be configured by %0.",$whoIsAllowed); | ||
| 116 | } else { | ||
| 117 | $rt.=gettexta("The operation you attempted (%0) can only be done by %1.",$what,$whoIsAllowed); | ||
| 118 | } | ||
| 119 | |||
| 120 | $rt .= "<ul><li>".gettext("If you have never established a password to use with FAQ-O-Matic, you can")." $newLoginButton.\n"; | ||
| 121 | $rt .= "<li>".gettext("If you have forgotten your password, you can")." $newPassButton.\n"; | ||
| 122 | $rt .= "<li>".gettext("If you have already logged in earlier today, it may be that the token I use to identify you has expired. Please log in again.")."\n"; | ||
| 123 | $rt .= "</ul>\n"; | ||
| 124 | } | ||
| 125 | |||
| 126 | $rt .= FAQ::OMatic::makeAref($params->{'_restart'}, | ||
| 127 | { 'id' => '', 'auth' => '', | ||
| 128 | '_pass_id'=>'', # since we saveTransients, our own | ||
| 129 | '_pass_pass'=>'', # transients must be explicitly killed | ||
| 130 | '_none_id'=>'' }, | ||
| 131 | 'POST', 'saveTransients'); | ||
| 132 | |||
| 133 | my $reason = FAQ::OMatic::stripInt($params->{'_reason'}); | ||
| 134 | if ($reason <= 3) { | ||
| 135 | $rt .= "<p>" | ||
| 136 | .gettext("Please offer one of the following forms of identification:")."\n"; | ||
| 137 | |||
| 138 | $rt .= "<p><input type=radio name=\"auth\" value=\"none\" checked>\n"; | ||
| 139 | $rt .= " ".gettext("No authentication, but my email address is:")."\n"; | ||
| 140 | $rt .= "<br>".gettext("Email:") | ||
| 141 | ." <input type=text name=\"_none_id\" value=\"\" size=60>\n"; | ||
| 142 | } | ||
| 143 | |||
| 144 | $rt .= "<p><input type=radio name=\"auth\" value=\"pass\""; | ||
| 145 | $rt .= " checked" if ($reason > 3); | ||
| 146 | $rt .= ">\n"; | ||
| 147 | $rt .= " ".gettext("Authenticated login:")."\n"; | ||
| 148 | $rt .= "<br>Email: <input type=text name=\"_pass_id\" value=\"\" size=60>\n"; | ||
| 149 | $rt .= "<br>".gettext("Password:")." <input type=password name=\"_pass_pass\" value=\"\" size=10>\n"; | ||
| 150 | |||
| 151 | $rt .= "<p><input type=submit name=\"_submit\" value=\"".gettext("Log In")."\">\n"; | ||
| 152 | $rt .= "</form>\n"; | ||
| 153 | |||
| 154 | # Give them the option of leaving whatever authentication they | ||
| 155 | # used to have intact, and giving up on "better" auth. | ||
| 156 | # $rt .= FAQ::OMatic::button(FAQ::OMatic::makeAref( | ||
| 157 | # '-command'=>'faq', | ||
| 158 | # '-params'=>$params, | ||
| 159 | # '-changedParams'=>{'partnum'=>'', | ||
| 160 | # 'checkSequenceNumber'=>''} | ||
| 161 | # ), | ||
| 162 | # "Cancel and Return to FAQ"); | ||
| 163 | |||
| 164 | $rt.=FAQ::OMatic::HelpMod::helpFor($params, 'authenticate'); | ||
| 165 | |||
| 166 | $rt .= FAQ::OMatic::pageFooter($params, ['help', 'faq']); | ||
| 167 | |||
| 168 | print $rt; | ||
| 169 | } | ||
| 170 | |||
| 171 | 1; | ||
| 172 | |||
| 173 |