[r1090]: branches / 2.5.4 / cgi-bin / yabb2 / Sources / LogInOut.pm Maximize Restore History

Download this file

LogInOut.pm    427 lines (372 with data), 14.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
###############################################################################
# LogInOut.pm #
# $Date: 2013-07-14 17:10:34 +0000 (Sun, 14 Jul 2013) $
###############################################################################
# YaBB: Yet another Bulletin Board #
# Open-Source Community Software for Webmasters #
# Version: YaBB 2.5.4 #
# Packaged: July 1, 2013 #
# Distributed by: http://www.yabbforum.com #
# =========================================================================== #
# Copyright (c) 2000-2013 YaBB (www.yabbforum.com) - All Rights Reserved. #
# Software by: The YaBB Development Team #
# with assistance from the YaBB community. #
###############################################################################
use CGI::Carp qw(fatalsToBrowser);
our $VERSION = '2.5.4';
$loginoutpmver = 'YaBB 2.5.4 $Revision: 1090 $';
if ( $action eq 'detailedversion' ) { return 1; }
if ($regcheck) { require Sources::Decoder; }
LoadLanguage('LogInOut');
$regstyle = q{};
sub Login {
if ( !$iamguest && $sessionvalid == 1 ) {
fatal_error( 'logged_in_already', $username );
}
$sharedLogin_title = $loginout_txt{'34'};
$yymain .= sharedLogin() . q~<script type="text/javascript">
<!--
document.loginform.username.focus();
//-->
</script>~;
$yytitle = $loginout_txt{'34'};
template();
return;
}
sub Login2 {
if ( !$iamguest && $sessionvalid == 1 ) {
fatal_error( 'logged_in_already', $username );
}
if ( $FORM{'username'} eq q{} ) { fatal_error('no_username'); }
if ( $FORM{'passwrd'} eq q{} ) { fatal_error('no_password'); }
$username = $FORM{'username'};
$username =~ s/\s/_/gxsm;
if ( $username =~ /[^ \w\x80-\xFF\[\]\(\)#\%\+,\-\|\.:=\?\@\^]/xsm ) {
fatal_error( 'invalid_character',
"$loginout_txt{'35'} $loginout_txt{'241'}" );
}
## Check if login ID is not and email address or screenname ##
if ( !-e "$memberdir/$username.vars" ) {
$test_id = MemberIndex( 'who_is', "$FORM{'username'}" );
if ( $test_id ne q{} ) { $username = $test_id; }
else { fatal_error('bad_credentials'); }
}
if ( -e "$memberdir/$username.pre" && -e "$memberdir/$username.vars" ) {
unlink "$memberdir/$username.pre";
}
if ( -e "$memberdir/$username.pre" && ( $regtype == 1 || $regtype == 2 ) ) {
fatal_error('not_activated');
}
# Need to do this to get correct case of username,
# for case insensitive systems. Can cause weird issues otherwise
$caseright = 0;
ManageMemberlist('load');
while ( ( $curmemb, $value ) = each %memberlist ) {
if ( $username =~ m/\A\Q$curmemb\E\Z/xsm ) { $caseright = 1; last; }
}
undef %memberlist;
if ( !$caseright ) {
$username = 'Guest';
fatal_error('bad_credentials');
}
if ( -e "$memberdir/$username.vars" ) {
LoadUser($username);
my $spass = ${ $uid . $username }{'password'};
my $cryptpass = encode_password("$FORM{'passwrd'}");
# convert non encrypted password to MD5 crypted one
if ( $spass eq $FORM{'passwrd'} && $spass ne $cryptpass ) {
# only encrypt the password if it's not already MD5 encrypted
# MD5 hashes in YaBB are always 22 chars long (base64)
if ( length( ${ $uid . $username }{'password'} ) != 22 ) {
${ $uid . $username }{'password'} = $cryptpass;
UserAccount($username);
$spass = $cryptpass;
}
}
if ( $spass ne $cryptpass ) {
$username = 'Guest';
fatal_error('bad_credentials');
}
}
else {
$username = 'Guest';
fatal_error('bad_credentials');
}
$iamadmin = ${ $uid . $username }{'position'} eq 'Administrator' ? 1 : 0;
$iamgmod = ${ $uid . $username }{'position'} eq 'Global Moderator' ? 1 : 0;
$sessionvalid = 1;
$iamguest = 0;
if ( $maintenance && !$iamadmin ) {
$username = 'Guest';
fatal_error('admin_login_only');
}
banning();
if ( $FORM{'cookielength'} == 1 ) {
$ck{'len'} = 'Sunday, 17-Jan-2038 00:00:00 GMT';
}
else { $ck{'len'} = q{}; }
${ $uid . $username }{'session'} = encode_password($user_ip);
UpdateCookie(
'write', $username,
encode_password( $FORM{'passwrd'} ),
${ $uid . $username }{'session'},
q{/}, $ck{'len'}
);
UserAccount( $username, 'update', q{-} );
# "-" to not update 'lastonline' here
buildIMS( $username, 'load' ); # isn't loaded because was Guest before
buildIMS( $username, q{} );
# rebuild the Members/$username.ims file on login
WriteLog();
if ( $FORM{'sredir'} ) {
$FORM{'sredir'} =~ s/\~/\=/gxsm;
$FORM{'sredir'} =~ s/x3B/;/gsm;
$FORM{'sredir'} =~ s/search2/search/gsm;
$FORM{'sredir'} = qq~?$FORM{'sredir'}~;
if ( $FORM{'sredir'} =~
/action=(register|login2|reminder|reminder2)/xsm )
{
$FORM{'sredir'} = q{};
}
}
$yySetLocation = qq~$scripturl$FORM{'sredir'}~;
redirectexit();
return;
}
sub Logout {
if ( $username ne 'Guest' ) {
RemoveUserOnline($username); # Remove user from online log
UserAccount( $username, 'update', 'lastonline' );
}
UpdateCookie('delete');
$yySetLocation = $guestaccess ? $scripturl : qq~$scripturl?action=login~;
$username = 'Guest';
redirectexit();
return;
}
sub sharedLogin {
get_template('Loginout');
if ( $action eq 'login' || $maintenance ) {
$yynavigation = qq~&rsaquo; $loginout_txt{'34'}~;
}
#cookie length is now all or nothing.
if ( $sharedLogin_title ne q{} ) {
$sharedlog = $mysharedloga;
$sharedlog =~ s/{yabb sharedLogin_title}/$sharedLogin_title/sm;
if ( $sharedLogin_text ne q{} ) {
$sharedlog .= $mysharedlogb;
$sharedlog =~ s/{yabb sharedLogin_text}/$sharedLogin_text/sm;
}
$sharedlog .= $mysharedlogc;
}
else {
$sharedlog = $mysharedlog_top;
}
if ($maintenance) { $hide_passbutton = ' visibility: hidden;'; }
if ( $maintenance || !$regtype ) {
$hide_regbutton = ' visibility: hidden;';
}
$sharedlog .= qq~
<form name="loginform" action="$scripturl?action=login2" method="post" accept-charset="$yycharset">
<input type="hidden" name="sredir" value="$INFO{'sesredir'}" />
$mysharedlog_bodya~;
$sharedlog =~ s/{yabb regstyle}/$regstyle/sm;
$sharedlog =~ s/{yabb hide_regbutton}/$hide_regbutton/gsm;
$sharedlog =~ s/{yabb hide_passbutton}/$hide_passbutton/gsm;
$loginform = 1;
$sharedLogin_title = q{};
$sharedLogin_text = q{};
return $sharedlog;
}
sub Reminder {
if ( !$iamguest && $sessionvalid == 1 ) {
fatal_error( 'logged_in_already', $username );
}
get_template('Loginout');
$yymain .= qq~<br /><br />
<form action="$scripturl?action=reminder2" method="post" name="reminder" onsubmit="return CheckReminderField();" accept-charset="$yycharset">
$myremindera~;
$yymain =~ s/{yabb mbname}/$mbname/sm;
$yymain =~ s/{yabb regstyle}/$regstyle/sm;
if ($regcheck) {
validation_code();
$yymain .= $myreminder_regcheck;
$yymain =~ s/{yabb flood_text}/$flood_text/sm;
$yymain =~ s/{yabb showcheck}/$showcheck/sm;
}
if ( $spam_questions_send && -e "$langdir/$language/spam.questions" ) {
SpamQuestion();
my $verification_question_desc;
if ($spam_questions_case) {
$verification_question_desc =
qq~<br />$loginout_txt{'verification_question_case'}~;
}
$yymain .= $myreminder_vericheck;
$yymain =~ s/{yabb spam_question}/$spam_question/sm;
$yymain =~ s/{yabb spam_question_id}/$spam_question_id/sm;
$yymain =~
s/{yabb verification_question_desc}/$verification_question_desc/sm;
}
$yymain .= $myreminder_endform;
$yymain .= qq~
<script type="text/javascript">
<!--
document.reminder.user.focus();
function CheckReminderField() {
if (document.reminder.user.value == '') {
alert("$loginout_txt{'error_user_info'}");
document.reminder.user.focus();
return false;
}~ .
(
$regcheck
? qq~
if (document.reminder.verification.value == '') {
alert("$loginout_txt{'error_verification'}");
document.reminder.verification.focus();
return false;
}~
: q{}
)
.
(
$spam_questions_send && -e "$langdir/$language/spam.questions"
? qq~
if (document.reminder.verification_question.value == '') {
alert("$loginout_txt{'error_verification_question'}");
document.reminder.verification_question.focus();
return false;
}~
: q{}
)
. q~
return true;
}
//-->
</script>
<br /><br />
~;
$yytitle = $loginout_txt{'669'};
$yynavigation = qq~&rsaquo; $loginout_txt{'669'}~;
template();
return;
}
sub Reminder2 {
if ( !$FORM{'user'} ) {
fatal_error( q{}, "$loginout_txt{'error_user_info'}" );
}
# generate random ID for password reset.
if ( !$iamguest && $sessionvalid == 1 ) {
fatal_error( 'logged_in_already', $username );
}
my $randid = keygen( 8, 'A' );
if ( $regcheck && !$iamadmin ) {
validation_check( $FORM{'verification'} );
}
if ( $spam_questions_send && -e "$langdir/$language/spam.questions" ) {
SpamQuestionCheck( $FORM{'verification_question'},
$FORM{'verification_question_id'} );
}
my $user = $FORM{'user'};
$user =~ s/\s/_/gxsm;
if ( !-e "$memberdir/$user.vars" ) {
$test_id = MemberIndex( 'who_is', $FORM{'user'} );
if ($test_id) { $user = $test_id; }
else { fatal_error( q{}, "$loginout_txt{'no_user_info_exists'}" ); }
}
# Fix to make it load in their own language
LoadUser($user);
if ( !${ $uid . $user }{'email'} ) { fatal_error('corrupt_member_file'); }
$username = $user;
WhatLanguage();
LoadLanguage('LogInOut');
LoadLanguage('Email');
undef $username;
$userfound = 0;
if ( -e "$memberdir/forgotten.passes" ) {
require "$memberdir/forgotten.passes";
}
if ( exists $pass{$user} ) { delete $pass{$user}; }
$pass{"$user"} = $randid;
fopen( FILE, ">$memberdir/forgotten.passes" )
|| fatal_error( 'cannot_open', "$memberdir/forgotten.passes", 1 );
while ( ( $key, $value ) = each %pass ) {
print {FILE} qq~\$pass{"$key"} = '$value';\n~
or croak 'cannot print to FILE';
}
print {FILE} '1;' or croak 'cannot print to FILE';
fclose(FILE);
$subject = "$loginout_txt{'36'} $mbname: ${$uid.$user}{'realname'}";
if ($do_scramble_id) { $cryptusername = cloak($user); }
else { $cryptusername = $user; }
require Sources::Mailer;
LoadLanguage('Email');
my $message = template_email(
$passwordreminderemail,
{
'displayname' => ${ $uid . $user }{'realname'},
'cryptusername' => $cryptusername,
'remindercode' => $randid
}
);
sendmail( ${ $uid . $user }{'email'}, $subject, $message );
get_template('Loginout');
$yymain .= $myreminder2;
$yymain =~ s/{yabb mbname}/$mbname/sm;
$yymain =~ s/{yabb forum_user}/$FORM{'user'}/sm;
$yytitle = "$loginout_txt{'669'}";
template();
return;
}
sub Reminder3 {
$id = $INFO{'ID'};
if ($do_scramble_id) { $user = decloak( $INFO{'user'} ); }
else { $user = $INFO{'user'}; }
if ( $id !~ /[a-zA-Z0-9]+/xsm ) {
fatal_error( 'invalid_character', "ID $loginout_txt{'241'}" );
}
if ( $user =~ /[^\w#\%\+\-\.\@\^]/xsm ) {
fatal_error( 'invalid_character', "User $loginout_txt{'241'}" );
}
# generate a new random password as the old one is one-way encrypted.
@chararray =
qw(0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
my $newpassword;
for my $i ( 0 .. 7 ) {
$newpassword .= $chararray[ int rand 61 ];
}
# load old userdata
LoadUser($user);
# update forgotten passwords database
require "$memberdir/forgotten.passes";
if ( $pass{$user} ne $id ) { fatal_error('wrong_id'); }
delete $pass{$user};
fopen( FORGOTTEN, ">$memberdir/forgotten.passes" )
|| fatal_error( 'cannot_open', "$memberdir/forgotten.passes", 1 );
while ( ( $key, $value ) = each %pass ) {
print {FORGOTTEN} qq~\$pass{"$key"} = '$value';\n~
or croak 'cannot print to FORGOTTEN';
}
print {FORGOTTEN} "\n1;" or croak 'cannot print to FORGOTTEN';
fclose(FORGOTTEN);
# add newly generated password to user data
${ $uid . $user }{'password'} = encode_password($newpassword);
UserAccount( $user, 'update' );
$FORM{'username'} = $user;
$FORM{'passwrd'} = $newpassword;
$FORM{'cookielength'} = 10;
$FORM{'sredir'} =
qq*action~profileCheck2;redir~myprofile;username~$INFO{'user'};passwrd~$newpassword;newpassword~1*;
Login2();
return;
}
sub InMaintenance {
if ( $maintenancetext ne q{} ) { $maintxt{'157'} = $maintenancetext; }
$sharedLogin_title = "$maintxt{'114'}";
$sharedLogin_text = "<b>$maintxt{'156'}</b><br />$maintxt{'157'}";
$yymain .= sharedLogin();
$yytitle = "$maintxt{'155'}";
template();
return;
}
1;