/**
  * @param string $file
  * @return array
  */
 private function dataForFile($file, $fullPath = null)
 {
     $loader = $this->scanEngine->getKnownFilesLoader();
     $data = array();
     if ($isKnownFile = $loader->isKnownFile($file)) {
         if ($loader->isKnownCoreFile($file)) {
             $data['cType'] = 'core';
         } else {
             if ($loader->isKnownPluginFile($file)) {
                 $data['cType'] = 'plugin';
                 list($itemName, $itemVersion, $cKey) = $loader->getKnownPluginData($file);
                 $data = array_merge($data, array('cName' => $itemName, 'cVersion' => $itemVersion, 'cKey' => $cKey));
             } else {
                 if ($loader->isKnownThemeFile($file)) {
                     $data['cType'] = 'theme';
                     list($itemName, $itemVersion, $cKey) = $loader->getKnownThemeData($file);
                     $data = array_merge($data, array('cName' => $itemName, 'cVersion' => $itemVersion, 'cKey' => $cKey));
                 }
             }
         }
     }
     $suppressDelete = false;
     $canRegenerate = false;
     if ($fullPath !== null) {
         $bootstrapPath = wordfence::getWAFBootstrapPath();
         $htaccessPath = get_home_path() . '.htaccess';
         $userIni = ini_get('user_ini.filename');
         $userIniPath = false;
         if ($userIni) {
             $userIniPath = get_home_path() . $userIni;
         }
         if ($fullPath == $htaccessPath) {
             $suppressDelete = true;
         } else {
             if ($userIniPath !== false && $fullPath == $userIniPath) {
                 $suppressDelete = true;
             } else {
                 if ($fullPath == $bootstrapPath) {
                     $suppressDelete = true;
                     $canRegenerate = true;
                 }
             }
         }
     }
     $data['canDiff'] = $isKnownFile;
     $data['canFix'] = $isKnownFile;
     $data['canDelete'] = !$isKnownFile && !$canRegenerate && !$suppressDelete;
     $data['canRegenerate'] = $canRegenerate;
     return $data;
 }
Exemple #2
0
 public function uninstall()
 {
     /** @var WP_Filesystem_Base $wp_filesystem */
     global $wp_filesystem;
     $htaccessPath = $this->getHtaccessPath();
     $userIniPath = $this->getUserIniPath();
     $adminURL = admin_url('/');
     $allow_relaxed_file_ownership = true;
     $homePath = dirname($htaccessPath);
     ob_start();
     if (false === ($credentials = request_filesystem_credentials($adminURL, '', false, $homePath, array('version', 'locale'), $allow_relaxed_file_ownership))) {
         ob_end_clean();
         return false;
     }
     if (!WP_Filesystem($credentials, $homePath, $allow_relaxed_file_ownership)) {
         // Failed to connect, Error and request again
         request_filesystem_credentials($adminURL, '', true, ABSPATH, array('version', 'locale'), $allow_relaxed_file_ownership);
         ob_end_clean();
         return false;
     }
     if ($wp_filesystem->errors->get_error_code()) {
         ob_end_clean();
         return false;
     }
     ob_end_clean();
     if ($wp_filesystem->is_file($htaccessPath)) {
         $htaccessContent = $wp_filesystem->get_contents($htaccessPath);
         $regex = '/# Wordfence WAF.*?# END Wordfence WAF/is';
         if (preg_match($regex, $htaccessContent, $matches)) {
             $htaccessContent = preg_replace($regex, '', $htaccessContent);
             if (!$wp_filesystem->put_contents($htaccessPath, $htaccessContent)) {
                 return false;
             }
         }
     }
     if ($wp_filesystem->is_file($userIniPath)) {
         $userIniContent = $wp_filesystem->get_contents($userIniPath);
         $regex = '/; Wordfence WAF.*?; END Wordfence WAF/is';
         if (preg_match($regex, $userIniContent, $matches)) {
             $userIniContent = preg_replace($regex, '', $userIniContent);
             if (!$wp_filesystem->put_contents($userIniPath, $userIniContent)) {
                 return false;
             }
         }
     }
     $bootstrapPath = wordfence::getWAFBootstrapPath();
     if ($wp_filesystem->is_file($bootstrapPath)) {
         $wp_filesystem->delete($bootstrapPath);
     }
     return true;
 }
Exemple #3
0
	<?php 
require 'menuHeader.php';
?>
	<?php 
$pageTitle = "Wordfence Web Application Firewall";
$helpLink = "http://docs.wordfence.com/en/WAF";
$helpLabel = "Learn more about the Wordfence Web Application Firewall";
include 'pageTitle.php';
?>
	<div class="wordfenceModeElem" id="wordfenceMode_waf"></div>

	<?php 
if (defined('WFWAF_ENABLED') && !WFWAF_ENABLED) {
    $message = 'To allow the firewall to re-enable, please remove this line from the appropriate file.';
    $pattern = '/define\\s*\\(\\s*(?:\'WFWAF_ENABLED\'|"WFWAF_ENABLED")\\s*,(.+?)\\)/x';
    $checkFiles = array(ABSPATH . 'wp-config.php', wordfence::getWAFBootstrapPath());
    foreach ($checkFiles as $path) {
        if (!file_exists($path)) {
            continue;
        }
        if (($contents = file_get_contents($path)) !== false) {
            if (preg_match($pattern, $contents, $matches) && (trim($matches[1]) == 'false' || trim($matches[1]) == '0')) {
                $message = "To allow the firewall to re-enable, please remove this line from the file '" . $path . "'.";
                break;
            }
        }
    }
    ?>
	<p class="wf-notice">The Wordfence Firewall is currently disabled because WFWAF_ENABLED is overridden and set to false. <?php 
    echo $message;
    ?>