Source of file staticrequesthandler.php
Size: 2,078 Bytes - Last Modified: 2021-12-23T10:34:48+00:00
/var/www/docs.ssmods.com/process/src/includes/staticrequesthandler.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | <?php namespace SilverStripe\StaticPublishQueue; return function ($cacheDir, $urlMapping = null) { // allow content authors to avoid static cache via cookie if (isset($_COOKIE['bypassStaticCache'])) { return false; } // Convert into a full URL $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80; $https = $port === '443' || isset($_SERVER['HTTPS']) || isset($_SERVER['HTTPS']); $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost'; $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; $url = $https ? 'https://' : 'http://'; $url .= $host . $uri; if (is_callable($urlMapping)) { $path = $urlMapping($url); } else { $path = URLtoPath($url); } if (!$path) { return false; } $cachePath = $cacheDir . DIRECTORY_SEPARATOR . $path; //check for directory traversal attack $realCacheDir = realpath($cacheDir); $realCachePath = realpath($dirname = dirname($cachePath)); // path is outside the cache dir if (substr($realCachePath, 0, strlen($realCacheDir)) !== $realCacheDir) { return false; } $cacheConfig = []; if (file_exists($cachePath . '.php')) { $cacheConfig = require $cachePath . '.php'; } elseif (!file_exists($cachePath . '.html')) { return false; } header('X-Cache-Hit: ' . date(\DateTime::COOKIE)); if (!empty($cacheConfig['responseCode'])) { header('HTTP/1.1 ' . $cacheConfig['responseCode']); } if (!empty($cacheConfig['headers'])) { foreach ($cacheConfig['headers'] as $header) { header($header, true); } } if (file_exists($cachePath . '.html')) { $etag = '"' . md5_file($cachePath . '.html') . '"'; if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] === $etag) { header('HTTP/1.1 304', true); return true; } header('ETag: ' . $etag); readfile($cachePath . '.html'); } return true; }; |