Diff
6 years ago
dashboard
7 years ago
rest-api
6 years ago
.htaccess
7 years ago
Diff.php
6 years ago
GeoLite2-Country.mmdb
6 years ago
IPTraf.php
6 years ago
IPTrafList.php
7 years ago
WFLSPHP52Compatability.php
6 years ago
compat.php
8 years ago
conntest.php
7 years ago
cronview.php
8 years ago
dbview.php
8 years ago
diffResult.php
8 years ago
email_genericAlert.php
7 years ago
email_newIssues.php
6 years ago
email_unlockRequest.php
8 years ago
email_unsubscribeRequest.php
7 years ago
flags.php
7 years ago
live_activity.php
8 years ago
menu_dashboard.php
7 years ago
menu_dashboard_options.php
7 years ago
menu_firewall.php
6 years ago
menu_firewall_blocking.php
7 years ago
menu_firewall_blocking_options.php
8 years ago
menu_firewall_waf.php
7 years ago
menu_firewall_waf_options.php
7 years ago
menu_options.php
6 years ago
menu_scanner.php
6 years ago
menu_scanner_credentials.php
8 years ago
menu_scanner_options.php
6 years ago
menu_support.php
7 years ago
menu_tools.php
7 years ago
menu_tools_diagnostic.php
6 years ago
menu_tools_importExport.php
7 years ago
menu_tools_livetraffic.php
6 years ago
menu_tools_twoFactor.php
7 years ago
menu_tools_whois.php
8 years ago
menu_wordfence_central.php
7 years ago
noc1.key
7 years ago
sysinfo.php
8 years ago
unknownFiles.php
8 years ago
viewFullActivityLog.php
8 years ago
wf503.php
7 years ago
wfAPI.php
6 years ago
wfActivityReport.php
6 years ago
wfAdminNoticeQueue.php
8 years ago
wfAlerts.php
6 years ago
wfArray.php
7 years ago
wfBrowscap.php
6 years ago
wfBrowscapCache.php
7 years ago
wfBulkCountries.php
7 years ago
wfCache.php
6 years ago
wfCentralAPI.php
6 years ago
wfConfig.php
6 years ago
wfCrawl.php
6 years ago
wfCredentialsController.php
7 years ago
wfCrypt.php
6 years ago
wfDB.php
7 years ago
wfDashboard.php
7 years ago
wfDateLocalization.php
8 years ago
wfDiagnostic.php
6 years ago
wfDict.php
8 years ago
wfDirectoryIterator.php
7 years ago
wfHelperBin.php
11 years ago
wfHelperString.php
11 years ago
wfIPWhitelist.php
7 years ago
wfImportExportController.php
7 years ago
wfIssues.php
6 years ago
wfJWT.php
7 years ago
wfLockedOut.php
7 years ago
wfLog.php
6 years ago
wfMD5BloomFilter.php
8 years ago
wfModuleController.php
7 years ago
wfNotification.php
8 years ago
wfOnboardingController.php
7 years ago
wfPersistenceController.php
8 years ago
wfRESTAPI.php
7 years ago
wfScan.php
6 years ago
wfScanEngine.php
6 years ago
wfSchema.php
6 years ago
wfStyle.php
7 years ago
wfSupportController.php
6 years ago
wfUnlockMsg.php
6 years ago
wfUpdateCheck.php
6 years ago
wfUtils.php
6 years ago
wfVersionCheckController.php
8 years ago
wfView.php
10 years ago
wfViewResult.php
8 years ago
wordfenceClass.php
6 years ago
wordfenceConstants.php
6 years ago
wordfenceHash.php
6 years ago
wordfenceScanner.php
6 years ago
wordfenceURLHoover.php
6 years ago
wfDashboard.php
235 lines
| 1 | <?php |
| 2 | |
| 3 | class wfDashboard { |
| 4 | const SCAN_SUCCESS = 1; |
| 5 | const SCAN_FAILED = 0; |
| 6 | const SCAN_NEVER_RAN = -1; |
| 7 | const SCAN_WARNINGS = 2; |
| 8 | |
| 9 | const FEATURE_ENABLED = 1; |
| 10 | const FEATURE_DISABLED = 0; |
| 11 | const FEATURE_PREMIUM = -1; |
| 12 | |
| 13 | public $scanLastCompletion; |
| 14 | public $scanLastStatusMessage; |
| 15 | public $scanLastStatus; |
| 16 | |
| 17 | public $notifications = array(); |
| 18 | |
| 19 | public $features = array(); |
| 20 | |
| 21 | public $lastGenerated; |
| 22 | |
| 23 | public $tdfCommunity; |
| 24 | public $tdfPremium; |
| 25 | |
| 26 | public $ips24h; |
| 27 | public $ips7d; |
| 28 | public $ips30d; |
| 29 | |
| 30 | public $loginsSuccess; |
| 31 | public $loginsFail; |
| 32 | |
| 33 | public $localBlocks; |
| 34 | |
| 35 | public $networkBlock24h; |
| 36 | public $networkBlock7d; |
| 37 | public $networkBlock30d; |
| 38 | |
| 39 | public $countriesLocal; |
| 40 | public $countriesNetwork; |
| 41 | public $wordfenceCentralConnected; |
| 42 | public $wordfenceCentralConnectTime; |
| 43 | public $wordfenceCentralConnectEmail; |
| 44 | public $wordfenceCentralDisconnected; |
| 45 | public $wordfenceCentralDisconnectTime; |
| 46 | public $wordfenceCentralDisconnectEmail; |
| 47 | |
| 48 | public static function processDashboardResponse($data) { |
| 49 | if (isset($data['notifications'])) { |
| 50 | foreach ($data['notifications'] as $n) { |
| 51 | if (!isset($n['id']) || !isset($n['priority']) || !isset($n['html'])) { |
| 52 | continue; |
| 53 | } |
| 54 | |
| 55 | new wfNotification($n['id'], $n['priority'], $n['html'], (isset($n['category']) ? $n['category'] : null)); |
| 56 | } |
| 57 | |
| 58 | unset($data['notifications']); |
| 59 | } |
| 60 | |
| 61 | if (isset($data['revoked'])) { |
| 62 | foreach ($data['revoked'] as $r) { |
| 63 | if (!isset($r['id'])) { |
| 64 | continue; |
| 65 | } |
| 66 | |
| 67 | $notification = wfNotification::getNotificationForID($r['id']); |
| 68 | if ($notification !== null) { |
| 69 | $notification->markAsRead(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | unset($data['revoked']); |
| 74 | } |
| 75 | wfConfig::set_ser('dashboardData', $data); |
| 76 | } |
| 77 | |
| 78 | public function __construct() { |
| 79 | // Scan values |
| 80 | $lastScanCompleted = wfConfig::get('lastScanCompleted'); |
| 81 | if ($lastScanCompleted === false || empty($lastScanCompleted)) { |
| 82 | $this->scanLastStatus = self::SCAN_NEVER_RAN; |
| 83 | } |
| 84 | else if ($lastScanCompleted == 'ok') { |
| 85 | $this->scanLastStatus = self::SCAN_SUCCESS; |
| 86 | |
| 87 | $i = new wfIssues(); |
| 88 | $this->scanLastCompletion = (int) wfScanner::shared()->lastScanTime(); |
| 89 | $issueCount = $i->getIssueCount(); |
| 90 | if ($issueCount) { |
| 91 | $this->scanLastStatus = self::SCAN_WARNINGS; |
| 92 | $this->scanLastStatusMessage = "{$issueCount} issue" . ($issueCount == 1 ? ' found' : 's found'); |
| 93 | } |
| 94 | } |
| 95 | else { |
| 96 | $this->scanLastStatus = self::SCAN_FAILED; |
| 97 | $n = wfNotification::getNotificationForCategory('wfplugin_scan', false); |
| 98 | if ($n !== null) { |
| 99 | $this->scanLastStatusMessage = $n->html; |
| 100 | } |
| 101 | else { |
| 102 | $this->scanLastStatusMessage = esc_html(substr($lastScanCompleted, 0, 100) . (strlen($lastScanCompleted) > 100 ? '...' : '')); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // Notifications |
| 107 | $this->notifications = wfNotification::notifications(); |
| 108 | |
| 109 | // Features |
| 110 | $countryBlocking = self::FEATURE_PREMIUM; |
| 111 | if (wfConfig::get('isPaid')) { |
| 112 | $countryBlocking = self::FEATURE_DISABLED; |
| 113 | $countryList = wfConfig::get('cbl_countries'); |
| 114 | if (!empty($countryList) && (wfConfig::get('cbl_loggedInBlocked', false) || wfConfig::get('cbl_loginFormBlocked', false) || wfConfig::get('cbl_restOfSiteBlocked', false))) { |
| 115 | $countryBlocking = self::FEATURE_ENABLED; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | $this->features = array(); //Deprecated |
| 120 | |
| 121 | $data = wfConfig::get_ser('dashboardData'); |
| 122 | $lastChecked = wfConfig::get('lastDashboardCheck', 0); |
| 123 | if ((!is_array($data) || (isset($data['generated']) && $data['generated'] + 3600 < time())) && $lastChecked + 3600 < time()) { |
| 124 | $wp_version = wfUtils::getWPVersion(); |
| 125 | $apiKey = wfConfig::get('apiKey'); |
| 126 | $api = new wfAPI($apiKey, $wp_version); |
| 127 | wfConfig::set('lastDashboardCheck', time()); |
| 128 | try { |
| 129 | $json = $api->getStaticURL('/stats.json'); |
| 130 | $data = @json_decode($json, true); |
| 131 | if ($json && is_array($data)) { |
| 132 | self::processDashboardResponse($data); |
| 133 | } |
| 134 | } |
| 135 | catch (Exception $e) { |
| 136 | //Do nothing |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // Last Generated |
| 141 | if (is_array($data) && isset($data['generated'])) { |
| 142 | $this->lastGenerated = $data['generated']; |
| 143 | } |
| 144 | |
| 145 | // TDF |
| 146 | if (is_array($data) && isset($data['tdf']) && isset($data['tdf']['community'])) { |
| 147 | $this->tdfCommunity = (int) $data['tdf']['community']; |
| 148 | $this->tdfPremium = (int) $data['tdf']['premium']; |
| 149 | } |
| 150 | |
| 151 | // Top IPs Blocked |
| 152 | $activityReport = new wfActivityReport(); |
| 153 | $this->ips24h = (array) $activityReport->getTopIPsBlocked(100, 1); |
| 154 | foreach ($this->ips24h as &$r24h) { |
| 155 | $r24h = (array) $r24h; |
| 156 | if (empty($r24h['countryName'])) { $r24h['countryName'] = 'Unknown'; } |
| 157 | } |
| 158 | $this->ips7d = (array) $activityReport->getTopIPsBlocked(100, 7); |
| 159 | foreach ($this->ips7d as &$r7d) { |
| 160 | $r7d = (array) $r7d; |
| 161 | if (empty($r7d['countryName'])) { $r7d['countryName'] = 'Unknown'; } |
| 162 | } |
| 163 | $this->ips30d = (array) $activityReport->getTopIPsBlocked(100, 30); |
| 164 | foreach ($this->ips30d as &$r30d) { |
| 165 | $r30d = (array) $r30d; |
| 166 | if (empty($r30d['countryName'])) { $r30d['countryName'] = 'Unknown'; } |
| 167 | } |
| 168 | |
| 169 | // Recent Logins |
| 170 | $logins = wordfence::getLog()->getHits('logins', 'loginLogout', 0, 200); |
| 171 | $this->loginsSuccess = array(); |
| 172 | $this->loginsFail = array(); |
| 173 | foreach ($logins as $l) { |
| 174 | if ($l['fail']) { |
| 175 | $this->loginsFail[] = array('t' => $l['ctime'], 'name' => $l['username'], 'ip' => $l['IP']); |
| 176 | } |
| 177 | else if ($l['action'] != 'logout') { |
| 178 | $this->loginsSuccess[] = array('t' => $l['ctime'], 'name' => $l['username'], 'ip' => $l['IP']); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // Local Attack Data |
| 183 | $this->localBlocks = array(); |
| 184 | $this->localBlocks[] = array('title' => __('Complex', 'wordfence'), 'type' => wfActivityReport::BLOCK_TYPE_COMPLEX, |
| 185 | '24h' => (int) $activityReport->getBlockedCount(1, wfActivityReport::BLOCK_TYPE_COMPLEX), |
| 186 | '7d' => (int) $activityReport->getBlockedCount(7, wfActivityReport::BLOCK_TYPE_COMPLEX), |
| 187 | '30d' => (int) $activityReport->getBlockedCount(30, wfActivityReport::BLOCK_TYPE_COMPLEX), |
| 188 | ); |
| 189 | $this->localBlocks[] = array('title' => __('Brute Force', 'wordfence'), 'type' => wfActivityReport::BLOCK_TYPE_BRUTE_FORCE, |
| 190 | '24h' => (int) $activityReport->getBlockedCount(1, wfActivityReport::BLOCK_TYPE_BRUTE_FORCE), |
| 191 | '7d' => (int) $activityReport->getBlockedCount(7, wfActivityReport::BLOCK_TYPE_BRUTE_FORCE), |
| 192 | '30d' => (int) $activityReport->getBlockedCount(30, wfActivityReport::BLOCK_TYPE_BRUTE_FORCE), |
| 193 | ); |
| 194 | $this->localBlocks[] = array('title' => __('Blacklist', 'wordfence'), 'type' => wfActivityReport::BLOCK_TYPE_BLACKLIST, |
| 195 | '24h' => (int) $activityReport->getBlockedCount(1, wfActivityReport::BLOCK_TYPE_BLACKLIST), |
| 196 | '7d' => (int) $activityReport->getBlockedCount(7, wfActivityReport::BLOCK_TYPE_BLACKLIST), |
| 197 | '30d' => (int) $activityReport->getBlockedCount(30, wfActivityReport::BLOCK_TYPE_BLACKLIST), |
| 198 | ); |
| 199 | |
| 200 | // Network Attack Data |
| 201 | if (is_array($data) && isset($data['attackdata']) && isset($data['attackdata']['24h'])) { |
| 202 | $this->networkBlock24h = $data['attackdata']['24h']; |
| 203 | $this->networkBlock7d = $data['attackdata']['7d']; |
| 204 | $this->networkBlock30d = $data['attackdata']['30d']; |
| 205 | } |
| 206 | |
| 207 | // Blocked Countries |
| 208 | $this->countriesLocal = (array) $activityReport->getTopCountriesBlocked(10, 7); |
| 209 | foreach ($this->countriesLocal as &$rLocal) { |
| 210 | $rLocal = (array) $rLocal; |
| 211 | if (empty($rLocal['countryName'])) { $rLocal['countryName'] = 'Unknown'; } |
| 212 | } |
| 213 | |
| 214 | if (is_array($data) && isset($data['countries']) && isset($data['countries']['7d'])) { |
| 215 | $networkCountries = array(); |
| 216 | foreach ($data['countries']['7d'] as $rNetwork) { |
| 217 | $countryCode = $rNetwork['cd']; |
| 218 | $countryName = $activityReport->getCountryNameByCode($countryCode); |
| 219 | if (empty($countryName)) { $countryName = 'Unknown'; } |
| 220 | $totalBlockCount = $rNetwork['ct']; |
| 221 | $networkCountries[] = array('countryCode' => $countryCode, 'countryName' => $countryName, 'totalBlockCount' => $totalBlockCount); |
| 222 | } |
| 223 | $this->countriesNetwork = $networkCountries; |
| 224 | } |
| 225 | |
| 226 | // Wordfence Central |
| 227 | $this->wordfenceCentralConnected = wfConfig::get('wordfenceCentralConnected'); |
| 228 | $this->wordfenceCentralConnectTime = wfConfig::get('wordfenceCentralConnectTime'); |
| 229 | $this->wordfenceCentralConnectEmail = wfConfig::get('wordfenceCentralConnectEmail'); |
| 230 | $this->wordfenceCentralDisconnected = wfConfig::get('wordfenceCentralDisconnected'); |
| 231 | $this->wordfenceCentralDisconnectTime = wfConfig::get('wordfenceCentralDisconnectTime'); |
| 232 | $this->wordfenceCentralDisconnectEmail = wfConfig::get('wordfenceCentralDisconnectEmail'); |
| 233 | } |
| 234 | } |
| 235 |