@@ -69,14 +69,23 @@ public function getSignupTime($id) {
69
69
}
70
70
public function changeNoFee ($ id ) {
71
71
$ field = array ('name ' => 'no_fees ' , 'type ' => 'i ' , 'value ' => !$ this ->isNoFee ($ id ));
72
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
73
+ $ this ->log ->LogWarn ($ this ->getUserName ($ id )." changed no_fees to " .$ this ->isNoFee ($ id )." from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
74
+ }
72
75
return $ this ->updateSingle ($ id , $ field );
73
76
}
74
77
public function setLocked ($ id , $ value ) {
75
78
$ field = array ('name ' => 'is_locked ' , 'type ' => 'i ' , 'value ' => $ value );
79
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
80
+ $ this ->log ->LogWarn ($ this ->getUserName ($ id )." changed is_locked to $ value from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
81
+ }
76
82
return $ this ->updateSingle ($ id , $ field );
77
83
}
78
84
public function changeAdmin ($ id ) {
79
85
$ field = array ('name ' => 'is_admin ' , 'type ' => 'i ' , 'value ' => !$ this ->isAdmin ($ id ));
86
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
87
+ $ this ->log ->LogWarn ($ this ->getUserName ($ id )." changed is_admin to " .$ this ->isAdmin ($ id )." from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
88
+ }
80
89
return $ this ->updateSingle ($ id , $ field );
81
90
}
82
91
public function setUserFailed ($ id , $ value ) {
@@ -145,6 +154,11 @@ public function checkLogin($username, $password) {
145
154
$ lastLoginTime = $ this ->getLastLogin ($ uid );
146
155
$ this ->updateLoginTimestamp ($ uid );
147
156
$ getIPAddress = $ this ->getUserIp ($ uid );
157
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
158
+ if ($ getIPAddress !== $ _SERVER ['REMOTE_ADDR ' ]) {
159
+ $ this ->log ->LogWarn ("$ username has logged in with a different IP [ " .$ _SERVER ['REMOTE_ADDR ' ]."] saved is [ $ getIPAddress] " );
160
+ }
161
+ }
148
162
$ setIPAddress = $ this ->setUserIp ($ uid , $ _SERVER ['REMOTE_ADDR ' ]);
149
163
$ this ->createSession ($ username , $ getIPAddress , $ lastLoginTime );
150
164
if ($ setIPAddress ) {
@@ -172,11 +186,17 @@ public function checkLogin($username, $password) {
172
186
}
173
187
}
174
188
$ this ->setErrorMessage ("Invalid username or password " );
189
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
190
+ $ this ->log ->LogInfo ("$ username failed login from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
191
+ }
175
192
if ($ id = $ this ->getUserId ($ username )) {
176
193
$ this ->incUserFailed ($ id );
177
194
// Check if this account should be locked
178
195
if (isset ($ this ->config ['maxfailed ' ]['login ' ]) && $ this ->getUserFailed ($ id ) >= $ this ->config ['maxfailed ' ]['login ' ]) {
179
196
$ this ->setLocked ($ id , 1 );
197
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
198
+ $ this ->log ->LogWarn ("$ username locked via failed logins from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] saved is [ " .$ this ->getUserIp ($ this ->getUserId ($ username ))."] " );
199
+ }
180
200
if ($ token = $ this ->token ->createToken ('account_unlock ' , $ id )) {
181
201
$ aData ['token ' ] = $ token ;
182
202
$ aData ['username ' ] = $ username ;
@@ -203,17 +223,23 @@ public function checkPin($userId, $pin=false) {
203
223
$ pin_hash = $ this ->getHash ($ pin );
204
224
if ($ stmt ->bind_param ('is ' , $ userId , $ pin_hash ) && $ stmt ->execute () && $ stmt ->bind_result ($ row_pin ) && $ stmt ->fetch ()) {
205
225
$ this ->setUserPinFailed ($ userId , 0 );
206
- return $ pin_hash === $ row_pin ;
226
+ return ($ pin_hash === $ row_pin );
227
+ }
228
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
229
+ $ this ->log ->LogInfo ($ this ->getUserName ($ userId )." incorrect pin from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
207
230
}
208
231
$ this ->incUserPinFailed ($ userId );
209
232
// Check if this account should be locked
210
233
if (isset ($ this ->config ['maxfailed ' ]['pin ' ]) && $ this ->getUserPinFailed ($ userId ) >= $ this ->config ['maxfailed ' ]['pin ' ]) {
211
234
$ this ->setLocked ($ userId , 1 );
235
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
236
+ $ this ->log ->LogWarn ($ this ->getUserName ($ userId )." was locked via incorrect pins from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
237
+ }
212
238
if ($ token = $ this ->token ->createToken ('account_unlock ' , $ userId )) {
213
239
$ username = $ this ->getUserName ($ userId );
214
240
$ aData ['token ' ] = $ token ;
215
241
$ aData ['username ' ] = $ username ;
216
- $ aData ['email ' ] = $ this ->getUserEmail ($ username );;
242
+ $ aData ['email ' ] = $ this ->getUserEmail ($ username );
217
243
$ aData ['subject ' ] = 'Account auto-locked ' ;
218
244
$ this ->mail ->sendMail ('notifications/locked ' , $ aData );
219
245
}
@@ -234,17 +260,25 @@ public function generatePin($userID, $current) {
234
260
$ newpin = $ this ->getHash ($ newpin );
235
261
$ aData ['subject ' ] = 'PIN Reset Request ' ;
236
262
$ stmt = $ this ->mysqli ->prepare ("UPDATE $ this ->table SET pin = ? WHERE ( id = ? AND pass = ? ) " );
237
-
238
263
if ($ this ->checkStmt ($ stmt ) && $ stmt ->bind_param ('sis ' , $ newpin , $ userID , $ current ) && $ stmt ->execute ()) {
239
264
if ($ stmt ->errno == 0 && $ stmt ->affected_rows === 1 ) {
240
265
if ($ this ->mail ->sendMail ('pin/reset ' , $ aData )) {
266
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
267
+ $ this ->log ->LogInfo ($ this ->getUserName ($ userID )." was sent a pin reset from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
268
+ }
241
269
return true ;
242
270
} else {
271
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
272
+ $ this ->log ->LogWarn ($ this ->getUserName ($ userID )." request a pin reset but the mailing failed from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
273
+ }
243
274
$ this ->setErrorMessage ('Unable to send mail to your address ' );
244
275
return false ;
245
276
}
246
277
}
247
278
}
279
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
280
+ $ this ->log ->LogWarn ($ this ->getUserName ($ userID )." incorrect pin reset attempt from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
281
+ }
248
282
$ this ->setErrorMessage ( 'Unable to generate PIN, current password incorrect? ' );
249
283
return false ;
250
284
}
@@ -319,14 +353,23 @@ public function sendChangeConfigEmail($strType, $userID) {
319
353
default :
320
354
$ aData ['subject ' ] = '' ;
321
355
}
356
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
357
+ $ this ->log ->LogInfo ($ this ->getUserName ($ userID )." was sent a $ strType token from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
358
+ }
322
359
if ($ this ->mail ->sendMail ('notifications/ ' .$ strType , $ aData )) {
323
360
return true ;
324
361
} else {
325
362
$ this ->setErrorMessage ('Failed to send the notification ' );
363
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
364
+ $ this ->log ->LogWarn ($ this ->getUserName ($ userID )." requested a $ strType token but the mailing failed from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
365
+ }
326
366
return false ;
327
367
}
328
368
}
329
- $ this ->setErrorMessage ('A request has already been sent to your e-mail address. Please wait 10 minutes for it to expire. ' );
369
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
370
+ $ this ->log ->LogWarn ($ this ->getUserName ($ userID )." attempted to request multiple $ strType tokens from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
371
+ }
372
+ $ this ->setErrorMessage ('A request has already been sent to your e-mail address. Please wait an hour for it to expire. ' );
330
373
return false ;
331
374
}
332
375
@@ -351,25 +394,44 @@ public function updatePassword($userID, $current, $new1, $new2, $strToken) {
351
394
}
352
395
$ current = $ this ->getHash ($ current );
353
396
$ new = $ this ->getHash ($ new1 );
397
+ if ($ this ->config ['twofactor ' ]['enabled ' ] && $ this ->config ['twofactor ' ]['options ' ]['changepw ' ]) {
398
+ $ tValid = $ this ->token ->isTokenValid ($ userID , $ strToken , 6 );
399
+ if ($ tValid ) {
400
+ if ($ this ->token ->deleteToken ($ strToken )) {
401
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
402
+ $ this ->log ->LogInfo ($ this ->getUserName ($ userID )." deleted change password token from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
403
+ }
404
+ // token deleted, continue
405
+ } else {
406
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
407
+ $ this ->log ->LogWarn ($ this ->getUserName ($ userID )." change password token failed to delete from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
408
+ }
409
+ $ this ->setErrorMessage ('Token deletion failed ' );
410
+ return false ;
411
+ }
412
+ } else {
413
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
414
+ $ this ->log ->LogWarn ($ this ->getUserName ($ userID )." attempted to use an invalid change password token from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
415
+ }
416
+ $ this ->setErrorMessage ('Invalid token ' );
417
+ return false ;
418
+ }
419
+ }
354
420
$ stmt = $ this ->mysqli ->prepare ("UPDATE $ this ->table SET pass = ? WHERE ( id = ? AND pass = ? ) " );
355
421
if ($ this ->checkStmt ($ stmt )) {
356
422
$ stmt ->bind_param ('sis ' , $ new , $ userID , $ current );
357
423
$ stmt ->execute ();
358
424
if ($ stmt ->errno == 0 && $ stmt ->affected_rows === 1 ) {
359
- // twofactor - consume the token if it is enabled and valid
360
- if ($ this ->config ['twofactor ' ]['enabled ' ] && $ this ->config ['twofactor ' ]['options ' ]['changepw ' ]) {
361
- $ tValid = $ this ->token ->isTokenValid ($ userID , $ strToken , 6 );
362
- if ($ tValid ) {
363
- $ this ->token ->deleteToken ($ strToken );
364
- } else {
365
- $ this ->setErrorMessage ('Invalid token ' );
366
- return false ;
367
- }
425
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
426
+ $ this ->log ->LogInfo ($ this ->getUserName ($ userID )." updated password from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
368
427
}
369
428
return true ;
370
429
}
371
430
$ stmt ->close ();
372
431
}
432
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
433
+ $ this ->log ->LogWarn ($ this ->getUserName ($ userID )." incorrect password update attempt from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
434
+ }
373
435
$ this ->setErrorMessage ( 'Unable to update password, current password wrong? ' );
374
436
return false ;
375
437
}
@@ -434,20 +496,38 @@ public function updateAccount($userID, $address, $threshold, $donate, $email, $i
434
496
$ threshold = min ($ this ->config ['ap_threshold ' ]['max ' ], max (0 , floatval ($ threshold )));
435
497
$ donate = min (100 , max (0 , floatval ($ donate )));
436
498
437
- // We passed all validation checks so update the account
438
- $ stmt = $ this ->mysqli -> prepare ( " UPDATE $ this ->table SET coin_address = ?, ap_threshold = ?, donate_percent = ?, email = ?, is_anonymous = ? WHERE id = ? " );
439
- if ( $ this -> checkStmt ( $ stmt ) && $ stmt -> bind_param ( ' sddsii ' , $ address , $ threshold , $ donate , $ email , $ is_anonymous , $ userID ) && $ stmt -> execute ())
440
- // twofactor - consume the token if it is enabled and valid
441
- if ($ this ->config [ ' twofactor ' ][ ' enabled ' ] && $ this -> config [ ' twofactor ' ][ ' options ' ][ ' details ' ] ) {
442
- $ tValid = $ this ->token -> isTokenValid ( $ userID , $ strToken , 5 );
443
- if ( $ tValid ) {
444
- $ this -> token -> deleteToken ( $ strToken );
499
+ // twofactor - consume the token if it is enabled and valid
500
+ if ( $ this ->config [ ' twofactor ' ][ ' enabled ' ] && $ this ->config [ ' twofactor ' ][ ' options ' ][ ' details ' ]) {
501
+ $ tValid = $ this -> token -> isTokenValid ( $ userID , $ strToken , 5 );
502
+ if ( $ tValid ) {
503
+ if ($ this ->token -> deleteToken ( $ strToken ) ) {
504
+ if ( $ this ->config [ ' logging ' ][ ' enabled ' ] && $ this -> config [ ' logging ' ][ ' level ' ] > 0 ) {
505
+ $ this -> log -> LogInfo ( $ this -> getUserName ( $ userID ). " deleted account update token for [ " . $ _SERVER [ ' REMOTE_ADDR ' ]. " ] " );
506
+ }
445
507
} else {
446
- $ this ->setErrorMessage ('Invalid token ' );
508
+ $ this ->setErrorMessage ('Token deletion failed ' );
509
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
510
+ $ this ->log ->LogWarn ($ this ->getUserName ($ userID )." updated their account details but token deletion failed from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
511
+ }
447
512
return false ;
448
513
}
514
+ } else {
515
+ $ this ->setErrorMessage ('Invalid token ' );
516
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
517
+ $ this ->log ->LogWarn ($ this ->getUserName ($ userID )." attempted to use an invalid token account update token from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
518
+ }
519
+ return false ;
520
+ }
521
+ }
522
+
523
+ // We passed all validation checks so update the account
524
+ $ stmt = $ this ->mysqli ->prepare ("UPDATE $ this ->table SET coin_address = ?, ap_threshold = ?, donate_percent = ?, email = ?, is_anonymous = ? WHERE id = ? " );
525
+ if ($ this ->checkStmt ($ stmt ) && $ stmt ->bind_param ('sddsii ' , $ address , $ threshold , $ donate , $ email , $ is_anonymous , $ userID ) && $ stmt ->execute ()) {
526
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
527
+ $ this ->log ->LogInfo ($ this ->getUserName ($ userID )." updated their account details from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
449
528
}
450
529
return true ;
530
+ }
451
531
// Catchall
452
532
$ this ->setErrorMessage ('Failed to update your account ' );
453
533
$ this ->debug ->append ('Account update failed: ' . $ this ->mysqli ->error );
@@ -542,7 +622,7 @@ public function logoutUser() {
542
622
$ port = ($ _SERVER ["SERVER_PORT " ] == "80 " || $ _SERVER ["SERVER_PORT " ] == "443 " ) ? "" : (": " .$ _SERVER ["SERVER_PORT " ]);
543
623
$ pushto = $ _SERVER ['SCRIPT_NAME ' ].'?page=login ' ;
544
624
$ location = (@$ _SERVER ['HTTPS ' ] == 'on ' ) ? 'https:// ' . $ _SERVER ['SERVER_NAME ' ] . $ port . $ pushto : 'http:// ' . $ _SERVER ['SERVER_NAME ' ] . $ port . $ pushto ;
545
- // if (!headers_sent()) header('Location: ' . $location);
625
+ if (!headers_sent ()) header ('Location: ' . $ location );
546
626
exit ('<meta http-equiv="refresh" content="0; url= ' . $ location . '"/> ' );
547
627
}
548
628
@@ -789,6 +869,13 @@ public function initResetPassword($username) {
789
869
}
790
870
$ aData ['username ' ] = $ this ->getUserName ($ this ->getUserId ($ username , true ));
791
871
$ aData ['subject ' ] = 'Password Reset Request ' ;
872
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
873
+ if ($ _SERVER ['REMOTE_ADDR ' ] !== $ this ->getUserIp ($ this ->getUserId ($ username , true ))) {
874
+ $ this ->log ->LogWarn ("$ username requested password reset from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] saved is [ " .$ this ->getUserIp ($ this ->getUserId ($ username , true ))."] " );
875
+ } else {
876
+ $ this ->log ->LogInfo ("$ username requested password reset from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] saved is [ " .$ this ->getUserIp ($ this ->getUserId ($ username , true ))."] " );
877
+ }
878
+ }
792
879
if ($ this ->mail ->sendMail ('password/reset ' , $ aData )) {
793
880
return true ;
794
881
} else {
@@ -812,7 +899,10 @@ public function isAuthenticated($logout=true) {
812
899
$ this ->getUserIp ($ _SESSION ['USERDATA ' ]['id ' ]) == $ _SERVER ['REMOTE_ADDR ' ]
813
900
) return true ;
814
901
// Catchall
815
- if ($ logout == true ) $ this ->logoutUser ($ _SERVER ['REQUEST_URI ' ]);
902
+ if ($ this ->config ['logging ' ]['enabled ' ] && $ this ->config ['logging ' ]['level ' ] > 0 ) {
903
+ $ this ->log ->LogWarn ("Forcing logout, user is locked or IP changed mid session from [ " .$ _SERVER ['REMOTE_ADDR ' ]."] " );
904
+ }
905
+ if ($ logout == true ) $ this ->logoutUser ();
816
906
return false ;
817
907
}
818
908
@@ -853,6 +943,7 @@ public function getCurrentIP($trustremote=true, $checkclient=false, $checkforwar
853
943
// Make our class available automatically
854
944
$ user = new User ();
855
945
$ user ->setDebug ($ debug );
946
+ $ user ->setLog ($ log );
856
947
$ user ->setMysql ($ mysqli );
857
948
$ user ->setSalt ($ config ['SALT ' ]);
858
949
$ user ->setSmarty ($ smarty );
0 commit comments