From: Lo?c C. <lo...@us...> - 2001-05-22 20:40:37
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat/lib In directory usw-pr-cvs1:/tmp/cvs-serv30745/chat/lib Modified Files: check_and_kick_user.lib.php3 Added Files: get_user_infos.lib.php3 Log Message: Too many changes to detail... --- NEW FILE --- <?php // // +--------------------------------------------------------------------------+ // | phpMyChat version 0.15.0 | // +--------------------------------------------------------------------------+ // | Copyright (c) 2000-2001 The phpHeaven-team | // +--------------------------------------------------------------------------+ // | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html | // +--------------------------------------------------------------------------+ // | This library contains a set of functions used to get some informations | // | about an user: | // | - pmcGetIp() = get the ip of the user | // | - pmcCheckBanish() = ensure the user is not banished from the | // | room he/she wants to enter in | // | - pmcRightLevel() = get the right level of the user for the | // | room he/she will enter in | // | | // | This script is called by the 'chat/lib/index_libs/main_index.lib.php3' | // | script. | // +--------------------------------------------------------------------------+ // | From the phpMyChat project: | // | http://www.phpheaven.net/projects/phpMyChat/ | // | | // | Authors: the phpHeaven-team <te...@ph...> | // +--------------------------------------------------------------------------+ // // $Id: get_user_infos.lib.php3,v 1.1 2001/05/22 20:40:34 loic1 Exp $ // // Set of functions and variables used to get some user's informations. // /** * Gets the values of some PHP environment variables that may contain the * IP address * * Uses the 'pmcGrabGlobals()' function defined in the * 'chat/lib/common.lib.php3' library. * * @return string the ip of the user * * @access public */ function pmcGetIp() { $toGrab = array('REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED'); pmcGrabGlobals($toGrab); // The 'main' ip $simpleIp = isset($GLOBALS['REMOTE_ADDR']) ? $GLOBALS['REMOTE_ADDR'] : ''; // Check if the 'main' ip is a proxy one and, in this case, try to get the // true ip // Step 1 $trueIp = isset($GLOBALS['HTTP_X_FORWARDED_FOR']) ? $GLOBALS['HTTP_X_FORWARDED_FOR'] : ''; if ($trueIp == '' && isset($GLOBALS['HTTP_X_FORWARDED'])) $trueIp = $GLOBALS['HTTP_X_FORWARDED']; if ($trueIp == '' && isset($GLOBALS['HTTP_FORWARDED_FOR'])) $trueIp = $GLOBALS['HTTP_FORWARDED_FOR']; if ($trueIp == '' && isset($GLOBALS['HTTP_FORWARDED'])) $trueIp = $GLOBALS['HTTP_FORWARDED']; $isProxy = ($trueIp != '') ? 1 : 0; // Step 2 if (!$isProxy) { $toGrab = array('HTTP_VIA', 'HTTP_X_COMING_FROM', 'HTTP_COMING_FROM'); pmcGrabGlobals($toGrab); $trueIp = isset($GLOBALS['HTTP_VIA']) ? $GLOBALS['HTTP_VIA'] : ''; if ($trueIp == '' && isset($GLOBALS['HTTP_X_COMING_FROM'])) $trueIp = $GLOBALS['HTTP_X_COMING_FROM']; if ($trueIp == '' && isset($GLOBALS['HTTP_COMING_FROM'])) $trueIp = $GLOBALS['HTTP_COMING_FROM']; if ($trueIp != '') $isProxy = 2; } // Step 3 if ($trueIp == $simpleIp) { $isProxy = 0; } unset($toGrab); // Returns the true IP if it has been found, else the proxy IP prefixed // by the 'p' character switch ($isProxy) { case 0: // True IP without proxy return $simpleIp; break; case 1: $b = ereg ('^([0-9]{1,3}\.){3,3}[0-9]{1,3}', $trueIp, $regs); if ($b && (count($regs) > 0)) { // True IP behind a proxy return $regs[0]; } else { // Proxy IP return 'p' . $simpleIp; } break; case 2: // Proxy IP return 'p' . $simpleIp; } // end of switch } // end of the 'pmcIsInto()' function /** * Ensure an user is not banished from the room he/she wants to enter in * * The 'pmcHandleMagicQuotes()' and the 'pmcIsInto()' functions are defined * inside the 'chat/lib/common.lib.php3' library * * @return string the ip of the user * * @global string the slashed nick of the user * @global string the ip of this user * @global string the name of the room this user wants to enter in * @global object the database handler * * @access public */ function pmcCheckBanish() { global $slashedNick; global $ip; global $targetRoom; global $dbLink; // Initialize a variable and clean the banished users table $isBanished = false; $dbLink->query("DELETE FROM " . C_BAN_TBL . " WHERE ban_until < " . time()); // 1. Search by nick $dbLink->query("SELECT ip, rooms FROM " . C_BAN_TBL . " WHERE username = '$slashedNick' LIMIT 1"); // This nick is banished from some rooms if (list($oldIp, $banishedFromRooms) = $dbLink->nextRecord()) { $dbLink->cleanResults(); $banishedFromRooms = pmcHandleMagicQuotes($banishedFromRooms, '', 1, 'del'); // Is the user banished from the room he wants to enter in? $isBanished = ($banishedFromRooms == '*' || pmcIsInto($targetRoom, $banishedFromRooms) >= 0); // If the user is banished, update his/her ip in the banished table if // necessary if ($isBanished && $ip != $oldIp && (substr($ip, 0, 1) != 'p' || substr($oldIp, 0, 1) == 'p')) { $dbLink->query("UPDATE " . C_BAN_TBL . " SET ip = '$ip' WHERE username = '$slashedNick'"); } } // end of the case where nick is banished from some rooms // 2. This nick isn't banished from any room, seek for a banished IP else { $dbLink->cleanResults(); $dbLink->query("SELECT rooms, ban_until FROM " . C_BAN_TBL . " WHERE ip = '$ip' LIMIT 1"); // Ip is banished from some rooms if (list($banishedFromRooms, $banUntil) = $dbLink->nextRecord()) { $dbLink->cleanResults(); $banishedFromRooms = pmcHandleMagicQuotes($banishedFromRooms, '', 1, 'del'); // Is the ip banished from the room user wants to enter in? $isBanished = ($banishedFromRooms == '*' || pmcIsInto($targetRoom, $banishedFromRooms) >= 0); // If the user is banished, add his/her nick to the banished users // table if necessary if ($isBanished) { $dbLink->query("INSERT INTO " . C_BAN_TBL . " (username, latin1, ip, rooms, ban_until) VALUES ('$slashedNick', " . $GLOBALS['latin1'] . ", '$ip', '" . pmcSlashSingleQuotes($banishedFromRooms) . "', '$banUntil')"); } } // end of the case where IP is banished from some rooms else { $dbLink->cleanResults(); } } // end of ip tests return $isBanished; } // end of the 'pmcCheckBanish()' function /** * Get the right level of the user for the room he/she will enter in * * The 'pmcIsInto()' function is defined inside the 'chat/lib/common.lib.php3' * library * * @return string the right level of the user * * @global boolean whether the user is a registered one or not * @global string the global right level of this user * @global string the list of rooms moderated by this user * @global string the slashed nick of the user * @global boolean whether the room has to be trully created or not * @global string the name of the room this user wants to enter in * @global string the slashed name of this room * @global object the database handler * * @access public */ function pmcRightLevel() { global $isRegUser; global $regUserPerms; global $regUserModeratedRooms; global $slashedNick; global $isCreateRoom; global $targetRoom; global $slashedTargetRoomName; global $dbLink; // 1. The user is the administrator or already moderator for the room // he/she will enter in if ($regUserPerms == 'admin') { return 'a'; } // 2. The user is already moderator for the room he/she will enter in else if ($regUserPerms == 'moderator' && pmcIsInto($targetRoom, $regUserModeratedRooms) >= 0) { return 'm'; } // 3. The room has to be created... if ($isCreateRoom) { // If the name of the room to be created is the same than one of an // existing room containing 'true' messages (not only notifications of // users entrance/exit) or containing only 'system' message but an user // is currently logged in, status will be 'user' $dbLink->query("SELECT COUNT(*) FROM " . C_MSG_TBL . " WHERE room = '$slashedTargetRoomName' AND username NOT LIKE 'SYS %' LIMIT 1"); list($isTrueMsg) = $dbLink->nextRecord(); $regUserPerms = ($isTrueMsg == 0) ? 'moderator' : 'user'; $dbLink->cleanResults(); if (!$isTrueMsg) { $dbLink->query("SELECT COUNT(*) FROM " . C_USR_TBL . " WHERE room = '$slashedTargetRoomName' AND username != '$slashedNick' LIMIT 1"); list($isAnybody) = $dbLink->nextRecord(); $regUserPerms = ($isAnybody == 0) ? 'moderator' : 'user'; $dbLink->cleanResults(); } // end of true new room // The user will be moderator for this room -> update tables if ($regUserPerms == 'moderator') { // If an other registered user is already moderator for the room to // create but there is no 'true' message in this room then sets his // status to 'user' for this room $dbLink->query("SELECT username, rooms FROM " . C_REG_TBL . " WHERE perms = 'moderator' AND username != '$slashedNick'"); while (list($otherModerator, $otherModeratedRooms) = $dbLink->nextRecord()) { $changed = false; $otherModerator = pmcHandleMagicQuotes($otherModerator, '', 1, 'del'); $otherModeratedRooms = pmcHandleMagicQuotes($otherModeratedRooms, '', 1, 'del'); $rooms = explode(',', $otherModeratedRooms); $arrayCnt = count($rooms); reset($rooms); for ($i = 0; $i < $arrayCnt; $i++) { if (strcasecmp($targetRoom, $rooms[$i]) == 0) { $rooms[$i] = ''; $changed = true; break; } } if ($changed) { $otherModeratedRooms = implode(',', $rooms); $otherModeratedRooms = ereg_replace('^,|,$', '', $otherModeratedRooms); $otherModeratedRooms = str_replace(',,', ',', $otherModeratedRooms); $dbLink->query("UPDATE " . C_REG_TBL . " SET rooms = '" . pmcSlashSingleQuotes($otherModeratedRooms) . "' WHERE username = '" . pmcSlashSingleQuotes($otherModerator) . "'"); $dbLink->query("UPDATE " . C_USR_TBL . " SET status = 'r' WHERE room = '$slashedTargetRoomName' AND username = '" . pmcSlashSingleQuotes($otherModerator) . "'"); } unset($rooms); } // Update the current user status for the room to be created $regUserModeratedRooms .= (empty($regUserModeratedRooms)) ? $targetRoom : ',' . $targetRoom; $dbLink->query("UPDATE " . C_REG_TBL . " SET perms = 'moderator', rooms = '" . pmcSlashSingleQuotes($regUserModeratedRooms) ."' WHERE username = '$slashedNick'"); return 'm'; } // end of updating tables else { return 'r'; } } // 4. Other cases else { return ($isRegUser) ? 'r' : 'u'; } } // end of the 'pmcRightLevel()' function ?> Index: check_and_kick_user.lib.php3 =================================================================== RCS file: /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/check_and_kick_user.lib.php3,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -r1.14 -r1.15 *** check_and_kick_user.lib.php3 2001/04/30 19:43:27 1.14 --- check_and_kick_user.lib.php3 2001/05/22 20:40:34 1.15 *************** *** 117,121 **** { // Gets the IP address ! include('./lib/get_ip.lib.' . C_EXTENSION); $usrQuery = 'INSERT INTO ' . C_USR_TBL . ' ' . '(session_id, u_time, room, username, latin1, status, ip) ' --- 117,122 ---- { // Gets the IP address ! include('./lib/get_user_infos.lib.' . C_EXTENSION); ! $ip = pmcGetIp(); $usrQuery = 'INSERT INTO ' . C_USR_TBL . ' ' . '(session_id, u_time, room, username, latin1, status, ip) ' |