Exemple #1
0
 public static function fileTooBig($file)
 {
     //Deals with files > 2 gigs on 32 bit systems which are reported with the wrong size due to integer overflow
     wfUtils::errorsOff();
     $fh = @fopen($file, 'r');
     wfUtils::errorsOn();
     if (!$fh) {
         return false;
     }
     $offset = WORDFENCE_MAX_FILE_SIZE_TO_PROCESS + 1;
     $tooBig = false;
     try {
         if (@fseek($fh, $offset, SEEK_SET) === 0) {
             if (strlen(fread($fh, 1)) === 1) {
                 $tooBig = true;
             }
         }
         //Otherwise we couldn't seek there so it must be smaller
         fclose($fh);
         return $tooBig;
     } catch (Exception $e) {
         return true;
     }
     //If we get an error don't scan this file, report it's too big.
 }
 public static function wfHash($file)
 {
     wfUtils::errorsOff();
     $md5 = @md5_file($file, false);
     wfUtils::errorsOn();
     if (!$md5) {
         return false;
     }
     $fp = @fopen($file, "rb");
     if (!$fp) {
         return false;
     }
     $ctx = hash_init('sha256');
     while (!feof($fp)) {
         hash_update($ctx, str_replace(array("\n", "\r", "\t", " "), "", fread($fp, 65536)));
     }
     $shac = hash_final($ctx, false);
     return array($md5, $shac);
 }
 private function scan_diskSpace()
 {
     $this->statusIDX['diskSpace'] = wordfence::statusStart("Scanning to check available disk space");
     wfUtils::errorsOff();
     $total = @disk_total_space('.');
     $free = @disk_free_space('.');
     wfUtils::errorsOn();
     if (!$total || !$free) {
         //If we get zeros it's probably not reading right. If free is zero then we're out of space and already in trouble.
         wordfence::statusEnd($this->statusIDX['diskSpace'], false);
         return;
     }
     $this->status(2, 'info', "Total disk space: " . sprintf('%.4f', $total / 1024 / 1024 / 1024) . "GB -- Free disk space: " . sprintf('%.4f', $free / 1024 / 1024 / 1024) . "GB");
     $freeMegs = sprintf('%.2f', $free / 1024 / 1024);
     $this->status(2, 'info', "The disk has {$freeMegs} MB space available");
     if ($freeMegs < 5) {
         $level = 1;
     } else {
         if ($freeMegs < 20) {
             $level = 2;
         } else {
             wordfence::statusEnd($this->statusIDX['diskSpace'], false);
             return;
         }
     }
     if ($this->addIssue('diskSpace', $level, 'diskSpace' . $level, 'diskSpace' . $level, "You have {$freeMegs}" . "MB disk space remaining", "You only have {$freeMegs}" . " Megabytes of your disk space remaining. Please free up disk space or your website may stop serving requests.", array('spaceLeft' => $freeMegs . "MB"))) {
         wordfence::statusEnd($this->statusIDX['diskSpace'], true);
     } else {
         wordfence::statusEnd($this->statusIDX['diskSpace'], false);
     }
 }
 private static function getTempDir()
 {
     if (!self::$tmpDirCache) {
         $dirs = self::getPotentialTempDirs();
         $finalDir = 'notmp';
         wfUtils::errorsOff();
         foreach ($dirs as $dir) {
             $dir = rtrim($dir, '/') . '/';
             $fh = @fopen($dir . 'wftmptest.txt', 'w');
             if (!$fh) {
                 continue;
             }
             $bytes = @fwrite($fh, 'test');
             if ($bytes != 4) {
                 @fclose($fh);
                 continue;
             }
             @fclose($fh);
             if (!@unlink($dir . 'wftmptest.txt')) {
                 continue;
             }
             $finalDir = $dir;
             break;
         }
         wfUtils::errorsOn();
         self::$tmpDirCache = $finalDir;
     }
     if (self::$tmpDirCache == 'notmp') {
         return false;
     } else {
         return self::$tmpDirCache;
     }
 }
 private static function getTempDir()
 {
     if (!self::$tmpDirCache) {
         $dirs = array(wfUtils::getPluginBaseDir() . 'wordfence/tmp/', sys_get_temp_dir(), ABSPATH . 'wp-content/uploads/');
         $finalDir = 'notmp';
         wfUtils::errorsOff();
         foreach ($dirs as $dir) {
             $dir = rtrim($dir, '/') . '/';
             $fh = @fopen($dir . 'wftmptest.txt', 'w');
             if (!$fh) {
                 continue;
             }
             $bytes = @fwrite($fh, 'test');
             if ($bytes != 4) {
                 @fclose($fh);
                 continue;
             }
             @fclose($fh);
             if (!@unlink($dir . 'wftmptest.txt')) {
                 continue;
             }
             $finalDir = $dir;
             break;
         }
         wfUtils::errorsOn();
         self::$tmpDirCache = $finalDir;
     }
     if (self::$tmpDirCache == 'notmp') {
         return false;
     } else {
         return self::$tmpDirCache;
     }
 }