Allow all if open_basedir is not set.
[core.git] / inc / classes / main / class_BaseFrameworkSystem.php
index 2b2d2683109df9c224f0d4d788370e09248010f1..3ea5bcf5d49cda30bbfa8d5f3ce1bd1096b90c13 100644 (file)
@@ -213,6 +213,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        private $listenerInstance = NULL;
 
+       /**
+        * An instance of a communicator
+        */
+       private $communicatorInstance = NULL;
+
        /**
         * Thousands separator
         */
@@ -279,7 +284,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         *
         * The integer size is 4 bytes on 32-bit and 8 bytes on a 64-bit system.
         */
-       private $archArrayElement = (PHP_INT_SIZE === 8 ? 64 : 32);
+       private $archArrayElement = FALSE;
 
        /***********************
         * Exception codes.... *
@@ -341,9 +346,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        const EXCEPTION_FATAL_ERROR                  = 0x035;
        const EXCEPTION_FILE_NOT_FOUND               = 0x036;
        const EXCEPTION_ASSERTION_FAILED             = 0x037;
-       const EXCEPTION_FILE_CANNOT_BE_READ          = 0x038;
-       const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
-       const EXCEPTION_FILTER_CHAIN_INTERCEPTED     = 0x03a;
+       const EXCEPTION_FILE_NOT_REACHABLE           = 0x038;
+       const EXCEPTION_FILE_CANNOT_BE_READ          = 0x039;
+       const EXCEPTION_FILE_CANNOT_BE_WRITTEN       = 0x03a;
+       const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03b;
+       const EXCEPTION_FILTER_CHAIN_INTERCEPTED     = 0x03c;
 
        /**
         * Hexadecimal->Decimal translation array
@@ -415,6 +422,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                        // Then set it
                        self::$startupTime = microtime(TRUE);
                } // END - if
+
+               // Set array element
+               $this->archArrayElement = (PHP_INT_SIZE === 8 ? 64 : 32);
        }
 
        /**
@@ -1501,6 +1511,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                return $this->listenerInstance;
        }
 
+       /**
+        * Getter for communicator instance
+        *
+        * @return      $communicatorInstance   An instance of a Communicator class
+        */
+       public final function getCommunicatorInstance () {
+               return $this->communicatorInstance;
+       }
+
+       /**
+        * Setter for communicator instance
+        *
+        * @param       $communicatorInstance   An instance of a Communicator class
+        * @return      void
+        */
+       protected final function setCommunicatorInstance (Communicator $communicatorInstance) {
+               $this->communicatorInstance = $communicatorInstance;
+       }
+
        /**
         * Setter for command name
         *
@@ -3198,6 +3227,58 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__)->debugOutput('packed=' . $packed . ' - EXIT!');
                return $packed;
        }
+
+       /**
+        * Checks whether the given file/path is in open_basedir(). This does not
+        * gurantee that the file is actually readable and/or writeable. If you need
+        * such gurantee then please use isReadableFile() instead.
+        *
+        * @param       $filePathName   Name of the file/path to be checked
+        * @return      $isReachable    Whether it is within open_basedir()
+        */
+       public static function isReachableFilePath ($filePathName) {
+               // Is not reachable by default
+               $isReachable = FALSE;
+
+               // Get open_basedir parameter
+               $openBaseDir = ini_get('open_basedir');
+
+               // Is it set?
+               if (!empty($openBaseDir)) {
+                       // Check all entries
+                       foreach (explode(PATH_SEPARATOR, $openBaseDir) as $dir) {
+                               // Check on existence
+                               if (substr($filePathName, 0, strlen($dir)) == $dir) {
+                                       // Is reachable
+                                       $isReachable = TRUE;
+                               } // END - if
+                       } // END - foreach
+               } else {
+                       // If open_basedir is not set, all is allowed
+                       $isReachable = TRUE;
+               }
+
+               // Return status
+               return $isReachable;
+       }
+
+       /**
+        * Checks whether the give file is within open_basedir() (done by
+        * isReachableFilePath()), is actually a file and is readable.
+        *
+        * @param       $fileName               Name of the file to be checked
+        * @return      $isReadable             Whether the file is readable (and therefor exists)
+        */
+       public static function isReadableFile ($fileName) {
+               // Default is not readable
+               $isReadable = FALSE;
+
+               // Is within parameters, so check if it is a file and readable
+               $isReadable = ((self::isReachableFilePath($fileName)) && (is_file($fileName)) && (is_readable($fileName)));
+
+               // Return status
+               return $isReadable;
+       }
 }
 
 // [EOF]