/** * * @see XenForo_Model_Ip::getSharedIpUsers() */ public function getSharedIpUsers($userId, $logDays) { $users = parent::getSharedIpUsers($userId, $logDays); $db = $this->_getDb(); $ipLogs = $db->fetchCol($db->limit(' SELECT DISTINCT ip_address FROM xf_moderator_log WHERE content_type IN (\'thread\', \'post\') AND action = \'post_as_user\' AND log_date > ? ', 500), XenForo_Application::$time - $logDays * 86400); foreach ($ipLogs as $key => $ipLog) { $ipLogs[$key] = XenForo_Helper_Ip::convertIpBinaryToString($ipLog); } foreach ($users as $userId => $user) { foreach ($user['ipLogs'] as $key => $ipLog) { if (in_array($ipLog['ip_address'], $ipLogs)) { unset($user['ipLogs'][$key]); } } if (empty($user['ipLogs'])) { unset($users[$userId]); } } return $users; }
public static function getRequestUrl(array $provider, $redirectUri, array $extraParams = array()) { $url = call_user_func_array('sprintf', array('%s/index.php?oauth/authorize/&client_id=%s&redirect_uri=%s&response_type=code&scope=%s', rtrim($provider['root'], '/'), rawurlencode($provider['client_id']), rawurlencode($redirectUri), rawurlencode(self::SCOPE))); if (XenForo_Application::getConfig()->get(bdApiConsumer_Option::CONFIG_TRACK_AUTHORIZE_URL_STATE) && !isset($extraParams['state'])) { $extraParams['state'] = base64_encode(json_encode(array('time' => XenForo_Application::$time, 'ip' => XenForo_Helper_Ip::convertIpBinaryToString(XenForo_Application::getSession()->get('ip'))))); } foreach ($extraParams as $key => $value) { $url .= sprintf('&%s=%s', $key, rawurlencode($value)); } return $url; }
public function getLastIp($userId) { $lastIp = $this->_getDb()->fetchOne(' SELECT ip FROM xf_ip WHERE user_id = ? ORDER BY log_date DESC LIMIT 1 ', $userId); return XenForo_Helper_Ip::convertIpBinaryToString($lastIp); }
public final function prepareEntry(array $entry) { $entry['content_title'] = XenForo_Helper_String::censorString($entry['content_title']); $entry['ipAddress'] = $entry['ip_address'] ? XenForo_Helper_Ip::convertIpBinaryToString($entry['ip_address']) : ''; $entry = $this->_prepareEntry($entry); if (!isset($entry['actionText'])) { $entry['actionText'] = new XenForo_Phrase('moderator_log_' . $entry['content_type'] . '_' . $entry['action'], json_decode($entry['action_params'], true)); } if (!isset($entry['contentUser'])) { $entry['contentUser'] = array('user_id' => $entry['content_user_id'], 'username' => $entry['content_username']); } return $entry; }
/** * Fetches the current IP for the specified online guest * * @return XenForo_ControllerResponse_Abstract */ public function actionGuestIp() { if (!$this->_getUserModel()->canViewIps($errorPhraseKey)) { throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey); } $ip = preg_replace('#[^0-9a-f]#', '', $this->_input->filterSingle('ip', XenForo_Input::STRING)); try { $ip = XenForo_Helper_Ip::convertIpBinaryToString(XenForo_Helper_Ip::convertHexToBin($ip)); } catch (Exception $e) { $ip = false; } if (!$ip) { // likely given an invalid IP return $this->responseError(new XenForo_Phrase('unexpected_error_occurred')); } $viewParams = array('ip' => $ip, 'host' => XenForo_Model_Ip::getHost($ip)); return $this->responseView('XenForo_ViewPublic_Online_GuestIp', 'online_guest_ip', $viewParams); }
/** * Does not currently handle redirects * * @param integer $start * @param array $options */ public function stepThreads($start, array $options) { $options = array_merge(array('limit' => 100, 'postDateStart' => 0, 'postLimit' => 800, 'max' => false), $options); $sDb = $this->_sourceDb; /* @var $model XenForo_Model_Import */ $model = $this->_importModel; if ($options['max'] === false) { $options['max'] = $sDb->fetchOne(' SELECT MAX(thread_id) FROM xf_thread '); } $threads = $sDb->fetchAll($sDb->limit("\r\r\n\t\t\t\tSELECT thread.*,\r\r\n\t\t\t\t\tIF (user.username IS NULL, thread.username, user.username) AS username\r\r\n\t\t\t\tFROM xf_thread AS thread\r\r\n\t\t\t\tLEFT JOIN xf_user AS user ON (user.user_id = thread.user_id)\r\r\n\t\t\t\tWHERE thread.thread_id >= " . $sDb->quote($start) . "\r\r\n\t\t\t\t\tAND thread.discussion_type <> 'redirect'\r\r\n\t\t\t", $options['limit'])); if (!$threads) { return true; } $next = 0; $total = 0; $totalPosts = 0; $nodeMap = $model->getImportContentMap('node'); $threadPrefixMap = $model->getImportContentMap('threadPrefix'); XenForo_Db::beginTransaction(); foreach ($threads as $thread) { $postDateStart = $options['postDateStart']; $next = $thread['thread_id'] + 1; $options['postDateStart'] = 0; $maxPosts = $options['postLimit'] - $totalPosts; $posts = $sDb->fetchAll($sDb->limit("\r\r\n\t\t\t\t\tSELECT post.*,\r\r\n\t\t\t\t\t\tIF (user.username IS NULL, post.username, user.username) AS username,\r\r\n\t\t\t\t\t\txf_ip.ip\r\r\n\t\t\t\t\tFROM xf_post AS post\r\r\n\t\t\t\t\tLEFT JOIN xf_user AS user ON (user.user_id = post.user_id)\r\r\n\t\t\t\t\tLEFT JOIN xf_ip ON (xf_ip.ip_id = post.ip_id)\r\r\n\t\t\t\t\tWHERE post.thread_id = " . $sDb->quote($thread['thread_id']) . "\r\r\n\t\t\t\t\t\tAND post.post_date > " . $sDb->quote($postDateStart) . "\r\r\n\t\t\t\t\tORDER BY post.post_date\r\r\n\t\t\t\t", $maxPosts)); if (!$posts) { if ($postDateStart) { // continuing thread but no remaining threads $total++; } continue; } if ($postDateStart) { // continuing already-imported thread $threadId = $model->mapThreadId($thread['thread_id']); $position = $this->_db->fetchOne(' SELECT MAX(position) FROM xf_post WHERE thread_id = ? ', $threadId); } else { $forumId = $this->_mapLookUp($nodeMap, $thread['node_id']); if (!$forumId) { continue; } $import = $this->_quickAssembleData($thread, array('node_id' => $forumId, 'title', 'reply_count', 'view_count', 'user_id' => $model->mapUserId($thread['user_id'], 0), 'username', 'post_date', 'sticky', 'discussion_state', 'discussion_open', 'discussion_type', 'prefix_id' => $this->_mapLookUp($threadPrefixMap, $thread['prefix_id'], 0))); $threadId = $model->importThread($thread['thread_id'], $import); if (!$threadId) { continue; } $subscriptions = $sDb->fetchPairs(' SELECT user_id, email_subscribe FROM xf_thread_watch WHERE thread_id = ? ', $thread['thread_id']); if ($subscriptions) { $userIdMap = $model->getImportContentMap('user', array_keys($subscriptions)); foreach ($subscriptions as $userId => $emailSubscribe) { if ($newUserId = $this->_mapLookUp($userIdMap, $userId)) { $model->importThreadWatch($newUserId, $threadId, $emailSubscribe); } } } } if ($threadId) { $quotedPostIds = array(); $quotedUserIds = array(); $userIdMap = $model->getUserIdsMapFromArray($posts, 'user_id'); foreach ($posts as $i => $post) { $import = $this->_quickAssembleData($post, array('thread_id' => $threadId, 'user_id' => $this->_mapLookUp($userIdMap, $post['user_id'], 0), 'username', 'post_date', 'message', 'ip' => XenForo_Helper_Ip::convertIpBinaryToString($post['ip']), 'message_state', 'attach_count', 'position', 'likes', 'last_edit_date', 'edit_count')); $post['new_post_id'] = $model->importPost($post['post_id'], $import); $options['postDateStart'] = $post['post_date']; $totalPosts++; // quotes if (stripos($post['message'], '[quote=') !== false) { if (preg_match_all('/\\[quote=("|\'|)(?P<username>[^,]*),post:\\s*(?P<post_id>\\d+)\\s*,\\s*member:\\s*(?P<user_id>\\d+)\\s*\\1\\]/siU', $post['message'], $quotes, PREG_SET_ORDER)) { $post['quotes'] = array(); foreach ($quotes as $quote) { $quotedPostId = intval($quote['post_id']); $quotedPostIds[] = $quotedPostId; $quotedUserId = intval($quote['user_id']); $quotedUserIds[] = $quotedUserId; $post['quotes'][$quote[0]] = array($quote['username'], $quotedPostId, $quotedUserId); } } } $posts[$i] = $post; } $postIdMap = empty($quotedPostIds) ? array() : $model->getImportContentMap('post', $quotedPostIds); $userIdMap = array_merge($userIdMap, empty($quotedUserIds) ? array() : $model->getImportContentMap('user', $quotedUserIds)); $db = XenForo_Application::getDb(); foreach ($posts as $post) { if (!empty($post['quotes'])) { $postQuotesRewrite = $this->_rewritePostQuotes($post['message'], $post['quotes'], $postIdMap, $userIdMap); if ($post['message'] != $postQuotesRewrite) { $db->update('xf_post', array('message' => $postQuotesRewrite), 'post_id = ' . $db->quote($post['new_post_id'])); } } } } if (count($posts) < $maxPosts) { // this thread completed $total++; $options['postDateStart'] = 0; } else { // pick up the thread on the next go-around break; } } if ($options['postDateStart']) { // thread not yet completed $next--; } XenForo_Db::commit(); $this->_session->incrementStepImportTotal($total); return array($next, $options, $this->_getProgressOutput($next - 1, $options['max'])); }
public function stepVisitorMessages($start, array $options) { $options = array_merge(array('limit' => 200, 'max' => false), $options); $sDb = $this->_sourceDb; $prefix = $this->_prefix; /* @var $model XenForo_Model_Import */ $model = $this->_importModel; if ($options['max'] === false) { $options['max'] = $sDb->fetchOne(' SELECT MAX(vmid) FROM ' . $prefix . 'visitormessage '); } $vms = $sDb->fetchAll($sDb->limit(' SELECT vm.*, IF(user.username IS NULL, vm.postusername, user.username) AS username FROM ' . $prefix . 'visitormessage AS vm LEFT JOIN ' . $prefix . 'user AS user ON (vm.postuserid = user.userid) WHERE vm.vmid > ' . $sDb->quote($start) . ' ORDER BY vm.vmid ', $options['limit'])); if (!$vms) { return true; } $next = 0; $total = 0; $userIds = array(); foreach ($vms as $vm) { $userIds[] = $vm['userid']; $userIds[] = $vm['postuserid']; } $userIdMap = $model->getImportContentMap('user', $userIds); XenForo_Db::beginTransaction(); $formatter = XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_Text'); $parser = XenForo_BbCode_Parser::create($formatter); foreach ($vms as $vm) { $next = $vm['vmid']; if (trim($vm['postusername']) === '') { continue; } $profileUserId = $this->_mapLookUp($userIdMap, $vm['userid']); if (!$profileUserId) { continue; } $postUserId = $this->_mapLookUp($userIdMap, $vm['postuserid'], 0); $import = array('profile_user_id' => $profileUserId, 'user_id' => $postUserId, 'username' => $this->_convertToUtf8($vm['postusername'], true), 'post_date' => $vm['dateline'], 'message' => $parser->render($this->_convertToUtf8($vm['pagetext'])), 'ip' => XenForo_Helper_Ip::convertIpBinaryToString($vm['ipaddress'])); switch ($vm['state']) { case 'deleted': $import['message_state'] = 'deleted'; break; case 'moderation': $import['message_state'] = 'moderated'; break; default: $import['message_state'] = 'visible'; } if ($model->importProfilePost($vm['vmid'], $import)) { $total++; } } XenForo_Db::commit(); $this->_session->incrementStepImportTotal($total); return array($next, $options, $this->_getProgressOutput($next, $options['max'])); }
public static function helperIp($ip) { $res = XenForo_Helper_Ip::convertIpBinaryToString($ip); return htmlspecialchars($res ? $res : $ip, ENT_COMPAT, 'utf-8'); }
public function prepareAdminLogEntry(array $entry) { $entry['ipAddress'] = $entry['ip_address'] ? XenForo_Helper_Ip::convertIpBinaryToString($entry['ip_address']) : ''; return $entry; }
/** * Searches for records of users using any of the IP addresses logged by the specified user * * @param integer ID of the user to check against * @param integer Number of days to look back in the logs * * @return array */ public function getSharedIpUsers($userId, $logDays) { $db = $this->_getDb(); // written this way due to mysql's ridiculous sub-query performance $recentIps = $db->fetchCol($db->limit(' SELECT DISTINCT ip FROM xf_ip WHERE user_id = ? AND log_date > ? ', 500), array($userId, XenForo_Application::$time - $logDays * 86400)); if (!$recentIps) { return array(); } $ipLogs = $db->fetchAll($db->limit(' SELECT * FROM xf_ip WHERE ip IN (' . $db->quote($recentIps) . ') AND user_id <> ? AND user_id > 0 AND log_date > ? ORDER BY log_date DESC ', 1000), array($userId, XenForo_Application::$time - $logDays * 86400)); $userIpLogs = array(); foreach ($ipLogs as $ipLog) { $ipLog['ip_address'] = XenForo_Helper_Ip::convertIpBinaryToString($ipLog['ip']); $userIpLogs[$ipLog['user_id']][] = $ipLog; } $userRecords = $this->getModelFromCache('XenForo_Model_User')->getUsersByIds(array_keys($userIpLogs), array('join' => XenForo_Model_User::FETCH_LAST_ACTIVITY)); $users = array(); foreach ($userIpLogs as $userId => $ipLog) { if (!isset($userRecords[$userId])) { continue; } $users[$userId] = $userRecords[$userId]; $users[$userId]['ipLogs'] = $ipLog; } return $users; }
public function actionUsermap() { if (!function_exists('geoip_record_by_name')) { throw $this->responseException($this->responseError(new XenForo_Phrase('geoip_not_installed'), 503)); } elseif (!geoip_db_avail(GEOIP_CITY_EDITION_REV0)) { throw $this->responseException($this->responseError(str_replace('{geoip_city_path}', geoip_db_filename(GEOIP_CITY_EDITION_REV0), new XenForo_Phrase('geoip_missing_database')), 503)); } $sessionModel = $this->_getSessionModel(); $bypassUserPrivacy = $this->_getUserModel()->canBypassUserPrivacy(); $conditions = array('cutOff' => array('>', $sessionModel->getOnlineStatusTimeout()), 'getInvisible' => $bypassUserPrivacy, 'getUnconfirmed' => $bypassUserPrivacy, 'forceInclude' => $bypassUserPrivacy ? false : XenForo_Visitor::getUserId()); $onlineUsers = $sessionModel->getSessionActivityRecords($conditions, array('perPage' => 5000, 'page' => 1, 'join' => XenForo_Model_Session::FETCH_USER, 'order' => 'view_date')); $users = $used_ip = $users_new = $users_added = $duplicate_location = array(); $users_newest = array(0 => array(), 1 => array(), 3 => array()); if (count($onlineUsers)) { foreach ($onlineUsers as $key => $user) { $user['ip'] = XenForo_Helper_Ip::convertIpBinaryToString($user['ip']); $onlineUsers[$key]['user_id'] = $user['user_id'] = intval($onlineUsers[$key]['user_id']); $users["{$user['user_id']}-{$user['ip']}"] = $user; } } $dataRegistryModel = $this->_getDataRegistryModel(); $users_cached = $dataRegistryModel->get('userMap'); if (count($users)) { foreach ($users as $key => $user) { if (isset($users_cached[$key])) { // Read from cache $type = substr($users_cached[$key], -1); if ($type < 3) { // Prioritize admins/mods and registered users if ($user['is_staff']) { $type = 3; } elseif ($user['user_id']) { $type = 0; } } $users_new[$key] = substr($users_cached[$key], 0, -1) . $type; } else { $user_location = @geoip_record_by_name($user['ip']); if (!($user_location['longitude'] == 0 && $user_location['latitude'] == 0)) { $type = $user['is_staff'] ? 3 : ($user['user_id'] ? 0 : ($user['robot_key'] ? 2 : 1)); if (!isset($used_ip[$user_location['longitude'] . ',' . $user_location['latitude']])) { $string = $user_location['longitude'] . ',' . $user_location['latitude'] . ',' . $type; if ($type < 2) { $users_new = @array_merge(array($key => $string), $users_new); } else { $users_new[$key] = $string; } $used_ip[$user_location['longitude'] . ',' . $user_location['latitude']] = true; } else { $duplicate_location = @array_merge(array($key => $string), $users_new); } } else { $duplicate_location = @array_merge(array($key => $string), $users_new); } } } } $dataRegistryModel->set('userMap', @array_merge((array) $users_new, (array) $duplicate_location)); foreach ($users_new as $key => $plot) { $type = substr($plot, -1); $users_newest[$type][] = substr($plot, 0, -2); } foreach ($users_newest as $key => $group) { $users_newest[$key] = @array_flip(@array_flip($users_newest[$key])); } $users_new = array(); foreach (array(3, 0, 2, 1) as $type) { if (!empty($users_newest[$type])) { foreach ($users_newest[$type] as $plot) { if (!isset($users_added[$plot])) { $users_new[] = $plot . ',' . $type; $users_added[$plot] = true; } } } } $js_array = 'DigitalPointUserMap._UserMap.allPoints = new Array ('; if (count($users_new)) { foreach ($users_new as $user) { $js_array .= "[{$user}],"; } $js_array = substr($js_array, 0, -1) . ')'; } else { $js_array .= ')'; } $viewParams = array('js_array' => $js_array, 'user_location' => @geoip_record_by_name($_SERVER['REMOTE_ADDR'])); return $this->responseView('DigitalPointUserMap_ViewPubic_UserMap_Index', 'usermap_index', $viewParams); }