[BUGFIX] Error if mcrypt is not available
authorAndreas Wolf <andreas.wolf@typo3.org>
Fri, 22 Mar 2013 14:47:09 +0000 (15:47 +0100)
committerAndreas Wolf <andreas.wolf@typo3.org>
Fri, 22 Mar 2013 14:47:09 +0000 (15:47 +0100)
Change-Id: Ief9b84c7897751092da2cc09a5c77edcff673225

Classes/Driver/WebDavDriver.php
Classes/Utility/EncryptionUtility.php

index e348c49..cb9b5b7 100644 (file)
@@ -31,6 +31,9 @@ include_once 'Sabre/autoload.php';
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 
+/**
+ * The driver class for WebDAV storages.
+ */
 class WebDavDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
 
        /**
index 01eb4db..6b6e299 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace TYPO3\FalWebdav\Utility;
 
+use \TYPO3\CMS\Core\Utility;
+
 /**
  * Utility methods for encrypting/decrypting data. Currently only supports Blowfish encryption in CBC mode,
  *
@@ -14,6 +16,11 @@ class EncryptionUtility {
 
        protected static $encryptionMode = MCRYPT_MODE_CBC;
 
+       /**
+        * @var \TYPO3\CMS\Core\Log\Logger
+        */
+       protected static $logger;
+
        public static function getEncryptionMethod() {
                return self::$encryptionMethod;
        }
@@ -23,6 +30,29 @@ class EncryptionUtility {
        }
 
        /**
+        * Returns TRUE if the mcrypt extension is available.
+        *
+        * @return bool
+        */
+       public static function isMcryptAvailable() {
+               return extension_loaded('mcrypt');
+       }
+
+       /**
+        * @return \TYPO3\CMS\Core\Log\Logger
+        */
+       protected static function getLogger() {
+               if (self::$logger === NULL) {
+                       /** @var $logManager \TYPO3\CMS\Core\Log\LogManager */
+                       $logManager = Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager');
+
+                       self::$logger = $logManager->getLogger(__CLASS__);
+               }
+
+               return self::$logger;
+       }
+
+       /**
         * Returns an initialization vector suitable for the chosen encryption method.
         *
         * @param string $encryptionMethod
@@ -85,6 +115,10 @@ class EncryptionUtility {
                if ($value == '') {
                        return '';
                }
+               if (!self::isMcryptAvailable()) {
+                       self::getLogger()->error('Encryption utility is not available. See reports module for more information.');
+                       return '';
+               }
 
                $td = self::createEncryptionContext();
                $iv = self::getInitializationVector();
@@ -118,6 +152,10 @@ class EncryptionUtility {
                if ($encryptedPassword == '') {
                        return '';
                }
+               if (!self::isMcryptAvailable()) {
+                       self::getLogger()->error('Encryption utility is not available. See reports module for more information.');
+                       return '';
+               }
 
                if (substr_count($encryptedPassword, '$') > 0) {
                        $passwordParts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('$', $encryptedPassword, TRUE);