public function login($user_id, $username, $ip_address) { $session = XenForo_Session::startPublicSession(); $session->set('user_id', $user_id); $session->set('username', $username); $session->set('ip', XenForo_Helper_Ip::convertIpStringToBinary($ip_address)); //$session->set('userAgent', $user_agent); $session->saveSessionToSource($session->getSessionId(), false); return $session; }
protected function _verifyIpAddress(&$ipAddress) { $ipAddress = (string) XenForo_Helper_Ip::convertIpStringToBinary($ipAddress); return true; }
/** * Deletes the session activity record for the specified user / IP address * * @param integer $userId * @param string $ip */ public function deleteSessionActivity($userId, $ip) { $userId = intval($userId); $ipNum = XenForo_Helper_Ip::convertIpStringToBinary($ip); $uniqueKey = $userId ? $userId : $ipNum; $db = $this->_getDb(); $db->delete('xf_session_activity', 'user_id = ' . $db->quote($userId) . ' AND unique_key = ' . $db->quote($uniqueKey)); }
/** * Starts the session running. * * @param string|null Session ID. If not provided, read from cookie. * @param string|null IP address in one of various formats, for limiting access. If null, grabbed automatically. */ public function start($sessionId = null, $ipAddress = null) { if (!headers_sent()) { header('Expires: Thu, 19 Nov 1981 08:52:00 GMT'); header('Cache-control: private, max-age=0'); } if ($sessionId === null) { if (isset($_POST['_xfSessionId']) && is_string($_POST['_xfSessionId'])) { $sessionId = $_POST['_xfSessionId']; } else { $cookie = XenForo_Application::get('config')->cookie->prefix . $this->_config['cookie']; $sessionId = isset($_COOKIE[$cookie]) ? $_COOKIE[$cookie] : ''; } $sessionId = is_string($sessionId) ? $sessionId : ''; } if ($ipAddress == null) { $ipAddress = XenForo_Helper_Ip::getBinaryIp(); } else { $ipAddress = XenForo_Helper_Ip::convertIpStringToBinary($ipAddress); } $this->_setup($sessionId, $ipAddress); }
/** * Checks for a match of one or more IPs against a list of IP and IP fragments * * @param string|array IP address(es) * @param array List of IP addresses * * @return boolean */ public function ipMatch($checkIps, array $ipList) { if (!is_array($checkIps)) { $checkIps = array($checkIps); } foreach ($checkIps as $ip) { $binary = XenForo_Helper_Ip::convertIpStringToBinary($ip); if (!$binary) { continue; } $firstByte = $binary[0]; if (!empty($ipList[$firstByte])) { foreach ($ipList[$firstByte] as $range) { if (XenForo_Helper_Ip::ipMatchesRange($binary, $range[0], $range[1])) { return true; } } } } return false; }
public function getUsersByIp($ip, $daysLimit = null) { if (!$ip) { return array(); } $ip = XenForo_Helper_Ip::convertIpStringToBinary($ip); if (!$ip) { return array(); } return $this->fetchAllKeyed(' SELECT user.*, ip.ip, MAX(ip.log_date) AS log_date FROM xf_ip AS ip INNER JOIN xf_user AS user ON (user.user_id = ip.user_id) WHERE ip.ip = ? ' . ($daysLimit ? ' AND ip.log_date > ' . (XenForo_Application::$time - $daysLimit * 86400) : '') . ' GROUP BY ip.user_id ORDER BY user.username ', 'user_id', $ip); }