You are here

function boost_in_cache_dir in Boost 7

Verify that the operation is going to operate in the cache dir.

Parameters

$file: relative directory or file.

2 calls to boost_in_cache_dir()
boost_mkdir in ./boost.module
Create a directory.
_boost_rmdir in ./boost.module
Recursive version of rmdir(); use with extreme caution.

File

./boost.module, line 1438
Caches generated output as a static file to be served directly from the webserver.

Code

function boost_in_cache_dir($file) {
  global $_boost;
  $good = TRUE;
  $real_file = realpath($file);
  $cache_dir = variable_get('boost_root_cache_dir', BOOST_ROOT_CACHE_DIR);
  $real_cache_dir = realpath($cache_dir);

  // Only operate in the cache dir.
  // Check the real path.
  if (strpos($file, $cache_dir) !== 0 || $real_file && $real_cache_dir && strpos($real_file, $real_cache_dir) !== 0) {
    $good = FALSE;
  }

  // Send error to watchdog.
  if (!$good) {
    watchdog('boost', 'An operation outside of the cache directory was attempted on your system. %file or %real_file is outside the cache directory %cache or %real_cache. Debug info below <br> !debug', array(
      '%file' => $file,
      '%real_file' => $real_file,
      '%cache' => $cache_dir,
      '%real_cache' => $real_cache_dir,
      '!debug' => boost_print_r($_boost),
    ), WATCHDOG_CRITICAL);
  }
  return $good;
}