Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordfenc.../lib
File: wfLog.php
<?php
[0] Fix | Delete
require_once(dirname(__FILE__) . '/wfDB.php');
[1] Fix | Delete
require_once(dirname(__FILE__) . '/wfUtils.php');
[2] Fix | Delete
require_once(dirname(__FILE__) . '/wfBrowscap.php');
[3] Fix | Delete
class wfLog {
[4] Fix | Delete
public $canLogHit = true;
[5] Fix | Delete
private $effectiveUserID = 0;
[6] Fix | Delete
private $hitsTable = '';
[7] Fix | Delete
private $apiKey = '';
[8] Fix | Delete
private $wp_version = '';
[9] Fix | Delete
private $db = false;
[10] Fix | Delete
private $googlePattern = '/\.(?:googlebot\.com|google\.[a-z]{2,3}|google\.[a-z]{2}\.[a-z]{2}|1e100\.net)$/i';
[11] Fix | Delete
private $loginsTable, $statusTable;
[12] Fix | Delete
private static $gbSafeCache = array();
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* @var wfRequestModel
[16] Fix | Delete
*/
[17] Fix | Delete
private $currentRequest;
[18] Fix | Delete
[19] Fix | Delete
public static function shared() {
[20] Fix | Delete
static $_shared = null;
[21] Fix | Delete
if ($_shared === null) {
[22] Fix | Delete
$_shared = new wfLog(wfConfig::get('apiKey'), wfUtils::getWPVersion());
[23] Fix | Delete
}
[24] Fix | Delete
return $_shared;
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Returns whether or not we have a cached record identifying the visitor as human. This is used both by certain
[29] Fix | Delete
* rate limiting features and by Live Traffic.
[30] Fix | Delete
*
[31] Fix | Delete
* @param bool|string $IP
[32] Fix | Delete
* @param bool|string $UA
[33] Fix | Delete
* @return bool
[34] Fix | Delete
*/
[35] Fix | Delete
public static function isHumanRequest($IP = false, $UA = false) {
[36] Fix | Delete
global $wpdb;
[37] Fix | Delete
[38] Fix | Delete
if ($IP === false) {
[39] Fix | Delete
$IP = wfUtils::getIP();
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
if ($UA === false || $UA === null) {
[43] Fix | Delete
$UA = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
$ipHex = wfDB::binaryValueToSQLHex(wfUtils::inet_pton($IP));
[47] Fix | Delete
$table = wfDB::networkTable('wfLiveTrafficHuman');
[48] Fix | Delete
if ($wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$table} WHERE IP = {$ipHex} AND identifier = %s AND expiration >= UNIX_TIMESTAMP()", hash('sha256', $UA, true)))) {
[49] Fix | Delete
return true;
[50] Fix | Delete
}
[51] Fix | Delete
return false;
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Creates a cache record for the requester to tag it as human.
[56] Fix | Delete
*
[57] Fix | Delete
* @param bool|string $IP
[58] Fix | Delete
* @param bool|string $UA
[59] Fix | Delete
* @return bool
[60] Fix | Delete
*/
[61] Fix | Delete
public static function cacheHumanRequester($IP = false, $UA = false) {
[62] Fix | Delete
global $wpdb;
[63] Fix | Delete
[64] Fix | Delete
if ($IP === false) {
[65] Fix | Delete
$IP = wfUtils::getIP();
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
if ($UA === false) {
[69] Fix | Delete
$UA = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
$ipHex = wfDB::binaryValueToSQLHex(wfUtils::inet_pton($IP));
[73] Fix | Delete
$table = wfDB::networkTable('wfLiveTrafficHuman');
[74] Fix | Delete
if ($wpdb->get_var($wpdb->prepare("INSERT IGNORE INTO {$table} (IP, identifier, expiration) VALUES ({$ipHex}, %s, UNIX_TIMESTAMP() + 86400)", hash('sha256', $UA, true)))) {
[75] Fix | Delete
return true;
[76] Fix | Delete
}
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Prunes any expired records from the human cache.
[81] Fix | Delete
*/
[82] Fix | Delete
public static function trimHumanCache() {
[83] Fix | Delete
global $wpdb;
[84] Fix | Delete
$table = wfDB::networkTable('wfLiveTrafficHuman');
[85] Fix | Delete
$wpdb->query("DELETE FROM {$table} WHERE `expiration` < UNIX_TIMESTAMP()");
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
public function __construct($apiKey, $wp_version){
[89] Fix | Delete
$this->apiKey = $apiKey;
[90] Fix | Delete
$this->wp_version = $wp_version;
[91] Fix | Delete
$this->hitsTable = wfDB::networkTable('wfHits');
[92] Fix | Delete
$this->loginsTable = wfDB::networkTable('wfLogins');
[93] Fix | Delete
$this->statusTable = wfDB::networkTable('wfStatus');
[94] Fix | Delete
[95] Fix | Delete
add_filter('determine_current_user', array($this, '_userIDDetermined'), 99, 1);
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
public function _userIDDetermined($userID) {
[99] Fix | Delete
//Needed because the REST API will clear the authenticated user if it fails a nonce check on the request
[100] Fix | Delete
$this->effectiveUserID = (int) $userID;
[101] Fix | Delete
return $userID;
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
public function initLogRequest() {
[105] Fix | Delete
if ($this->currentRequest === null) {
[106] Fix | Delete
$this->currentRequest = new wfRequestModel();
[107] Fix | Delete
[108] Fix | Delete
$this->currentRequest->ctime = sprintf('%.6f', microtime(true));
[109] Fix | Delete
$this->currentRequest->statusCode = 200;
[110] Fix | Delete
$this->currentRequest->isGoogle = (wfCrawl::isGoogleCrawler() ? 1 : 0);
[111] Fix | Delete
$this->currentRequest->IP = wfUtils::inet_pton(wfUtils::getIP());
[112] Fix | Delete
$this->currentRequest->userID = $this->getCurrentUserID();
[113] Fix | Delete
$this->currentRequest->URL = wfUtils::getRequestedURL();
[114] Fix | Delete
$this->currentRequest->referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
[115] Fix | Delete
$this->currentRequest->UA = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
[116] Fix | Delete
$this->currentRequest->jsRun = 0;
[117] Fix | Delete
[118] Fix | Delete
add_action('wp_loaded', array($this, 'actionSetRequestJSEnabled'));
[119] Fix | Delete
add_action('init', array($this, 'actionSetRequestOnInit'), 9999);
[120] Fix | Delete
[121] Fix | Delete
if (function_exists('register_shutdown_function')) {
[122] Fix | Delete
register_shutdown_function(array($this, 'logHit'));
[123] Fix | Delete
}
[124] Fix | Delete
}
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
public function actionSetRequestJSEnabled() {
[128] Fix | Delete
if (get_current_user_id() > 0) {
[129] Fix | Delete
$this->currentRequest->jsRun = true;
[130] Fix | Delete
return;
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
$IP = wfUtils::getIP();
[134] Fix | Delete
$UA = $this->currentRequest->UA;
[135] Fix | Delete
$this->currentRequest->jsRun = wfLog::isHumanRequest($IP, $UA);
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* CloudFlare's plugin changes $_SERVER['REMOTE_ADDR'] on init.
[140] Fix | Delete
*/
[141] Fix | Delete
public function actionSetRequestOnInit() {
[142] Fix | Delete
$this->currentRequest->IP = wfUtils::inet_pton(wfUtils::getIP());
[143] Fix | Delete
$this->currentRequest->userID = $this->getCurrentUserID();
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* @return wfRequestModel
[148] Fix | Delete
*/
[149] Fix | Delete
public function getCurrentRequest() {
[150] Fix | Delete
return $this->currentRequest;
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
public function logLogin($action, $fail, $username){
[154] Fix | Delete
if(! $username){
[155] Fix | Delete
return;
[156] Fix | Delete
}
[157] Fix | Delete
$user = get_user_by('login', $username);
[158] Fix | Delete
$userID = 0;
[159] Fix | Delete
if($user){
[160] Fix | Delete
$userID = $user->ID;
[161] Fix | Delete
if(! $userID){
[162] Fix | Delete
return;
[163] Fix | Delete
}
[164] Fix | Delete
}
[165] Fix | Delete
else {
[166] Fix | Delete
$user = get_user_by('email', $username);
[167] Fix | Delete
if ($user) {
[168] Fix | Delete
$userID = $user->ID;
[169] Fix | Delete
if (!$userID) {
[170] Fix | Delete
return;
[171] Fix | Delete
}
[172] Fix | Delete
}
[173] Fix | Delete
}
[174] Fix | Delete
// change the action flag here if the user does not exist.
[175] Fix | Delete
if ($action == 'loginFailValidUsername' && $userID == 0) {
[176] Fix | Delete
$action = 'loginFailInvalidUsername';
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
$hitID = 0;
[180] Fix | Delete
if ($this->currentRequest !== null) {
[181] Fix | Delete
$this->currentRequest->userID = $userID;
[182] Fix | Delete
$this->currentRequest->action = $action;
[183] Fix | Delete
$this->currentRequest->save();
[184] Fix | Delete
$hitID = $this->currentRequest->getPrimaryKey();
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
//Else userID stays 0 but we do log this even though the user doesn't exist.
[188] Fix | Delete
$ipHex = wfDB::binaryValueToSQLHex(wfUtils::inet_pton(wfUtils::getIP()));
[189] Fix | Delete
$this->getDB()->queryWrite("insert into " . $this->loginsTable . " (hitID, ctime, fail, action, username, userID, IP, UA) values (%d, %f, %d, '%s', '%s', %s, {$ipHex}, '%s')",
[190] Fix | Delete
$hitID,
[191] Fix | Delete
sprintf('%.6f', microtime(true)),
[192] Fix | Delete
$fail,
[193] Fix | Delete
$action,
[194] Fix | Delete
$username,
[195] Fix | Delete
$userID,
[196] Fix | Delete
(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '')
[197] Fix | Delete
);
[198] Fix | Delete
}
[199] Fix | Delete
private function getCurrentUserID(){
[200] Fix | Delete
if (!function_exists('get_current_user_id') || !defined('AUTH_COOKIE')) { //If pluggable.php is loaded early by some other plugin on a multisite installation, it leads to an error because AUTH_COOKIE is undefined and WP doesn't check for it first
[201] Fix | Delete
return 0;
[202] Fix | Delete
}
[203] Fix | Delete
$id = get_current_user_id();
[204] Fix | Delete
return $id ? $id : 0;
[205] Fix | Delete
}
[206] Fix | Delete
public function logLeechAndBlock($type) { //404 or hit
[207] Fix | Delete
if (!wfRateLimit::mightRateLimit($type)) {
[208] Fix | Delete
return;
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
wfRateLimit::countHit($type, wfUtils::getIP());
[212] Fix | Delete
[213] Fix | Delete
if (wfRateLimit::globalRateLimit()->shouldEnforce($type)) {
[214] Fix | Delete
$this->takeBlockingAction('maxGlobalRequests', __("Exceeded the maximum global requests per minute for crawlers or humans.", 'wordfence'));
[215] Fix | Delete
}
[216] Fix | Delete
else if (wfRateLimit::crawlerViewsRateLimit()->shouldEnforce($type)) {
[217] Fix | Delete
$this->takeBlockingAction('maxRequestsCrawlers', __("Exceeded the maximum number of requests per minute for crawlers.", 'wordfence')); //may not exit
[218] Fix | Delete
}
[219] Fix | Delete
else if (wfRateLimit::crawler404sRateLimit()->shouldEnforce($type)) {
[220] Fix | Delete
$this->takeBlockingAction('max404Crawlers', __("Exceeded the maximum number of page not found errors per minute for a crawler.", 'wordfence'));
[221] Fix | Delete
}
[222] Fix | Delete
else if (wfRateLimit::humanViewsRateLimit()->shouldEnforce($type)) {
[223] Fix | Delete
$this->takeBlockingAction('maxRequestsHumans', __("Exceeded the maximum number of page requests per minute for humans.", 'wordfence'));
[224] Fix | Delete
}
[225] Fix | Delete
else if (wfRateLimit::human404sRateLimit()->shouldEnforce($type)) {
[226] Fix | Delete
$this->takeBlockingAction('max404Humans', __("Exceeded the maximum number of page not found errors per minute for humans.", 'wordfence'));
[227] Fix | Delete
}
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
public function tagRequestForBlock($reason, $wfsn = false) {
[231] Fix | Delete
if ($this->currentRequest !== null) {
[232] Fix | Delete
$this->currentRequest->statusCode = 403;
[233] Fix | Delete
$this->currentRequest->action = 'blocked:' . ($wfsn ? 'wfsn' : 'wordfence');
[234] Fix | Delete
$this->currentRequest->actionDescription = $reason;
[235] Fix | Delete
}
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
public function tagRequestForLockout($reason) {
[239] Fix | Delete
if ($this->currentRequest !== null) {
[240] Fix | Delete
$this->currentRequest->statusCode = 503;
[241] Fix | Delete
$this->currentRequest->action = 'lockedOut';
[242] Fix | Delete
$this->currentRequest->actionDescription = $reason;
[243] Fix | Delete
}
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
/**
[247] Fix | Delete
* @return bool|int
[248] Fix | Delete
*/
[249] Fix | Delete
public function logHit() {
[250] Fix | Delete
$liveTrafficEnabled = wfConfig::liveTrafficEnabled();
[251] Fix | Delete
$action = $this->currentRequest->action;
[252] Fix | Delete
$logHitOK = $this->logHitOK();
[253] Fix | Delete
if (!$logHitOK) {
[254] Fix | Delete
return false;
[255] Fix | Delete
}
[256] Fix | Delete
if (!$liveTrafficEnabled && !$action) {
[257] Fix | Delete
return false;
[258] Fix | Delete
}
[259] Fix | Delete
if ($this->currentRequest !== null) {
[260] Fix | Delete
if ($this->currentRequest->save()) {
[261] Fix | Delete
return $this->currentRequest->getPrimaryKey();
[262] Fix | Delete
}
[263] Fix | Delete
}
[264] Fix | Delete
return false;
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
public function getHits($hitType /* 'hits' or 'logins' */, $type, $afterTime, $limit = 50, $IP = false){
[268] Fix | Delete
global $wpdb;
[269] Fix | Delete
$IPSQL = "";
[270] Fix | Delete
if($IP){
[271] Fix | Delete
$ipHex = wfDB::binaryValueToSQLHex(wfUtils::inet_pton($IP));
[272] Fix | Delete
$IPSQL = " and IP={$ipHex} ";
[273] Fix | Delete
$sqlArgs = array($afterTime, $limit);
[274] Fix | Delete
} else {
[275] Fix | Delete
$sqlArgs = array($afterTime, $limit);
[276] Fix | Delete
}
[277] Fix | Delete
if($hitType == 'hits'){
[278] Fix | Delete
$securityOnly = !wfConfig::liveTrafficEnabled();
[279] Fix | Delete
$delayedHumanBotFiltering = false;
[280] Fix | Delete
[281] Fix | Delete
if($type == 'hit'){
[282] Fix | Delete
$typeSQL = " ";
[283] Fix | Delete
} else if($type == 'crawler'){
[284] Fix | Delete
if ($securityOnly) {
[285] Fix | Delete
$typeSQL = " ";
[286] Fix | Delete
$delayedHumanBotFiltering = true;
[287] Fix | Delete
}
[288] Fix | Delete
else {
[289] Fix | Delete
$now = time();
[290] Fix | Delete
$typeSQL = " and jsRun = 0 and {$now} - ctime > 30 ";
[291] Fix | Delete
}
[292] Fix | Delete
} else if($type == 'gCrawler'){
[293] Fix | Delete
$typeSQL = " and isGoogle = 1 ";
[294] Fix | Delete
} else if($type == '404'){
[295] Fix | Delete
$typeSQL = " and statusCode = 404 ";
[296] Fix | Delete
} else if($type == 'human'){
[297] Fix | Delete
if ($securityOnly) {
[298] Fix | Delete
$typeSQL = " ";
[299] Fix | Delete
$delayedHumanBotFiltering = true;
[300] Fix | Delete
}
[301] Fix | Delete
else {
[302] Fix | Delete
$typeSQL = " and jsRun = 1 ";
[303] Fix | Delete
}
[304] Fix | Delete
} else if($type == 'ruser'){
[305] Fix | Delete
$typeSQL = " and userID > 0 ";
[306] Fix | Delete
} else {
[307] Fix | Delete
wordfence::status(1, 'error', sprintf(/* translators: Error message. */ __("Invalid log type to wfLog: %s", 'wordfence'), $type));
[308] Fix | Delete
return false;
[309] Fix | Delete
}
[310] Fix | Delete
array_unshift($sqlArgs, "select h.*, u.display_name from {$this->hitsTable} h
[311] Fix | Delete
LEFT JOIN {$wpdb->users} u on h.userID = u.ID
[312] Fix | Delete
where ctime > %f $IPSQL $typeSQL order by ctime desc limit %d");
[313] Fix | Delete
$results = call_user_func_array(array($this->getDB(), 'querySelect'), $sqlArgs);
[314] Fix | Delete
[315] Fix | Delete
if ($delayedHumanBotFiltering) {
[316] Fix | Delete
$browscap = wfBrowscap::shared();
[317] Fix | Delete
foreach ($results as $index => $res) {
[318] Fix | Delete
if ($res['UA']) {
[319] Fix | Delete
$b = $browscap->getBrowser($res['UA']);
[320] Fix | Delete
if ($b && $b['Parent'] != 'DefaultProperties') {
[321] Fix | Delete
$jsRun = wfUtils::truthyToBoolean($res['jsRun']);
[322] Fix | Delete
if (!wfConfig::liveTrafficEnabled() && !$jsRun) {
[323] Fix | Delete
$jsRun = !(isset($b['Crawler']) && $b['Crawler']);
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
if ($type == 'crawler' && $jsRun || $type == 'human' && !$jsRun) {
[327] Fix | Delete
unset($results[$index]);
[328] Fix | Delete
}
[329] Fix | Delete
}
[330] Fix | Delete
}
[331] Fix | Delete
}
[332] Fix | Delete
}
[333] Fix | Delete
[334] Fix | Delete
} else if($hitType == 'logins'){
[335] Fix | Delete
array_unshift($sqlArgs, "select l.*, u.display_name from {$this->loginsTable} l
[336] Fix | Delete
LEFT JOIN {$wpdb->users} u on l.userID = u.ID
[337] Fix | Delete
where ctime > %f $IPSQL order by ctime desc limit %d");
[338] Fix | Delete
$results = call_user_func_array(array($this->getDB(), 'querySelect'), $sqlArgs );
[339] Fix | Delete
[340] Fix | Delete
} else {
[341] Fix | Delete
wordfence::status(1, 'error', sprintf(/* translators: Error message. */ __("getHits got invalid hitType: %s", 'wordfence'), $hitType));
[342] Fix | Delete
return false;
[343] Fix | Delete
}
[344] Fix | Delete
$this->processGetHitsResults($type, $results);
[345] Fix | Delete
return $results;
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
private function processActionDescription($description) {
[349] Fix | Delete
switch ($description) {
[350] Fix | Delete
case wfWAFIPBlocksController::WFWAF_BLOCK_UAREFIPRANGE:
[351] Fix | Delete
return __('UA/Hostname/Referrer/IP Range not allowed', 'wordfence');
[352] Fix | Delete
default:
[353] Fix | Delete
return $description;
[354] Fix | Delete
}
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
/**
[358] Fix | Delete
* @param string $type
[359] Fix | Delete
* @param array $results
[360] Fix | Delete
* @throws Exception
[361] Fix | Delete
*/
[362] Fix | Delete
public function processGetHitsResults($type, &$results) {
[363] Fix | Delete
$serverTime = $this->getDB()->querySingle("select unix_timestamp()");
[364] Fix | Delete
[365] Fix | Delete
$this->resolveIPs($results);
[366] Fix | Delete
$ourURL = parse_url(site_url());
[367] Fix | Delete
$ourHost = strtolower($ourURL['host']);
[368] Fix | Delete
$ourHost = preg_replace('/^www\./i', '', $ourHost);
[369] Fix | Delete
$browscap = wfBrowscap::shared();
[370] Fix | Delete
[371] Fix | Delete
$patternBlocks = wfBlock::patternBlocks(true);
[372] Fix | Delete
[373] Fix | Delete
foreach($results as &$res){
[374] Fix | Delete
$res['type'] = $type;
[375] Fix | Delete
$res['IP'] = wfUtils::inet_ntop($res['IP']);
[376] Fix | Delete
$res['timeAgo'] = wfUtils::makeTimeAgo($serverTime - $res['ctime']);
[377] Fix | Delete
$res['blocked'] = false;
[378] Fix | Delete
$res['rangeBlocked'] = false;
[379] Fix | Delete
$res['ipRangeID'] = -1;
[380] Fix | Delete
if (array_key_exists('actionDescription', $res))
[381] Fix | Delete
$res['actionDescription'] = $this->processActionDescription($res['actionDescription']);
[382] Fix | Delete
[383] Fix | Delete
$ipBlock = wfBlock::findIPBlock($res['IP']);
[384] Fix | Delete
if ($ipBlock !== false) {
[385] Fix | Delete
$res['blocked'] = true;
[386] Fix | Delete
$res['blockID'] = $ipBlock->id;
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
foreach ($patternBlocks as $b) {
[390] Fix | Delete
if (empty($b->ipRange)) { continue; }
[391] Fix | Delete
$range = new wfUserIPRange($b->ipRange);
[392] Fix | Delete
if ($range->isIPInRange($res['IP'])) {
[393] Fix | Delete
$res['rangeBlocked'] = true;
[394] Fix | Delete
$res['ipRangeID'] = $b->id;
[395] Fix | Delete
break;
[396] Fix | Delete
}
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
$res['extReferer'] = false;
[400] Fix | Delete
if(isset( $res['referer'] ) && $res['referer']){
[401] Fix | Delete
if(wfUtils::hasXSS($res['referer'] )){ //filtering out XSS
[402] Fix | Delete
$res['referer'] = '';
[403] Fix | Delete
}
[404] Fix | Delete
}
[405] Fix | Delete
if( isset( $res['referer'] ) && $res['referer']){
[406] Fix | Delete
$refURL = parse_url($res['referer']);
[407] Fix | Delete
if(is_array($refURL) && isset($refURL['host']) && $refURL['host']){
[408] Fix | Delete
$refHost = strtolower(preg_replace('/^www\./i', '', $refURL['host']));
[409] Fix | Delete
if($refHost != $ourHost){
[410] Fix | Delete
$res['extReferer'] = true;
[411] Fix | Delete
//now extract search terms
[412] Fix | Delete
$q = false;
[413] Fix | Delete
if(preg_match('/(?:google|bing|alltheweb|aol|ask)\./i', $refURL['host'])){
[414] Fix | Delete
$q = 'q';
[415] Fix | Delete
} else if(stristr($refURL['host'], 'yahoo.')){
[416] Fix | Delete
$q = 'p';
[417] Fix | Delete
} else if(stristr($refURL['host'], 'baidu.')){
[418] Fix | Delete
$q = 'wd';
[419] Fix | Delete
}
[420] Fix | Delete
if($q){
[421] Fix | Delete
$queryVars = array();
[422] Fix | Delete
if( isset( $refURL['query'] ) ) {
[423] Fix | Delete
parse_str($refURL['query'], $queryVars);
[424] Fix | Delete
if(isset($queryVars[$q])){
[425] Fix | Delete
$res['searchTerms'] = urlencode($queryVars[$q]);
[426] Fix | Delete
}
[427] Fix | Delete
}
[428] Fix | Delete
}
[429] Fix | Delete
}
[430] Fix | Delete
}
[431] Fix | Delete
if($res['extReferer']){
[432] Fix | Delete
if ( isset( $referringPage ) && stristr( $referringPage['host'], 'google.' ) )
[433] Fix | Delete
{
[434] Fix | Delete
parse_str( $referringPage['query'], $queryVars );
[435] Fix | Delete
// echo $queryVars['q']; // This is the search term used
[436] Fix | Delete
}
[437] Fix | Delete
}
[438] Fix | Delete
}
[439] Fix | Delete
$res['browser'] = false;
[440] Fix | Delete
if($res['UA']){
[441] Fix | Delete
$b = $browscap->getBrowser($res['UA']);
[442] Fix | Delete
if($b && $b['Parent'] != 'DefaultProperties'){
[443] Fix | Delete
$res['browser'] = array(
[444] Fix | Delete
'browser' => !empty($b['Browser']) ? $b['Browser'] : "",
[445] Fix | Delete
'version' => !empty($b['Version']) ? $b['Version'] : "",
[446] Fix | Delete
'platform' => !empty($b['Platform']) ? $b['Platform'] : "",
[447] Fix | Delete
'isMobile' => !empty($b['isMobileDevice']) ? $b['isMobileDevice'] : "",
[448] Fix | Delete
'isCrawler' => !empty($b['Crawler']) ? $b['Crawler'] : "",
[449] Fix | Delete
);
[450] Fix | Delete
[451] Fix | Delete
if (isset($res['jsRun']) && !wfConfig::liveTrafficEnabled() && !wfUtils::truthyToBoolean($res['jsRun'])) {
[452] Fix | Delete
$res['jsRun'] = !(isset($b['Crawler']) && $b['Crawler']) ? '1' : '0';
[453] Fix | Delete
}
[454] Fix | Delete
}
[455] Fix | Delete
else {
[456] Fix | Delete
$IP = wfUtils::getIP();
[457] Fix | Delete
$res['browser'] = array(
[458] Fix | Delete
'isCrawler' => !wfLog::isHumanRequest($IP, $res['UA']) ? 'true' : ''
[459] Fix | Delete
);
[460] Fix | Delete
}
[461] Fix | Delete
}
[462] Fix | Delete
[463] Fix | Delete
[464] Fix | Delete
if($res['userID']){
[465] Fix | Delete
$ud = get_userdata($res['userID']);
[466] Fix | Delete
if($ud){
[467] Fix | Delete
$res['user'] = array(
[468] Fix | Delete
'editLink' => wfUtils::editUserLink($res['userID']),
[469] Fix | Delete
'display_name' => $res['display_name'],
[470] Fix | Delete
'ID' => $res['userID']
[471] Fix | Delete
);
[472] Fix | Delete
}
[473] Fix | Delete
} else {
[474] Fix | Delete
$res['user'] = false;
[475] Fix | Delete
}
[476] Fix | Delete
}
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
public function resolveIPs(&$results){
[480] Fix | Delete
if(sizeof($results) < 1){ return; }
[481] Fix | Delete
$IPs = array();
[482] Fix | Delete
foreach($results as &$res){
[483] Fix | Delete
if($res['IP']){ //Can also be zero in case of non IP events
[484] Fix | Delete
$IPs[] = $res['IP'];
[485] Fix | Delete
}
[486] Fix | Delete
}
[487] Fix | Delete
$IPLocs = wfUtils::getIPsGeo($IPs); //Creates an array with IP as key and data as value
[488] Fix | Delete
[489] Fix | Delete
foreach($results as &$res){
[490] Fix | Delete
$ip_printable = wfUtils::inet_ntop($res['IP']);
[491] Fix | Delete
if(isset($IPLocs[$ip_printable])){
[492] Fix | Delete
$res['loc'] = $IPLocs[$ip_printable];
[493] Fix | Delete
} else {
[494] Fix | Delete
$res['loc'] = false;
[495] Fix | Delete
}
[496] Fix | Delete
}
[497] Fix | Delete
}
[498] Fix | Delete
public function logHitOK(){
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function