예제 #1
0
 public static function onError($number, $message, $file, $line)
 {
     if (error_reporting() === 0) {
         return;
     }
     $msg = $message . ' at ' . $file . '#' . $line;
     self::$logger->warning($msg, array('app' => 'PHP'));
 }
예제 #2
0
 /**
  * see http://php.net/manual/en/function.fopen.php
  *
  * @param string $path
  * @param string $mode
  * @return resource
  */
 public function fopen($path, $mode)
 {
     $encryptionEnabled = $this->encryptionManager->isEnabled();
     $shouldEncrypt = false;
     $encryptionModule = null;
     $header = $this->getHeader($path);
     $fullPath = $this->getFullPath($path);
     $encryptionModuleId = $this->util->getEncryptionModuleId($header);
     $size = $unencryptedSize = 0;
     $targetExists = $this->file_exists($path);
     $targetIsEncrypted = false;
     if ($targetExists) {
         // in case the file exists we require the explicit module as
         // specified in the file header - otherwise we need to fail hard to
         // prevent data loss on client side
         if (!empty($encryptionModuleId)) {
             $targetIsEncrypted = true;
             $encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId);
         }
         $size = $this->storage->filesize($path);
         $unencryptedSize = $this->filesize($path);
     }
     try {
         if ($mode === 'w' || $mode === 'w+' || $mode === 'wb' || $mode === 'wb+') {
             if (!empty($encryptionModuleId)) {
                 $encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId);
                 $shouldEncrypt = $encryptionModule->shouldEncrypt($fullPath);
             } elseif ($encryptionEnabled) {
                 $encryptionModule = $this->encryptionManager->getDefaultEncryptionModule();
                 $shouldEncrypt = $encryptionModule->shouldEncrypt($fullPath);
             }
         } else {
             // only get encryption module if we found one in the header
             if (!empty($encryptionModuleId)) {
                 $encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId);
                 $shouldEncrypt = true;
             }
         }
     } catch (ModuleDoesNotExistsException $e) {
         $this->logger->warning('Encryption module "' . $encryptionModuleId . '" not found, file will be stored unencrypted (' . $e->getMessage() . ')');
     }
     // encryption disabled on write of new file and write to existing unencrypted file -> don't encrypt
     if (!$encryptionEnabled || !$this->mount->getOption('encrypt', true)) {
         if (!$targetExists || !$targetIsEncrypted) {
             $shouldEncrypt = false;
         }
     }
     if ($shouldEncrypt === true && !$this->util->isExcluded($fullPath) && $encryptionModule !== null) {
         $source = $this->storage->fopen($path, $mode);
         $handle = \OC\Files\Stream\Encryption::wrap($source, $path, $fullPath, $header, $this->uid, $encryptionModule, $this->storage, $this, $this->util, $this->fileHelper, $mode, $size, $unencryptedSize);
         return $handle;
     } else {
         return $this->storage->fopen($path, $mode);
     }
 }
예제 #3
0
 protected function cleanFiles($files)
 {
     foreach ($files as $file) {
         if (file_exists($file)) {
             try {
                 \OC_Helper::rmdirr($file);
             } catch (\UnexpectedValueException $ex) {
                 $this->log->warning("Error deleting temporary file/folder: {file} - Reason: {error}", array('file' => $file, 'error' => $ex->getMessage()));
             }
         }
     }
 }