diff -r de56132c008d -r bdac73ed481e plugins/admin/UserManager.php --- a/plugins/admin/UserManager.php Sun Mar 28 21:49:26 2010 -0400 +++ b/plugins/admin/UserManager.php Sun Mar 28 23:10:46 2010 -0400 @@ -13,589 +13,589 @@ function page_Admin_UserManager() { - global $db, $session, $paths, $template, $plugins; // Common objects - global $lang; - if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN ) - { - $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true); - echo '

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

'; - echo '

' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '

'; - return; - } - - require_once(ENANO_ROOT . '/includes/math.php'); - require_once(ENANO_ROOT . '/includes/diffiehellman.php'); - - $GLOBALS['dh_supported'] = $dh_supported; - - //die('
' . htmlspecialchars(print_r($_POST, true)) . '
'); - - if ( isset($_POST['action']['save']) ) - { - # - # BEGIN VALIDATION - # - - $errors = array(); - - if ( defined('ENANO_DEMO_MODE') ) - { - $errors[] = $lang->get('acpum_err_nosave_demo'); - } - - $user_id = intval($_POST['user_id']); - if ( empty($user_id) || $user_id == 1 ) - $errors[] = 'Invalid user ID.'; - - if ( isset($_POST['delete_account']) && count($errors) < 1 ) - { - $q = $db->sql_query('DELETE FROM '.table_prefix."users_extra WHERE user_id=$user_id;"); - if ( !$q ) - $db->_die(); - $q = $db->sql_query('DELETE FROM '.table_prefix."users WHERE user_id=$user_id;"); - if ( !$q ) - $db->_die(); - $q = $db->sql_query('DELETE FROM '.table_prefix."session_keys WHERE user_id=$user_id;"); - if ( !$q ) - $db->_die(); - echo '
' . $lang->get('acpum_msg_delete_success') . '
'; - - // deleting own account? - if ( $user_id === $session->user_id ) - { - // cute little hack to boot them out of the admin panel - echo ''; - } - } - else - { - if ( $session->user_id == $user_id ) - { - $username = $session->username; - $password = false; - $email = $session->email; - $real_name = $session->real_name; - } - else - { - $username = $_POST['username']; - if ( !preg_match('#^'.$session->valid_username.'$#', $username) ) - $errors[] = $lang->get('acpum_err_illegal_username'); - - $password = false; - if ( $_POST['changing_pw'] == 'yes' ) - { - $password = $session->get_aes_post('new_password'); - } - - $email = $_POST['email']; - if ( !preg_match('/^(?:[\w\d]+\.?)+@((?:(?:[\w\d]\-?)+\.)+\w{2,4}|localhost)$/', $email) ) - $errors[] = $lang->get('acpum_err_illegal_email'); - - $real_name = $_POST['real_name']; - } - - $signature = RenderMan::preprocess_text($_POST['signature'], true, false); - - $user_level = intval($_POST['user_level']); - if ( $user_level < USER_LEVEL_MEMBER || $user_level > USER_LEVEL_ADMIN ) - $errors[] = 'Invalid user level'; - - $user_rank = $_POST['user_rank']; - if ( $user_rank !== 'NULL' ) - { - $user_rank = intval($user_rank); - if ( !$user_rank ) - $errors[] = 'Invalid user rank'; - } - - $imaddr_aim = htmlspecialchars($_POST['imaddr_aim']); - $imaddr_msn = htmlspecialchars($_POST['imaddr_msn']); - $imaddr_yahoo = htmlspecialchars($_POST['imaddr_yahoo']); - $imaddr_xmpp = htmlspecialchars($_POST['imaddr_xmpp']); - $homepage = htmlspecialchars($_POST['homepage']); - $location = htmlspecialchars($_POST['location']); - $occupation = htmlspecialchars($_POST['occupation']); - $hobbies = htmlspecialchars($_POST['hobbies']); - $email_public = ( isset($_POST['email_public']) ) ? '1' : '0'; - $user_title = htmlspecialchars($_POST['user_title']); - - if ( !preg_match('/@([a-z0-9-]+)(\.([a-z0-9-\.]+))?/', $imaddr_msn) && !empty($imaddr_msn) ) - { - $imaddr_msn = "$imaddr_msn@hotmail.com"; - } - - if ( !preg_match('#^https?://#', $homepage) ) - { - $homepage = "http://$homepage"; - } - - if ( !preg_match('/^http:\/\/([a-z0-9-.]+)([A-z0-9@#\$%\&:;<>,\.\?=\+\(\)\[\]_\/\\\\]*?)$/i', $homepage) ) - { - $homepage = ''; - } - - // true for quiet operation - list(, , $avatar_post_fail) = avatar_post($user_id, true); - - if ( count($errors) < 1 && !$avatar_post_fail ) - { - $q = $db->sql_query('SELECT u.user_level, u.user_has_avatar, u.avatar_type, u.username FROM '.table_prefix.'users AS u WHERE u.user_id = ' . $user_id . ';'); - if ( !$q ) - $db->_die(); - - if ( $db->numrows() < 1 ) - { - echo 'Couldn\'t select user data: no rows returned'; - } - - $row = $db->fetchrow(); - $existing_level =& $row['user_level']; - $avi_type =& $row['avatar_type']; - $has_avi = ( $row['user_has_avatar'] == 1 ); - $old_username = $row['username']; - $db->free_result(); - - $to_update_users = array(); - if ( $user_id != $session->user_id ) - { - $to_update_users['username'] = $username; - if ( $password ) - { - $session->set_password($user_id, $password); - } - $to_update_users['email'] = $email; - $to_update_users['real_name'] = $real_name; - } - $to_update_users['signature'] = $signature; - $to_update_users['user_level'] = $user_level; - $to_update_users['user_rank'] = $user_rank; - $to_update_users['user_title'] = $user_title; - - if ( $user_rank > 0 ) - { - $to_update_users['user_rank_userset'] = '0'; - } - - if ( isset($_POST['account_active']) ) - { - $to_update_users['account_active'] = "1"; - } - else - { - $to_update_users['account_active'] = "0"; - $to_update_users['activation_key'] = sha1($session->dss_rand()); - } - - if ( count($errors) < 1 ) - { - $to_update_users_extra = array(); - $to_update_users_extra['user_aim'] = $imaddr_aim; - $to_update_users_extra['user_msn'] = $imaddr_msn; - $to_update_users_extra['user_yahoo'] = $imaddr_yahoo; - $to_update_users_extra['user_xmpp'] = $imaddr_xmpp; - $to_update_users_extra['user_homepage'] = $homepage; - $to_update_users_extra['user_location'] = $location; - $to_update_users_extra['user_job'] = $occupation; - $to_update_users_extra['user_hobbies'] = $hobbies; - $to_update_users_extra['email_public'] = ( $email_public ) ? '1' : '0'; - - $update_sql = ''; - - foreach ( $to_update_users as $key => $unused_crap ) - { - $value =& $to_update_users[$key]; - if ( $value !== 'NULL' ) - $value = "'" . $db->escape($value) . "'"; + global $db, $session, $paths, $template, $plugins; // Common objects + global $lang; + if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN ) + { + $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true); + echo '

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

'; + echo '

' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '

'; + return; + } + + require_once(ENANO_ROOT . '/includes/math.php'); + require_once(ENANO_ROOT . '/includes/diffiehellman.php'); + + $GLOBALS['dh_supported'] = $dh_supported; + + //die('
' . htmlspecialchars(print_r($_POST, true)) . '
'); + + if ( isset($_POST['action']['save']) ) + { + # + # BEGIN VALIDATION + # + + $errors = array(); + + if ( defined('ENANO_DEMO_MODE') ) + { + $errors[] = $lang->get('acpum_err_nosave_demo'); + } + + $user_id = intval($_POST['user_id']); + if ( empty($user_id) || $user_id == 1 ) + $errors[] = 'Invalid user ID.'; + + if ( isset($_POST['delete_account']) && count($errors) < 1 ) + { + $q = $db->sql_query('DELETE FROM '.table_prefix."users_extra WHERE user_id=$user_id;"); + if ( !$q ) + $db->_die(); + $q = $db->sql_query('DELETE FROM '.table_prefix."users WHERE user_id=$user_id;"); + if ( !$q ) + $db->_die(); + $q = $db->sql_query('DELETE FROM '.table_prefix."session_keys WHERE user_id=$user_id;"); + if ( !$q ) + $db->_die(); + echo '
' . $lang->get('acpum_msg_delete_success') . '
'; + + // deleting own account? + if ( $user_id === $session->user_id ) + { + // cute little hack to boot them out of the admin panel + echo ''; + } + } + else + { + if ( $session->user_id == $user_id ) + { + $username = $session->username; + $password = false; + $email = $session->email; + $real_name = $session->real_name; + } + else + { + $username = $_POST['username']; + if ( !preg_match('#^'.$session->valid_username.'$#', $username) ) + $errors[] = $lang->get('acpum_err_illegal_username'); + + $password = false; + if ( $_POST['changing_pw'] == 'yes' ) + { + $password = $session->get_aes_post('new_password'); + } + + $email = $_POST['email']; + if ( !preg_match('/^(?:[\w\d]+\.?)+@((?:(?:[\w\d]\-?)+\.)+\w{2,4}|localhost)$/', $email) ) + $errors[] = $lang->get('acpum_err_illegal_email'); + + $real_name = $_POST['real_name']; + } + + $signature = RenderMan::preprocess_text($_POST['signature'], true, false); + + $user_level = intval($_POST['user_level']); + if ( $user_level < USER_LEVEL_MEMBER || $user_level > USER_LEVEL_ADMIN ) + $errors[] = 'Invalid user level'; + + $user_rank = $_POST['user_rank']; + if ( $user_rank !== 'NULL' ) + { + $user_rank = intval($user_rank); + if ( !$user_rank ) + $errors[] = 'Invalid user rank'; + } + + $imaddr_aim = htmlspecialchars($_POST['imaddr_aim']); + $imaddr_msn = htmlspecialchars($_POST['imaddr_msn']); + $imaddr_yahoo = htmlspecialchars($_POST['imaddr_yahoo']); + $imaddr_xmpp = htmlspecialchars($_POST['imaddr_xmpp']); + $homepage = htmlspecialchars($_POST['homepage']); + $location = htmlspecialchars($_POST['location']); + $occupation = htmlspecialchars($_POST['occupation']); + $hobbies = htmlspecialchars($_POST['hobbies']); + $email_public = ( isset($_POST['email_public']) ) ? '1' : '0'; + $user_title = htmlspecialchars($_POST['user_title']); + + if ( !preg_match('/@([a-z0-9-]+)(\.([a-z0-9-\.]+))?/', $imaddr_msn) && !empty($imaddr_msn) ) + { + $imaddr_msn = "$imaddr_msn@hotmail.com"; + } + + if ( !preg_match('#^https?://#', $homepage) ) + { + $homepage = "http://$homepage"; + } + + if ( !preg_match('/^http:\/\/([a-z0-9-.]+)([A-z0-9@#\$%\&:;<>,\.\?=\+\(\)\[\]_\/\\\\]*?)$/i', $homepage) ) + { + $homepage = ''; + } + + // true for quiet operation + list(, , $avatar_post_fail) = avatar_post($user_id, true); + + if ( count($errors) < 1 && !$avatar_post_fail ) + { + $q = $db->sql_query('SELECT u.user_level, u.user_has_avatar, u.avatar_type, u.username FROM '.table_prefix.'users AS u WHERE u.user_id = ' . $user_id . ';'); + if ( !$q ) + $db->_die(); + + if ( $db->numrows() < 1 ) + { + echo 'Couldn\'t select user data: no rows returned'; + } + + $row = $db->fetchrow(); + $existing_level =& $row['user_level']; + $avi_type =& $row['avatar_type']; + $has_avi = ( $row['user_has_avatar'] == 1 ); + $old_username = $row['username']; + $db->free_result(); + + $to_update_users = array(); + if ( $user_id != $session->user_id ) + { + $to_update_users['username'] = $username; + if ( $password ) + { + $session->set_password($user_id, $password); + } + $to_update_users['email'] = $email; + $to_update_users['real_name'] = $real_name; + } + $to_update_users['signature'] = $signature; + $to_update_users['user_level'] = $user_level; + $to_update_users['user_rank'] = $user_rank; + $to_update_users['user_title'] = $user_title; + + if ( $user_rank > 0 ) + { + $to_update_users['user_rank_userset'] = '0'; + } + + if ( isset($_POST['account_active']) ) + { + $to_update_users['account_active'] = "1"; + } + else + { + $to_update_users['account_active'] = "0"; + $to_update_users['activation_key'] = sha1($session->dss_rand()); + } + + if ( count($errors) < 1 ) + { + $to_update_users_extra = array(); + $to_update_users_extra['user_aim'] = $imaddr_aim; + $to_update_users_extra['user_msn'] = $imaddr_msn; + $to_update_users_extra['user_yahoo'] = $imaddr_yahoo; + $to_update_users_extra['user_xmpp'] = $imaddr_xmpp; + $to_update_users_extra['user_homepage'] = $homepage; + $to_update_users_extra['user_location'] = $location; + $to_update_users_extra['user_job'] = $occupation; + $to_update_users_extra['user_hobbies'] = $hobbies; + $to_update_users_extra['email_public'] = ( $email_public ) ? '1' : '0'; + + $update_sql = ''; + + foreach ( $to_update_users as $key => $unused_crap ) + { + $value =& $to_update_users[$key]; + if ( $value !== 'NULL' ) + $value = "'" . $db->escape($value) . "'"; - $update_sql .= ( empty($update_sql) ? '' : ',' ) . "$key=$value"; - } - - $update_sql = 'UPDATE ' . table_prefix . "users SET $update_sql WHERE user_id=$user_id;"; - - $update_sql_extra = ''; - - foreach ( $to_update_users_extra as $key => $unused_crap ) - { - $value =& $to_update_users_extra[$key]; - $value = $db->escape($value); - $update_sql_extra .= ( empty($update_sql_extra) ? '' : ',' ) . "$key='$value'"; - } - - $update_sql_extra = 'UPDATE '.table_prefix."users_extra SET $update_sql_extra WHERE user_id=$user_id;"; - - if ( !$db->sql_query($update_sql) ) - $db->_die(); - - if ( !$db->sql_query($update_sql_extra) ) - $db->_die(); - - // If the username was changed, we need to update their user page as well - if ( $old_username != $username ) - { - $page = new PageProcessor($old_username, 'User'); - if ( $page->exists() ) - { - // they have a user page, rename it - $old_urlname = $db->escape(sanitize_page_id($old_username)); - $new_urlname = $db->escape(sanitize_page_id($username)); - $sql = array( - 'UPDATE ' . table_prefix . "pages SET urlname = '$new_urlname' WHERE urlname = '$old_urlname' AND namespace = 'User';", - // Change the page's title ONLY if it exactly matches the old username - 'UPDATE ' . table_prefix . "pages SET name = '" . $db->escape($username) . "' WHERE urlname = '$new_urlname' AND name = '" . $db->escape($old_username) . "' AND namespace = 'User';", - 'UPDATE ' . table_prefix . "logs SET page_id = '$new_urlname' WHERE page_id = '$old_urlname' AND namespace = 'User';", - 'UPDATE ' . table_prefix . "tags SET page_id = '$new_urlname' WHERE page_id = '$old_urlname' AND namespace = 'User';", - 'UPDATE ' . table_prefix . "comments SET page_id = '$new_urlname' WHERE page_id = '$old_urlname' AND namespace = 'User';", - 'UPDATE ' . table_prefix . "page_text SET page_id = '$new_urlname' WHERE page_id = '$old_urlname' AND namespace = 'User';", - 'UPDATE ' . table_prefix . "categories SET page_id = '$new_urlname' WHERE page_id = '$old_urlname' AND namespace = 'User';" - ); - foreach ( $sql as $q ) - { - if ( !$db->sql_query($q) ) - $db->_die('UserManager renaming user page post-username change'); - } - } - } - - if ( $existing_level != $user_level ) - { - // We need to update group memberships - if ( $existing_level == USER_LEVEL_ADMIN ) - { - $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,author_uid,page_text) VALUES(\'security\',\'u_from_admin\',' . time() . ', \'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\', ' . $session->user_id . ', \'' . $db->escape($session->username) . '\', \'' . $db->escape($username) . '\');'); - if ( !$q ) - $db->_die(); - $session->remove_user_from_group($user_id, GROUP_ID_ADMIN); - } - else if ( $existing_level == USER_LEVEL_MOD ) - { - $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,author_uid,page_text) VALUES(\'security\',\'u_from_mod\',' . time() . ', \'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\', ' . $session->user_id . ', \'' . $db->escape($session->username) . '\', \'' . $db->escape($username) . '\');'); - if ( !$q ) - $db->_die(); - $session->remove_user_from_group($user_id, GROUP_ID_MOD); - } - - if ( $user_level == USER_LEVEL_ADMIN ) - { - $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,author_uid,page_text) VALUES(\'security\',\'u_to_admin\',' . time() . ', \'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\', ' . $session->user_id . ', \'' . $db->escape($session->username) . '\', \'' . $db->escape($username) . '\');'); - if ( !$q ) - $db->_die(); - $session->add_user_to_group($user_id, GROUP_ID_ADMIN, false); - } - else if ( $user_level == USER_LEVEL_MOD ) - { - $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,author_uid,page_text) VALUES(\'security\',\'u_to_mod\',' . time() . ', \'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\', ' . $session->user_id . ', \'' . $db->escape($session->username) . '\', \'' . $db->escape($username) . '\');'); - if ( !$q ) - $db->_die(); - $session->add_user_to_group($user_id, GROUP_ID_MOD, false); - } - } - - // user level updated, regenerate the ranks cache - generate_cache_userranks(); - - echo '
' . $lang->get('acpum_msg_save_success') . '
'; - } - } - } - - if ( count($errors) > 0 || @$avatar_post_fail ) - { - if ( count($errors) > 0 ) - { - echo '
- ' . $lang->get('acpum_err_validation_fail') . ' - -
'; - } - $form = new Admin_UserManager_SmartForm(); - $form->user_id = $user_id; - $form->username = $username; - $form->email = $email; - $form->real_name = $real_name; - $form->signature = $signature; - $form->user_level = $user_level; - $form->user_rank = $user_rank; - $form->user_title = $user_title; - $form->im = array( - 'aim' => $imaddr_aim, - 'yahoo' => $imaddr_yahoo, - 'msn' => $imaddr_msn, - 'xmpp' => $imaddr_xmpp - ); - $form->contact = array( - 'homepage' => $homepage, - 'location' => $location, - 'job' => $occupation, - 'hobbies' => $hobbies - ); - $form->email_public = ( isset($_POST['email_public']) ); - $form->account_active = ( isset($_POST['account_active']) ); - // This is SAFE. The smartform calls is_valid_ip() on this value, thus preventing XSS - // attempts from making it into the form HTML. Badly coded templates may still be - // affected, but if have_reg_ip is checked for, then you're fine. - $form->reg_ip_addr = $_POST['user_registration_ip']; - echo $form->render(); - return false; - } - - # - # END VALIDATION - # - } - else if ( isset($_POST['action']['go']) || ( isset($_GET['src']) && $_GET['src'] == 'get' ) || ($pathsuser = $paths->getParam(0)) ) - { - if ( isset($_GET['user']) ) - { - $username =& $_GET['user']; - } - else if ( isset($_GET['username']) ) - { - $username =& $_GET['username']; - } - else if ( isset($_POST['username']) ) - { - $username =& $_POST['username']; - } - else if ( $pathsuser ) - { - $username = str_replace('_', ' ', dirtify_page_id($pathsuser)); - } - else - { - echo 'No username provided'; - return false; - } - $q = $db->sql_query('SELECT u.user_id AS authoritative_uid, u.username, u.email, u.real_name, u.signature, u.account_active, u.user_level, u.user_rank, u.user_title, u.user_has_avatar, u.avatar_type, u.user_registration_ip, x.* FROM '.table_prefix.'users AS u - LEFT JOIN '.table_prefix.'users_extra AS x - ON ( u.user_id = x.user_id OR x.user_id IS NULL ) - WHERE ( ' . ENANO_SQLFUNC_LOWERCASE . '(u.username) = \'' . $db->escape(strtolower($username)) . '\' OR u.username = \'' . $db->escape($username) . '\' ) AND u.user_id != 1;'); - if ( !$q ) - $db->_die(); - - if ( $db->numrows() < 1 ) - { - echo '
' . $lang->get('acpum_err_bad_username') . '
'; - } - else - { - $row = $db->fetchrow(); - $row['user_id'] = $row['authoritative_uid']; - $form = new Admin_UserManager_SmartForm(); - $form->user_id = $row['user_id']; - $form->username = $row['username']; - $form->email = $row['email']; - $form->real_name = $row['real_name']; - $form->signature = $row['signature']; - $form->user_level= $row['user_level']; - $form->user_rank = $row['user_rank']; - $form->user_title= $row['user_title']; - $form->account_active = ( $row['account_active'] == 1 ); - $form->email_public = ( $row['email_public'] == 1 ); - $form->has_avatar = ( $row['user_has_avatar'] == 1 ); - $form->avi_type = $row['avatar_type']; - $form->im = array( - 'aim' => $row['user_aim'], - 'yahoo' => $row['user_yahoo'], - 'msn' => $row['user_msn'], - 'xmpp' => $row['user_xmpp'] - ); - $form->contact = array( - 'homepage' => $row['user_homepage'], - 'location' => $row['user_location'], - 'job' => $row['user_job'], - 'hobbies' => $row['user_hobbies'], - ); - $form->email_public = ( $row['email_public'] == 1 ); - $form->reg_ip_addr = ( $row['user_registration_ip'] ) ? $row['user_registration_ip'] : ''; - $html = $form->render(); - if ( !$html ) - { - echo 'Internal error: form processor returned false'; - } - else - { - echo $html; - } - return true; - } - } - else if ( isset($_POST['action']['clear_sessions']) ) - { - if ( defined('ENANO_DEMO_MODE') ) - { - echo '
' . $lang->get('acpum_err_sessionclear_demo') . '
'; - } - else - { - // Get the current session information so the user doesn't get logged out - $aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE); - $sk = md5($session->sid_super); - $qb = $db->sql_query('SELECT session_key,salt,auth_level,source_ip,time FROM '.table_prefix.'session_keys WHERE session_key=\''.$sk.'\' AND user_id='.$session->user_id.' AND auth_level='.USER_LEVEL_ADMIN); - if ( !$qb ) - { - die('Error selecting session key info block B: '.$db->get_error()); - } - if ( $db->numrows($qb) < 1 ) - { - die('Error: cannot read admin session info block B, aborting table clear process'); - } - $qa = $db->sql_query('SELECT session_key,salt,auth_level,source_ip,time FROM '.table_prefix.'session_keys WHERE session_key=\''.md5($session->sid).'\' AND user_id='.$session->user_id.' AND auth_level='.USER_LEVEL_MEMBER); - if ( !$qa ) - { - die('Error selecting session key info block A: '.$db->get_error()); - } - if ( $db->numrows($qa) < 1 ) - { - die('Error: cannot read user session info block A, aborting table clear process'); - } - $ra = $db->fetchrow($qa); - $rb = $db->fetchrow($qb); - $db->free_result($qa); - $db->free_result($qb); - - $db->sql_query('DELETE FROM '.table_prefix.'session_keys;'); - $db->sql_query('INSERT INTO '.table_prefix.'session_keys( session_key,salt,user_id,auth_level,source_ip,time ) VALUES( \''.$ra['session_key'].'\', \'' . $db->escape($ra['salt']) . '\', \''.$session->user_id.'\', \''.$ra['auth_level'].'\', \''.$ra['source_ip'].'\', '.$ra['time'].' ),( \''.$rb['session_key'].'\', \'' . $db->escape($rb['salt']) . '\', \''.$session->user_id.'\', \''.$rb['auth_level'].'\', \''.$rb['source_ip'].'\', '.$rb['time'].' )'); - - echo '
' . $lang->get('acpum_msg_sessionclear_success') . '
'; - } - } - echo '
'; - echo '

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

'; - echo '

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

'; - echo ' - - - - - - -
' . $lang->get('acpum_field_search_user') . '
- ' . $lang->get('acpum_field_search_user_hint') . ' -
' . $template->username_field('username') . ' - -
'; - echo '

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

'; - echo '

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

'; - echo '

'; - echo '
'; - - if(isset($_GET['action']) && isset($_GET['user'])) - { - switch($_GET['action']) - { - case "activate": - $e = $db->sql_query('SELECT activation_key FROM '.table_prefix.'users WHERE username=\'' . $db->escape($_GET['user']) . '\''); - if ( $e ) - { - // attempt to activate the account - $row = $db->fetchrow(); - $db->free_result(); - if ( $session->activate_account($_GET['user'], $row['activation_key']) ) - { - echo '
' . $lang->get('acpum_msg_activate_success', array('username' => htmlspecialchars($_GET['user']))) . '
'; - $db->sql_query('DELETE FROM '.table_prefix.'logs WHERE time_id=' . $db->escape($_GET['logid'])); - } - else - { - echo '
' . $lang->get('acpum_err_activate_fail', array('username' => htmlspecialchars($_GET['user']))) . '
'; - } - } - else - { - echo '
Error activating account: '.$db->get_error().'
'; - } - break; - case "sendemail": - if ( $session->send_activation_mail($_GET['user'] ) ) - { - echo '
' . $lang->get('acpum_msg_activate_email_success', array('username' => htmlspecialchars($_GET['user']))) . '
'; - $db->sql_query('DELETE FROM '.table_prefix.'logs WHERE time_id=' . $db->escape($_GET['logid'])); - } - else - { - echo '
' . $lang->get('acpum_err_activate_email_fail', array('username' => htmlspecialchars($_GET['user']))) . '
'; - } - break; - case "deny": - $e = $db->sql_query('DELETE FROM '.table_prefix.'logs WHERE log_type=\'admin\' AND action=\'activ_req\' AND time_id=\'' . $db->escape($_GET['logid']) . '\';'); - if ( !$e ) - { - echo '
Error during row deletion: '.$db->get_error().'
'; - } - else - { - echo '
' . $lang->get('acpum_msg_activate_deny_success', array('username' => htmlspecialchars($_GET['user']))) . '
'; - } - break; - } - } - $q = $db->sql_query('SELECT l.log_type, l.action, l.time_id, l.date_string, l.author, l.edit_summary, u.user_coppa FROM '.table_prefix.'logs AS l - LEFT JOIN '.table_prefix.'users AS u - ON ( u.username = l.edit_summary OR u.username IS NULL ) - WHERE log_type=\'admin\' AND action=\'activ_req\' ORDER BY time_id DESC;'); - if($q) - { - if($db->numrows() > 0) - { - $n = $db->numrows(); - $str = ( $n == 1 ) ? - $lang->get('acpum_heading_activation_one') : - $lang->get('acpum_heading_activation_plural', array('count' => strval($n))); - - echo '

' . $str . '

'; - - echo '
- - - - - - - - '; - $cls = 'row2'; - while($row = $db->fetchrow()) - { - if($cls == 'row2') $cls = 'row1'; - else $cls = 'row2'; - $coppa = ( $row['user_coppa'] == '1' ) ? '' . $lang->get('acpum_coppauser_yes') . '' : $lang->get('acpum_coppauser_no'); - echo ' - - - - - - - - '; - } - echo '
' . $lang->get('acpum_col_activate_timestamp') . '' . $lang->get('acpum_col_activate_requestedby') . '' . $lang->get('acpum_col_activate_requestedfor') . '' . $lang->get('acpum_col_activate_coppauser') . '' . $lang->get('acpum_col_activate_actions') . '
'.enano_date(ED_DATE | ED_TIME, $row['time_id']).''.$row['author'].''.$row['edit_summary'].'' . $coppa . ' - ' . $lang->get('acpum_btn_activate_now') . ' - - ' . $lang->get('acpum_btn_send_email') . ' - - ' . $lang->get('acpum_btn_activate_deny') . ' -
'; - echo '
'; - } - $db->free_result(); - } - - acp_usermanager_lockouts(); + $update_sql .= ( empty($update_sql) ? '' : ',' ) . "$key=$value"; + } + + $update_sql = 'UPDATE ' . table_prefix . "users SET $update_sql WHERE user_id=$user_id;"; + + $update_sql_extra = ''; + + foreach ( $to_update_users_extra as $key => $unused_crap ) + { + $value =& $to_update_users_extra[$key]; + $value = $db->escape($value); + $update_sql_extra .= ( empty($update_sql_extra) ? '' : ',' ) . "$key='$value'"; + } + + $update_sql_extra = 'UPDATE '.table_prefix."users_extra SET $update_sql_extra WHERE user_id=$user_id;"; + + if ( !$db->sql_query($update_sql) ) + $db->_die(); + + if ( !$db->sql_query($update_sql_extra) ) + $db->_die(); + + // If the username was changed, we need to update their user page as well + if ( $old_username != $username ) + { + $page = new PageProcessor($old_username, 'User'); + if ( $page->exists() ) + { + // they have a user page, rename it + $old_urlname = $db->escape(sanitize_page_id($old_username)); + $new_urlname = $db->escape(sanitize_page_id($username)); + $sql = array( + 'UPDATE ' . table_prefix . "pages SET urlname = '$new_urlname' WHERE urlname = '$old_urlname' AND namespace = 'User';", + // Change the page's title ONLY if it exactly matches the old username + 'UPDATE ' . table_prefix . "pages SET name = '" . $db->escape($username) . "' WHERE urlname = '$new_urlname' AND name = '" . $db->escape($old_username) . "' AND namespace = 'User';", + 'UPDATE ' . table_prefix . "logs SET page_id = '$new_urlname' WHERE page_id = '$old_urlname' AND namespace = 'User';", + 'UPDATE ' . table_prefix . "tags SET page_id = '$new_urlname' WHERE page_id = '$old_urlname' AND namespace = 'User';", + 'UPDATE ' . table_prefix . "comments SET page_id = '$new_urlname' WHERE page_id = '$old_urlname' AND namespace = 'User';", + 'UPDATE ' . table_prefix . "page_text SET page_id = '$new_urlname' WHERE page_id = '$old_urlname' AND namespace = 'User';", + 'UPDATE ' . table_prefix . "categories SET page_id = '$new_urlname' WHERE page_id = '$old_urlname' AND namespace = 'User';" + ); + foreach ( $sql as $q ) + { + if ( !$db->sql_query($q) ) + $db->_die('UserManager renaming user page post-username change'); + } + } + } + + if ( $existing_level != $user_level ) + { + // We need to update group memberships + if ( $existing_level == USER_LEVEL_ADMIN ) + { + $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,author_uid,page_text) VALUES(\'security\',\'u_from_admin\',' . time() . ', \'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\', ' . $session->user_id . ', \'' . $db->escape($session->username) . '\', \'' . $db->escape($username) . '\');'); + if ( !$q ) + $db->_die(); + $session->remove_user_from_group($user_id, GROUP_ID_ADMIN); + } + else if ( $existing_level == USER_LEVEL_MOD ) + { + $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,author_uid,page_text) VALUES(\'security\',\'u_from_mod\',' . time() . ', \'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\', ' . $session->user_id . ', \'' . $db->escape($session->username) . '\', \'' . $db->escape($username) . '\');'); + if ( !$q ) + $db->_die(); + $session->remove_user_from_group($user_id, GROUP_ID_MOD); + } + + if ( $user_level == USER_LEVEL_ADMIN ) + { + $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,author_uid,page_text) VALUES(\'security\',\'u_to_admin\',' . time() . ', \'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\', ' . $session->user_id . ', \'' . $db->escape($session->username) . '\', \'' . $db->escape($username) . '\');'); + if ( !$q ) + $db->_die(); + $session->add_user_to_group($user_id, GROUP_ID_ADMIN, false); + } + else if ( $user_level == USER_LEVEL_MOD ) + { + $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,author_uid,page_text) VALUES(\'security\',\'u_to_mod\',' . time() . ', \'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\', ' . $session->user_id . ', \'' . $db->escape($session->username) . '\', \'' . $db->escape($username) . '\');'); + if ( !$q ) + $db->_die(); + $session->add_user_to_group($user_id, GROUP_ID_MOD, false); + } + } + + // user level updated, regenerate the ranks cache + generate_cache_userranks(); + + echo '
' . $lang->get('acpum_msg_save_success') . '
'; + } + } + } + + if ( count($errors) > 0 || @$avatar_post_fail ) + { + if ( count($errors) > 0 ) + { + echo '
+ ' . $lang->get('acpum_err_validation_fail') . ' + +
'; + } + $form = new Admin_UserManager_SmartForm(); + $form->user_id = $user_id; + $form->username = $username; + $form->email = $email; + $form->real_name = $real_name; + $form->signature = $signature; + $form->user_level = $user_level; + $form->user_rank = $user_rank; + $form->user_title = $user_title; + $form->im = array( + 'aim' => $imaddr_aim, + 'yahoo' => $imaddr_yahoo, + 'msn' => $imaddr_msn, + 'xmpp' => $imaddr_xmpp + ); + $form->contact = array( + 'homepage' => $homepage, + 'location' => $location, + 'job' => $occupation, + 'hobbies' => $hobbies + ); + $form->email_public = ( isset($_POST['email_public']) ); + $form->account_active = ( isset($_POST['account_active']) ); + // This is SAFE. The smartform calls is_valid_ip() on this value, thus preventing XSS + // attempts from making it into the form HTML. Badly coded templates may still be + // affected, but if have_reg_ip is checked for, then you're fine. + $form->reg_ip_addr = $_POST['user_registration_ip']; + echo $form->render(); + return false; + } + + # + # END VALIDATION + # + } + else if ( isset($_POST['action']['go']) || ( isset($_GET['src']) && $_GET['src'] == 'get' ) || ($pathsuser = $paths->getParam(0)) ) + { + if ( isset($_GET['user']) ) + { + $username =& $_GET['user']; + } + else if ( isset($_GET['username']) ) + { + $username =& $_GET['username']; + } + else if ( isset($_POST['username']) ) + { + $username =& $_POST['username']; + } + else if ( $pathsuser ) + { + $username = str_replace('_', ' ', dirtify_page_id($pathsuser)); + } + else + { + echo 'No username provided'; + return false; + } + $q = $db->sql_query('SELECT u.user_id AS authoritative_uid, u.username, u.email, u.real_name, u.signature, u.account_active, u.user_level, u.user_rank, u.user_title, u.user_has_avatar, u.avatar_type, u.user_registration_ip, x.* FROM '.table_prefix.'users AS u + LEFT JOIN '.table_prefix.'users_extra AS x + ON ( u.user_id = x.user_id OR x.user_id IS NULL ) + WHERE ( ' . ENANO_SQLFUNC_LOWERCASE . '(u.username) = \'' . $db->escape(strtolower($username)) . '\' OR u.username = \'' . $db->escape($username) . '\' ) AND u.user_id != 1;'); + if ( !$q ) + $db->_die(); + + if ( $db->numrows() < 1 ) + { + echo '
' . $lang->get('acpum_err_bad_username') . '
'; + } + else + { + $row = $db->fetchrow(); + $row['user_id'] = $row['authoritative_uid']; + $form = new Admin_UserManager_SmartForm(); + $form->user_id = $row['user_id']; + $form->username = $row['username']; + $form->email = $row['email']; + $form->real_name = $row['real_name']; + $form->signature = $row['signature']; + $form->user_level= $row['user_level']; + $form->user_rank = $row['user_rank']; + $form->user_title= $row['user_title']; + $form->account_active = ( $row['account_active'] == 1 ); + $form->email_public = ( $row['email_public'] == 1 ); + $form->has_avatar = ( $row['user_has_avatar'] == 1 ); + $form->avi_type = $row['avatar_type']; + $form->im = array( + 'aim' => $row['user_aim'], + 'yahoo' => $row['user_yahoo'], + 'msn' => $row['user_msn'], + 'xmpp' => $row['user_xmpp'] + ); + $form->contact = array( + 'homepage' => $row['user_homepage'], + 'location' => $row['user_location'], + 'job' => $row['user_job'], + 'hobbies' => $row['user_hobbies'], + ); + $form->email_public = ( $row['email_public'] == 1 ); + $form->reg_ip_addr = ( $row['user_registration_ip'] ) ? $row['user_registration_ip'] : ''; + $html = $form->render(); + if ( !$html ) + { + echo 'Internal error: form processor returned false'; + } + else + { + echo $html; + } + return true; + } + } + else if ( isset($_POST['action']['clear_sessions']) ) + { + if ( defined('ENANO_DEMO_MODE') ) + { + echo '
' . $lang->get('acpum_err_sessionclear_demo') . '
'; + } + else + { + // Get the current session information so the user doesn't get logged out + $aes = AESCrypt::singleton(AES_BITS, AES_BLOCKSIZE); + $sk = md5($session->sid_super); + $qb = $db->sql_query('SELECT session_key,salt,auth_level,source_ip,time FROM '.table_prefix.'session_keys WHERE session_key=\''.$sk.'\' AND user_id='.$session->user_id.' AND auth_level='.USER_LEVEL_ADMIN); + if ( !$qb ) + { + die('Error selecting session key info block B: '.$db->get_error()); + } + if ( $db->numrows($qb) < 1 ) + { + die('Error: cannot read admin session info block B, aborting table clear process'); + } + $qa = $db->sql_query('SELECT session_key,salt,auth_level,source_ip,time FROM '.table_prefix.'session_keys WHERE session_key=\''.md5($session->sid).'\' AND user_id='.$session->user_id.' AND auth_level='.USER_LEVEL_MEMBER); + if ( !$qa ) + { + die('Error selecting session key info block A: '.$db->get_error()); + } + if ( $db->numrows($qa) < 1 ) + { + die('Error: cannot read user session info block A, aborting table clear process'); + } + $ra = $db->fetchrow($qa); + $rb = $db->fetchrow($qb); + $db->free_result($qa); + $db->free_result($qb); + + $db->sql_query('DELETE FROM '.table_prefix.'session_keys;'); + $db->sql_query('INSERT INTO '.table_prefix.'session_keys( session_key,salt,user_id,auth_level,source_ip,time ) VALUES( \''.$ra['session_key'].'\', \'' . $db->escape($ra['salt']) . '\', \''.$session->user_id.'\', \''.$ra['auth_level'].'\', \''.$ra['source_ip'].'\', '.$ra['time'].' ),( \''.$rb['session_key'].'\', \'' . $db->escape($rb['salt']) . '\', \''.$session->user_id.'\', \''.$rb['auth_level'].'\', \''.$rb['source_ip'].'\', '.$rb['time'].' )'); + + echo '
' . $lang->get('acpum_msg_sessionclear_success') . '
'; + } + } + echo '
'; + echo '

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

'; + echo '

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

'; + echo ' + + + + + + +
' . $lang->get('acpum_field_search_user') . '
+ ' . $lang->get('acpum_field_search_user_hint') . ' +
' . $template->username_field('username') . ' + +
'; + echo '

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

'; + echo '

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

'; + echo '

'; + echo '
'; + + if(isset($_GET['action']) && isset($_GET['user'])) + { + switch($_GET['action']) + { + case "activate": + $e = $db->sql_query('SELECT activation_key FROM '.table_prefix.'users WHERE username=\'' . $db->escape($_GET['user']) . '\''); + if ( $e ) + { + // attempt to activate the account + $row = $db->fetchrow(); + $db->free_result(); + if ( $session->activate_account($_GET['user'], $row['activation_key']) ) + { + echo '
' . $lang->get('acpum_msg_activate_success', array('username' => htmlspecialchars($_GET['user']))) . '
'; + $db->sql_query('DELETE FROM '.table_prefix.'logs WHERE time_id=' . $db->escape($_GET['logid'])); + } + else + { + echo '
' . $lang->get('acpum_err_activate_fail', array('username' => htmlspecialchars($_GET['user']))) . '
'; + } + } + else + { + echo '
Error activating account: '.$db->get_error().'
'; + } + break; + case "sendemail": + if ( $session->send_activation_mail($_GET['user'] ) ) + { + echo '
' . $lang->get('acpum_msg_activate_email_success', array('username' => htmlspecialchars($_GET['user']))) . '
'; + $db->sql_query('DELETE FROM '.table_prefix.'logs WHERE time_id=' . $db->escape($_GET['logid'])); + } + else + { + echo '
' . $lang->get('acpum_err_activate_email_fail', array('username' => htmlspecialchars($_GET['user']))) . '
'; + } + break; + case "deny": + $e = $db->sql_query('DELETE FROM '.table_prefix.'logs WHERE log_type=\'admin\' AND action=\'activ_req\' AND time_id=\'' . $db->escape($_GET['logid']) . '\';'); + if ( !$e ) + { + echo '
Error during row deletion: '.$db->get_error().'
'; + } + else + { + echo '
' . $lang->get('acpum_msg_activate_deny_success', array('username' => htmlspecialchars($_GET['user']))) . '
'; + } + break; + } + } + $q = $db->sql_query('SELECT l.log_type, l.action, l.time_id, l.date_string, l.author, l.edit_summary, u.user_coppa FROM '.table_prefix.'logs AS l + LEFT JOIN '.table_prefix.'users AS u + ON ( u.username = l.edit_summary OR u.username IS NULL ) + WHERE log_type=\'admin\' AND action=\'activ_req\' ORDER BY time_id DESC;'); + if($q) + { + if($db->numrows() > 0) + { + $n = $db->numrows(); + $str = ( $n == 1 ) ? + $lang->get('acpum_heading_activation_one') : + $lang->get('acpum_heading_activation_plural', array('count' => strval($n))); + + echo '

' . $str . '

'; + + echo '
+ + + + + + + + '; + $cls = 'row2'; + while($row = $db->fetchrow()) + { + if($cls == 'row2') $cls = 'row1'; + else $cls = 'row2'; + $coppa = ( $row['user_coppa'] == '1' ) ? '' . $lang->get('acpum_coppauser_yes') . '' : $lang->get('acpum_coppauser_no'); + echo ' + + + + + + + + '; + } + echo '
' . $lang->get('acpum_col_activate_timestamp') . '' . $lang->get('acpum_col_activate_requestedby') . '' . $lang->get('acpum_col_activate_requestedfor') . '' . $lang->get('acpum_col_activate_coppauser') . '' . $lang->get('acpum_col_activate_actions') . '
'.enano_date(ED_DATE | ED_TIME, $row['time_id']).''.$row['author'].''.$row['edit_summary'].'' . $coppa . ' + ' . $lang->get('acpum_btn_activate_now') . ' + + ' . $lang->get('acpum_btn_send_email') . ' + + ' . $lang->get('acpum_btn_activate_deny') . ' +
'; + echo '
'; + } + $db->free_result(); + } + + acp_usermanager_lockouts(); } /** @@ -606,698 +606,698 @@ class Admin_UserManager_SmartForm { - - /** - * Universally Unique Identifier (UUID) for this editor instance. Used to unique-itize Javascript functions and whatnot. - * @var string - */ - - var $uuid = ''; - - /** - * User ID that we're editing. - * @var int - */ - - var $user_id = 0; - - /** - * Username - * @var string - */ - - var $username = ''; - - /** - * E-mail address - * @var string - */ - - var $email = ''; - - /** - * Real name - * @var string - */ - - var $real_name = ''; - - /** - * Signature - * @var string - */ - - var $signature = ''; - - /** - * IM contact information - * @var array - */ - - var $im = array(); - - /** - * Real-life contact info - * @var array - */ - - var $contact = array(); - - /** - * User level - * @var int - */ - - var $user_level = USER_LEVEL_MEMBER; - - /** - * User-specific user rank - * @var int - */ - - var $user_rank = NULL; - - /** - * User's custom title - * @var int - */ - - var $user_title = ''; - - /** - * Account activated - * @var bool - */ - - var $account_active = true; - - /** - * Email public switch - * @var bool - */ - - var $email_public = false; - - /** - * Whether the user has an avatar or not. - * @var bool - */ - - var $has_avatar = false; - - /** - * The type of avatar the user has. One of "jpg", "png", or "gif". - * @var string - */ - - var $avi_type = 'png'; - - /** - * The IP address of the user during registration - * @var string - */ - - var $reg_ip_addr = ''; - - /** - * Constructor. - */ - - function Admin_UserManager_SmartForm() - { - $this->uuid = md5( mt_rand() . microtime() ); - } - - /** - * Renders and returns the finished form. - * @return string - */ - - function render() - { - global $db, $session, $paths, $template, $plugins; // Common objects - global $lang; - global $dh_supported; - if ( file_exists( ENANO_ROOT . "/themes/$template->theme/admin_usermanager_form.tpl" ) ) - { - $parser = $template->makeParser('admin_usermanager_form.tpl'); - } - else - { - $tpl_code = << - - - -
- - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- {lang:acpum_heading_editing_user} {USERNAME} -
- {lang:acpum_heading_basic_options} -
- {lang:acpum_field_username}
- {lang:acpum_field_username_hint} -
- disabled="disabled" /> - {lang:acpum_msg_same_user_username} -
- {lang:acpum_field_password} - -
- {lang:acpum_field_password_hint} - -
- - -
- {lang:acpum_field_email} - - disabled="disabled" /> - {lang:acpum_msg_same_user_email} -
- {lang:acpum_field_realname} - - disabled="disabled" /> - {lang:acpum_msg_same_user_realname} -
- {lang:acpum_field_signature} - - {SIGNATURE_FIELD} -
- {lang:acpum_field_usertitle}
- - {lang:acpum_field_usertitle_hint} - -
- -
- {lang:acpum_heading_imcontact} -
{lang:acpum_field_aim}
{lang:acpum_field_wlm}
{lang:acpum_field_wlm_hint}
{lang:acpum_field_yim}
{lang:acpum_field_xmpp}
- {lang:acpum_heading_contact_extra} -
{lang:acpum_field_homepage}
{lang:acpum_field_homepage_hint}
{lang:acpum_field_location}
{lang:acpum_field_job}
{lang:acpum_field_hobbies}

{lang:acpum_field_email_public_hint}
checked="checked" size="30" />
- {lang:acpum_avatar_heading} -
- {lang:usercp_avatar_label_current} - - - {AVATAR_ALT} - - {lang:acpum_avatar_image_none} - -
- {lang:acpum_avatar_lbl_change} - - -
-
-
- -
- -
-
-
- {lang:acpum_heading_adminonly} -
{lang:acpum_field_active_title}
- {lang:acpum_field_active_hint} -
- {lang:acpum_field_userlevel}
- {lang:acpum_field_userlevel_hint} -
- -
- {lang:acpum_field_userrank}
- {lang:acpum_field_userrank_hint} -
- -
- {lang:acpum_field_reg_ip} - - {REG_IP_ADDR} - -
- {lang:acpum_field_deleteaccount_title} - - - -
- - -
-
- -
- - - - - - {AES_JAVASCRIPT} - + + /** + * Universally Unique Identifier (UUID) for this editor instance. Used to unique-itize Javascript functions and whatnot. + * @var string + */ + + var $uuid = ''; + + /** + * User ID that we're editing. + * @var int + */ + + var $user_id = 0; + + /** + * Username + * @var string + */ + + var $username = ''; + + /** + * E-mail address + * @var string + */ + + var $email = ''; + + /** + * Real name + * @var string + */ + + var $real_name = ''; + + /** + * Signature + * @var string + */ + + var $signature = ''; + + /** + * IM contact information + * @var array + */ + + var $im = array(); + + /** + * Real-life contact info + * @var array + */ + + var $contact = array(); + + /** + * User level + * @var int + */ + + var $user_level = USER_LEVEL_MEMBER; + + /** + * User-specific user rank + * @var int + */ + + var $user_rank = NULL; + + /** + * User's custom title + * @var int + */ + + var $user_title = ''; + + /** + * Account activated + * @var bool + */ + + var $account_active = true; + + /** + * Email public switch + * @var bool + */ + + var $email_public = false; + + /** + * Whether the user has an avatar or not. + * @var bool + */ + + var $has_avatar = false; + + /** + * The type of avatar the user has. One of "jpg", "png", or "gif". + * @var string + */ + + var $avi_type = 'png'; + + /** + * The IP address of the user during registration + * @var string + */ + + var $reg_ip_addr = ''; + + /** + * Constructor. + */ + + function Admin_UserManager_SmartForm() + { + $this->uuid = md5( mt_rand() . microtime() ); + } + + /** + * Renders and returns the finished form. + * @return string + */ + + function render() + { + global $db, $session, $paths, $template, $plugins; // Common objects + global $lang; + global $dh_supported; + if ( file_exists( ENANO_ROOT . "/themes/$template->theme/admin_usermanager_form.tpl" ) ) + { + $parser = $template->makeParser('admin_usermanager_form.tpl'); + } + else + { + $tpl_code = << + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ {lang:acpum_heading_editing_user} {USERNAME} +
+ {lang:acpum_heading_basic_options} +
+ {lang:acpum_field_username}
+ {lang:acpum_field_username_hint} +
+ disabled="disabled" /> + {lang:acpum_msg_same_user_username} +
+ {lang:acpum_field_password} + +
+ {lang:acpum_field_password_hint} + +
+ + +
+ {lang:acpum_field_email} + + disabled="disabled" /> + {lang:acpum_msg_same_user_email} +
+ {lang:acpum_field_realname} + + disabled="disabled" /> + {lang:acpum_msg_same_user_realname} +
+ {lang:acpum_field_signature} + + {SIGNATURE_FIELD} +
+ {lang:acpum_field_usertitle}
+ + {lang:acpum_field_usertitle_hint} + +
+ +
+ {lang:acpum_heading_imcontact} +
{lang:acpum_field_aim}
{lang:acpum_field_wlm}
{lang:acpum_field_wlm_hint}
{lang:acpum_field_yim}
{lang:acpum_field_xmpp}
+ {lang:acpum_heading_contact_extra} +
{lang:acpum_field_homepage}
{lang:acpum_field_homepage_hint}
{lang:acpum_field_location}
{lang:acpum_field_job}
{lang:acpum_field_hobbies}

{lang:acpum_field_email_public_hint}
checked="checked" size="30" />
+ {lang:acpum_avatar_heading} +
+ {lang:usercp_avatar_label_current} + + + {AVATAR_ALT} + + {lang:acpum_avatar_image_none} + +
+ {lang:acpum_avatar_lbl_change} + + +
+
+
+ +
+ +
+
+
+ {lang:acpum_heading_adminonly} +
{lang:acpum_field_active_title}
+ {lang:acpum_field_active_hint} +
+ {lang:acpum_field_userlevel}
+ {lang:acpum_field_userlevel_hint} +
+ +
+ {lang:acpum_field_userrank}
+ {lang:acpum_field_userrank_hint} +
+ +
+ {lang:acpum_field_reg_ip} + + {REG_IP_ADDR} + +
+ {lang:acpum_field_deleteaccount_title} + + + +
+ + +
+
+ +
+ + + + + + {AES_JAVASCRIPT} + EOF; - $parser = $template->makeParserText($tpl_code); - } - - $this->username = htmlspecialchars($this->username); - $this->email = htmlspecialchars($this->email); - $this->user_id = intval($this->user_id); - $this->real_name = htmlspecialchars($this->real_name); - $this->signature = htmlspecialchars($this->signature); - $this->user_level = intval($this->user_level); - - $im_aim = ( isset($this->im['aim']) ) ? $this->im['aim'] : false; - $im_yahoo = ( isset($this->im['yahoo']) ) ? $this->im['yahoo'] : false; - $im_msn = ( isset($this->im['msn']) ) ? $this->im['msn'] : false; - $im_xmpp = ( isset($this->im['xmpp']) ) ? $this->im['xmpp'] : false; - - $homepage = ( isset($this->contact['homepage']) ) ? $this->contact['homepage'] : false; - $location = ( isset($this->contact['location']) ) ? $this->contact['location'] : false; - $job = ( isset($this->contact['job']) ) ? $this->contact['job'] : false; - $hobbies = ( isset($this->contact['hobbies']) ) ? $this->contact['hobbies'] : false; - - if ( empty($this->username) ) - { - // @error One or more required parameters not set - return 'Admin_UserManager_SmartForm::render: Invalid parameter ($form->username)'; - } - - if ( empty($this->user_id) ) - { - // @error One or more required parameters not set - return 'Admin_UserManager_SmartForm::render: Invalid parameter ($form->user_id)'; - } - - if ( empty($this->email) ) - { - // @error One or more required parameters not set - return 'Admin_UserManager_SmartForm::render: Invalid parameter ($form->email)'; - } - - $form_action = makeUrlNS('Special', 'Administration', 'module=' . $paths->cpage['module'], true); - $aes_javascript = $session->aes_javascript("useredit_$this->uuid", 'new_password'); - - // build rank list - $q = $db->sql_query('SELECT rank_id, rank_title FROM ' . table_prefix . 'ranks'); - if ( !$q ) - $db->_die(); - $rank_list = '' . "\n"; - while ( $row = $db->fetchrow() ) - { - $rank_list .= '' . "\n"; - } - - $parser->assign_vars(array( - 'UUID' => $this->uuid, - 'USERNAME' => $this->username, - 'EMAIL' => $this->email, - 'USER_ID' => $this->user_id, - 'AES_FORM' => $session->generate_aes_form(), - 'REAL_NAME' => $this->real_name, - 'SIGNATURE_FIELD' => $template->tinymce_textarea('signature', $this->signature, 10, 50), - 'USER_TITLE' => $this->user_title, - 'USER_LEVEL_MEMBER' => USER_LEVEL_CHPREF, - 'USER_LEVEL_MOD' => USER_LEVEL_MOD, - 'USER_LEVEL_ADMIN' => USER_LEVEL_ADMIN, - 'AES_JAVASCRIPT' => $aes_javascript, - 'IM_AIM' => $im_aim, - 'IM_YAHOO' => $im_yahoo, - 'IM_WLM' => $im_msn, - 'IM_XMPP' => $im_xmpp, - 'HOMEPAGE' => $homepage, - 'LOCATION' => $location, - 'JOB' => $job, - 'HOBBIES' => $hobbies, - 'FORM_ACTION' => $form_action, - 'REG_IP_ADDR' => $this->reg_ip_addr, - 'RANK_LIST' => $rank_list, - 'GRAVATAR_URL' => make_gravatar_url($this->email, 16) - )); - - if ( $this->has_avatar ) - { - $parser->assign_vars(array( - 'AVATAR_SRC' => make_avatar_url($this->user_id, $this->avi_type), - 'AVATAR_ALT' => $lang->get('usercp_avatar_image_alt', array('username' => $this->username), $this->email) - )); - } - - $parser->assign_bool(array( - 'password_meter' => ( getConfig('pw_strength_enable') == '1' ), - 'ul_member' => ( $this->user_level == USER_LEVEL_CHPREF ), - 'ul_mod' => ( $this->user_level == USER_LEVEL_MOD ), - 'ul_admin' => ( $this->user_level == USER_LEVEL_ADMIN ), - 'account_active' => ( $this->account_active === true ), - 'email_public' => ( $this->email_public === true ), - 'same_user' => ( $this->user_id == $session->user_id ), - 'user_has_avatar' => ( $this->has_avatar ), - 'have_reg_ip' => ( intval(@strlen($this->reg_ip_addr)) > 0 && is_valid_ip($this->reg_ip_addr) ) - )); - - $parsed = $parser->run(); - return $parsed; - } - + $parser = $template->makeParserText($tpl_code); + } + + $this->username = htmlspecialchars($this->username); + $this->email = htmlspecialchars($this->email); + $this->user_id = intval($this->user_id); + $this->real_name = htmlspecialchars($this->real_name); + $this->signature = htmlspecialchars($this->signature); + $this->user_level = intval($this->user_level); + + $im_aim = ( isset($this->im['aim']) ) ? $this->im['aim'] : false; + $im_yahoo = ( isset($this->im['yahoo']) ) ? $this->im['yahoo'] : false; + $im_msn = ( isset($this->im['msn']) ) ? $this->im['msn'] : false; + $im_xmpp = ( isset($this->im['xmpp']) ) ? $this->im['xmpp'] : false; + + $homepage = ( isset($this->contact['homepage']) ) ? $this->contact['homepage'] : false; + $location = ( isset($this->contact['location']) ) ? $this->contact['location'] : false; + $job = ( isset($this->contact['job']) ) ? $this->contact['job'] : false; + $hobbies = ( isset($this->contact['hobbies']) ) ? $this->contact['hobbies'] : false; + + if ( empty($this->username) ) + { + // @error One or more required parameters not set + return 'Admin_UserManager_SmartForm::render: Invalid parameter ($form->username)'; + } + + if ( empty($this->user_id) ) + { + // @error One or more required parameters not set + return 'Admin_UserManager_SmartForm::render: Invalid parameter ($form->user_id)'; + } + + if ( empty($this->email) ) + { + // @error One or more required parameters not set + return 'Admin_UserManager_SmartForm::render: Invalid parameter ($form->email)'; + } + + $form_action = makeUrlNS('Special', 'Administration', 'module=' . $paths->cpage['module'], true); + $aes_javascript = $session->aes_javascript("useredit_$this->uuid", 'new_password'); + + // build rank list + $q = $db->sql_query('SELECT rank_id, rank_title FROM ' . table_prefix . 'ranks'); + if ( !$q ) + $db->_die(); + $rank_list = '' . "\n"; + while ( $row = $db->fetchrow() ) + { + $rank_list .= '' . "\n"; + } + + $parser->assign_vars(array( + 'UUID' => $this->uuid, + 'USERNAME' => $this->username, + 'EMAIL' => $this->email, + 'USER_ID' => $this->user_id, + 'AES_FORM' => $session->generate_aes_form(), + 'REAL_NAME' => $this->real_name, + 'SIGNATURE_FIELD' => $template->tinymce_textarea('signature', $this->signature, 10, 50), + 'USER_TITLE' => $this->user_title, + 'USER_LEVEL_MEMBER' => USER_LEVEL_CHPREF, + 'USER_LEVEL_MOD' => USER_LEVEL_MOD, + 'USER_LEVEL_ADMIN' => USER_LEVEL_ADMIN, + 'AES_JAVASCRIPT' => $aes_javascript, + 'IM_AIM' => $im_aim, + 'IM_YAHOO' => $im_yahoo, + 'IM_WLM' => $im_msn, + 'IM_XMPP' => $im_xmpp, + 'HOMEPAGE' => $homepage, + 'LOCATION' => $location, + 'JOB' => $job, + 'HOBBIES' => $hobbies, + 'FORM_ACTION' => $form_action, + 'REG_IP_ADDR' => $this->reg_ip_addr, + 'RANK_LIST' => $rank_list, + 'GRAVATAR_URL' => make_gravatar_url($this->email, 16) + )); + + if ( $this->has_avatar ) + { + $parser->assign_vars(array( + 'AVATAR_SRC' => make_avatar_url($this->user_id, $this->avi_type), + 'AVATAR_ALT' => $lang->get('usercp_avatar_image_alt', array('username' => $this->username), $this->email) + )); + } + + $parser->assign_bool(array( + 'password_meter' => ( getConfig('pw_strength_enable') == '1' ), + 'ul_member' => ( $this->user_level == USER_LEVEL_CHPREF ), + 'ul_mod' => ( $this->user_level == USER_LEVEL_MOD ), + 'ul_admin' => ( $this->user_level == USER_LEVEL_ADMIN ), + 'account_active' => ( $this->account_active === true ), + 'email_public' => ( $this->email_public === true ), + 'same_user' => ( $this->user_id == $session->user_id ), + 'user_has_avatar' => ( $this->has_avatar ), + 'have_reg_ip' => ( intval(@strlen($this->reg_ip_addr)) > 0 && is_valid_ip($this->reg_ip_addr) ) + )); + + $parsed = $parser->run(); + return $parsed; + } + } function acp_usermanager_lockouts($homewrap = false) { - global $db, $session, $paths, $template, $plugins; // Common objects - global $lang; - - // Locked out users - - if ( !empty($_GET['clear_lockout']) && is_valid_ip($_GET['clear_lockout']) ) - { - $ip = $db->escape($_GET['clear_lockout']); - $q = $db->sql_query('DELETE FROM ' . table_prefix . "lockout WHERE ipaddr = '$ip' AND timestamp > ( " . time() . " - (" . getConfig('lockout_duration', 15) . "*60) );"); - if ( !$q ) - $db->_die(); - - echo '
' . $lang->get('acphome_msg_lockout_clear_success', array('ip' => htmlspecialchars($ip))) . '
'; - } - - $q = $db->sql_query('SELECT COUNT(id) AS fail_count, ipaddr, username, timestamp FROM ' . table_prefix . "lockout\n" - . " WHERE timestamp > ( " . time() . " - " . intval(getConfig('lockout_duration', 15)) . "*60 ) GROUP BY ipaddr ORDER BY COUNT(id) DESC, timestamp DESC;"); - if ( !$q ) - $db->_die(); - - if ( $db->numrows() > 0 ) - { - if ( $homewrap ) - echo '
'; - echo '

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

'; - echo '

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

'; - - ?> -
- - - - - - - - - fetchrow() ) - { - echo ''; - echo ''; - echo ''; - // status - echo ''; - // time left - if ( $row['fail_count'] >= getConfig('lockout_threshold', 5) ) - { - $expire_time = $row['timestamp'] + ( getConfig('lockout_duration', 15) * 60 ); - $time_left = round(($expire_time - time()) / 60); - $minutes = $time_left == 1 ? $lang->get('etc_unit_minute') : $lang->get('etc_unit_minutes'); - echo ''; - } - else - { - echo ''; - } - // action - $btn_text = $row['fail_count'] >= getConfig('lockout_threshold', 5) ? $lang->get('acphome_btn_lockout_unblock') : $lang->get('acphome_btn_lockout_clear'); - echo ''; - echo ''; - } - echo '
get('acphome_th_locked_out_ip'); ?>get('acphome_th_locked_out_username'); ?>get('acphome_th_locked_out_status'); ?>get('acphome_th_locked_out_time'); ?>
' . htmlspecialchars($row['ipaddr']) . '' . htmlspecialchars($row['username']) . '' . - ( $row['fail_count'] >= getConfig('lockout_threshold', 5) - ? '' . $lang->get('acphome_lbl_locked_out_banned') . '' - : $lang->get('acphome_lbl_locked_out_warned', array('fail_count' => $row['fail_count'])) - ) - . '' . "$time_left $minutes" . '' . $btn_text . '
'; - echo '
'; - if ( $homewrap ) - echo '
'; - } - - $db->free_result(); + global $db, $session, $paths, $template, $plugins; // Common objects + global $lang; + + // Locked out users + + if ( !empty($_GET['clear_lockout']) && is_valid_ip($_GET['clear_lockout']) ) + { + $ip = $db->escape($_GET['clear_lockout']); + $q = $db->sql_query('DELETE FROM ' . table_prefix . "lockout WHERE ipaddr = '$ip' AND timestamp > ( " . time() . " - (" . getConfig('lockout_duration', 15) . "*60) );"); + if ( !$q ) + $db->_die(); + + echo '
' . $lang->get('acphome_msg_lockout_clear_success', array('ip' => htmlspecialchars($ip))) . '
'; + } + + $q = $db->sql_query('SELECT COUNT(id) AS fail_count, ipaddr, username, timestamp FROM ' . table_prefix . "lockout\n" + . " WHERE timestamp > ( " . time() . " - " . intval(getConfig('lockout_duration', 15)) . "*60 ) GROUP BY ipaddr ORDER BY COUNT(id) DESC, timestamp DESC;"); + if ( !$q ) + $db->_die(); + + if ( $db->numrows() > 0 ) + { + if ( $homewrap ) + echo '
'; + echo '

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

'; + echo '

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

'; + + ?> +
+ + + + + + + + + fetchrow() ) + { + echo ''; + echo ''; + echo ''; + // status + echo ''; + // time left + if ( $row['fail_count'] >= getConfig('lockout_threshold', 5) ) + { + $expire_time = $row['timestamp'] + ( getConfig('lockout_duration', 15) * 60 ); + $time_left = round(($expire_time - time()) / 60); + $minutes = $time_left == 1 ? $lang->get('etc_unit_minute') : $lang->get('etc_unit_minutes'); + echo ''; + } + else + { + echo ''; + } + // action + $btn_text = $row['fail_count'] >= getConfig('lockout_threshold', 5) ? $lang->get('acphome_btn_lockout_unblock') : $lang->get('acphome_btn_lockout_clear'); + echo ''; + echo ''; + } + echo '
get('acphome_th_locked_out_ip'); ?>get('acphome_th_locked_out_username'); ?>get('acphome_th_locked_out_status'); ?>get('acphome_th_locked_out_time'); ?>
' . htmlspecialchars($row['ipaddr']) . '' . htmlspecialchars($row['username']) . '' . + ( $row['fail_count'] >= getConfig('lockout_threshold', 5) + ? '' . $lang->get('acphome_lbl_locked_out_banned') . '' + : $lang->get('acphome_lbl_locked_out_warned', array('fail_count' => $row['fail_count'])) + ) + . '' . "$time_left $minutes" . '' . $btn_text . '
'; + echo '
'; + if ( $homewrap ) + echo '
'; + } + + $db->free_result(); }