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: wfDashboard.php
<?php
[0] Fix | Delete
[1] Fix | Delete
class wfDashboard {
[2] Fix | Delete
const SCAN_SUCCESS = 1;
[3] Fix | Delete
const SCAN_FAILED = 0;
[4] Fix | Delete
const SCAN_NEVER_RAN = -1;
[5] Fix | Delete
const SCAN_WARNINGS = 2;
[6] Fix | Delete
[7] Fix | Delete
const FEATURE_ENABLED = 1;
[8] Fix | Delete
const FEATURE_DISABLED = 0;
[9] Fix | Delete
const FEATURE_PREMIUM = -1;
[10] Fix | Delete
[11] Fix | Delete
public $scanLastCompletion;
[12] Fix | Delete
public $scanLastStatusMessage;
[13] Fix | Delete
public $scanLastStatus;
[14] Fix | Delete
[15] Fix | Delete
public $notifications = array();
[16] Fix | Delete
[17] Fix | Delete
public $features = array();
[18] Fix | Delete
[19] Fix | Delete
public $lastGenerated;
[20] Fix | Delete
[21] Fix | Delete
public $tdfCommunity;
[22] Fix | Delete
public $tdfPremium;
[23] Fix | Delete
[24] Fix | Delete
public $ips24h;
[25] Fix | Delete
public $ips7d;
[26] Fix | Delete
public $ips30d;
[27] Fix | Delete
[28] Fix | Delete
public $loginsSuccess;
[29] Fix | Delete
public $loginsFail;
[30] Fix | Delete
[31] Fix | Delete
public $localBlocks;
[32] Fix | Delete
[33] Fix | Delete
public $networkBlock24h;
[34] Fix | Delete
public $networkBlock7d;
[35] Fix | Delete
public $networkBlock30d;
[36] Fix | Delete
[37] Fix | Delete
public $countriesLocal;
[38] Fix | Delete
public $countriesNetwork;
[39] Fix | Delete
public $wordfenceCentralConnected;
[40] Fix | Delete
public $wordfenceCentralConnectTime;
[41] Fix | Delete
public $wordfenceCentralConnectEmail;
[42] Fix | Delete
public $wordfenceCentralDisconnected;
[43] Fix | Delete
public $wordfenceCentralDisconnectTime;
[44] Fix | Delete
public $wordfenceCentralDisconnectEmail;
[45] Fix | Delete
[46] Fix | Delete
public static function processDashboardResponse($data) {
[47] Fix | Delete
if (isset($data['notifications'])) {
[48] Fix | Delete
foreach ($data['notifications'] as $n) {
[49] Fix | Delete
if (!isset($n['id']) || !isset($n['priority']) || !isset($n['html'])) {
[50] Fix | Delete
continue;
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
new wfNotification($n['id'], $n['priority'], $n['html'], (isset($n['category']) ? $n['category'] : null));
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
unset($data['notifications']);
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
if (isset($data['revoked'])) {
[60] Fix | Delete
foreach ($data['revoked'] as $r) {
[61] Fix | Delete
if (!isset($r['id'])) {
[62] Fix | Delete
continue;
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
$notification = wfNotification::getNotificationForID($r['id']);
[66] Fix | Delete
if ($notification !== null) {
[67] Fix | Delete
$notification->markAsRead();
[68] Fix | Delete
}
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
unset($data['revoked']);
[72] Fix | Delete
}
[73] Fix | Delete
wfConfig::set_ser('dashboardData', $data, false, wfConfig::DONT_AUTOLOAD);
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
public function __construct() {
[77] Fix | Delete
// Scan values
[78] Fix | Delete
$lastScanCompleted = wfConfig::get('lastScanCompleted');
[79] Fix | Delete
if ($lastScanCompleted === false || empty($lastScanCompleted)) {
[80] Fix | Delete
$this->scanLastStatus = self::SCAN_NEVER_RAN;
[81] Fix | Delete
}
[82] Fix | Delete
else if ($lastScanCompleted == 'ok') {
[83] Fix | Delete
$this->scanLastStatus = self::SCAN_SUCCESS;
[84] Fix | Delete
[85] Fix | Delete
$i = new wfIssues();
[86] Fix | Delete
$this->scanLastCompletion = (int) wfScanner::shared()->lastScanTime();
[87] Fix | Delete
$issueCount = $i->getIssueCount();
[88] Fix | Delete
if ($issueCount) {
[89] Fix | Delete
$this->scanLastStatus = self::SCAN_WARNINGS;
[90] Fix | Delete
$this->scanLastStatusMessage = "{$issueCount} issue" . ($issueCount == 1 ? ' found' : 's found');
[91] Fix | Delete
}
[92] Fix | Delete
}
[93] Fix | Delete
else {
[94] Fix | Delete
$this->scanLastStatus = self::SCAN_FAILED;
[95] Fix | Delete
$n = wfNotification::getNotificationForCategory('wfplugin_scan', false);
[96] Fix | Delete
if ($n !== null) {
[97] Fix | Delete
$this->scanLastStatusMessage = $n->html;
[98] Fix | Delete
}
[99] Fix | Delete
else {
[100] Fix | Delete
$this->scanLastStatusMessage = esc_html(substr($lastScanCompleted, 0, 100) . (strlen($lastScanCompleted) > 100 ? '...' : ''));
[101] Fix | Delete
}
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
// Notifications
[105] Fix | Delete
$this->notifications = wfNotification::notifications();
[106] Fix | Delete
[107] Fix | Delete
// Features
[108] Fix | Delete
$countryBlocking = self::FEATURE_PREMIUM;
[109] Fix | Delete
if (wfConfig::get('isPaid')) {
[110] Fix | Delete
$countryBlocking = self::FEATURE_DISABLED;
[111] Fix | Delete
$countryList = wfConfig::get('cbl_countries');
[112] Fix | Delete
if (!empty($countryList) && (wfConfig::get('cbl_loggedInBlocked', false) || wfConfig::get('cbl_loginFormBlocked', false) || wfConfig::get('cbl_restOfSiteBlocked', false))) {
[113] Fix | Delete
$countryBlocking = self::FEATURE_ENABLED;
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
$this->features = array(); //Deprecated
[118] Fix | Delete
[119] Fix | Delete
$data = wfConfig::get_ser('dashboardData');
[120] Fix | Delete
$lastChecked = wfConfig::get('lastDashboardCheck', 0);
[121] Fix | Delete
if ((!is_array($data) || (isset($data['generated']) && $data['generated'] + 3600 < time())) && $lastChecked + 3600 < time()) {
[122] Fix | Delete
$wp_version = wfUtils::getWPVersion();
[123] Fix | Delete
$apiKey = wfConfig::get('apiKey');
[124] Fix | Delete
$api = new wfAPI($apiKey, $wp_version);
[125] Fix | Delete
wfConfig::set('lastDashboardCheck', time());
[126] Fix | Delete
try {
[127] Fix | Delete
$json = $api->getStaticURL('/stats.json');
[128] Fix | Delete
$data = @json_decode($json, true);
[129] Fix | Delete
if ($json && is_array($data)) {
[130] Fix | Delete
self::processDashboardResponse($data);
[131] Fix | Delete
}
[132] Fix | Delete
}
[133] Fix | Delete
catch (Exception $e) {
[134] Fix | Delete
//Do nothing
[135] Fix | Delete
}
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
// Last Generated
[139] Fix | Delete
if (is_array($data) && isset($data['generated'])) {
[140] Fix | Delete
$this->lastGenerated = $data['generated'];
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
// TDF
[144] Fix | Delete
if (is_array($data) && isset($data['tdf']) && isset($data['tdf']['community'])) {
[145] Fix | Delete
$this->tdfCommunity = (int) $data['tdf']['community'];
[146] Fix | Delete
$this->tdfPremium = (int) $data['tdf']['premium'];
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
// Top IPs Blocked
[150] Fix | Delete
$activityReport = new wfActivityReport();
[151] Fix | Delete
$this->ips24h = (array) $activityReport->getTopIPsBlocked(100, 1);
[152] Fix | Delete
foreach ($this->ips24h as &$r24h) {
[153] Fix | Delete
$r24h = (array) $r24h;
[154] Fix | Delete
if (empty($r24h['countryName'])) { $r24h['countryName'] = 'Unknown'; }
[155] Fix | Delete
}
[156] Fix | Delete
$this->ips7d = (array) $activityReport->getTopIPsBlocked(100, 7);
[157] Fix | Delete
foreach ($this->ips7d as &$r7d) {
[158] Fix | Delete
$r7d = (array) $r7d;
[159] Fix | Delete
if (empty($r7d['countryName'])) { $r7d['countryName'] = 'Unknown'; }
[160] Fix | Delete
}
[161] Fix | Delete
$this->ips30d = (array) $activityReport->getTopIPsBlocked(100, 30);
[162] Fix | Delete
foreach ($this->ips30d as &$r30d) {
[163] Fix | Delete
$r30d = (array) $r30d;
[164] Fix | Delete
if (empty($r30d['countryName'])) { $r30d['countryName'] = 'Unknown'; }
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
// Recent Logins
[168] Fix | Delete
$logins = wordfence::getLog()->getHits('logins', 'loginLogout', 0, 200);
[169] Fix | Delete
$this->loginsSuccess = array();
[170] Fix | Delete
$this->loginsFail = array();
[171] Fix | Delete
foreach ($logins as $l) {
[172] Fix | Delete
if ($l['fail']) {
[173] Fix | Delete
$this->loginsFail[] = array('t' => $l['ctime'], 'name' => $l['username'], 'ip' => $l['IP']);
[174] Fix | Delete
}
[175] Fix | Delete
else if ($l['action'] != 'logout') {
[176] Fix | Delete
$this->loginsSuccess[] = array('t' => $l['ctime'], 'name' => $l['username'], 'ip' => $l['IP']);
[177] Fix | Delete
}
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
// Local Attack Data
[181] Fix | Delete
$this->localBlocks = array();
[182] Fix | Delete
$this->localBlocks[] = array('title' => __('Complex', 'wordfence'), 'type' => wfActivityReport::BLOCK_TYPE_COMPLEX,
[183] Fix | Delete
'24h' => (int) $activityReport->getBlockedCount(1, wfActivityReport::BLOCK_TYPE_COMPLEX),
[184] Fix | Delete
'7d' => (int) $activityReport->getBlockedCount(7, wfActivityReport::BLOCK_TYPE_COMPLEX),
[185] Fix | Delete
'30d' => (int) $activityReport->getBlockedCount(30, wfActivityReport::BLOCK_TYPE_COMPLEX),
[186] Fix | Delete
);
[187] Fix | Delete
$this->localBlocks[] = array('title' => __('Brute Force', 'wordfence'), 'type' => wfActivityReport::BLOCK_TYPE_BRUTE_FORCE,
[188] Fix | Delete
'24h' => (int) $activityReport->getBlockedCount(1, wfActivityReport::BLOCK_TYPE_BRUTE_FORCE),
[189] Fix | Delete
'7d' => (int) $activityReport->getBlockedCount(7, wfActivityReport::BLOCK_TYPE_BRUTE_FORCE),
[190] Fix | Delete
'30d' => (int) $activityReport->getBlockedCount(30, wfActivityReport::BLOCK_TYPE_BRUTE_FORCE),
[191] Fix | Delete
);
[192] Fix | Delete
$this->localBlocks[] = array('title' => __('Blocklist', 'wordfence'), 'type' => wfActivityReport::BLOCK_TYPE_BLACKLIST,
[193] Fix | Delete
'24h' => (int) $activityReport->getBlockedCount(1, wfActivityReport::BLOCK_TYPE_BLACKLIST),
[194] Fix | Delete
'7d' => (int) $activityReport->getBlockedCount(7, wfActivityReport::BLOCK_TYPE_BLACKLIST),
[195] Fix | Delete
'30d' => (int) $activityReport->getBlockedCount(30, wfActivityReport::BLOCK_TYPE_BLACKLIST),
[196] Fix | Delete
);
[197] Fix | Delete
[198] Fix | Delete
// Network Attack Data
[199] Fix | Delete
if (is_array($data) && isset($data['attackdata']) && isset($data['attackdata']['24h'])) {
[200] Fix | Delete
$this->networkBlock24h = $data['attackdata']['24h'];
[201] Fix | Delete
$this->networkBlock7d = $data['attackdata']['7d'];
[202] Fix | Delete
$this->networkBlock30d = $data['attackdata']['30d'];
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
// Blocked Countries
[206] Fix | Delete
$this->countriesLocal = (array) $activityReport->getTopCountriesBlocked(10, 7);
[207] Fix | Delete
foreach ($this->countriesLocal as &$rLocal) {
[208] Fix | Delete
$rLocal = (array) $rLocal;
[209] Fix | Delete
if (empty($rLocal['countryName'])) { $rLocal['countryName'] = 'Unknown'; }
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
if (is_array($data) && isset($data['countries']) && isset($data['countries']['7d'])) {
[213] Fix | Delete
$networkCountries = array();
[214] Fix | Delete
foreach ($data['countries']['7d'] as $rNetwork) {
[215] Fix | Delete
$countryCode = $rNetwork['cd'];
[216] Fix | Delete
$countryName = $activityReport->getCountryNameByCode($countryCode);
[217] Fix | Delete
if (empty($countryName)) { $countryName = 'Unknown'; }
[218] Fix | Delete
$totalBlockCount = $rNetwork['ct'];
[219] Fix | Delete
$networkCountries[] = array('countryCode' => $countryCode, 'countryName' => $countryName, 'totalBlockCount' => $totalBlockCount);
[220] Fix | Delete
}
[221] Fix | Delete
$this->countriesNetwork = $networkCountries;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
// Wordfence Central
[225] Fix | Delete
$this->wordfenceCentralConnected = wfCentral::_isConnected(); // This value is cached.
[226] Fix | Delete
$this->wordfenceCentralConnectTime = wfConfig::get('wordfenceCentralConnectTime');
[227] Fix | Delete
$this->wordfenceCentralConnectEmail = wfConfig::get('wordfenceCentralConnectEmail');
[228] Fix | Delete
$this->wordfenceCentralDisconnected = wfConfig::get('wordfenceCentralDisconnected');
[229] Fix | Delete
$this->wordfenceCentralDisconnectTime = wfConfig::get('wordfenceCentralDisconnectTime');
[230] Fix | Delete
$this->wordfenceCentralDisconnectEmail = wfConfig::get('wordfenceCentralDisconnectEmail');
[231] Fix | Delete
}
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function