1, 'password_hash' => 'Invité'); // If a cookie is set, we get the user_id and password hash from it if (isset($_COOKIE[$cookie_name])) list($cookie['user_id'], $cookie['password_hash']) = @unserialize($_COOKIE[$cookie_name]); if ($cookie['user_id'] > 1) { // Check if there's a user with the user ID and password hash from the cookie $_query = 'SELECT u.*, g.*, o.logged, o.idle FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '.$db->prefix.'online AS o ON o.user_id=u.id WHERE u.id='.intval($cookie['user_id']); $result = $db->query($_query) or error('Impossible de retrouver les informations utilisateur', __FILE__, __LINE__, $db->error()); $pun_user = $db->fetch_assoc($result); // If user authorisation failed if (!isset($pun_user['id']) || md5($cookie_seed.$pun_user['password']) !== $cookie['password_hash']) { pun_setcookie(0, random_pass(8), $expire); set_default_user(); return; } // Set a default language if the user selected language no longer exists if (!$pun_user['language'] || !@file_exists(PUN_ROOT.'lang/'.$pun_user['language'])) $pun_user['language'] = $pun_config['o_default_lang']; // Set a default style if the user selected style no longer exists if (!@file_exists(PUN_ROOT.'style/'.$pun_user['style'].'.css')) $pun_user['style'] = $pun_config['o_default_style']; if (!$pun_user['disp_topics']) $pun_user['disp_topics'] = $pun_config['o_disp_topics_default']; if (!$pun_user['disp_posts']) $pun_user['disp_posts'] = $pun_config['o_disp_posts_default']; if ($pun_user['save_pass'] == '0') $expire = 0; // Define this if you want this visit to affect the online list and the users last visit data if (!defined('PUN_QUIET_VISIT')) { // Update the online list if (!$pun_user['logged']) $db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$db->escape($pun_user['username']).'\', '.$now.')') or error('Impossbile d\'insérer dans la liste des utilisateurs en ligne', __FILE__, __LINE__, $db->error()); else { // Special case: We've timed out, but no other user has browsed the forums since we timed out if ($pun_user['logged'] < ($now-$pun_config['o_timeout_visit'])) { $db->query('UPDATE '.$db->prefix.'users SET last_visit='.$pun_user['logged'].' WHERE id='.$pun_user['id']) or error('Impossible de mettre à jour les données de visite de l\'utilisateur', __FILE__, __LINE__, $db->error()); $pun_user['last_visit'] = $pun_user['logged']; } $idle_sql = ($pun_user['idle'] == '1') ? ', idle=0' : ''; $db->query('UPDATE '.$db->prefix.'online SET logged='.$now.$idle_sql.' WHERE user_id='.$pun_user['id']) or error('Impossible de mettre à jour la liste des utilisateurs en ligne', __FILE__, __LINE__, $db->error()); } } $pun_user['is_guest'] = false; } else set_default_user(); } // // Fill $pun_user with default values (for guests) // function set_default_user() { global $db, $pun_user, $pun_config; $remote_addr = get_remote_address(); // Fetch guest user $result = $db->query('SELECT u.*, g.*, o.logged FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '.$db->prefix.'online AS o ON o.ident=\''.$remote_addr.'\' WHERE u.id=1') or error('Impossible de retrouver les informations d\'invité', __FILE__, __LINE__, $db->error()); if (!$db->num_rows($result)) exit('Impossible de retrouver les informations invité. La table \''.$db->prefix.'users\' doit contenir une entrée avec un id = 1 qui représente les utilisateurs anonymes.'); $pun_user = $db->fetch_assoc($result); // Update online list if (!$pun_user['logged']) $db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES(1, \''.$db->escape($remote_addr).'\', '.time().')') or error('Impossbile d\'insérer dans la liste des utilisateurs en ligne', __FILE__, __LINE__, $db->error()); else $db->query('UPDATE '.$db->prefix.'online SET logged='.time().' WHERE ident=\''.$db->escape($remote_addr).'\'') or error('Impossible de mettre à jour la liste des utilisateurs en ligne', __FILE__, __LINE__, $db->error()); $pun_user['disp_topics'] = $pun_config['o_disp_topics_default']; $pun_user['disp_posts'] = $pun_config['o_disp_posts_default']; $pun_user['timezone'] = $pun_config['o_server_timezone']; $pun_user['language'] = $pun_config['o_default_lang']; $pun_user['style'] = $pun_config['o_default_style']; $pun_user['is_guest'] = true; } // // Set a cookie, PunBB style! // function pun_setcookie($user_id, $password_hash, $expire) { global $cookie_name, $cookie_path, $cookie_domain, $cookie_secure, $cookie_seed; // Enable sending of a P3P header by removing // from the following line (try this if login is failing in IE6) // @header('P3P: CP="CUR ADM"'); setcookie($cookie_name, serialize(array($user_id, md5($cookie_seed.$password_hash))), $expire, $cookie_path, $cookie_domain, $cookie_secure); } // // Check whether the connecting user is banned (and delete any expired bans while we're at it) // function check_bans() { global $db, $pun_config, $lang_common, $pun_user, $pun_bans; // Admins aren't affected if ($pun_user['g_id'] == PUN_ADMIN || !$pun_bans) return; // Add a dot at the end of the IP address to prevent banned address 192.168.0.5 from matching e.g. 192.168.0.50 $user_ip = get_remote_address().'.'; $bans_altered = false; foreach ($pun_bans as $cur_ban) { // Has this ban expired? if ($cur_ban['expire'] != '' && $cur_ban['expire'] <= time()) { $db->query('DELETE FROM '.$db->prefix.'bans WHERE id='.$cur_ban['id']) or error('Impossible de supprimé le bannissement expiré', __FILE__, __LINE__, $db->error()); $bans_altered = true; continue; } if ($cur_ban['username'] != '' && !strcasecmp($pun_user['username'], $cur_ban['username'])) { $db->query('DELETE FROM '.$db->prefix.'online WHERE ident=\''.$db->escape($pun_user['username']).'\'') or error('Impossible de supprimer de la liste des utilisateur en ligne', __FILE__, __LINE__, $db->error()); message($lang_common['Ban message'].' '.(($cur_ban['expire'] != '') ? $lang_common['Ban message 2'].' '.strtolower(format_time($cur_ban['expire'], true)).'. ' : '').(($cur_ban['message'] != '') ? $lang_common['Ban message 3'].'

'.pun_htmlspecialchars($cur_ban['message']).'

' : '

').$lang_common['Ban message 4'].' '.$pun_config['o_admin_email'].'.', true); } if ($cur_ban['ip'] != '') { $cur_ban_ips = explode(' ', $cur_ban['ip']); for ($i = 0; $i < count($cur_ban_ips); ++$i) { $cur_ban_ips[$i] = $cur_ban_ips[$i].'.'; if (substr($user_ip, 0, strlen($cur_ban_ips[$i])) == $cur_ban_ips[$i]) { $db->query('DELETE FROM '.$db->prefix.'online WHERE ident=\''.$db->escape($pun_user['username']).'\'') or error('Impossible de supprimer de la liste des utilisateur en ligne', __FILE__, __LINE__, $db->error()); message($lang_common['Ban message'].' '.(($cur_ban['expire'] != '') ? $lang_common['Ban message 2'].' '.strtolower(format_time($cur_ban['expire'], true)).'. ' : '').(($cur_ban['message'] != '') ? $lang_common['Ban message 3'].'

'.pun_htmlspecialchars($cur_ban['message']).'

' : '

').$lang_common['Ban message 4'].' '.$pun_config['o_admin_email'].'.', true); } } } } // If we removed any expired bans during our run-through, we need to regenerate the bans cache if ($bans_altered) { require_once PUN_ROOT.'include/cache.php'; generate_bans_cache(); } } // // Update "Users online" // function update_users_online() { global $db, $pun_config, $pun_user; $now = time(); // Fetch all online list entries that are older than "o_timeout_online" $result = $db->query('SELECT * FROM '.$db->prefix.'online WHERE logged<'.($now-$pun_config['o_timeout_online'])) or error('Impossible de retrouver les anciennes entrées de la liste des utilisateurs', __FILE__, __LINE__, $db->error()); while ($cur_user = $db->fetch_assoc($result)) { // If the entry is a guest, delete it if ($cur_user['user_id'] == '1') $db->query('DELETE FROM '.$db->prefix.'online WHERE ident=\''.$db->escape($cur_user['ident']).'\'') or error('Impossible de supprimer de la liste des utilisateurs en ligne', __FILE__, __LINE__, $db->error()); else { // If the entry is older than "o_timeout_visit", update last_visit for the user in question, then delete him/her from the online list if ($cur_user['logged'] < ($now-$pun_config['o_timeout_visit'])) { $db->query('UPDATE '.$db->prefix.'users SET last_visit='.$cur_user['logged'].' WHERE id='.$cur_user['user_id']) or error('Impossible de mettre à jour les données de visite de l\'utilisateur', __FILE__, __LINE__, $db->error()); $db->query('DELETE FROM '.$db->prefix.'online WHERE user_id='.$cur_user['user_id']) or error('Impossible de supprimer de la liste des utilisateurs en ligne', __FILE__, __LINE__, $db->error()); } else if ($cur_user['idle'] == '0') $db->query('UPDATE '.$db->prefix.'online SET idle=1 WHERE user_id='.$cur_user['user_id']) or error('Impossible d\'insérer à la liste des utilisateurs en ligne', __FILE__, __LINE__, $db->error()); } } } // // Generate the "navigator" that appears at the top of every page // function generate_navlinks() { global $pun_config, $lang_common, $pun_user; // Index and Userlist should always be displayed $links[] = '