Diff
11 years ago
.htaccess
14 years ago
Diff.php
14 years ago
GeoIP.dat
10 years ago
IPTraf.php
11 years ago
compat.php
10 years ago
conntest.php
11 years ago
cronview.php
10 years ago
dashboard.php
10 years ago
dbview.php
11 years ago
diffResult.php
11 years ago
email_genericAlert.php
10 years ago
email_newIssues.php
10 years ago
email_passwdChanged.php
10 years ago
email_pleaseChangePasswd.php
10 years ago
email_unlockRequest.php
11 years ago
menuHeader.php
12 years ago
menu_activity.php
10 years ago
menu_blockedIPs.php
10 years ago
menu_countryBlocking.php
10 years ago
menu_diagnostic.php
10 years ago
menu_options.php
10 years ago
menu_passwd.php
10 years ago
menu_rangeBlocking.php
10 years ago
menu_scan.php
10 years ago
menu_scanSchedule.php
10 years ago
menu_sitePerf.php
11 years ago
menu_sitePerfStats.php
11 years ago
menu_twoFactor.php
10 years ago
menu_waf.php
10 years ago
menu_whois.php
11 years ago
pageTitle.php
11 years ago
schedWeekEntry.php
12 years ago
sysinfo.php
10 years ago
unknownFiles.php
11 years ago
viewFullActivityLog.php
10 years ago
wf503.php
10 years ago
wfAPI.php
10 years ago
wfAction.php
14 years ago
wfActivityReport.php
10 years ago
wfArray.php
13 years ago
wfBrowscap.php
12 years ago
wfBrowscapCache.php
10 years ago
wfBulkCountries.php
13 years ago
wfCache.php
10 years ago
wfConfig.php
10 years ago
wfCountryMap.php
13 years ago
wfCrawl.php
10 years ago
wfCrypt.php
11 years ago
wfDB.php
10 years ago
wfDiagnostic.php
10 years ago
wfDict.php
14 years ago
wfDirectoryIterator.php
11 years ago
wfGeoIP.php
10 years ago
wfHelperBin.php
11 years ago
wfHelperString.php
11 years ago
wfIPWhitelist.php
10 years ago
wfIssues.php
10 years ago
wfLockedOut.php
13 years ago
wfLog.php
10 years ago
wfRate.php
14 years ago
wfScan.php
11 years ago
wfScanEngine.php
10 years ago
wfSchema.php
10 years ago
wfUnlockMsg.php
11 years ago
wfUpdateCheck.php
11 years ago
wfUtils.php
10 years ago
wfView.php
10 years ago
wfViewResult.php
11 years ago
wordfenceClass.php
10 years ago
wordfenceConstants.php
10 years ago
wordfenceHash.php
10 years ago
wordfenceScanner.php
10 years ago
wordfenceURLHoover.php
11 years ago
wfDiagnostic.php
246 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 = array( |
| 51 | 'Filesystem' => array( |
| 52 | 'isTmpReadable' => 'Checking if web server can read from <code>~/plugins/wordfence/tmp</code>', |
| 53 | 'isTmpWritable' => 'Checking if web server can write to <code>~/plugins/wordfence/tmp</code>', |
| 54 | 'testWfCache' => 'Checking if web server can write to <code>~/wp-content/wfcache</code>', |
| 55 | ), |
| 56 | 'MySQL' => array( |
| 57 | 'userCanDelete' => 'Checking if MySQL user has <code>DELETE</code> privilege', |
| 58 | 'userCanInsert' => 'Checking if MySQL user has <code>INSERT</code> privilege', |
| 59 | 'userCanSelect' => 'Checking if MySQL user has <code>SELECT</code> privilege', |
| 60 | 'userCanCreate' => 'Checking if MySQL user has <code>CREATE TABLE</code> privilege', |
| 61 | 'userCanAlter' => 'Checking if MySQL user has <code>ALTER TABLE</code> privilege', |
| 62 | 'userCanDrop' => 'Checking if MySQL user has <code>DROP</code> privilege', |
| 63 | 'userCanTruncate' => 'Checking if MySQL user has <code>TRUNCATE</code> privilege', |
| 64 | ), |
| 65 | 'PHP' => array( |
| 66 | 'phpVersion' => 'PHP version >= PHP 5.2.4<br><em> (<a href="https://wordpress.org/about/requirements/" target="_blank">Minimum version required by WordPress</a>)</em>', |
| 67 | 'hasOpenSSL' => 'Checking for OpenSSL support', |
| 68 | 'hasCurl' => 'Checking for cURL support', |
| 69 | ), |
| 70 | 'Connectivity' => array( |
| 71 | 'connectToServer1' => 'Connecting to Wordfence servers (http)', |
| 72 | 'connectToServer2' => 'Connecting to Wordfence servers (https)', |
| 73 | ), |
| 74 | // 'Configuration' => array( |
| 75 | // 'howGetIPs' => 'How does get IPs', |
| 76 | // ), |
| 77 | ); |
| 78 | |
| 79 | protected $results = array(); |
| 80 | |
| 81 | public function __construct() |
| 82 | { |
| 83 | foreach ($this->description as $title => $tests) { |
| 84 | $this->results[$title] = array(); |
| 85 | foreach ($tests as $name => $description) { |
| 86 | $result = $this->$name(); |
| 87 | |
| 88 | if (is_bool($result)) { |
| 89 | $result = array( |
| 90 | 'test' => $result, |
| 91 | 'message' => $result ? 'OK' : 'FAIL', |
| 92 | ); |
| 93 | } |
| 94 | |
| 95 | $result['label'] = $description; |
| 96 | |
| 97 | $this->results[$title][] = $result; |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | public function getResults() |
| 103 | { |
| 104 | return $this->results; |
| 105 | } |
| 106 | |
| 107 | public function isTmpReadable() { |
| 108 | return is_readable(WORDFENCE_PATH . 'tmp'); |
| 109 | } |
| 110 | |
| 111 | public function isTmpWritable() { |
| 112 | return is_writable(WORDFENCE_PATH . 'tmp'); |
| 113 | } |
| 114 | |
| 115 | public function userCanInsert() { |
| 116 | return wfGrant::get()->insert; |
| 117 | } |
| 118 | |
| 119 | public function testWfCache() { |
| 120 | $result = wfCache::cacheDirectoryTest(); |
| 121 | return array( |
| 122 | 'test' => $result === false, |
| 123 | 'message' => is_string($result) ? $result : 'OK' |
| 124 | ); |
| 125 | } |
| 126 | |
| 127 | public function userCanDelete() { |
| 128 | return wfGrant::get()->delete; |
| 129 | } |
| 130 | |
| 131 | public function userCanSelect() { |
| 132 | return wfGrant::get()->select; |
| 133 | } |
| 134 | |
| 135 | public function userCanCreate() { |
| 136 | return wfGrant::get()->create; |
| 137 | } |
| 138 | |
| 139 | public function userCanDrop() { |
| 140 | return wfGrant::get()->drop; |
| 141 | } |
| 142 | |
| 143 | public function userCanTruncate() { |
| 144 | return wfGrant::get()->drop && wfGrant::get()->delete; |
| 145 | } |
| 146 | |
| 147 | public function userCanAlter() { |
| 148 | return wfGrant::get()->alter; |
| 149 | } |
| 150 | |
| 151 | public function phpVersion() |
| 152 | { |
| 153 | return array( |
| 154 | 'test' => version_compare(phpversion(), $this->minVersion['PHP'], '>='), |
| 155 | 'message' => phpversion(), |
| 156 | ); |
| 157 | } |
| 158 | |
| 159 | public function hasOpenSSL() { |
| 160 | return is_callable('openssl_open'); |
| 161 | } |
| 162 | |
| 163 | public function hasCurl() { |
| 164 | if (!is_callable('curl_version')) { |
| 165 | return false; |
| 166 | } |
| 167 | $version = curl_version(); |
| 168 | return array( |
| 169 | 'test' => version_compare($version['version'], $this->minVersion['cURL'], '>='), |
| 170 | 'message' => $version['version'], |
| 171 | ); |
| 172 | } |
| 173 | |
| 174 | public function connectToServer1() { |
| 175 | return $this->_connectToServer('http'); |
| 176 | } |
| 177 | |
| 178 | public function connectToServer2() { |
| 179 | return $this->_connectToServer('https'); |
| 180 | } |
| 181 | |
| 182 | public function _connectToServer($protocol) { |
| 183 | $cronURL = admin_url('admin-ajax.php'); |
| 184 | $cronURL = preg_replace('/^(https?:\/\/)/i', '://noc1.wordfence.com/scanptest/', $cronURL); |
| 185 | $cronURL .= '?action=wordfence_doScan&isFork=0&cronKey=47e9d1fa6a675b5999999333'; |
| 186 | $cronURL = $protocol . $cronURL; |
| 187 | $result = wp_remote_post($cronURL, array( |
| 188 | 'timeout' => 10, //Must be less than max execution time or more than 2 HTTP children will be occupied by scan |
| 189 | 'blocking' => true, //Non-blocking seems to block anyway, so we use blocking |
| 190 | // This causes cURL to throw errors in some versions since WordPress uses its own certificate bundle ('CA certificate set, but certificate verification is disabled') |
| 191 | // 'sslverify' => false, |
| 192 | 'headers' => array() |
| 193 | )); |
| 194 | if( (! is_wp_error($result)) && $result['response']['code'] == 200 && strpos($result['body'], "scanptestok") !== false){ |
| 195 | return true; |
| 196 | } |
| 197 | |
| 198 | ob_start(); |
| 199 | if(is_wp_error($result)){ |
| 200 | echo "wp_remote_post() test to noc1.wordfence.com failed! Response was: " . $result->get_error_message() . "<br />\n"; |
| 201 | } else { |
| 202 | echo "wp_remote_post() test to noc1.wordfence.com failed! Response was: " . $result['response']['code'] . " " . $result['response']['message'] . "<br />\n"; |
| 203 | echo "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.<br />\n"; |
| 204 | echo "This additional info may help you diagnose the issue. The response headers we received were:<br />\n"; |
| 205 | foreach($result['headers'] as $key => $value){ |
| 206 | echo "$key => $value<br />\n"; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | return array( |
| 211 | 'test' => false, |
| 212 | 'message' => ob_get_clean() |
| 213 | ); |
| 214 | } |
| 215 | |
| 216 | public function howGetIPs() |
| 217 | { |
| 218 | $howGet = wfConfig::get('howGetIPs', false); |
| 219 | if ($howGet) { |
| 220 | if (empty($_SERVER[$howGet])) { |
| 221 | return array( |
| 222 | 'test' => false, |
| 223 | 'message' => 'We cannot read $_SERVER[' . $howGet . ']', |
| 224 | ); |
| 225 | } |
| 226 | return array( |
| 227 | 'test' => true, |
| 228 | 'message' => $howGet, |
| 229 | ); |
| 230 | } |
| 231 | foreach (array('HTTP_CF_CONNECTING_IP', 'HTTP_X_REAL_IP', 'HTTP_X_FORWARDED_FOR') as $test) { |
| 232 | if (!empty($_SERVER[$test])) { |
| 233 | return array( |
| 234 | 'test' => false, |
| 235 | 'message' => 'Should be: ' . $test |
| 236 | ); |
| 237 | } |
| 238 | } |
| 239 | return array( |
| 240 | 'test' => true, |
| 241 | 'message' => 'REMOTE_ADDR', |
| 242 | ); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 |