Diff
8 years ago
dashboard
7 years ago
rest-api
7 years ago
.htaccess
7 years ago
Diff.php
14 years ago
GeoLite2-Country.mmdb
7 years ago
IPTraf.php
8 years ago
IPTrafList.php
7 years ago
WFLSPHP52Compatability.php
7 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
7 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
7 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
7 years ago
menu_scanner.php
7 years ago
menu_scanner_credentials.php
8 years ago
menu_scanner_options.php
8 years ago
menu_support.php
7 years ago
menu_tools.php
7 years ago
menu_tools_diagnostic.php
7 years ago
menu_tools_importExport.php
7 years ago
menu_tools_livetraffic.php
7 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
7 years ago
wfActivityReport.php
7 years ago
wfAdminNoticeQueue.php
8 years ago
wfArray.php
7 years ago
wfBrowscap.php
8 years ago
wfBrowscapCache.php
7 years ago
wfBulkCountries.php
7 years ago
wfCache.php
9 years ago
wfCentralAPI.php
7 years ago
wfConfig.php
7 years ago
wfCrawl.php
8 years ago
wfCredentialsController.php
7 years ago
wfCrypt.php
7 years ago
wfDB.php
7 years ago
wfDashboard.php
7 years ago
wfDateLocalization.php
8 years ago
wfDiagnostic.php
7 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
7 years ago
wfJWT.php
7 years ago
wfLockedOut.php
7 years ago
wfLog.php
7 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
7 years ago
wfScanEngine.php
7 years ago
wfSchema.php
7 years ago
wfStyle.php
7 years ago
wfSupportController.php
7 years ago
wfUnlockMsg.php
7 years ago
wfUpdateCheck.php
8 years ago
wfUtils.php
7 years ago
wfVersionCheckController.php
8 years ago
wfView.php
10 years ago
wfViewResult.php
8 years ago
wordfenceClass.php
7 years ago
wordfenceConstants.php
7 years ago
wordfenceHash.php
7 years ago
wordfenceScanner.php
7 years ago
wordfenceURLHoover.php
7 years ago
wfNotification.php
163 lines
| 1 | <?php |
| 2 | class wfNotification { |
| 3 | const PRIORITY_LOW = 1500; |
| 4 | const PRIORITY_DEFAULT = 1000; |
| 5 | const PRIORITY_HIGH = 500; |
| 6 | const PRIORITY_HIGH_CRITICAL = 501; |
| 7 | const PRIORITY_HIGH_WARNING = 502; |
| 8 | |
| 9 | protected $_id; |
| 10 | protected $_category; |
| 11 | protected $_priority; |
| 12 | protected $_ctime; |
| 13 | protected $_html; |
| 14 | protected $_links; |
| 15 | |
| 16 | public static function notifications($since = 0) { |
| 17 | global $wpdb; |
| 18 | $table_wfNotifications = wfDB::networkTable('wfNotifications'); |
| 19 | $rawNotifications = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table_wfNotifications} WHERE `new` = 1 AND `ctime` > %d ORDER BY `priority` ASC, `ctime` DESC", $since), ARRAY_A); |
| 20 | $notifications = array(); |
| 21 | foreach ($rawNotifications as $raw) { |
| 22 | $notifications[] = new wfNotification($raw['id'], $raw['priority'], $raw['html'], $raw['category'], $raw['ctime'], json_decode($raw['links'], true), true); |
| 23 | } |
| 24 | return $notifications; |
| 25 | } |
| 26 | |
| 27 | public static function getNotificationForID($id) { |
| 28 | global $wpdb; |
| 29 | $table_wfNotifications = wfDB::networkTable('wfNotifications'); |
| 30 | $rawNotifications = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table_wfNotifications} WHERE `id` = %s ORDER BY `priority` ASC, `ctime` DESC", $id), ARRAY_A); |
| 31 | if (count($rawNotifications) == 1) { |
| 32 | $raw = $rawNotifications[0]; |
| 33 | return new wfNotification($raw['id'], $raw['priority'], $raw['html'], $raw['category'], $raw['ctime'], json_decode($raw['links'], true), true); |
| 34 | } |
| 35 | return null; |
| 36 | } |
| 37 | |
| 38 | public static function getNotificationForCategory($category, $requireNew = true) { |
| 39 | global $wpdb; |
| 40 | $table_wfNotifications = wfDB::networkTable('wfNotifications'); |
| 41 | $rawNotifications = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table_wfNotifications} WHERE " . ($requireNew ? '`new` = 1 AND ' : '') . "`category` = %s ORDER BY `priority` ASC, `ctime` DESC LIMIT 1", $category), ARRAY_A); |
| 42 | if (count($rawNotifications) == 1) { |
| 43 | $raw = $rawNotifications[0]; |
| 44 | return new wfNotification($raw['id'], $raw['priority'], $raw['html'], $raw['category'], $raw['ctime'], json_decode($raw['links'], true), true); |
| 45 | } |
| 46 | return null; |
| 47 | } |
| 48 | |
| 49 | public static function reconcileNotificationsWithOptions() { |
| 50 | $notification_updatesNeeded = wfConfig::get('notification_updatesNeeded'); |
| 51 | $notification_securityAlerts = wfConfig::get('notification_securityAlerts') || !wfConfig::p(); |
| 52 | $notification_promotions = wfConfig::get('notification_promotions') || !wfConfig::p(); |
| 53 | $notification_blogHighlights = wfConfig::get('notification_blogHighlights') || !wfConfig::p(); |
| 54 | $notification_productUpdates = wfConfig::get('notification_productUpdates') || !wfConfig::p(); |
| 55 | $notification_scanStatus = wfConfig::get('notification_scanStatus'); |
| 56 | |
| 57 | $notifications = self::notifications(); |
| 58 | foreach ($notifications as $n) { |
| 59 | $category = $n->category; |
| 60 | |
| 61 | if (preg_match('/^release/i', $category) && !$notification_productUpdates) { $n->markAsRead(); } |
| 62 | if (preg_match('/^digest/i', $category) && !$notification_blogHighlights) { $n->markAsRead(); } |
| 63 | if (preg_match('/^alert/i', $category) && !$notification_securityAlerts) { $n->markAsRead(); } |
| 64 | if (preg_match('/^promo/i', $category) && !$notification_promotions) { $n->markAsRead(); } |
| 65 | |
| 66 | switch ($category) { |
| 67 | case 'wfplugin_scan': |
| 68 | if (!$notification_scanStatus) { $n->markAsRead(); } |
| 69 | break; |
| 70 | case 'wfplugin_updates': |
| 71 | if (!$notification_updatesNeeded) { $n->markAsRead(); } |
| 72 | break; |
| 73 | case 'wfplugin_keyconflict': |
| 74 | default: |
| 75 | //Allow it |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | public function __construct($id, $priority, $html, $category = null, $ctime = null, $links = null, $memoryOnly = false) { |
| 82 | if ($id === null) { |
| 83 | $id = 'site-' . wfUtils::base32_encode(pack('I', wfConfig::atomicInc('lastNotificationID'))); |
| 84 | } |
| 85 | |
| 86 | if ($category === null) { |
| 87 | $category = ''; |
| 88 | } |
| 89 | |
| 90 | if ($ctime === null) { |
| 91 | $ctime = time(); |
| 92 | } |
| 93 | |
| 94 | if (!is_array($links)) { |
| 95 | $links = array(); |
| 96 | } |
| 97 | |
| 98 | $this->_id = $id; |
| 99 | $this->_category = $category; |
| 100 | $this->_priority = $priority; |
| 101 | $this->_ctime = $ctime; |
| 102 | $this->_html = $html; |
| 103 | $this->_links = $links; |
| 104 | |
| 105 | global $wpdb; |
| 106 | if (!$memoryOnly) { |
| 107 | $linksJSON = json_encode($links); |
| 108 | |
| 109 | $notification_updatesNeeded = wfConfig::get('notification_updatesNeeded'); |
| 110 | $notification_securityAlerts = wfConfig::get('notification_securityAlerts') || !wfConfig::p(); |
| 111 | $notification_promotions = wfConfig::get('notification_promotions') || !wfConfig::p(); |
| 112 | $notification_blogHighlights = wfConfig::get('notification_blogHighlights') || !wfConfig::p(); |
| 113 | $notification_productUpdates = wfConfig::get('notification_productUpdates') || !wfConfig::p(); |
| 114 | $notification_scanStatus = wfConfig::get('notification_scanStatus'); |
| 115 | |
| 116 | if (preg_match('/^release/i', $category) && !$notification_productUpdates) { return; } |
| 117 | if (preg_match('/^digest/i', $category) && !$notification_blogHighlights) { return; } |
| 118 | if (preg_match('/^alert/i', $category) && !$notification_securityAlerts) { return; } |
| 119 | if (preg_match('/^promo/i', $category) && !$notification_promotions) { return; } |
| 120 | |
| 121 | switch ($category) { |
| 122 | case 'wfplugin_scan': |
| 123 | if (!$notification_scanStatus) { return; } |
| 124 | break; |
| 125 | case 'wfplugin_updates': |
| 126 | if (!$notification_updatesNeeded) { return; } |
| 127 | break; |
| 128 | case 'wfplugin_keyconflict': |
| 129 | default: |
| 130 | //Allow it |
| 131 | break; |
| 132 | } |
| 133 | |
| 134 | $table_wfNotifications = wfDB::networkTable('wfNotifications'); |
| 135 | if (!empty($category)) { |
| 136 | $existing = self::getNotificationForCategory($category); |
| 137 | if ($existing) { |
| 138 | $wpdb->query($wpdb->prepare("UPDATE {$table_wfNotifications} SET priority = %d, ctime = %d, html = %s, links = %s WHERE id = %s", $priority, $ctime, $html, $linksJSON, $existing->id)); |
| 139 | return; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | $wpdb->query($wpdb->prepare("INSERT IGNORE INTO {$table_wfNotifications} (id, category, priority, ctime, html, links) VALUES (%s, %s, %d, %d, %s, %s)", $id, $category, $priority, $ctime, $html, $linksJSON)); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | public function __get($key){ |
| 148 | if ($key == 'id') { return $this->_id; } |
| 149 | else if ($key == 'category') { return $this->_category; } |
| 150 | else if ($key == 'priority') { return $this->_priority; } |
| 151 | else if ($key == 'ctime') { return $this->_ctime; } |
| 152 | else if ($key == 'html') { return $this->_html; } |
| 153 | else if ($key == 'links') { return $this->_links; } |
| 154 | throw new InvalidArgumentException(); |
| 155 | } |
| 156 | |
| 157 | public function markAsRead() { |
| 158 | global $wpdb; |
| 159 | $table_wfNotifications = wfDB::networkTable('wfNotifications'); |
| 160 | $wpdb->query($wpdb->prepare("UPDATE {$table_wfNotifications} SET `new` = 0 WHERE `id` = %s", $this->_id)); |
| 161 | } |
| 162 | } |
| 163 |