88 * License: GNU/GPLv2
99 * @see LICENSE.txt
1010 *
11- * This file: Front-end handler (last modified: 2020.07.08 ).
11+ * This file: Front-end handler (last modified: 2020.07.12 ).
1212 */
1313
1414namespace phpMussel \FrontEnd ;
@@ -444,7 +444,7 @@ public function view(string $Page = '')
444444 ) {
445445 $ TwoFactorState = ['Number ' => $ this ->twoFactorNumber ()];
446446 $ TwoFactorState ['Hash ' ] = password_hash ($ TwoFactorState ['Number ' ], $ this ->DefaultAlgo );
447- $ this ->Loader ->Cache ->setEntry ('TwoFactorState: ' . $ Cookie , '0 ' . $ TwoFactorState ['Hash ' ], $ this ->Loader -> Time + $ this -> TwoFactorTTL );
447+ $ this ->Loader ->Cache ->setEntry ('TwoFactorState: ' . $ Cookie , '0 ' . $ TwoFactorState ['Hash ' ], $ this ->TwoFactorTTL );
448448 $ TwoFactorState ['Template ' ] = sprintf ($ TwoFactorMessage , $ TryUser , $ TwoFactorState ['Number ' ]);
449449 if (preg_match ('~^[^<>]+<[^<>]+>$~ ' , $ TryUser )) {
450450 $ TwoFactorState ['Name ' ] = trim (preg_replace ('~^([^<>]+)<[^<>]+>$~ ' , '\1 ' , $ TryUser ));
@@ -463,14 +463,16 @@ public function view(string $Page = '')
463463 $ this ->Loader ->Events ->fireEvent ('sendMail ' , '' , ...$ EventData );
464464 $ this ->Permissions = 3 ;
465465 } else {
466- $ this ->Loader ->Cache ->setEntry ($ Cookie , $ this ->ThisSession , $ this ->Loader ->Time + $ this ->SessionTTL );
467466 $ this ->Permissions = 1 ;
468467 }
468+ $ this ->Loader ->Cache ->setEntry ($ Cookie , $ this ->ThisSession , $ this ->SessionTTL );
469469 }
470470 } else {
471+ $ TryUser = $ _POST ['username ' ];
471472 $ FE ['state_msg ' ] = $ this ->Loader ->L10N ->getString ('response_login_invalid_password ' );
472473 }
473474 } else {
475+ $ TryUser = $ _POST ['username ' ];
474476 $ FE ['state_msg ' ] = $ this ->Loader ->L10N ->getString ('response_login_invalid_username ' );
475477 }
476478 }
@@ -479,7 +481,7 @@ public function view(string $Page = '')
479481 if ($ FE ['state_msg ' ]) {
480482 $ LoginAttempts ++;
481483 $ TimeToAdd = ($ LoginAttempts > 4 ) ? ($ LoginAttempts - 4 ) * 86400 : 86400 ;
482- $ this ->Loader ->Cache ->setEntry ('LoginAttempts ' . $ _SERVER [$ this ->Loader ->Configuration ['core ' ]['ipaddr ' ]], $ LoginAttempts , $ this -> Loader -> Time + $ TimeToAdd );
484+ $ this ->Loader ->Cache ->setEntry ('LoginAttempts ' . $ _SERVER [$ this ->Loader ->Configuration ['core ' ]['ipaddr ' ]], $ LoginAttempts , $ TimeToAdd ?: 86400 );
483485 $ LoggerMessage = $ FE ['state_msg ' ];
484486 }
485487 } elseif ($ this ->Permissions === 3 ) {
@@ -489,8 +491,11 @@ public function view(string $Page = '')
489491 $ LoggerMessage = $ this ->Loader ->L10N ->getString ('state_logged_in ' );
490492 }
491493
494+ /** Safer for the front-end logger. */
495+ $ TryUser = preg_replace ('~[\x00-\x1f]~ ' , '' , $ TryUser ?? $ this ->User );
496+
492497 /** Handle front-end logging. */
493- $ this ->frontendLogger ($ _SERVER [$ this ->Loader ->Configuration ['core ' ]['ipaddr ' ]], $ TryUser ?? $ this -> User , $ LoggerMessage ?? '' );
498+ $ this ->frontendLogger ($ _SERVER [$ this ->Loader ->Configuration ['core ' ]['ipaddr ' ]], $ TryUser , $ LoggerMessage ?? '' );
494499 }
495500
496501 /** Determine whether the user has logged in. */
@@ -523,7 +528,7 @@ public function view(string $Page = '')
523528
524529 /** User has submitted a 2FA code. Attempt to verify it. */
525530 if (password_verify ($ _POST ['2fa ' ], substr ($ TwoFactorState , 1 ))) {
526- $ this ->Loader ->Cache ->setEntry ('TwoFactorState: ' . $ _COOKIE ['PHPMUSSEL-ADMIN ' ], '1 ' , $ this ->Loader -> Time + $ this -> SessionTTL );
531+ $ this ->Loader ->Cache ->setEntry ('TwoFactorState: ' . $ _COOKIE ['PHPMUSSEL-ADMIN ' ], '1 ' , $ this ->SessionTTL );
527532 $ Try = 1 ;
528533 $ this ->Loader ->Cache ->deleteEntry ('Failed2FA ' . $ _SERVER [$ this ->Loader ->Configuration ['core ' ]['ipaddr ' ]]);
529534 if ($ this ->Loader ->Configuration ['frontend ' ]['frontend_log ' ]) {
@@ -532,17 +537,17 @@ public function view(string $Page = '')
532537 } else {
533538 $ Failed2FA ++;
534539 $ TimeToAdd = ($ Failed2FA > 4 ) ? ($ Failed2FA - 4 ) * 86400 : 86400 ;
535- $ this ->Loader ->Cache ->setEntry ('Failed2FA ' . $ _SERVER [$ this ->Loader ->Configuration ['core ' ]['ipaddr ' ]], $ Failed2FA , $ this -> Loader -> Time + $ TimeToAdd );
540+ $ this ->Loader ->Cache ->setEntry ('Failed2FA ' . $ _SERVER [$ this ->Loader ->Configuration ['core ' ]['ipaddr ' ]], $ Failed2FA , $ TimeToAdd ?: 86400 );
536541 if ($ this ->Loader ->Configuration ['frontend ' ]['frontend_log ' ]) {
537542 $ this ->frontendLogger ($ _SERVER [$ this ->Loader ->Configuration ['core ' ]['ipaddr ' ]], $ SessionUser , $ this ->Loader ->L10N ->getString ('response_2fa_invalid ' ));
538543 }
539544 $ FE ['state_msg ' ] = $ this ->Loader ->L10N ->getString ('response_2fa_invalid ' );
540545 }
546+ }
541547
542- /** Revert permissions if not authenticated. */
543- if ($ Try !== 1 ) {
544- $ this ->Permissions = 3 ;
545- }
548+ /** Revert permissions if not authenticated. */
549+ if ($ Try !== 1 ) {
550+ $ this ->Permissions = 3 ;
546551 }
547552 }
548553 }
@@ -599,6 +604,9 @@ public function view(string $Page = '')
599604 /** Provide the option to log out (omit home link). */
600605 $ FE ['bNav ' ] = sprintf ('<a href="?phpmussel-page=logout">%s</a><br /> ' , $ this ->Loader ->L10N ->getString ('link_log_out ' ));
601606
607+ /** Aesthetic spacer. */
608+ $ FE ['2fa_status_spacer ' ] = empty ($ FE ['state_msg ' ]) ? '' : '<br /><br /> ' ;
609+
602610 /** Show them the two-factor authentication page. */
603611 $ FE ['FE_Content ' ] = $ this ->Loader ->parse (
604612 $ this ->Loader ->L10N ->Data ,
@@ -659,7 +667,7 @@ public function view(string $Page = '')
659667 /** Fetch remote phpMussel version information and cache it if necessary. */
660668 if (!($ RemoteYAMLphpMussel = $ this ->Loader ->Cache ->getEntry ('phpmussel-ver.yaml ' ))) {
661669 $ RemoteYAMLphpMussel = $ this ->Loader ->request ($ RemoteVerPath . 'phpmussel-ver.yaml ' , [], 8 );
662- $ this ->Loader ->Cache ->setEntry ('phpmussel-ver.yaml ' , $ RemoteYAMLphpMussel ?: '- ' , $ this -> Loader -> Time + 86400 );
670+ $ this ->Loader ->Cache ->setEntry ('phpmussel-ver.yaml ' , $ RemoteYAMLphpMussel ?: '- ' , 86400 );
663671 }
664672
665673 /** Process remote phpMussel version information. */
@@ -699,7 +707,7 @@ public function view(string $Page = '')
699707 /** Fetch remote PHP version information and cache it if necessary. */
700708 if (!($ RemoteYamlPHP = $ this ->Loader ->Cache ->getEntry ('php-ver.yaml ' ))) {
701709 $ RemoteYamlPHP = $ this ->Loader ->request ($ RemoteVerPath . 'php-ver.yaml ' , [], 8 );
702- $ this ->Loader ->Cache ->setEntry ('php-ver.yaml ' , $ RemoteYamlPHP ?: '- ' , $ this -> Loader -> Time + 86400 );
710+ $ this ->Loader ->Cache ->setEntry ('php-ver.yaml ' , $ RemoteYamlPHP ?: '- ' , 86400 );
703711 }
704712
705713 /** Process remote PHP version information. */
0 commit comments