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
wfUpdateCheck.php
553 lines
| 1 | <?php |
| 2 | |
| 3 | class wfUpdateCheck { |
| 4 | |
| 5 | private $needs_core_update = false; |
| 6 | private $core_update_version = 0; |
| 7 | private $plugin_updates = array(); |
| 8 | private $all_plugins = array(); |
| 9 | private $plugin_slugs = array(); |
| 10 | private $theme_updates = array(); |
| 11 | private $api = null; |
| 12 | |
| 13 | public function __construct() { |
| 14 | $this->api = new wfAPI(wfConfig::get('apiKey'), wfUtils::getWPVersion()); |
| 15 | } |
| 16 | |
| 17 | public function __sleep() { |
| 18 | return array('needs_core_update', 'core_update_version', 'plugin_updates', 'all_plugins', 'plugin_slugs', 'theme_updates'); |
| 19 | } |
| 20 | |
| 21 | public function __wakeup() { |
| 22 | $this->api = new wfAPI(wfConfig::get('apiKey'), wfUtils::getWPVersion()); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * @return bool |
| 27 | */ |
| 28 | public function needsAnyUpdates() { |
| 29 | return $this->needsCoreUpdate() || count($this->getPluginUpdates()) > 0 || count($this->getThemeUpdates()) > 0; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Check for any core, plugin or theme updates. |
| 34 | * |
| 35 | * @return $this |
| 36 | */ |
| 37 | public function checkAllUpdates($useCachedValued = true) { |
| 38 | return $this->checkCoreUpdates($useCachedValued) |
| 39 | ->checkPluginUpdates($useCachedValued) |
| 40 | ->checkThemeUpdates($useCachedValued); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Check if there is an update to the WordPress core. |
| 45 | * |
| 46 | * @return $this |
| 47 | */ |
| 48 | public function checkCoreUpdates($useCachedValued = true) { |
| 49 | $this->needs_core_update = false; |
| 50 | |
| 51 | if (!function_exists('wp_version_check')) { |
| 52 | require_once(ABSPATH . WPINC . '/update.php'); |
| 53 | } |
| 54 | if (!function_exists('get_preferred_from_update_core')) { |
| 55 | require_once(ABSPATH . 'wp-admin/includes/update.php'); |
| 56 | } |
| 57 | |
| 58 | include(ABSPATH . WPINC . '/version.php'); //defines $wp_version |
| 59 | |
| 60 | $update_core = get_preferred_from_update_core(); |
| 61 | if ($useCachedValued && isset($update_core->last_checked) && isset($update_core->version_checked) && 12 * HOUR_IN_SECONDS > (time() - $update_core->last_checked) && $update_core->version_checked == $wp_version) { //Duplicate of _maybe_update_core, which is a private call |
| 62 | //Do nothing, use cached value |
| 63 | } |
| 64 | else { |
| 65 | wp_version_check(); |
| 66 | $update_core = get_preferred_from_update_core(); |
| 67 | } |
| 68 | |
| 69 | if (isset($update_core->response) && $update_core->response == 'upgrade') { |
| 70 | $this->needs_core_update = true; |
| 71 | $this->core_update_version = $update_core->current; |
| 72 | } |
| 73 | |
| 74 | return $this; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Check if any plugins need an update. |
| 79 | * |
| 80 | * @return $this |
| 81 | */ |
| 82 | public function checkPluginUpdates($useCachedValued = true) { |
| 83 | $this->plugin_updates = array(); |
| 84 | |
| 85 | if (!function_exists('wp_update_plugins')) { |
| 86 | require_once(ABSPATH . WPINC . '/update.php'); |
| 87 | } |
| 88 | |
| 89 | if (!function_exists('plugins_api')) { |
| 90 | require_once(ABSPATH . '/wp-admin/includes/plugin-install.php'); |
| 91 | } |
| 92 | |
| 93 | $update_plugins = get_site_transient('update_plugins'); |
| 94 | if ($useCachedValued && isset($update_plugins->last_checked) && 12 * HOUR_IN_SECONDS > (time() - $update_plugins->last_checked)) { //Duplicate of _maybe_update_plugins, which is a private call |
| 95 | //Do nothing, use cached value |
| 96 | } |
| 97 | else { |
| 98 | wp_update_plugins(); |
| 99 | $update_plugins = get_site_transient('update_plugins'); |
| 100 | } |
| 101 | |
| 102 | //Get the full plugin list |
| 103 | if (!function_exists('get_plugins')) { |
| 104 | require_once(ABSPATH . '/wp-admin/includes/plugin.php'); |
| 105 | } |
| 106 | $installedPlugins = get_plugins(); |
| 107 | |
| 108 | if ($update_plugins && !empty($update_plugins->response)) { |
| 109 | foreach ($update_plugins->response as $plugin => $vals) { |
| 110 | if (!function_exists('get_plugin_data')) { |
| 111 | require_once(ABSPATH . '/wp-admin/includes/plugin.php'); |
| 112 | } |
| 113 | |
| 114 | $pluginFile = wfUtils::getPluginBaseDir() . $plugin; |
| 115 | if (!file_exists($pluginFile)) { //Plugin has been removed since the update status was pulled |
| 116 | unset($installedPlugins[$plugin]); |
| 117 | continue; |
| 118 | } |
| 119 | |
| 120 | $valsArray = (array) $vals; |
| 121 | |
| 122 | $slug = (isset($valsArray['slug']) ? $valsArray['slug'] : null); |
| 123 | if ($slug === null) { //Plugin may have been removed from the repo or was never in it so guess |
| 124 | if (preg_match('/^([^\/]+)\//', $pluginFile, $matches)) { |
| 125 | $slug = $matches[1]; |
| 126 | } |
| 127 | else if (preg_match('/^([^\/.]+)\.php$/', $pluginFile, $matches)) { |
| 128 | $slug = $matches[1]; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | $data = get_plugin_data($pluginFile); |
| 133 | $data['pluginFile'] = $pluginFile; |
| 134 | $data['newVersion'] = (isset($valsArray['new_version']) ? $valsArray['new_version'] : 'Unknown'); |
| 135 | $data['slug'] = $slug; |
| 136 | $data['wpURL'] = (isset($valsArray['url']) ? rtrim($valsArray['url'], '/') : null); |
| 137 | |
| 138 | //Check the vulnerability database |
| 139 | if ($slug !== null && isset($data['Version'])) { |
| 140 | $status = $this->isPluginVulnerable($slug, $data['Version']); |
| 141 | $data['vulnerable'] = !!$status; |
| 142 | if (is_string($status)) { |
| 143 | $data['vulnerabilityLink'] = $status; |
| 144 | } |
| 145 | } |
| 146 | else { |
| 147 | $data['vulnerable'] = false; |
| 148 | } |
| 149 | |
| 150 | if ($slug !== null) { |
| 151 | $this->plugin_slugs[] = $slug; |
| 152 | $this->all_plugins[$slug] = $data; |
| 153 | } |
| 154 | |
| 155 | $this->plugin_updates[] = $data; |
| 156 | unset($installedPlugins[$plugin]); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | //We have to grab the slugs from the update response because no built-in function exists to return the true slug from the local files |
| 161 | if ($update_plugins && !empty($update_plugins->no_update)) { |
| 162 | foreach ($update_plugins->no_update as $plugin => $vals) { |
| 163 | if (!function_exists('get_plugin_data')) { |
| 164 | require_once(ABSPATH . '/wp-admin/includes/plugin.php'); |
| 165 | } |
| 166 | |
| 167 | $pluginFile = wfUtils::getPluginBaseDir() . $plugin; |
| 168 | if (!file_exists($pluginFile)) { //Plugin has been removed since the update status was pulled |
| 169 | unset($installedPlugins[$plugin]); |
| 170 | continue; |
| 171 | } |
| 172 | |
| 173 | $valsArray = (array) $vals; |
| 174 | |
| 175 | $data = get_plugin_data($pluginFile); |
| 176 | $data['pluginFile'] = $pluginFile; |
| 177 | $data['slug'] = (isset($valsArray['slug']) ? $valsArray['slug'] : null); |
| 178 | $data['wpURL'] = (isset($valsArray['url']) ? rtrim($valsArray['url'], '/') : null); |
| 179 | |
| 180 | //Check the vulnerability database |
| 181 | if (isset($valsArray['slug']) && isset($data['Version'])) { |
| 182 | $status = $this->isPluginVulnerable($valsArray['slug'], $data['Version']); |
| 183 | $data['vulnerable'] = !!$status; |
| 184 | if (is_string($status)) { |
| 185 | $data['vulnerabilityLink'] = $status; |
| 186 | } |
| 187 | } |
| 188 | else { |
| 189 | $data['vulnerable'] = false; |
| 190 | } |
| 191 | |
| 192 | if (isset($valsArray['slug'])) { |
| 193 | $this->plugin_slugs[] = $valsArray['slug']; |
| 194 | $this->all_plugins[$valsArray['slug']] = $data; |
| 195 | } |
| 196 | |
| 197 | unset($installedPlugins[$plugin]); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | //Get the remaining plugins (not in the wordpress.org repo for whatever reason) |
| 202 | foreach ($installedPlugins as $plugin => $data) { |
| 203 | $pluginFile = wfUtils::getPluginBaseDir() . $plugin; |
| 204 | if (!file_exists($pluginFile)) { //Plugin has been removed since the list was generated |
| 205 | continue; |
| 206 | } |
| 207 | |
| 208 | $data = get_plugin_data($pluginFile); |
| 209 | |
| 210 | $slug = null; |
| 211 | if (preg_match('/^([^\/]+)\//', $plugin, $matches)) { |
| 212 | $slug = $matches[1]; |
| 213 | } |
| 214 | else if (preg_match('/^([^\/.]+)\.php$/', $plugin, $matches)) { |
| 215 | $slug = $matches[1]; |
| 216 | } |
| 217 | |
| 218 | if ($slug !== null) { |
| 219 | $this->plugin_slugs[] = $slug; |
| 220 | $this->all_plugins[$slug] = $data; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | return $this; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Check if any themes need an update. |
| 229 | * |
| 230 | * @return $this |
| 231 | */ |
| 232 | public function checkThemeUpdates($useCachedValued = true) { |
| 233 | $this->theme_updates = array(); |
| 234 | |
| 235 | if (!function_exists('wp_update_themes')) { |
| 236 | require_once(ABSPATH . WPINC . '/update.php'); |
| 237 | } |
| 238 | |
| 239 | $update_themes = get_site_transient('update_themes'); |
| 240 | if ($useCachedValued && isset($update_themes->last_checked) && 12 * HOUR_IN_SECONDS > (time() - $update_themes->last_checked)) { //Duplicate of _maybe_update_themes, which is a private call |
| 241 | //Do nothing, use cached value |
| 242 | } |
| 243 | else { |
| 244 | wp_update_themes(); |
| 245 | $update_themes = get_site_transient('update_themes'); |
| 246 | } |
| 247 | |
| 248 | if ($update_themes && (!empty($update_themes->response))) { |
| 249 | if (!function_exists('wp_get_themes')) { |
| 250 | require_once(ABSPATH . '/wp-includes/theme.php'); |
| 251 | } |
| 252 | $themes = wp_get_themes(); |
| 253 | foreach ($update_themes->response as $theme => $vals) { |
| 254 | foreach ($themes as $name => $themeData) { |
| 255 | if (strtolower($name) == $theme) { |
| 256 | $vulnerable = false; |
| 257 | if (isset($themeData['Version'])) { |
| 258 | $vulnerable = $this->isThemeVulnerable($theme, $themeData['Version']); |
| 259 | } |
| 260 | |
| 261 | $this->theme_updates[] = array( |
| 262 | 'newVersion' => (isset($vals['new_version']) ? $vals['new_version'] : 'Unknown'), |
| 263 | 'package' => (isset($vals['package']) ? $vals['package'] : null), |
| 264 | 'URL' => (isset($vals['url']) ? $vals['url'] : null), |
| 265 | 'Name' => $themeData['Name'], |
| 266 | 'name' => $themeData['Name'], |
| 267 | 'version' => $themeData['Version'], |
| 268 | 'vulnerable' => $vulnerable |
| 269 | ); |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | return $this; |
| 275 | } |
| 276 | |
| 277 | public function checkAllVulnerabilities() { |
| 278 | $this->checkPluginVulnerabilities(); |
| 279 | $this->checkThemeVulnerabilities(); |
| 280 | } |
| 281 | |
| 282 | public function checkPluginVulnerabilities() { |
| 283 | if (!function_exists('wp_update_plugins')) { |
| 284 | require_once(ABSPATH . WPINC . '/update.php'); |
| 285 | } |
| 286 | |
| 287 | if (!function_exists('plugins_api')) { |
| 288 | require_once(ABSPATH . '/wp-admin/includes/plugin-install.php'); |
| 289 | } |
| 290 | |
| 291 | $vulnerabilities = array(); |
| 292 | |
| 293 | //Get the full plugin list |
| 294 | if (!function_exists('get_plugins')) { |
| 295 | require_once(ABSPATH . '/wp-admin/includes/plugin.php'); |
| 296 | } |
| 297 | $installedPlugins = get_plugins(); |
| 298 | |
| 299 | //Get the info for plugins on wordpress.org |
| 300 | $this->checkPluginUpdates(); |
| 301 | $update_plugins = get_site_transient('update_plugins'); |
| 302 | if ($update_plugins) { |
| 303 | if (!function_exists('get_plugin_data')) |
| 304 | { |
| 305 | require_once(ABSPATH . '/wp-admin/includes/plugin.php'); |
| 306 | } |
| 307 | |
| 308 | if (!empty($update_plugins->response)) { |
| 309 | foreach ($update_plugins->response as $plugin => $vals) { |
| 310 | $pluginFile = wfUtils::getPluginBaseDir() . $plugin; |
| 311 | if (!file_exists($pluginFile)) { //Plugin has been removed since the update status was pulled |
| 312 | unset($installedPlugins[$plugin]); |
| 313 | continue; |
| 314 | } |
| 315 | |
| 316 | $valsArray = (array) $vals; |
| 317 | $data = get_plugin_data($pluginFile); |
| 318 | |
| 319 | $slug = (isset($valsArray['slug']) ? $valsArray['slug'] : null); |
| 320 | if ($slug === null) { //Plugin may have been removed from the repo or was never in it so guess |
| 321 | if (preg_match('/^([^\/]+)\//', $plugin, $matches)) { |
| 322 | $slug = $matches[1]; |
| 323 | } |
| 324 | else if (preg_match('/^([^\/.]+)\.php$/', $plugin, $matches)) { |
| 325 | $slug = $matches[1]; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | $record = array(); |
| 330 | $record['slug'] = $slug; |
| 331 | $record['toVersion'] = (isset($valsArray['new_version']) ? $valsArray['new_version'] : 'Unknown'); |
| 332 | $record['fromVersion'] = (isset($data['Version']) ? $data['Version'] : 'Unknown'); |
| 333 | $record['vulnerable'] = false; |
| 334 | $vulnerabilities[] = $record; |
| 335 | |
| 336 | unset($installedPlugins[$plugin]); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | if (!empty($update_plugins->no_update)) { |
| 341 | foreach ($update_plugins->no_update as $plugin => $vals) { |
| 342 | $pluginFile = wfUtils::getPluginBaseDir() . $plugin; |
| 343 | if (!file_exists($pluginFile)) { //Plugin has been removed since the update status was pulled |
| 344 | unset($installedPlugins[$plugin]); |
| 345 | continue; |
| 346 | } |
| 347 | |
| 348 | $valsArray = (array) $vals; |
| 349 | $data = get_plugin_data($pluginFile); |
| 350 | |
| 351 | $slug = (isset($valsArray['slug']) ? $valsArray['slug'] : null); |
| 352 | if ($slug === null) { //Plugin may have been removed from the repo or was never in it so guess |
| 353 | if (preg_match('/^([^\/]+)\//', $plugin, $matches)) { |
| 354 | $slug = $matches[1]; |
| 355 | } |
| 356 | else if (preg_match('/^([^\/.]+)\.php$/', $plugin, $matches)) { |
| 357 | $slug = $matches[1]; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | $record = array(); |
| 362 | $record['slug'] = $slug; |
| 363 | $record['fromVersion'] = (isset($data['Version']) ? $data['Version'] : 'Unknown'); |
| 364 | $record['vulnerable'] = false; |
| 365 | $vulnerabilities[] = $record; |
| 366 | |
| 367 | unset($installedPlugins[$plugin]); |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | //Get the remaining plugins (not in the wordpress.org repo for whatever reason) |
| 373 | foreach ($installedPlugins as $plugin => $data) { |
| 374 | $pluginFile = wfUtils::getPluginBaseDir() . $plugin; |
| 375 | if (!file_exists($pluginFile)) { //Plugin has been removed since the update status was pulled |
| 376 | continue; |
| 377 | } |
| 378 | |
| 379 | $data = get_plugin_data($pluginFile); |
| 380 | |
| 381 | $slug = null; |
| 382 | if (preg_match('/^([^\/]+)\//', $plugin, $matches)) { |
| 383 | $slug = $matches[1]; |
| 384 | } |
| 385 | else if (preg_match('/^([^\/.]+)\.php$/', $plugin, $matches)) { |
| 386 | $slug = $matches[1]; |
| 387 | } |
| 388 | |
| 389 | $record = array(); |
| 390 | $record['slug'] = $slug; |
| 391 | $record['fromVersion'] = (isset($data['Version']) ? $data['Version'] : 'Unknown'); |
| 392 | $record['vulnerable'] = false; |
| 393 | $vulnerabilities[] = $record; |
| 394 | } |
| 395 | |
| 396 | if (count($vulnerabilities) > 0) { |
| 397 | try { |
| 398 | $result = $this->api->call('plugin_vulnerability_check', array(), array( |
| 399 | 'plugins' => json_encode($vulnerabilities), |
| 400 | )); |
| 401 | |
| 402 | foreach ($vulnerabilities as &$v) { |
| 403 | $vulnerableList = $result['vulnerable']; |
| 404 | foreach ($vulnerableList as $r) { |
| 405 | if ($r['slug'] == $v['slug']) { |
| 406 | $v['vulnerable'] = !!$r['vulnerable']; |
| 407 | if (isset($r['link'])) { |
| 408 | $v['link'] = $r['link']; |
| 409 | } |
| 410 | break; |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | catch (Exception $e) { |
| 416 | //Do nothing |
| 417 | } |
| 418 | |
| 419 | wfConfig::set_ser('vulnerabilities_plugin', $vulnerabilities); |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | public function checkThemeVulnerabilities() { |
| 424 | if (!function_exists('wp_update_themes')) { |
| 425 | require_once(ABSPATH . WPINC . '/update.php'); |
| 426 | } |
| 427 | |
| 428 | if (!function_exists('plugins_api')) { |
| 429 | require_once(ABSPATH . '/wp-admin/includes/plugin-install.php'); |
| 430 | } |
| 431 | |
| 432 | $this->checkThemeUpdates(); |
| 433 | $update_themes = get_site_transient('update_themes'); |
| 434 | |
| 435 | $vulnerabilities = array(); |
| 436 | if ($update_themes && !empty($update_themes->response)) { |
| 437 | if (!function_exists('get_plugin_data')) |
| 438 | { |
| 439 | require_once(ABSPATH . '/wp-admin/includes/plugin.php'); |
| 440 | } |
| 441 | |
| 442 | foreach ($update_themes->response as $themeSlug => $vals) { |
| 443 | |
| 444 | $valsArray = (array) $vals; |
| 445 | $theme = wp_get_theme($themeSlug); |
| 446 | |
| 447 | $record = array(); |
| 448 | $record['slug'] = $themeSlug; |
| 449 | $record['toVersion'] = (isset($valsArray['new_version']) ? $valsArray['new_version'] : 'Unknown'); |
| 450 | $record['fromVersion'] = $theme->version; |
| 451 | $record['vulnerable'] = false; |
| 452 | $vulnerabilities[] = $record; |
| 453 | } |
| 454 | |
| 455 | try { |
| 456 | $result = $this->api->call('theme_vulnerability_check', array(), array( |
| 457 | 'themes' => json_encode($vulnerabilities), |
| 458 | )); |
| 459 | |
| 460 | foreach ($vulnerabilities as &$v) { |
| 461 | $vulnerableList = $result['vulnerable']; |
| 462 | foreach ($vulnerableList as $r) { |
| 463 | if ($r['slug'] == $v['slug']) { |
| 464 | $v['vulnerable'] = !!$r['vulnerable']; |
| 465 | break; |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | catch (Exception $e) { |
| 471 | //Do nothing |
| 472 | } |
| 473 | |
| 474 | wfConfig::set_ser('vulnerabilities_theme', $vulnerabilities); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | public function isPluginVulnerable($slug, $version) { |
| 479 | return $this->_isSlugVulnerable('vulnerabilities_plugin', $slug, $version); |
| 480 | } |
| 481 | |
| 482 | public function isThemeVulnerable($slug, $version) { |
| 483 | return $this->_isSlugVulnerable('vulnerabilities_theme', $slug, $version); |
| 484 | } |
| 485 | |
| 486 | private function _isSlugVulnerable($vulnerabilitiesKey, $slug, $version) { |
| 487 | $vulnerabilities = wfConfig::get_ser($vulnerabilitiesKey, array()); |
| 488 | foreach ($vulnerabilities as $v) { |
| 489 | if ($v['slug'] == $slug) { |
| 490 | if ($v['fromVersion'] == 'Unknown' && $v['toVersion'] == 'Unknown') { |
| 491 | if ($v['vulnerable'] && isset($v['link']) && is_string($v['link'])) { return $v['link']; } |
| 492 | return $v['vulnerable']; |
| 493 | } |
| 494 | else if ((!isset($v['toVersion']) || $v['toVersion'] == 'Unknown') && version_compare($version, $v['fromVersion']) >= 0) { |
| 495 | if ($v['vulnerable'] && isset($v['link']) && is_string($v['link'])) { return $v['link']; } |
| 496 | return $v['vulnerable']; |
| 497 | } |
| 498 | else if ($v['fromVersion'] == 'Unknown' && isset($v['toVersion']) && version_compare($version, $v['toVersion']) < 0) { |
| 499 | if ($v['vulnerable'] && isset($v['link']) && is_string($v['link'])) { return $v['link']; } |
| 500 | return $v['vulnerable']; |
| 501 | } |
| 502 | else if (version_compare($version, $v['fromVersion']) >= 0 && isset($v['toVersion']) && version_compare($version, $v['toVersion']) < 0) { |
| 503 | if ($v['vulnerable'] && isset($v['link']) && is_string($v['link'])) { return $v['link']; } |
| 504 | return $v['vulnerable']; |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | return false; |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * @return boolean |
| 513 | */ |
| 514 | public function needsCoreUpdate() { |
| 515 | return $this->needs_core_update; |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * @return int |
| 520 | */ |
| 521 | public function getCoreUpdateVersion() { |
| 522 | return $this->core_update_version; |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * @return array |
| 527 | */ |
| 528 | public function getPluginUpdates() { |
| 529 | return $this->plugin_updates; |
| 530 | } |
| 531 | |
| 532 | /** |
| 533 | * @return array |
| 534 | */ |
| 535 | public function getAllPlugins() { |
| 536 | return $this->all_plugins; |
| 537 | } |
| 538 | |
| 539 | /** |
| 540 | * @return array |
| 541 | */ |
| 542 | public function getPluginSlugs() { |
| 543 | return $this->plugin_slugs; |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * @return array |
| 548 | */ |
| 549 | public function getThemeUpdates() { |
| 550 | return $this->theme_updates; |
| 551 | } |
| 552 | } |
| 553 |