diff -r adfbe522c95f -r 05fe0039d952 plugins/SpecialUserFuncs.php --- a/plugins/SpecialUserFuncs.php Sun Oct 25 00:09:11 2009 -0400 +++ b/plugins/SpecialUserFuncs.php Tue Nov 03 22:08:48 2009 -0500 @@ -48,101 +48,27 @@ function page_Special_Login() { global $db, $session, $paths, $template, $plugins; // Common objects - global $__login_status; - global $lang; - - require_once(ENANO_ROOT . '/includes/math.php'); - require_once(ENANO_ROOT . '/includes/diffiehellman.php'); - global $dh_supported; + global $login_result; + global $lang, $output; - $locked_out = false; - // are we locked out? - $threshold = ( $_ = getConfig('lockout_threshold') ) ? intval($_) : 5; - $duration = ( $_ = getConfig('lockout_duration') ) ? intval($_) : 15; - // convert to minutes - $duration = $duration * 60; - $policy = ( $x = getConfig('lockout_policy') && in_array(getConfig('lockout_policy'), array('lockout', 'disable', 'captcha')) ) ? getConfig('lockout_policy') : 'lockout'; - if ( $policy != 'disable' ) - { - $ipaddr = $db->escape($_SERVER['REMOTE_ADDR']); - $timestamp_cutoff = time() - $duration; - $q = $session->sql('SELECT timestamp FROM '.table_prefix.'lockout WHERE timestamp > ' . $timestamp_cutoff . ' AND ipaddr = \'' . $ipaddr . '\' ORDER BY timestamp DESC;'); - $fails = $db->numrows(); - if ( $fails >= $threshold ) - { - $row = $db->fetchrow(); - $locked_out = true; - $lockdata = array( - 'locked_out' => true, - 'lockout_threshold' => $threshold, - 'lockout_duration' => ( $duration / 60 ), - 'lockout_fails' => $fails, - 'lockout_policy' => $policy, - 'lockout_last_time' => $row['timestamp'], - 'time_rem' => ( $duration / 60 ) - round( ( time() - $row['timestamp'] ) / 60 ), - 'captcha' => '' - ); - if ( $policy == 'captcha' ) - { - $lockdata['captcha'] = $session->make_captcha(); - } - } - $db->free_result(); - } - - if ( isset($_GET['act']) && $_GET['act'] == 'getkey' ) - { - header('Content-type: text/javascript'); - $username = ( $session->user_logged_in ) ? $session->username : false; - $response = Array( - 'username' => $username, - 'key' => $pubkey, - 'challenge' => $challenge, - 'locked_out' => false - ); - - if ( $locked_out ) - { - foreach ( $lockdata as $x => $y ) - { - $response[$x] = $y; - } - unset($x, $y); - } - - // 1.1.3: generate diffie hellman key - $response['dh_supported'] = $dh_supported; - if ( $dh_supported ) - { - $dh_key_priv = dh_gen_private(); - $dh_key_pub = dh_gen_public($dh_key_priv); - $dh_key_priv = $_math->str($dh_key_priv); - $dh_key_pub = $_math->str($dh_key_pub); - $response['dh_public_key'] = $dh_key_pub; - // store the keys in the DB - $q = $db->sql_query('INSERT INTO ' . table_prefix . "diffiehellman( public_key, private_key ) VALUES ( '$dh_key_pub', '$dh_key_priv' );"); - if ( !$q ) - $db->die_json(); - } - - $response = enano_json_encode($response); - echo $response; - return null; - } - + // Determine which level we're going up to $level = ( isset($_GET['level']) && in_array($_GET['level'], array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') ) ) ? intval($_GET['level']) : USER_LEVEL_MEMBER; if ( isset($_POST['login']) ) { - if ( in_array($_POST['auth_level'], array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') ) ) + if ( in_array($_POST['level'], array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') ) ) { - $level = intval($_POST['auth_level']); + $level = intval($_POST['level']); } } - + // Don't allow going from guest straight to elevated + // FIXME do we want to allow this with a CSRF check? if ( $level > USER_LEVEL_MEMBER && !$session->user_logged_in ) { $level = USER_LEVEL_MEMBER; } + + // If we're already at or above this level, redirect to the target page or, if no target + // specified, back to the main page. if ( $level <= USER_LEVEL_MEMBER && $session->user_logged_in ) { if ( $target = $paths->getAllParams() ) @@ -152,176 +78,136 @@ $paths->main_page(); } - $template->header(); - echo '
'; - $header = ( $level > USER_LEVEL_MEMBER ) ? $lang->get('user_login_message_short_elev') : $lang->get('user_login_message_short'); - if ( isset($_POST['login']) ) - { - $errstring = $__login_status['error']; - switch($__login_status['error']) - { - case 'key_not_found': - $errstring = $lang->get('user_err_key_not_found'); - break; - case 'ERR_DH_KEY_NOT_FOUND': - $errstring = $lang->get('user_err_dh_key_not_found'); // . " -- {$__login_status['debug']}"; - break; - case 'ERR_DH_KEY_NOT_INTEGER': - $errstring = $lang->get('user_err_dh_key_not_numeric'); - break; - case 'key_wrong_length': - $errstring = $lang->get('user_err_key_wrong_length'); - break; - case 'too_big_for_britches': - $errstring = $lang->get('user_err_too_big_for_britches'); - break; - case 'invalid_credentials': - $errstring = $lang->get('user_err_invalid_credentials'); - if ( getConfig('lockout_policy', 'lockout') == 'lockout' ) - { - $errstring .= $lang->get('user_err_invalid_credentials_lockout', array('fails' => $__login_status['lockout_fails'])); - } - else if ( getConfig('lockout_policy', 'lockout') == 'captcha' ) - { - $errstring .= $lang->get('user_err_invalid_credentials_lockout_captcha', array('fails' => $__login_status['lockout_fails'])); - } - break; - case 'backend_fail': - $errstring = $lang->get('user_err_backend_fail'); - break; - case 'locked_out': - $attempts = intval($__login_status['lockout_fails']); - if ( $attempts > $__login_status['lockout_threshold']) - $attempts = $__login_status['lockout_threshold']; - - $server_time = time(); - $time_rem = ( intval(@$__login_status['lockout_last_time']) == time() ) ? $__login_status['lockout_duration'] : $__login_status['lockout_duration'] - round( ( $server_time - $__login_status['lockout_last_time'] ) / 60 ); - if ( $time_rem < 1 ) - $time_rem = $__login_status['lockout_duration']; - - $s = ( $time_rem == 1 ) ? '' : $lang->get('meta_plural'); - - $captcha_string = ( $__login_status['lockout_policy'] == 'captcha' ) ? $lang->get('user_err_locked_out_captcha_blurb') : ''; - $errstring = $lang->get('user_err_locked_out', array('plural' => $s, 'captcha_blurb' => $captcha_string, 'time_rem' => $time_rem)); - - break; - default: - $errstring = $lang->get($errstring); - break; - } - echo '
'.$errstring.'
'; - } + // Lockout aliasing + $lockout =& $login_result['lockout']; + + $output->header(); + echo ''; + if ( $p = $paths->getAllParams() ) { - echo ''; + echo ''; } else if ( isset($_POST['login']) && isset($_POST['return_to']) ) { - echo ''; + echo ''; + } + + // determine what the "remember me" checkbox should say + $session_time = intval(getConfig('session_remember_time', '30')); + if ( $session_time === 0 ) + { + // sessions are infinite + $text_remember = $lang->get('user_login_check_remember_infinite'); } + else + { + // is the number of days evenly divisible by 7? if so, use weeks + if ( $session_time % 7 == 0 ) + { + $session_time = $session_time / 7; + $unit = 'week'; + } + else + { + $unit = 'day'; + } + // if it's not equal to 1, pluralize it + if ( $session_time != 1 ) + { + $unit .= $lang->get('meta_plural'); + } + $text_remember = $lang->get('user_login_check_remember', array( + 'session_length' => $session_time, + 'length_units' => $lang->get("etc_unit_$unit") + )); + } + + if ( $error_text = login_get_error($login_result) ) + { + echo '
' . htmlspecialchars($error_text) . '
'; + } + + // + // START FORM + // ?>
- + + - - - + + + + + - + + setHook('login_form_html'); foreach ( $code as $cmd ) { eval($cmd); } + + // level-2 only: "Remember me" switch if ( $level <= USER_LEVEL_MEMBER ) { - // "remember me" switch - // first order of business is to determine what the checkbox should say - $session_time = intval(getConfig('session_remember_time', '30')); - if ( $session_time === 0 ) - { - // sessions are infinite - $text_remember = $lang->get('user_login_check_remember_infinite'); - } - else - { - // is the number of days evenly divisible by 7? if so, use weeks - if ( $session_time % 7 == 0 ) - { - $session_time = $session_time / 7; - $unit = 'week'; - } - else - { - $unit = 'day'; - } - // if it's not equal to 1, pluralize it - if ( $session_time != 1 ) - { - $unit .= 's'; - } - $text_remember = $lang->get('user_login_check_remember', array( - 'session_length' => $session_time, - 'length_units' => $lang->get("etc_unit_$unit") - )); - } ?> + + '; } - else if ( $level <= USER_LEVEL_MEMBER && ( isset($_GET['use_crypt']) && $_GET['use_crypt']=='0' ) ) + // Crypto disable: crypto OFF, normal login + else if ( $level <= USER_LEVEL_MEMBER && $crypto_disable ) { echo ''; } - else if ( $level > USER_LEVEL_MEMBER && !strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') && $dh_supported ) + // Crypto disable: crypto on, ELEV login + else if ( $level > USER_LEVEL_MEMBER && $GLOBALS['dh_supported'] ) { echo ''; echo '
+ + USER_LEVEL_MEMBER ) ? $lang->get('user_login_message_short_elev') : $lang->get('user_login_message_short'); ?> +
+ ' . $lang->get('user_login_body', array('reg_link' => makeUrlNS('Special', 'Register'))) . '

'; - } else - { echo '

' . $lang->get('user_login_body_elev') . '

'; - } ?>
get('user_login_field_username'); ?>: - user_logged_in ) - { - echo 'value="' . $session->username . '"'; - } - ?> /> + + + + get('user_login_forgotpass_blurb', array('forgotpass_link' => makeUrlNS('Special', 'PasswordReset'))); ?>
get('user_login_createaccount_blurb', array('reg_link' => makeUrlNS('Special', 'Register'))); ?>
get('user_login_field_password'); ?>: -
get('user_login_field_captcha'); ?>:
+ get('user_login_field_captcha'); ?>: +
+
+ + +
- +
@@ -334,9 +220,16 @@
'; @@ -349,7 +242,8 @@ echo '
'; @@ -362,7 +256,8 @@ echo '
'; @@ -372,15 +267,17 @@ } ?> +
- +
- + +