public static function getWPFileContent($file, $cType, $cName, $cVersion) { if ($cType == 'plugin') { if (preg_match('#^/?wp-content/plugins/[^/]+/#', $file)) { $file = preg_replace('#^/?wp-content/plugins/[^/]+/#', '', $file); } else { //If user is using non-standard wp-content dir, then use /plugins/ in pattern to figure out what to strip off $file = preg_replace('#^.*[^/]+/plugins/[^/]+/#', '', $file); } } else { if ($cType == 'theme') { if (preg_match('#/?wp-content/themes/[^/]+/#', $file)) { $file = preg_replace('#/?wp-content/themes/[^/]+/#', '', $file); } else { $file = preg_replace('#^.*[^/]+/themes/[^/]+/#', '', $file); } } else { if ($cType == 'core') { } else { return array('errorMsg' => "An invalid type was specified to get file."); } } } $api = new wfAPI(wfConfig::get('apiKey'), wfUtils::getWPVersion()); try { $contResult = $api->binCall('get_wp_file_content', array('v' => wfUtils::getWPVersion(), 'file' => $file, 'cType' => $cType, 'cName' => $cName, 'cVersion' => $cVersion)); if ($contResult['data']) { return array('fileContent' => $contResult['data']); } else { throw new Exception("We could not fetch a core WordPress file from the Wordfence API."); } } catch (Exception $e) { return array('errorMsg' => wp_kses($e->getMessage(), array())); } }
/** * @throws wfScanKnownFilesException */ public function fetchKnownFiles() { try { $dataArr = $this->api->binCall('get_known_files', json_encode(array('plugins' => $this->plugins, 'themes' => $this->themes))); if ($dataArr['code'] != 200) { throw new wfScanKnownFilesException("Got error response from Wordfence servers: " . $dataArr['code'], $dataArr['code']); } $this->knownFiles = @json_decode($dataArr['data'], true); if (!is_array($this->knownFiles)) { throw new wfScanKnownFilesException("Invalid response from Wordfence servers."); } } catch (Exception $e) { throw new wfScanKnownFilesException($e->getMessage(), $e->getCode(), $e); } }