Diff
8 years ago
dashboard
7 years ago
.htaccess
8 years ago
Diff.php
14 years ago
GeoLite2-Country.mmdb
8 years ago
IPTraf.php
8 years ago
IPTrafList.php
8 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
live_activity.php
8 years ago
menu_dashboard.php
8 years ago
menu_dashboard_options.php
8 years ago
menu_firewall.php
8 years ago
menu_firewall_blocking.php
8 years ago
menu_firewall_blocking_options.php
8 years ago
menu_firewall_waf.php
8 years ago
menu_firewall_waf_options.php
8 years ago
menu_options.php
7 years ago
menu_scanner.php
8 years ago
menu_scanner_credentials.php
8 years ago
menu_scanner_options.php
8 years ago
menu_support.php
8 years ago
menu_tools.php
8 years ago
menu_tools_commentSpam.php
8 years ago
menu_tools_diagnostic.php
7 years ago
menu_tools_livetraffic.php
7 years ago
menu_tools_twoFactor.php
8 years ago
menu_tools_whois.php
8 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
8 years ago
wfBulkCountries.php
8 years ago
wfCache.php
9 years ago
wfConfig.php
7 years ago
wfCountryMap.php
8 years ago
wfCrawl.php
8 years ago
wfCredentialsController.php
8 years ago
wfCrypt.php
8 years ago
wfDB.php
8 years ago
wfDashboard.php
8 years ago
wfDateLocalization.php
8 years ago
wfDiagnostic.php
8 years ago
wfDict.php
8 years ago
wfDirectoryIterator.php
8 years ago
wfHelperBin.php
11 years ago
wfHelperString.php
11 years ago
wfIPWhitelist.php
9 years ago
wfImportExportController.php
8 years ago
wfIssues.php
7 years ago
wfLockedOut.php
7 years ago
wfLog.php
7 years ago
wfMD5BloomFilter.php
8 years ago
wfNotification.php
8 years ago
wfOnboardingController.php
7 years ago
wfPersistenceController.php
8 years ago
wfRESTAPI.php
9 years ago
wfScan.php
7 years ago
wfScanEngine.php
7 years ago
wfSchema.php
8 years ago
wfStyle.php
8 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
8 years ago
wordfenceScanner.php
7 years ago
wordfenceURLHoover.php
7 years ago
wfDiagnostic.php
596 lines
| 1 | <?php |
| 2 | |
| 3 | class wfGrant |
| 4 | { |
| 5 | public $select = false; |
| 6 | public $update = false; |
| 7 | public $insert = false; |
| 8 | public $delete = false; |
| 9 | public $alter = false; |
| 10 | public $create = false; |
| 11 | public $drop = false; |
| 12 | |
| 13 | public static function get() |
| 14 | { |
| 15 | static $instance; |
| 16 | if ($instance === null) { |
| 17 | $instance = new self; |
| 18 | } |
| 19 | return $instance; |
| 20 | } |
| 21 | |
| 22 | private function __construct() |
| 23 | { |
| 24 | global $wpdb; |
| 25 | $rows = $wpdb->get_results("SHOW GRANTS FOR current_user()", ARRAY_N); |
| 26 | |
| 27 | foreach ($rows as $row) { |
| 28 | preg_match("/GRANT (.+) ON (.+) TO/", $row[0], $matches); |
| 29 | foreach (explode(",", $matches[1]) as $permission) { |
| 30 | $permission = str_replace(" ", "_", trim(strtolower($permission))); |
| 31 | if ($permission === 'all_privileges') { |
| 32 | foreach ($this as $key => $value) { |
| 33 | $this->$key = true; |
| 34 | } |
| 35 | break 2; |
| 36 | } |
| 37 | $this->$permission = true; |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | class wfDiagnostic |
| 44 | { |
| 45 | protected $minVersion = array( |
| 46 | 'PHP' => '5.2.4', |
| 47 | 'cURL' => '1.0', |
| 48 | ); |
| 49 | |
| 50 | protected $description = false; //Defined in the constructor to allow for localization |
| 51 | |
| 52 | protected $results = array(); |
| 53 | |
| 54 | public function __construct() |
| 55 | { |
| 56 | $this->description = array( |
| 57 | 'Wordfence Status' => array( |
| 58 | 'description' => __('General information about the Wordfence installation.', 'wordfence'), |
| 59 | 'tests' => array( |
| 60 | 'wfVersion' => __('Wordfence Version', 'wordfence'), |
| 61 | ), |
| 62 | ), |
| 63 | 'Filesystem' => array( |
| 64 | 'description' => __('Ability to read/write various files.', 'wordfence'), |
| 65 | 'tests' => array( |
| 66 | 'isPluginReadable' => __('Checking if web server can read from <code>~/plugins/wordfence</code>', 'wordfence'), |
| 67 | 'isPluginWritable' => __('Checking if web server can write to <code>~/plugins/wordfence</code>', 'wordfence'), |
| 68 | 'isWAFReadable' => __('Checking if web server can read from <code>~/wp-content/wflogs</code>', 'wordfence'), |
| 69 | 'isWAFWritable' => __('Checking if web server can write to <code>~/wp-content/wflogs</code>', 'wordfence'), |
| 70 | ), |
| 71 | ), |
| 72 | 'Wordfence Config' => array( |
| 73 | 'description' => __('Ability to save Wordfence settings to the database.', 'wordfence'), |
| 74 | 'tests' => array( |
| 75 | 'configWritableSet' => __('Checking basic config reading/writing', 'wordfence'), |
| 76 | 'configWritableSetSer' => __('Checking serialized config reading/writing', 'wordfence'), |
| 77 | ), |
| 78 | ), |
| 79 | 'Wordfence Firewall' => array( |
| 80 | 'description' => __('Current WAF configuration.', 'wordfence'), |
| 81 | 'tests' => array( |
| 82 | 'wafAutoPrepend' => __('WAF auto prepend active', 'wordfence'), |
| 83 | 'wafLogPath' => __('WAF log path', 'wordfence'), |
| 84 | 'wafSubdirectoryInstall' => __('WAF subdirectory installation', 'wordfence'), |
| 85 | 'wafAutoPrependFilePath' => __('wordfence-waf.php path', 'wordfence'), |
| 86 | ), |
| 87 | ), |
| 88 | 'MySQL' => array( |
| 89 | 'description' => __('Database version and privileges.', 'wordfence'), |
| 90 | 'tests' => array( |
| 91 | 'databaseVersion' => __('Database Version', 'wordfence'), |
| 92 | 'userCanDelete' => __('Checking if MySQL user has <code>DELETE</code> privilege', 'wordfence'), |
| 93 | 'userCanInsert' => __('Checking if MySQL user has <code>INSERT</code> privilege', 'wordfence'), |
| 94 | 'userCanUpdate' => __('Checking if MySQL user has <code>UPDATE</code> privilege', 'wordfence'), |
| 95 | 'userCanSelect' => __('Checking if MySQL user has <code>SELECT</code> privilege', 'wordfence'), |
| 96 | 'userCanCreate' => __('Checking if MySQL user has <code>CREATE TABLE</code> privilege', 'wordfence'), |
| 97 | 'userCanAlter' => __('Checking if MySQL user has <code>ALTER TABLE</code> privilege', 'wordfence'), |
| 98 | 'userCanDrop' => __('Checking if MySQL user has <code>DROP</code> privilege', 'wordfence'), |
| 99 | 'userCanTruncate' => __('Checking if MySQL user has <code>TRUNCATE</code> privilege', 'wordfence'), |
| 100 | ) |
| 101 | ), |
| 102 | 'PHP Environment' => array( |
| 103 | 'description' => __('PHP version, important PHP extensions.', 'wordfence'), |
| 104 | 'tests' => array( |
| 105 | 'phpVersion' => __('PHP version >= PHP 5.2.4<br><em> (<a href="https://wordpress.org/about/requirements/" target="_blank" rel="noopener noreferrer">Minimum version required by WordPress</a>)</em>', 'wordfence'), |
| 106 | 'processOwner' => __('Process Owner', 'wordfence'), |
| 107 | 'hasOpenSSL' => __('Checking for OpenSSL support', 'wordfence'), |
| 108 | 'openSSLVersion' => __('Checking OpenSSL version', 'wordfence'), |
| 109 | 'hasCurl' => __('Checking for cURL support', 'wordfence'), |
| 110 | 'curlFeatures' => __('cURL Features Code', 'wordfence'), |
| 111 | 'curlHost' => __('cURL Host', 'wordfence'), |
| 112 | 'curlProtocols' => __('cURL Support Protocols', 'wordfence'), |
| 113 | 'curlSSLVersion' => __('cURL SSL Version', 'wordfence'), |
| 114 | 'curlLibZVersion' => __('cURL libz Version', 'wordfence'), |
| 115 | 'displayErrors' => __('Checking <code>display_errors</code><br><em> (<a href="http://php.net/manual/en/errorfunc.configuration.php#ini.display-errors" target="_blank" rel="noopener noreferrer">Should be disabled on production servers</a>)</em>', 'wordfence'), |
| 116 | ) |
| 117 | ), |
| 118 | 'Connectivity' => array( |
| 119 | 'description' => __('Ability to connect to the Wordfence servers and your own site.', 'wordfence'), |
| 120 | 'tests' => array( |
| 121 | 'connectToServer1' => __('Connecting to Wordfence servers (http)', 'wordfence'), |
| 122 | 'connectToServer2' => __('Connecting to Wordfence servers (https)', 'wordfence'), |
| 123 | 'connectToSelf' => __('Connecting back to this site', 'wordfence'), |
| 124 | 'serverIP' => __('IP(s) used by this server', 'wordfence'), |
| 125 | ) |
| 126 | ), |
| 127 | ); |
| 128 | |
| 129 | foreach ($this->description as $title => $tests) { |
| 130 | $this->results[$title] = array( |
| 131 | 'description' => $tests['description'], |
| 132 | ); |
| 133 | foreach ($tests['tests'] as $name => $description) { |
| 134 | if (!method_exists($this, $name)) { |
| 135 | continue; |
| 136 | } |
| 137 | |
| 138 | $result = $this->$name(); |
| 139 | |
| 140 | if (is_bool($result)) { |
| 141 | $result = array( |
| 142 | 'test' => $result, |
| 143 | 'message' => $result ? 'OK' : 'FAIL', |
| 144 | ); |
| 145 | } |
| 146 | |
| 147 | $result['label'] = $description; |
| 148 | $result['name'] = $name; |
| 149 | |
| 150 | $this->results[$title]['results'][] = $result; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | public function getResults() |
| 156 | { |
| 157 | return $this->results; |
| 158 | } |
| 159 | |
| 160 | public function wfVersion() { |
| 161 | return array('test' => true, 'message' => WORDFENCE_VERSION . ' (' . WORDFENCE_BUILD_NUMBER . ')'); |
| 162 | } |
| 163 | |
| 164 | public function isPluginReadable() { |
| 165 | return is_readable(WORDFENCE_PATH); |
| 166 | } |
| 167 | |
| 168 | public function isPluginWritable() { |
| 169 | return is_writable(WORDFENCE_PATH); |
| 170 | } |
| 171 | |
| 172 | public function isWAFReadable() { |
| 173 | if (!is_readable(WFWAF_LOG_PATH)) { |
| 174 | return array('test' => false, 'message' => __('No files readable', 'wordfence')); |
| 175 | } |
| 176 | |
| 177 | $files = array( |
| 178 | WFWAF_LOG_PATH . 'attack-data.php', |
| 179 | WFWAF_LOG_PATH . 'ips.php', |
| 180 | WFWAF_LOG_PATH . 'config.php', |
| 181 | WFWAF_LOG_PATH . 'rules.php', |
| 182 | WFWAF_LOG_PATH . 'wafRules.rules', |
| 183 | ); |
| 184 | $unreadable = array(); |
| 185 | foreach ($files as $f) { |
| 186 | if (!file_exists($f)) { |
| 187 | $unreadable[] = sprintf(__('File "%s" does not exist', 'wordfence'), basename($f)); |
| 188 | } |
| 189 | else if (!is_readable($f)) { |
| 190 | $unreadable[] = sprintf(__('File "%s" is unreadable', 'wordfence'), basename($f)); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | if (count($unreadable) > 0) { |
| 195 | return array('test' => false, 'message' => implode(', ', $unreadable)); |
| 196 | } |
| 197 | |
| 198 | return true; |
| 199 | } |
| 200 | |
| 201 | public function isWAFWritable() { |
| 202 | if (!is_writable(WFWAF_LOG_PATH)) { |
| 203 | return array('test' => false, 'message' => __('No files writable', 'wordfence')); |
| 204 | } |
| 205 | |
| 206 | $files = array( |
| 207 | WFWAF_LOG_PATH . 'attack-data.php', |
| 208 | WFWAF_LOG_PATH . 'ips.php', |
| 209 | WFWAF_LOG_PATH . 'config.php', |
| 210 | WFWAF_LOG_PATH . 'rules.php', |
| 211 | WFWAF_LOG_PATH . 'wafRules.rules', |
| 212 | ); |
| 213 | $unwritable = array(); |
| 214 | foreach ($files as $f) { |
| 215 | if (!file_exists($f)) { |
| 216 | $unwritable[] = sprintf(__('File "%s" does not exist', 'wordfence'), basename($f)); |
| 217 | } |
| 218 | else if (!is_writable($f)) { |
| 219 | $unwritable[] = sprintf(__('File "%s" is unwritable', 'wordfence'), basename($f)); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | if (count($unwritable) > 0) { |
| 224 | return array('test' => false, 'message' => implode(', ', $unwritable)); |
| 225 | } |
| 226 | |
| 227 | return true; |
| 228 | } |
| 229 | |
| 230 | public function databaseVersion() { |
| 231 | global $wpdb; |
| 232 | $version = $wpdb->get_var("SELECT VERSION()"); |
| 233 | return array('test' => true, 'message' => $version); |
| 234 | } |
| 235 | |
| 236 | public function userCanInsert() { |
| 237 | return wfGrant::get()->insert; |
| 238 | } |
| 239 | |
| 240 | public function userCanUpdate() { |
| 241 | return wfGrant::get()->update; |
| 242 | } |
| 243 | |
| 244 | public function userCanDelete() { |
| 245 | return wfGrant::get()->delete; |
| 246 | } |
| 247 | |
| 248 | public function userCanSelect() { |
| 249 | return wfGrant::get()->select; |
| 250 | } |
| 251 | |
| 252 | public function userCanCreate() { |
| 253 | return wfGrant::get()->create; |
| 254 | } |
| 255 | |
| 256 | public function userCanDrop() { |
| 257 | return wfGrant::get()->drop; |
| 258 | } |
| 259 | |
| 260 | public function userCanTruncate() { |
| 261 | return wfGrant::get()->drop && wfGrant::get()->delete; |
| 262 | } |
| 263 | |
| 264 | public function userCanAlter() { |
| 265 | return wfGrant::get()->alter; |
| 266 | } |
| 267 | |
| 268 | public function phpVersion() |
| 269 | { |
| 270 | return array( |
| 271 | 'test' => version_compare(phpversion(), $this->minVersion['PHP'], '>='), |
| 272 | 'message' => phpversion(), |
| 273 | ); |
| 274 | } |
| 275 | |
| 276 | public function configWritableSet() { |
| 277 | global $wpdb; |
| 278 | $show = $wpdb->hide_errors(); |
| 279 | $val = md5(time()); |
| 280 | wfConfig::set('configWritingTest', $val, wfConfig::DONT_AUTOLOAD); |
| 281 | $testVal = wfConfig::get('configWritingTest'); |
| 282 | $wpdb->show_errors($show); |
| 283 | return array( |
| 284 | 'test' => ($val === $testVal), |
| 285 | 'message' => __('Basic config writing', 'wordfence') |
| 286 | ); |
| 287 | } |
| 288 | public function configWritableSetSer() { |
| 289 | global $wpdb; |
| 290 | $show = $wpdb->hide_errors(); |
| 291 | $val = md5(time()); |
| 292 | wfConfig::set_ser('configWritingTest_ser', array($val), false, wfConfig::DONT_AUTOLOAD); |
| 293 | $testVal = @array_shift(wfConfig::get_ser('configWritingTest_ser', array(), false)); |
| 294 | $wpdb->show_errors($show); |
| 295 | return array( |
| 296 | 'test' => ($val === $testVal), |
| 297 | 'message' => __('Serialized config writing', 'wordfence') |
| 298 | ); |
| 299 | } |
| 300 | |
| 301 | public function wafAutoPrepend() { |
| 302 | return array('test' => true, 'infoOnly' => true, 'message' => (defined('WFWAF_AUTO_PREPEND') && WFWAF_AUTO_PREPEND ? __('Yes', 'wordfence') : __('No', 'wordfence'))); |
| 303 | } |
| 304 | public function wafLogPath() { |
| 305 | $logPath = __('(not set)', 'wordfence'); |
| 306 | if (defined('WFWAF_LOG_PATH')) { |
| 307 | $logPath = WFWAF_LOG_PATH; |
| 308 | if (strpos($logPath, ABSPATH) === 0) { |
| 309 | $logPath = '~/' . substr($logPath, strlen(ABSPATH)); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | return array('test' => true, 'infoOnly' => true, 'message' => $logPath); |
| 314 | } |
| 315 | |
| 316 | public function wafSubdirectoryInstall() { |
| 317 | return array('test' => true, 'infoOnly' => true, 'message' => (defined('WFWAF_SUBDIRECTORY_INSTALL') && WFWAF_SUBDIRECTORY_INSTALL ? __('Yes', 'wordfence') : __('No', 'wordfence'))); |
| 318 | } |
| 319 | |
| 320 | public function wafAutoPrependFilePath() { |
| 321 | $path = wordfence::getWAFBootstrapPath(); |
| 322 | if (!file_exists($path)) { |
| 323 | $path = ''; |
| 324 | } |
| 325 | return array('test' => true, 'infoOnly' => true, 'message' => $path); |
| 326 | } |
| 327 | |
| 328 | public function processOwner() { |
| 329 | $disabledFunctions = explode(',', ini_get('disable_functions')); |
| 330 | |
| 331 | if (is_callable('posix_geteuid')) { |
| 332 | if (!is_callable('posix_getpwuid') || in_array('posix_getpwuid', $disabledFunctions)) { |
| 333 | return array( |
| 334 | 'test' => false, |
| 335 | 'message' => __('Unavailable', 'wordfence'), |
| 336 | ); |
| 337 | } |
| 338 | |
| 339 | $processOwner = posix_getpwuid(posix_geteuid()); |
| 340 | if ($processOwner !== null) |
| 341 | { |
| 342 | return array( |
| 343 | 'test' => true, |
| 344 | 'message' => $processOwner['name'], |
| 345 | ); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | $usernameOrUserEnv = getenv('USERNAME') ? getenv('USERNAME') : getenv('USER'); |
| 350 | if (!empty($usernameOrUserEnv)) { //Check some environmental variable possibilities |
| 351 | return array( |
| 352 | 'test' => true, |
| 353 | 'message' => $usernameOrUserEnv, |
| 354 | ); |
| 355 | } |
| 356 | |
| 357 | $currentUser = get_current_user(); |
| 358 | if (!empty($currentUser)) { //php.net comments indicate on Windows this returns the process owner rather than the file owner |
| 359 | return array( |
| 360 | 'test' => true, |
| 361 | 'message' => $currentUser, |
| 362 | ); |
| 363 | } |
| 364 | |
| 365 | if (!empty($_SERVER['LOGON_USER'])) { //Last resort for IIS since POSIX functions are unavailable, Source: https://msdn.microsoft.com/en-us/library/ms524602(v=vs.90).aspx |
| 366 | return array( |
| 367 | 'test' => true, |
| 368 | 'message' => $_SERVER['LOGON_USER'], |
| 369 | ); |
| 370 | } |
| 371 | |
| 372 | return array( |
| 373 | 'test' => false, |
| 374 | 'message' => __('Unknown', 'wordfence'), |
| 375 | ); |
| 376 | } |
| 377 | |
| 378 | public function hasOpenSSL() { |
| 379 | return is_callable('openssl_open'); |
| 380 | } |
| 381 | |
| 382 | public function openSSLVersion() { |
| 383 | if (!function_exists('openssl_verify') || !defined('OPENSSL_VERSION_NUMBER') || !defined('OPENSSL_VERSION_TEXT')) { |
| 384 | return false; |
| 385 | } |
| 386 | $compare = wfVersionCheckController::shared()->checkOpenSSLVersion(); |
| 387 | return array( |
| 388 | 'test' => $compare == wfVersionCheckController::VERSION_COMPATIBLE, |
| 389 | 'message' => OPENSSL_VERSION_TEXT . ' (0x' . dechex(OPENSSL_VERSION_NUMBER) . ')', |
| 390 | ); |
| 391 | } |
| 392 | |
| 393 | public function hasCurl() { |
| 394 | if (!is_callable('curl_version')) { |
| 395 | return false; |
| 396 | } |
| 397 | $version = curl_version(); |
| 398 | return array( |
| 399 | 'test' => version_compare($version['version'], $this->minVersion['cURL'], '>='), |
| 400 | 'message' => $version['version'] . ' (0x' . dechex($version['version_number']) . ')', |
| 401 | ); |
| 402 | } |
| 403 | |
| 404 | public function curlFeatures() { |
| 405 | if (!is_callable('curl_version')) { |
| 406 | return false; |
| 407 | } |
| 408 | $version = curl_version(); |
| 409 | return array( |
| 410 | 'test' => true, |
| 411 | 'message' => '0x' . dechex($version['features']), |
| 412 | 'infoOnly' => true, |
| 413 | ); |
| 414 | } |
| 415 | |
| 416 | public function curlHost() { |
| 417 | if (!is_callable('curl_version')) { |
| 418 | return false; |
| 419 | } |
| 420 | $version = curl_version(); |
| 421 | return array( |
| 422 | 'test' => true, |
| 423 | 'message' => $version['host'], |
| 424 | 'infoOnly' => true, |
| 425 | ); |
| 426 | } |
| 427 | |
| 428 | public function curlProtocols() { |
| 429 | if (!is_callable('curl_version')) { |
| 430 | return false; |
| 431 | } |
| 432 | $version = curl_version(); |
| 433 | return array( |
| 434 | 'test' => true, |
| 435 | 'message' => implode(', ', $version['protocols']), |
| 436 | 'infoOnly' => true, |
| 437 | ); |
| 438 | } |
| 439 | |
| 440 | public function curlSSLVersion() { |
| 441 | if (!is_callable('curl_version')) { |
| 442 | return false; |
| 443 | } |
| 444 | $version = curl_version(); |
| 445 | return array( |
| 446 | 'test' => true, |
| 447 | 'message' => $version['ssl_version'], |
| 448 | 'infoOnly' => true, |
| 449 | ); |
| 450 | } |
| 451 | |
| 452 | public function curlLibZVersion() { |
| 453 | if (!is_callable('curl_version')) { |
| 454 | return false; |
| 455 | } |
| 456 | $version = curl_version(); |
| 457 | return array( |
| 458 | 'test' => true, |
| 459 | 'message' => $version['libz_version'], |
| 460 | 'infoOnly' => true, |
| 461 | ); |
| 462 | } |
| 463 | |
| 464 | public function displayErrors() { |
| 465 | if (!is_callable('ini_get')) { |
| 466 | return false; |
| 467 | } |
| 468 | $value = ini_get('display_errors'); |
| 469 | $isOn = strtolower($value) == 'on' || $value == 1; |
| 470 | return array( |
| 471 | 'test' => !$isOn, |
| 472 | 'message' => $isOn ? __('On', 'wordfence') : __('Off', 'wordfence'), |
| 473 | 'infoOnly' => true, |
| 474 | ); |
| 475 | } |
| 476 | |
| 477 | public function connectToServer1() { |
| 478 | return $this->_connectToServer('http'); |
| 479 | } |
| 480 | |
| 481 | public function connectToServer2() { |
| 482 | return $this->_connectToServer('https'); |
| 483 | } |
| 484 | |
| 485 | public function _connectToServer($protocol) { |
| 486 | $cronURL = admin_url('admin-ajax.php'); |
| 487 | $cronURL = preg_replace('/^(https?:\/\/)/i', '://noc1.wordfence.com/scanptest/', $cronURL); |
| 488 | $cronURL .= '?action=wordfence_doScan&isFork=0&cronKey=47e9d1fa6a675b5999999333'; |
| 489 | $cronURL = $protocol . $cronURL; |
| 490 | $result = wp_remote_post($cronURL, array( |
| 491 | 'timeout' => 10, //Must be less than max execution time or more than 2 HTTP children will be occupied by scan |
| 492 | 'blocking' => true, //Non-blocking seems to block anyway, so we use blocking |
| 493 | // This causes cURL to throw errors in some versions since WordPress uses its own certificate bundle ('CA certificate set, but certificate verification is disabled') |
| 494 | // 'sslverify' => false, |
| 495 | 'headers' => array() |
| 496 | )); |
| 497 | if( (! is_wp_error($result)) && $result['response']['code'] == 200 && strpos($result['body'], "scanptestok") !== false){ |
| 498 | return true; |
| 499 | } |
| 500 | |
| 501 | $detail = ''; |
| 502 | if (is_wp_error($result)) { |
| 503 | $message = __('wp_remote_post() test to noc1.wordfence.com failed! Response was: ', 'wordfence') . $result->get_error_message(); |
| 504 | } |
| 505 | else { |
| 506 | $message = __('wp_remote_post() test to noc1.wordfence.com failed! Response was: ', 'wordfence') . $result['response']['code'] . " " . $result['response']['message'] . "\n"; |
| 507 | $message .= __('This likely means that your hosting provider is blocking requests to noc1.wordfence.com or has set up a proxy that is not behaving itself.', 'wordfence') . "\n"; |
| 508 | if (isset($result['http_response']) && is_object($result['http_response']) && method_exists($result['http_response'], 'get_response_object') && is_object($result['http_response']->get_response_object()) && property_exists($result['http_response']->get_response_object(), 'raw')) { |
| 509 | $detail = str_replace("\r\n", "\n", $result['http_response']->get_response_object()->raw); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | return array( |
| 514 | 'test' => false, |
| 515 | 'message' => $message, |
| 516 | 'detail' => $detail, |
| 517 | ); |
| 518 | } |
| 519 | |
| 520 | public function connectToSelf() { |
| 521 | $adminAJAX = admin_url('admin-ajax.php?action=wordfence_testAjax'); |
| 522 | $result = wp_remote_post($adminAJAX, array( |
| 523 | 'timeout' => 10, //Must be less than max execution time or more than 2 HTTP children will be occupied by scan |
| 524 | 'blocking' => true, //Non-blocking seems to block anyway, so we use blocking |
| 525 | 'headers' => array() |
| 526 | )); |
| 527 | |
| 528 | if ((!is_wp_error($result)) && $result['response']['code'] == 200 && strpos($result['body'], "WFSCANTESTOK") !== false) { |
| 529 | $host = parse_url($adminAJAX, PHP_URL_HOST); |
| 530 | if ($host !== null) { |
| 531 | $ips = wfUtils::resolveDomainName($host); |
| 532 | $ips = implode(', ', $ips); |
| 533 | return array('test' => true, 'message' => sprintf(__('OK - %s', 'wordfence'), $ips)); |
| 534 | } |
| 535 | return true; |
| 536 | } |
| 537 | |
| 538 | $detail = ''; |
| 539 | if (is_wp_error($result)) { |
| 540 | $message = __('wp_remote_post() test back to this server failed! Response was: ', 'wordfence') . $result->get_error_message(); |
| 541 | } |
| 542 | else { |
| 543 | $message = __('wp_remote_post() test back to this server failed! Response was: ', 'wordfence') . $result['response']['code'] . " " . $result['response']['message'] . "\n"; |
| 544 | $message .= __('This additional info may help you diagnose the issue. The response headers we received were:', 'wordfence') . "\n"; |
| 545 | if (isset($result['http_response']) && is_object($result['http_response']) && method_exists($result['http_response'], 'get_response_object') && is_object($result['http_response']->get_response_object()) && property_exists($result['http_response']->get_response_object(), 'raw')) { |
| 546 | $detail = str_replace("\r\n", "\n", $result['http_response']->get_response_object()->raw); |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | return array( |
| 551 | 'test' => false, |
| 552 | 'message' => $message, |
| 553 | 'detail' => $detail, |
| 554 | ); |
| 555 | } |
| 556 | |
| 557 | public function serverIP() { |
| 558 | $serverIPs = wfUtils::serverIPs(); |
| 559 | return array( |
| 560 | 'test' => true, |
| 561 | 'infoOnly' => true, |
| 562 | 'message' => implode(',', $serverIPs), |
| 563 | ); |
| 564 | } |
| 565 | |
| 566 | public function howGetIPs() |
| 567 | { |
| 568 | $howGet = wfConfig::get('howGetIPs', false); |
| 569 | if ($howGet) { |
| 570 | if (empty($_SERVER[$howGet])) { |
| 571 | return array( |
| 572 | 'test' => false, |
| 573 | 'message' => sprintf(__('We cannot read $_SERVER[%s]', 'wordfence'), $howGet), |
| 574 | ); |
| 575 | } |
| 576 | return array( |
| 577 | 'test' => true, |
| 578 | 'message' => $howGet, |
| 579 | ); |
| 580 | } |
| 581 | foreach (array('HTTP_CF_CONNECTING_IP', 'HTTP_X_REAL_IP', 'HTTP_X_FORWARDED_FOR') as $test) { |
| 582 | if (!empty($_SERVER[$test])) { |
| 583 | return array( |
| 584 | 'test' => false, |
| 585 | 'message' => __('Should be: ', 'wordfence') . $test |
| 586 | ); |
| 587 | } |
| 588 | } |
| 589 | return array( |
| 590 | 'test' => true, |
| 591 | 'message' => 'REMOTE_ADDR', |
| 592 | ); |
| 593 | } |
| 594 | } |
| 595 | |
| 596 |