Diff
1 year ago
audit-log
1 year ago
dashboard
1 year ago
rest-api
1 year ago
.htaccess
7 years ago
Diff.php
6 years ago
GeoLite2-Country.mmdb
1 year ago
IPTraf.php
1 year ago
IPTrafList.php
1 year ago
WFLSPHP52Compatability.php
6 years ago
compat.php
8 years ago
diffResult.php
1 year ago
email_genericAlert.php
5 years ago
email_newIssues.php
3 years ago
email_unlockRequest.php
5 years ago
email_unsubscribeRequest.php
4 years ago
flags.php
7 years ago
live_activity.php
4 years ago
menu_dashboard.php
3 years ago
menu_dashboard_options.php
3 years ago
menu_firewall.php
3 years ago
menu_firewall_blocking.php
4 years ago
menu_firewall_blocking_options.php
3 years ago
menu_firewall_waf.php
4 years ago
menu_firewall_waf_options.php
3 years ago
menu_install.php
3 years ago
menu_options.php
1 year ago
menu_scanner.php
2 years ago
menu_scanner_credentials.php
1 year ago
menu_scanner_options.php
3 years ago
menu_support.php
1 year ago
menu_tools.php
1 year ago
menu_tools_auditlog.php
1 year ago
menu_tools_diagnostic.php
1 year ago
menu_tools_importExport.php
4 years ago
menu_tools_livetraffic.php
2 years ago
menu_tools_twoFactor.php
4 years ago
menu_tools_whois.php
3 years ago
menu_wordfence_central.php
3 years ago
noc1.key
7 years ago
sodium_compat_fast.php
2 years ago
sysinfo.php
1 year ago
viewFullActivityLog.php
4 years ago
wf503.php
2 years ago
wfAPI.php
1 year ago
wfActivityReport.php
1 year ago
wfAdminNoticeQueue.php
4 years ago
wfAlerts.php
5 years ago
wfArray.php
3 years ago
wfAuditLog.php
1 year ago
wfBrowscap.php
3 years ago
wfBrowscapCache.php
7 years ago
wfBulkCountries.php
2 years ago
wfCache.php
3 years ago
wfCentralAPI.php
1 year ago
wfConfig.php
1 year ago
wfCrawl.php
1 year ago
wfCredentialsController.php
1 year ago
wfCrypt.php
6 years ago
wfCurlInterceptor.php
3 years ago
wfDB.php
1 year ago
wfDashboard.php
1 year ago
wfDateLocalization.php
2 years ago
wfDeactivationOption.php
3 years ago
wfDiagnostic.php
1 year ago
wfDict.php
8 years ago
wfDirectoryIterator.php
7 years ago
wfFileUtils.php
2 years ago
wfHelperBin.php
11 years ago
wfHelperString.php
1 year ago
wfIPWhitelist.php
5 years ago
wfImportExportController.php
5 years ago
wfInaccessibleDirectoryException.php
2 years ago
wfInvalidPathException.php
3 years ago
wfIpLocation.php
3 years ago
wfIpLocator.php
3 years ago
wfIssues.php
1 year ago
wfJWT.php
7 years ago
wfLicense.php
3 years ago
wfLockedOut.php
2 years ago
wfLog.php
1 year ago
wfMD5BloomFilter.php
8 years ago
wfModuleController.php
7 years ago
wfNotification.php
8 years ago
wfOnboardingController.php
1 year ago
wfPersistenceController.php
1 year ago
wfRESTAPI.php
7 years ago
wfScan.php
2 years ago
wfScanEngine.php
1 year ago
wfScanEntrypoint.php
3 years ago
wfScanFile.php
1 year ago
wfScanFileLink.php
3 years ago
wfScanFileListItem.php
1 year ago
wfScanFileProperties.php
1 year ago
wfScanMonitor.php
2 years ago
wfScanPath.php
3 years ago
wfSchema.php
1 year ago
wfStyle.php
1 year ago
wfSupportController.php
1 year ago
wfUnlockMsg.php
5 years ago
wfUpdateCheck.php
1 year ago
wfUtils.php
1 year ago
wfVersionCheckController.php
3 years ago
wfVersionSupport.php
1 year ago
wfView.php
5 years ago
wfViewResult.php
1 year ago
wfWebsite.php
3 years ago
wordfenceClass.php
1 year ago
wordfenceConstants.php
1 year ago
wordfenceHash.php
1 year ago
wordfenceScanner.php
1 year ago
wordfenceURLHoover.php
2 years ago
wfAdminNoticeQueue.php
195 lines
| 1 | <?php |
| 2 | |
| 3 | class wfAdminNoticeQueue { |
| 4 | protected static function _notices() { |
| 5 | return self::_purgeObsoleteNotices(wfConfig::get_ser('adminNoticeQueue', array())); |
| 6 | } |
| 7 | |
| 8 | private static function _purgeObsoleteNotices($notices) { |
| 9 | $altered = false; |
| 10 | foreach ($notices as $id => $notice) { |
| 11 | if ($notice['category'] === 'php8') { |
| 12 | unset($notices[$id]); |
| 13 | $altered = true; |
| 14 | } |
| 15 | } |
| 16 | if ($altered) |
| 17 | self::_setNotices($notices); |
| 18 | return $notices; |
| 19 | } |
| 20 | |
| 21 | protected static function _setNotices($notices) { |
| 22 | wfConfig::set_ser('adminNoticeQueue', $notices); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Adds an admin notice to the display queue. |
| 27 | * |
| 28 | * @param string $severity |
| 29 | * @param string $messageHTML |
| 30 | * @param bool|string $category If not false, notices with the same category will be removed prior to adding this one. |
| 31 | * @param bool|array $users If not false, an array of user IDs the notice should show for. |
| 32 | */ |
| 33 | public static function addAdminNotice($severity, $messageHTML, $category = false, $users = false) { |
| 34 | $notices = self::_notices(); |
| 35 | foreach ($notices as $id => $n) { |
| 36 | $usersMatches = false; |
| 37 | if (isset($n['users'])) { |
| 38 | $usersMatches = wfUtils::sets_equal($n['users'], $users); |
| 39 | } |
| 40 | else if ($users === false) { |
| 41 | $usersMatches = true; |
| 42 | } |
| 43 | |
| 44 | $categoryMatches = false; |
| 45 | if ($category !== false && isset($n['category']) && $n['category'] == $category) { |
| 46 | $categoryMatches = true; |
| 47 | } |
| 48 | |
| 49 | if ($usersMatches && $categoryMatches) { |
| 50 | unset($notices[$id]); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | $id = wfUtils::uuid(); |
| 55 | $notices[$id] = array( |
| 56 | 'severity' => $severity, |
| 57 | 'messageHTML' => $messageHTML, |
| 58 | ); |
| 59 | |
| 60 | if ($category !== false) { |
| 61 | $notices[$id]['category'] = $category; |
| 62 | } |
| 63 | |
| 64 | if ($users !== false) { |
| 65 | $notices[$id]['users'] = $users; |
| 66 | } |
| 67 | |
| 68 | self::_setNotices($notices); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Removes an admin notice using one of three possible search methods: |
| 73 | * |
| 74 | * 1. If $id matches. $category and $users are ignored |
| 75 | * 2. If $category matches. $users must be false for this. |
| 76 | * 3. If $category matches and the notice's user IDs matches $users. |
| 77 | * |
| 78 | * @param bool|int $id |
| 79 | * @param bool|string $category |
| 80 | * @param bool|int[] $users |
| 81 | */ |
| 82 | public static function removeAdminNotice($id = false, $category = false, $users = false) { |
| 83 | if ($id === false && $category === false && $users === false) { |
| 84 | return; |
| 85 | } |
| 86 | else if ($id !== false) { |
| 87 | $category = false; |
| 88 | $users = false; |
| 89 | } |
| 90 | |
| 91 | $notices = self::_notices(); |
| 92 | $found = false; |
| 93 | foreach ($notices as $nid => $n) { |
| 94 | if ($id == $nid) { //ID match |
| 95 | unset($notices[$nid]); |
| 96 | $found=true; |
| 97 | break; |
| 98 | } |
| 99 | else if ($id !== false) { |
| 100 | continue; |
| 101 | } |
| 102 | |
| 103 | if ($category !== false && isset($n['category']) && $category == $n['category']) { |
| 104 | if ($users !== false) { |
| 105 | if (isset($n['users']) && wfUtils::sets_equal($users, $n['users'])) { |
| 106 | unset($notices[$nid]); |
| 107 | $found=true; |
| 108 | } |
| 109 | } |
| 110 | else { |
| 111 | unset($notices[$nid]); |
| 112 | $found=true; |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | if($found) |
| 117 | self::_setNotices($notices); |
| 118 | } |
| 119 | |
| 120 | public static function hasNotice($category = false, $users = false) { |
| 121 | $notices = self::_notices(); |
| 122 | foreach ($notices as $nid => $n) { |
| 123 | $categoryMatches = false; |
| 124 | if (($category === false && !isset($n['category'])) || ($category !== false && isset($n['category']) && $category == $n['category'])) { |
| 125 | $categoryMatches = true; |
| 126 | } |
| 127 | |
| 128 | $usersMatches = false; |
| 129 | if (($users === false && !isset($n['users'])) || ($users !== false && isset($n['users']) && wfUtils::sets_equal($users, $n['users']))) { |
| 130 | $usersMatches = true; |
| 131 | } |
| 132 | |
| 133 | if ($categoryMatches && $usersMatches) { |
| 134 | return true; |
| 135 | } |
| 136 | } |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | public static function enqueueAdminNotices() { |
| 141 | $user = wp_get_current_user(); |
| 142 | if ($user->ID == 0) { |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | $networkAdmin = is_multisite() && is_network_admin(); |
| 147 | $notices = self::_notices(); |
| 148 | $added = false; |
| 149 | foreach ($notices as $nid => $n) { |
| 150 | if (isset($n['users']) && array_search($user->ID, $n['users']) === false) { |
| 151 | continue; |
| 152 | } |
| 153 | |
| 154 | $notice = new wfAdminNotice($nid, $n['severity'], $n['messageHTML']); |
| 155 | if ($networkAdmin) { |
| 156 | add_action('network_admin_notices', array($notice, 'displayNotice')); |
| 157 | } |
| 158 | else { |
| 159 | add_action('admin_notices', array($notice, 'displayNotice')); |
| 160 | } |
| 161 | |
| 162 | $added = true; |
| 163 | } |
| 164 | |
| 165 | return $added; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | class wfAdminNotice { |
| 170 | const SEVERITY_CRITICAL = 'critical'; |
| 171 | const SEVERITY_WARNING = 'warning'; |
| 172 | const SEVERITY_INFO = 'info'; |
| 173 | |
| 174 | private $_id; |
| 175 | private $_severity; |
| 176 | private $_messageHTML; |
| 177 | |
| 178 | public function __construct($id, $severity, $messageHTML) { |
| 179 | $this->_id = $id; |
| 180 | $this->_severity = $severity; |
| 181 | $this->_messageHTML = $messageHTML; |
| 182 | } |
| 183 | |
| 184 | public function displayNotice() { |
| 185 | $severityClass = 'notice-info'; |
| 186 | if ($this->_severity == self::SEVERITY_CRITICAL) { |
| 187 | $severityClass = 'notice-error'; |
| 188 | } |
| 189 | else if ($this->_severity == self::SEVERITY_WARNING) { |
| 190 | $severityClass = 'notice-warning'; |
| 191 | } |
| 192 | |
| 193 | echo '<div class="wf-admin-notice notice ' . $severityClass . '" data-notice-id="' . esc_attr($this->_id) . '"><p>' . $this->_messageHTML . '</p><p><a class="wf-btn wf-btn-default wf-btn-sm wf-dismiss-link" href="#" onclick="wordfenceExt.dismissAdminNotice(\'' . esc_attr($this->_id) . '\'); return false;" role="button">' . esc_html__('Dismiss', 'wordfence') . '</a></p></div>'; |
| 194 | } |
| 195 | } |