public function login() { global $db_type, $lang_login; $form_username = feather_trim($this->request->post('req_username')); $form_password = feather_trim($this->request->post('req_password')); $save_pass = $this->request->post('save_pass'); $user = DB::for_table('users')->where('username', $form_username)->find_one(); $authorized = false; if (!empty($user->password)) { $form_password_hash = feather_hash($form_password); // Will result in a SHA-1 hash // If the length isn't 40 then the password isn't using sha1, so it must be md5 from 1.2 // Maybe this should be removed if (strlen($user->password) != 40) { if (md5($form_password) == $user->password) { $authorized = true; DB::for_table('users')->where('id', $user->id)->find_one()->set('password', $form_password_hash)->save(); } } else { $authorized = $user->password == $form_password_hash; } } if (!$authorized) { message($lang_login['Wrong user/pass'] . ' <a href="' . get_link('login/action/forget/') . '">' . $lang_login['Forgotten pass'] . '</a>'); } // Update the status if this is the first time the user logged in if ($user->group_id == FEATHER_UNVERIFIED) { DB::for_table('users')->where('id', $user->id)->find_one()->set('group_id', $this->config['o_default_user_group'])->save(); // Regenerate the users info cache if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) { require FEATHER_ROOT . 'include/cache.php'; } generate_users_info_cache(); } // Remove this user's guest entry from the online list DB::for_table('online')->where('ident', get_remote_address())->delete_many(); $expire = $save_pass == '1' ? time() + 1209600 : time() + $this->config['o_timeout_visit']; feather_setcookie($user->id, $form_password_hash, $expire); // Reset tracked topics set_tracked_topics(null); // Try to determine if the data in redirect_url is valid (if not, we redirect to index.php after login) $redirect_url = validate_redirect($this->request->post('redirect_url'), get_base_url()); redirect(feather_escape($redirect_url), $lang_login['Login redirect']); }
$initial_group_id = $random_pass == 0 ? $panther_config['o_default_user_group'] : PANTHER_UNVERIFIED; $password_hash = panther_hash($password1 . $password_salt); // Add the user $insert = array('username' => $username, 'group_id' => $initial_group_id, 'password' => $password_hash, 'salt' => $password_salt, 'email' => $email, 'email_setting' => $panther_config['o_default_email_setting'], 'timezone' => $panther_config['o_default_timezone'], 'dst' => $panther_config['o_default_dst'], 'language' => $panther_config['o_default_lang'], 'style' => $panther_config['o_default_style'], 'registered' => $now, 'registration_ip' => get_remote_address(), 'last_visit' => $now); $db->insert('users', $insert); $new_uid = $db->lastInsertId($db->prefix . 'users'); if ($random_pass == '1') { $info = array('subject' => array('<board_title>' => $panther_config['o_board_title']), 'message' => array('<base_url>' => get_base_url(), '<username>' => $username, '<password>' => $password1, '<login_url>' => panther_link($panther_url['login']))); $mail_tpl = $mailer->parse(PANTHER_ROOT . 'lang/' . $panther_user['language'] . '/mail_templates/welcome.tpl', $info); $mailer->send($email, $mail_tpl['subject'], $mail_tpl['message']); } // Regenerate the users info cache if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) { require PANTHER_ROOT . 'include/cache.php'; } generate_users_info_cache(); redirect(panther_link($panther_url['admin_maintenance']), $lang_admin_maintenance['User created message']); } } // Get the first post ID from the db $ps = $db->select('posts', 'id', array(), '', 'id ASC LIMIT 1'); $first_id = $ps->rowCount() ? $ps->fetchColumn() : 0; $page_title = array($panther_config['o_board_title'], $lang_admin_common['Admin'], $lang_admin_common['Maintenance']); define('PANTHER_ACTIVE_PAGE', 'admin'); require PANTHER_ROOT . 'header.php'; $options = array(); $ps = $db->run('SELECT u.id, u.username, g.g_title FROM ' . $db->prefix . 'users AS u INNER JOIN ' . $db->prefix . 'groups AS g ON u.group_id=g.g_id WHERE u.id!=1 ORDER BY u.id ASC'); foreach ($ps as $result) { $options[] = array('id' => $result['id'], 'username' => $result['username'], 'group_title' => $result['g_title']); } $forums = $catgeories = array();
public function insert_user($user) { global $lang_register; // Insert the new user into the database. We do this now to get the last inserted ID for later use $now = time(); $intial_group_id = $this->config['o_regs_verify'] == '0' ? $this->config['o_default_user_group'] : FEATHER_UNVERIFIED; $password_hash = feather_hash($user['password1']); // Add the user $insert_user = array('username' => $user['username'], 'group_id' => $intial_group_id, 'password' => $password_hash, 'email' => $user['email1'], 'email_setting' => $this->config['o_default_email_setting'], 'timezone' => $this->config['o_default_timezone'], 'dst' => 0, 'language' => $user['language'], 'style' => $this->config['o_default_style'], 'registered' => $now, 'registration_ip' => get_remote_address(), 'last_visit' => $now); DB::for_table('users')->create()->set($insert_user)->save(); $new_uid = DB::get_db()->lastInsertId($this->feather->prefix . 'users'); if ($this->config['o_regs_verify'] == '0') { // Regenerate the users info cache if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) { require FEATHER_ROOT . 'include/cache.php'; } generate_users_info_cache(); } // If the mailing list isn't empty, we may need to send out some alerts if ($this->config['o_mailing_list'] != '') { // If we previously found out that the email was banned if (isset($user['banned_email'])) { // Load the "banned email register" template $mail_tpl = trim(file_get_contents(FEATHER_ROOT . 'lang/' . $this->user->language . '/mail_templates/banned_email_register.tpl')); // The first row contains the subject $first_crlf = strpos($mail_tpl, "\n"); $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8)); $mail_message = trim(substr($mail_tpl, $first_crlf)); $mail_message = str_replace('<username>', $user['username'], $mail_message); $mail_message = str_replace('<email>', $user['email1'], $mail_message); $mail_message = str_replace('<profile_url>', get_link('user/' . $new_uid . '/'), $mail_message); $mail_message = str_replace('<board_mailer>', $this->config['o_board_title'], $mail_message); pun_mail($this->config['o_mailing_list'], $mail_subject, $mail_message); } // If we previously found out that the email was a dupe if (!empty($dupe_list)) { // Load the "dupe email register" template $mail_tpl = trim(file_get_contents(FEATHER_ROOT . 'lang/' . $this->user->language . '/mail_templates/dupe_email_register.tpl')); // The first row contains the subject $first_crlf = strpos($mail_tpl, "\n"); $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8)); $mail_message = trim(substr($mail_tpl, $first_crlf)); $mail_message = str_replace('<username>', $user['username'], $mail_message); $mail_message = str_replace('<dupe_list>', implode(', ', $dupe_list), $mail_message); $mail_message = str_replace('<profile_url>', get_link('user/' . $new_uid . '/'), $mail_message); $mail_message = str_replace('<board_mailer>', $this->config['o_board_title'], $mail_message); pun_mail($this->config['o_mailing_list'], $mail_subject, $mail_message); } // Should we alert people on the admin mailing list that a new user has registered? if ($this->config['o_regs_report'] == '1') { // Load the "new user" template $mail_tpl = trim(file_get_contents(FEATHER_ROOT . 'lang/' . $this->user->language . '/mail_templates/new_user.tpl')); // The first row contains the subject $first_crlf = strpos($mail_tpl, "\n"); $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8)); $mail_message = trim(substr($mail_tpl, $first_crlf)); $mail_message = str_replace('<username>', $user['username'], $mail_message); $mail_message = str_replace('<base_url>', get_base_url() . '/', $mail_message); $mail_message = str_replace('<profile_url>', get_link('user/' . $new_uid . '/'), $mail_message); $mail_message = str_replace('<admin_url>', get_link('user/' . $new_uid . '/section/admin/'), $mail_message); $mail_message = str_replace('<board_mailer>', $this->config['o_board_title'], $mail_message); pun_mail($this->config['o_mailing_list'], $mail_subject, $mail_message); } } // Must the user verify the registration or do we log him/her in right now? if ($this->config['o_regs_verify'] == '1') { // Load the "welcome" template $mail_tpl = trim(file_get_contents(FEATHER_ROOT . 'lang/' . $this->user->language . '/mail_templates/welcome.tpl')); // The first row contains the subject $first_crlf = strpos($mail_tpl, "\n"); $mail_subject = trim(substr($mail_tpl, 8, $first_crlf - 8)); $mail_message = trim(substr($mail_tpl, $first_crlf)); $mail_subject = str_replace('<board_title>', $this->config['o_board_title'], $mail_subject); $mail_message = str_replace('<base_url>', get_base_url() . '/', $mail_message); $mail_message = str_replace('<username>', $user['username'], $mail_message); $mail_message = str_replace('<password>', $user['password1'], $mail_message); $mail_message = str_replace('<login_url>', get_link('login/'), $mail_message); $mail_message = str_replace('<board_mailer>', $this->config['o_board_title'], $mail_message); pun_mail($user['email1'], $mail_subject, $mail_message); message($lang_register['Reg email'] . ' <a href="mailto:' . feather_escape($this->config['o_admin_email']) . '">' . feather_escape($this->config['o_admin_email']) . '</a>.', true); } feather_setcookie($new_uid, $password_hash, time() + $this->config['o_timeout_visit']); redirect(get_base_url(), $lang_register['Reg complete']); }
/** * Regenerate FluxBB cache after conversion */ function generate_cache() { // Load the cache script require_once PUN_ROOT . 'include/cache.php'; // Generate cache generate_config_cache(); generate_bans_cache(); generate_quickjump_cache(); generate_censoring_cache(); generate_users_info_cache(); clear_feed_cache(); }
public function delete_users() { global $lang_admin_users; if ($this->request->post('users')) { $user_ids = is_array($this->request->post('users')) ? array_keys($this->request->post('users')) : explode(',', $this->request->post('users')); $user_ids = array_map('intval', $user_ids); // Delete invalid IDs $user_ids = array_diff($user_ids, array(0, 1)); } else { $user_ids = array(); } if (empty($user_ids)) { message($lang_admin_users['No users selected']); } // Are we trying to delete any admins? $is_admin = DB::for_table('users')->where_in('id', $user_ids)->where('group_id', FEATHER_ADMIN)->find_one(); if ($is_admin) { message($lang_admin_users['No delete admins message']); } if ($this->request->post('delete_users_comply')) { // Fetch user groups $user_groups = array(); $select_fetch_user_groups = array('id', 'group_id'); $result = DB::for_table('users')->select_many($select_fetch_user_groups)->where_in('id', $user_ids)->find_many(); foreach ($result as $cur_user) { if (!isset($user_groups[$cur_user['group_id']])) { $user_groups[$cur_user['group_id']] = array(); } $user_groups[$cur_user['group_id']][] = $cur_user['id']; } // Are any users moderators? $group_ids = array_keys($user_groups); $select_fetch_user_mods = array('g_id', 'g_moderator'); $result = DB::for_table('groups')->select_many($select_fetch_user_mods)->where_in('g_id', $group_ids)->find_many(); foreach ($result as $cur_group) { if ($cur_group['g_moderator'] == '0') { unset($user_groups[$cur_group['g_id']]); } } // Fetch forum list and clean up their moderator list $select_mods = array('id', 'moderators'); $result = DB::for_table('forums')->select_many($select_mods)->find_many(); foreach ($result as $cur_forum) { $cur_moderators = $cur_forum['moderators'] != '' ? unserialize($cur_forum['moderators']) : array(); foreach ($user_groups as $group_users) { $cur_moderators = array_diff($cur_moderators, $group_users); } if (!empty($cur_moderators)) { DB::for_table('forums')->where('id', $cur_forum['id'])->find_one()->set('moderators', serialize($cur_moderators))->save(); } else { DB::for_table('forums')->where('id', $cur_forum['id'])->find_one()->set_expr('moderators', 'NULL')->save(); } } // Delete any subscriptions DB::for_table('topic_subscriptions')->where_in('user_id', $user_ids)->delete_many(); DB::for_table('forum_subscriptions')->where_in('user_id', $user_ids)->delete_many(); // Remove them from the online list (if they happen to be logged in) DB::for_table('online')->where_in('user_id', $user_ids)->delete_many(); // Should we delete all posts made by these users? if ($this->request->post('delete_posts')) { require FEATHER_ROOT . 'include/search_idx.php'; @set_time_limit(0); // Find all posts made by this user $select_user_posts = array('p.id', 'p.topic_id', 't.forum_id'); $result = DB::for_table('posts')->table_alias('p')->select_many($select_user_posts)->inner_join('topics', array('t.id', '=', 'p.topic_id'), 't')->inner_join('forums', array('f.id', '=', 't.forum_id'), 'f')->where('p.poster_id', $user_ids)->find_many(); if ($result) { foreach ($result as $cur_post) { // Determine whether this post is the "topic post" or not $result2 = DB::for_table('posts')->where('topic_id', $cur_post['topic_id'])->order_by('posted')->find_one_col('id'); if ($this->db->result($result2) == $cur_post['id']) { delete_topic($cur_post['topic_id']); } else { delete_post($cur_post['id'], $cur_post['topic_id']); } update_forum($cur_post['forum_id']); } } } else { // Set all their posts to guest DB::for_table('posts')->where_in('poster_id', '1')->update_many('poster_id', $user_ids); } // Delete the users DB::for_table('users')->where_in('id', $user_ids)->delete_many(); // Delete user avatars foreach ($user_ids as $user_id) { delete_avatar($user_id); } // Regenerate the users info cache if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) { require FEATHER_ROOT . 'include/cache.php'; } generate_users_info_cache(); redirect(get_link('admin/users/'), $lang_admin_users['Users delete redirect']); } return $user_ids; }
public function collect_stats() { // Collect some statistics from the database if (file_exists(FORUM_CACHE_DIR . 'cache_users_info.php')) { include FORUM_CACHE_DIR . 'cache_users_info.php'; } if (!defined('feather_userS_INFO_LOADED')) { if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) { require FEATHER_ROOT . 'include/cache.php'; } generate_users_info_cache(); require FORUM_CACHE_DIR . 'cache_users_info.php'; } $stats_query = DB::for_table('forums')->select_expr('SUM(num_topics)', 'total_topics')->select_expr('SUM(num_posts)', 'total_posts')->find_one(); $stats['total_topics'] = intval($stats_query['total_topics']); $stats['total_posts'] = intval($stats_query['total_posts']); if ($this->user->g_view_users == '1') { $stats['newest_user'] = '******' . get_link('user/' . $stats['last_user']['id']) . '/">' . feather_escape($stats['last_user']['username']) . '</a>'; } else { $stats['newest_user'] = feather_escape($stats['last_user']['username']); } return $stats; }
public function update_profile($id, $info, $section) { global $lang_common, $lang_profile, $lang_prof_reg, $pd; $username_updated = false; // Validate input depending on section switch ($section) { case 'essentials': $form = array('timezone' => floatval($this->request->post('form_timezone')), 'dst' => $this->request->post('form_dst') ? '1' : '0', 'time_format' => intval($this->request->post('form_time_format')), 'date_format' => intval($this->request->post('form_date_format'))); // Make sure we got a valid language string if ($this->request->post('form_language')) { $languages = forum_list_langs(); $form['language'] = feather_trim($this->request->post('form_language')); if (!in_array($form['language'], $languages)) { message($lang_common['Bad request'], '404'); } } if ($this->user->is_admmod) { $form['admin_note'] = feather_trim($this->request->post('admin_note')); // Are we allowed to change usernames? if ($this->user->g_id == FEATHER_ADMIN || $this->user->g_moderator == '1' && $this->user->g_mod_rename_users == '1') { $form['username'] = feather_trim($this->request->post('req_username')); if ($form['username'] != $info['old_username']) { // Check username require FEATHER_ROOT . 'lang/' . $this->user->language . '/register.php'; $errors = ''; $errors = check_username($form['username'], $errors, $id); if (!empty($errors)) { message($errors[0]); } $username_updated = true; } } // We only allow administrators to update the post count if ($this->user->g_id == FEATHER_ADMIN) { $form['num_posts'] = intval($this->request->post('num_posts')); } } if ($this->config['o_regs_verify'] == '0' || $this->user->is_admmod) { require FEATHER_ROOT . 'include/email.php'; // Validate the email address $form['email'] = strtolower(feather_trim($this->request->post('req_email'))); if (!is_valid_email($form['email'])) { message($lang_common['Invalid email']); } } break; case 'personal': $form = array('realname' => $this->request->post('form_realname') ? feather_trim($this->request->post('form_realname')) : '', 'url' => $this->request->post('form_url') ? feather_trim($this->request->post('form_url')) : '', 'location' => $this->request->post('form_location') ? feather_trim($this->request->post('form_location')) : ''); // Add http:// if the URL doesn't contain it already (while allowing https://, too) if ($this->user->g_post_links == '1') { if ($form['url'] != '') { $url = url_valid($form['url']); if ($url === false) { message($lang_profile['Invalid website URL']); } $form['url'] = $url['url']; } } else { if (!empty($form['url'])) { message($lang_profile['Website not allowed']); } $form['url'] = ''; } if ($this->user->g_id == FEATHER_ADMIN) { $form['title'] = feather_trim($this->request->post('title')); } elseif ($this->user->g_set_title == '1') { $form['title'] = feather_trim($this->request->post('title')); if ($form['title'] != '') { // A list of words that the title may not contain // If the language is English, there will be some duplicates, but it's not the end of the world $forbidden = array('member', 'moderator', 'administrator', 'banned', 'guest', utf8_strtolower($lang_common['Member']), utf8_strtolower($lang_common['Moderator']), utf8_strtolower($lang_common['Administrator']), utf8_strtolower($lang_common['Banned']), utf8_strtolower($lang_common['Guest'])); if (in_array(utf8_strtolower($form['title']), $forbidden)) { message($lang_profile['Forbidden title']); } } } break; case 'messaging': $form = array('jabber' => feather_trim($this->request->post('form_jabber')), 'icq' => feather_trim($this->request->post('form_icq')), 'msn' => feather_trim($this->request->post('form_msn')), 'aim' => feather_trim($this->request->post('form_aim')), 'yahoo' => feather_trim($this->request->post('form_yahoo'))); // If the ICQ UIN contains anything other than digits it's invalid if (preg_match('%[^0-9]%', $form['icq'])) { message($lang_prof_reg['Bad ICQ']); } break; case 'personality': $form = array(); // Clean up signature from POST if ($this->config['o_signatures'] == '1') { $form['signature'] = feather_linebreaks(feather_trim($this->request->post('signature'))); // Validate signature if (feather_strlen($form['signature']) > $this->config['p_sig_length']) { message(sprintf($lang_prof_reg['Sig too long'], $this->config['p_sig_length'], feather_strlen($form['signature']) - $this->config['p_sig_length'])); } elseif (substr_count($form['signature'], "\n") > $this->config['p_sig_lines'] - 1) { message(sprintf($lang_prof_reg['Sig too many lines'], $this->config['p_sig_lines'])); } elseif ($form['signature'] && $this->config['p_sig_all_caps'] == '0' && is_all_uppercase($form['signature']) && !$this->user->is_admmod) { $form['signature'] = utf8_ucwords(utf8_strtolower($form['signature'])); } // Validate BBCode syntax if ($this->config['p_sig_bbcode'] == '1') { require FEATHER_ROOT . 'include/parser.php'; $errors = array(); $form['signature'] = preparse_bbcode($form['signature'], $errors, true); if (count($errors) > 0) { message('<ul><li>' . implode('</li><li>', $errors) . '</li></ul>'); } } } break; case 'display': $form = array('disp_topics' => feather_trim($this->request->post('form_disp_topics')), 'disp_posts' => feather_trim($this->request->post('form_disp_posts')), 'show_smilies' => $this->request->post('form_show_smilies') ? '1' : '0', 'show_img' => $this->request->post('form_show_img') ? '1' : '0', 'show_img_sig' => $this->request->post('form_show_img_sig') ? '1' : '0', 'show_avatars' => $this->request->post('form_show_avatars') ? '1' : '0', 'show_sig' => $this->request->post('form_show_sig') ? '1' : '0'); if ($form['disp_topics'] != '') { $form['disp_topics'] = intval($form['disp_topics']); if ($form['disp_topics'] < 3) { $form['disp_topics'] = 3; } elseif ($form['disp_topics'] > 75) { $form['disp_topics'] = 75; } } if ($form['disp_posts'] != '') { $form['disp_posts'] = intval($form['disp_posts']); if ($form['disp_posts'] < 3) { $form['disp_posts'] = 3; } elseif ($form['disp_posts'] > 75) { $form['disp_posts'] = 75; } } // Make sure we got a valid style string if ($this->request->post('form_style')) { $styles = forum_list_styles(); $form['style'] = feather_trim($this->request->post('form_style')); if (!in_array($form['style'], $styles)) { message($lang_common['Bad request'], '404'); } } break; case 'privacy': $form = array('email_setting' => intval($this->request->post('form_email_setting')), 'notify_with_post' => $this->request->post('form_notify_with_post') ? '1' : '0', 'auto_notify' => $this->request->post('form_auto_notify') ? '1' : '0'); if ($form['email_setting'] < 0 || $form['email_setting'] > 2) { $form['email_setting'] = $this->config['o_default_email_setting']; } break; default: message($lang_common['Bad request'], '404'); } // Single quotes around non-empty values and nothing for empty values $temp = array(); foreach ($form as $key => $input) { $temp[$key] = $input; } if (empty($temp)) { message($lang_common['Bad request'], '404'); } DB::for_table('users')->where('id', $id)->find_one()->set($temp)->save(); // If we changed the username we have to update some stuff if ($username_updated) { $bans_updated = DB::for_table('bans')->where('username', $info['old_username'])->update_many('username', $form['username']); DB::for_table('posts')->where('poster_id', $id)->update_many('poster', $form['username']); DB::for_table('posts')->where('edited_by', $info['old_username'])->update_many('edited_by', $form['username']); DB::for_table('topics')->where('poster', $info['old_username'])->update_many('poster', $form['username']); DB::for_table('topics')->where('last_poster', $info['old_username'])->update_many('last_poster', $form['username']); DB::for_table('forums')->where('last_poster', $info['old_username'])->update_many('last_poster', $form['username']); DB::for_table('online')->where('ident', $info['old_username'])->update_many('ident', $form['username']); // If the user is a moderator or an administrator we have to update the moderator lists $group_id = DB::for_table('users')->where('id', $id)->find_one_col('group_id'); $group_mod = DB::for_table('groups')->where('g_id', $group_id)->find_one_col('g_moderator'); if ($group_id == FEATHER_ADMIN || $group_mod == '1') { $select_mods = array('id', 'moderators'); $result = DB::for_table('forums')->select_many($select_mods)->find_many(); foreach ($result as $cur_forum) { $cur_moderators = $cur_forum['moderators'] != '' ? unserialize($cur_forum['moderators']) : array(); if (in_array($id, $cur_moderators)) { unset($cur_moderators[$info['old_username']]); $cur_moderators[$form['username']] = $id; uksort($cur_moderators, 'utf8_strcasecmp'); DB::for_table('forums')->where('id', $cur_forum['id'])->find_one()->set('moderators', serialize($cur_moderators))->save(); } } } // Regenerate the users info cache if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) { require FEATHER_ROOT . 'include/cache.php'; } generate_users_info_cache(); // Check if the bans table was updated and regenerate the bans cache when needed if ($bans_updated) { generate_bans_cache(); } } redirect(get_link('user/' . $id . '/section/' . $section . '/'), $lang_profile['Profile redirect']); }