"; $app .= "Android: Google Play 'FreeOTP Authenticator' by Red Hat
"; $app .= "Apple: App Store 'OTP Auth' by Roland Moers


"; return $app; } # function set_2fa($data, $user, $tfa, $ans, $err) { $draw = false; $pg = '

Two Factor Authentication Settings

'; if ($err !== null and $err != '') $pg .= "$err

"; $pg .= ''; $pg .= ''; $pg .= ''; $pg .= '
'; $pg .= makeForm('2fa'); $pg .= ''; $pg .= ''; break; case 'test': $pg .= ''; $pg .= ''; break; case 'ok': $pg .= ''; break; } $pg .= '
'; switch ($tfa) { case '': $pg .= '
'; $pg .= "You don't have Two Factor Authentication (2FA) setup yet

"; $pg .= 'To use 2FA you need an App on your phone/tablet
'; $pg .= app_txt('ones'); $pg .= 'Click here to begin the setup process for 2FA: '; $pg .= ''; $pg .= '
'; $pg .= '2FA is not yet enabled.
'; $pg .= 'Your 2FA key has been created but needs testing.

'; if (isset($ans['2fa_key'])) { $key = $ans['2fa_key']; $sfainfo = $ans['2fa_issuer'].': '.$ans['2fa_auth'].' '. $ans['2fa_hash'].' '.$ans['2fa_time'].'s'; $who = substr($user, 0, 8); $sfaurl = 'otpauth://'.$ans['2fa_auth'].'/'.$ans['2fa_issuer']. ':'.htmlspecialchars($who).'?secret='.$ans['2fa_key']. '&algorithm='.$ans['2fa_hash'].'&issuer='.$ans['2fa_issuer']; $draw = true; addQR(); } else { $key = 'unavailable'; $sfainfo = 'unavailable'; $sfaurl = 'unavailable'; } $pg .= "Your 2FA Secret Key is: $key
"; $pg .= "2FA Settings are $sfainfo

"; $pg .= "To setup 2FA in your App: Click here
"; $pg .= "or scan the qrcode/barcode below with your App:

"; $pg .= '
'; $pg .= 'A qrcode will show here if your browser supports html5/canvas'; $pg .= "

"; $pg .= 'Then enter your App 2FA Value: '; $pg .= '
'; $pg .= app_txt('2FA apps'); $pg .= 'N.B. if you wish to setup 2FA on more than one device,
'; $pg .= 'you should setup all devices before testing one of them.
'; $pg .= 'If you have an old 2FA Secret Key in your device for this web site,
'; $pg .= 'delete it before scanning in the new 2FA Secret Key.

'; $pg .= 'WARNING: if you lose your 2FA device you will need to know
'; $pg .= 'the 2FA Secret Key to manually setup a new device,
'; $pg .= 'so your should copy it and store it somewhere securely.
'; $pg .= 'For security reasons, the site will not show you an active 2FA Secret Key.
'; $pg .= '
'; $pg .= '2FA is enabled on your account.

'; $pg .= 'If you wish to replace your Secret Key with a new one:

'; $pg .= 'Current 2FA Value: '; $pg .= '*

'; $pg .= '*WARNING: replacing the Secret Key will disable 2FA
'; $pg .= 'until you successfully test the new key,
'; $pg .= 'thus getting a new key is effectively the same as disabling 2FA.

'; $pg .= '
'; $pg .= '
'; $pg .= '2FA means that you need 2 codes to login to your account.
'; $pg .= 'You will also need the 2FA code to modify any important settings in your account.
'; $pg .= 'The 1st code is your current password.
'; $pg .= 'The 2nd code is a number that your 2FA device will generate each time.
'; $pg .= 'Your 2FA device would be, for example, your phone or tablet.

'; $pg .= 'Each time you need a 2FA code, you use your device to generate a number
'; $pg .= 'that you type into the "*2nd Authentication:" field on any page that has it.

'; $pg .= 'WARNING: once you have successfully tested and enabled 2FA,
'; $pg .= 'you will be unable to access or even reset your account without 2FA.
'; $pg .= 'There is no option to recover your 2FA from the web site,
'; $pg .= 'and you must know your 2FA code in order to be able to disable 2FA.

'; $pg .= 'WARNING: it is important to not store your login password in your 2FA device.
'; $pg .= 'These 2 together will give full access to your account.'; $pg .= '
'; if ($draw !== false) { $qr = shell_exec("../pool/myqr.sh '$sfaurl'"); if ($qr !== null and strlen($qr) > 30) { $pg .= "\n"; if (strpos($qr, 'var tw=1,fa=0,qrx=') === false) error_log("QR error for '$user' res='$qr'"); } else { if ($qr === null) $qr = 'null'; error_log("QR failed for '$user' res='$qr'"); } } return $pg; } # function do2fa($data, $user) { $err = ''; $setup = getparam('Setup', false); $testemail = false; if ($setup === 'Setup') { // rand() included as part of the entropy $ans = get2fa($user, 'setup', rand(1073741824,2147483647), 0); $testemail = true; } else { $value = getparam('Value', false); $test = getparam('Test', false); if ($test === 'Test' and $value !== null) { $ans = get2fa($user, 'test', 0, $value); $testemail = true; } else { $nw = getparam('New', false); if ($nw === 'New' and $value !== null) { $ans = get2fa($user, 'new', rand(1073741824,2147483647), $value); $testemail = true; } else $ans = get2fa($user, '', 0, 0); } } if ($ans['STATUS'] != 'ok') $err = 'DBERR'; else { if (isset($ans['2fa_error'])) $err = $ans['2fa_error']; if ($testemail and $err == '') { $ans2 = userSettings($user); if ($ans2['STATUS'] != 'ok') dbdown(); // Should be no other reason? if (!isset($ans2['email'])) $err = 'An error occurred, check your details below'; else { $email = $ans2['email']; $emailinfo = getOpts($user, emailOptList()); if ($emailinfo['STATUS'] != 'ok') $err = 'An error occurred, check your details below'; else { if ($setup === 'Setup') twofaSetup($email, zeip(), $emailinfo); else if ($test === 'Test') twofaEnabled($email, zeip(), $emailinfo); else if ($nw === 'New') twofaSetup($email, zeip(), $emailinfo); } } } } if (!isset($ans['2fa_status'])) $tfa = null; else $tfa = $ans['2fa_status']; $pg = set_2fa($data, $user, $tfa, $ans, $err); return $pg; } # function show_2fa($info, $page, $menu, $name, $user) { gopage($info, NULL, 'do2fa', $page, $menu, $name, $user); } # ?>