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
//* 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
+ } // END - if
+
+ // 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]
* be verified here.
*
* @param $fileName The file name we shall pass to fopen()
- * @throws FileIsEmptyException If the provided file name is empty.
- * @throws FileIoException If fopen() returns not a file resource
+ * @throws FileIsEmptyException If the provided file name is empty.
+ * @throws FileIoException If the file is not reachable
+ * @throws FileReadProtectedException If the file is not found or cannot be read
* @return void
*/
public static final function createFrameworkRawFileInputPointer ($fileName) {
if ((is_null($fileName)) || (empty($fileName))) {
// No filename given
throw new FileIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif (!file_exists($fileName)) {
+ } elseif (!BaseFrameworkSystem::isReachableFilePath($fileName)) {
// File does not exist!
- throw new FileIoException($fileName, self::EXCEPTION_FILE_NOT_FOUND);
- } elseif (!is_readable($fileName)) {
+ throw new FileIoException($fileName, self::EXCEPTION_FILE_NOT_REACHABLE);
+ } elseif (!BaseFrameworkSystem::isReadableFile($fileName)) {
// File does not exist!
throw new FileReadProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_READ);
}
* be verified here.
*
* @param $fileName The file name we shall pass to fopen()
- * @throws FileIsEmptyException If the provided file name is empty.
- * @throws FileIoException If fopen() returns not a file resource
+ * @throws FileIsEmptyException If the provided file name is empty.
+ * @throws FileIoException If the file is not reachable
+ * @throws FileReadProtectedException If the file cannot be read from
* @return void
*/
public static final function createFrameworkTextFileInputPointer ($fileName) {
if ((is_null($fileName)) || (empty($fileName))) {
// No filename given
throw new FileIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif (!file_exists($fileName)) {
+ } elseif (!BaseFrameworkSystem::isReachableFilePath($fileName)) {
// File does not exist!
- throw new FileIoException($fileName, self::EXCEPTION_FILE_NOT_FOUND);
- } elseif (!is_readable($fileName)) {
+ throw new FileIoException($fileName, self::EXCEPTION_FILE_NOT_REACHABLE);
+ } elseif (!BaseFrameworkSystem::isReadableFile($fileName)) {
// File does not exist!
throw new FileReadProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_READ);
}
if ((is_null($fileName)) || (empty($fileName))) {
// No filename given
throw new FileIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
- } elseif ((file_exists($fileName)) && (!is_readable($fileName))) {
+ } elseif (!BaseFrameworkSystem::isReachableFilePath($fileName)) {
+ // File exists but cannot be read
+ throw new FileIoException($fileName, self::EXCEPTION_FILE_NOT_REACHABLE);
+ } elseif (!BaseFrameworkSystem::isReadableFile($fileName)) {
// File exists but cannot be read
throw new FileReadProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_READ);
- } elseif ((file_exists($fileName)) && (!is_writable($fileName))) {
+ } elseif (!is_writable($fileName)) {
// File exists but cannot be written
- throw new FileWriteProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_READ);
+ throw new FileWriteProtectedException($fileName, self::EXCEPTION_FILE_CANNOT_BE_WRITTEN);
}
// Try to open a handler
$cacheFile = $this->getTemplateInstance()->getImageCacheFqfn();
// Does it exist?
- if (file_exists($cacheFile)) {
+ if (BaseFrameworkSystem::isReadableFile($cacheFile)) {
// Remove it
@unlink($cacheFile);
} // END - if
$buffer_valid = true;
}
}
- if (!$buffer_valid && is_readable('/dev/urandom')) {
+ if (!$buffer_valid && BaseFrameworkSystem::isReadableFile('/dev/urandom')) {
$f = fopen('/dev/urandom', 'r');
$read = static::strlen($buffer);
while ($read < $length) {
$fqfn = FrameworkConfiguration::getSelfInstance()->getConfigEntry('base_path') . 'inc/database/lib-' . FrameworkConfiguration::getSelfInstance()->getConfigEntry('db_type') . '.php';
// Load the database layer include
-if ((file_exists($fqfn)) && (is_file($fqfn)) && (is_readable($fqfn))) {
+if (BaseFrameworkSystem::isReadableFile($fqfn)) {
// Load the layer
require($fqfn);
} else {
// Layer is missing!
- ApplicationEntryPoint::app_exit(sprintf("[Main:] Database layer is missing! (%s) -> R.I.P.",
+ ApplicationEntryPoint::app_exit(sprintf('[Main:] Database layer is missing! (%s) -> R.I.P.',
FrameworkConfiguration::getSelfInstance()->getConfigEntry('db_type')
));
}
} // END - if
// IS the cache there?
- if (file_exists($this->listCacheFQFN)) {
+ if (BaseFrameworkSystem::isReadableFile($this->listCacheFQFN)) {
// Get content
$cacheContent = file_get_contents($this->listCacheFQFN);
} // END - if
// Does the class cache exist?
- if (file_exists($this->classCacheFQFN)) {
+ if (BaseFrameworkSystem::isReadableFile($this->listCacheFQFN)) {
// Then include it
require($this->classCacheFQFN);
$appFqFn = $basePathFile . '/' . $appInc . '.php';
// Does the include file exists?
- if ((file_exists($appFqFn)) && (is_file($appFqFn)) && (is_readable($appFqFn))) {
+ if (BaseFrameworkSystem::isReadableFile($appFqFn)) {
// Load it
//* DEBUG: */ print basename(__FILE__)."[".__LINE__."]: Loading ".basename($appFqFn)." - START\n";
require($appFqFn);