function generateResponse($path) { global $stateFile; $state = getState($stateFile); if ($state == "Offline") { header('HTTP/1.1 307 Temporary Redirect'); # Simulate a network error by redirecting to self. header('Location: ' . $_SERVER['REQUEST_URI']); } else { // A little securuty checking can't hurt. if (strstr($path, "..")) { exit; } if ($path[0] == '/') { $path = '..' . $path; } generateNoCacheHTTPHeader(); if (file_exists($path)) { header("Last-Modified: " . gmdate("D, d M Y H:i:s T", filemtime($path))); header("Content-Type: " . contentType($path)); print file_get_contents($path); } else { header('HTTP/1.1 404 Not Found'); } } }
function generateResponse($path) { global $stateFile; $state = getState($stateFile); if ($state == "Offline") { # Simulate a network error by replying with a nonsense response. header('HTTP/1.1 307 Temporary Redirect'); header('Location: ' . $_SERVER['REQUEST_URI']); # Redirect to self. header('Content-Length: 1'); header('Content-Length: 5', false); # Multiple content-length headers, some network stacks can detect this condition faster. echo "Intentionally incorrect response."; } else { // A little securuty checking can't hurt. if (strstr($path, "..")) { exit; } if ($path[0] == '/') { $path = '..' . $path; } generateNoCacheHTTPHeader(); if (file_exists($path)) { header("Last-Modified: " . gmdate("D, d M Y H:i:s T", filemtime($path))); header("Content-Type: " . contentType($path)); print file_get_contents($path); } else { header('HTTP/1.1 404 Not Found'); } } }
return "application/xml"; if (preg_match("/\.xhtml$/", $path)) return "application/xhtml+xml"; if (preg_match("/\.svg$/", $path)) return "application/svg+xml"; if (preg_match("/\.xsl$/", $path)) return "application/xslt+xml"; if (preg_match("/\.gif$/", $path)) return "image/gif"; if (preg_match("/\.jpg$/", $path)) return "image/jpeg"; if (preg_match("/\.png$/", $path)) return "image/png"; return "text/plain"; } $path = $_GET['path']; $expectedReferer = $_GET['expected-referer']; $referer = $_SERVER["HTTP_REFERER"]; if ($expectedReferer == $referer && file_exists($path)) { header('HTTP/1.1 200 OK'); header("Cache-control: no-store"); header("Content-Type: " . contentType($path)); print file_get_contents($path); } else { header('HTTP/1.1 404 Not Found'); } ?>
$types = ['png' => 'image/png', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'gif' => 'image/gif']; $parts = explode('.', $file); $ext = strtolower(array_pop($parts)); if (isset($ext, $types)) { return $types[$ext]; } } $path = str_replace(['~', '..'], '', input('path', '/')); $file = RAPTOR_UPLOAD_DIR . '/' . $path; if (!is_file($file) || !contentType($file)) { header('HTTP/1.1 404 Not Found'); } if (!class_exists('Imagine\\Gd\\Imagine')) { header('Content-type: ' . contentType($file)); readfile($file); return; } $cacheFile = __DIR__ . '/' . $path; $cacheDir = dirname($cacheFile); if (!file_exists($cacheDir)) { mkdir($cacheDir, 0777, true); } if (!is_dir($cacheDir)) { throw new Exception('Cache directory does not exist, and could not be created.'); } $imagine = new Imagine\Gd\Imagine(); $size = new Imagine\Image\Box(50, 50); $mode = Imagine\Image\ImageInterface::THUMBNAIL_INSET; $imagine->open($file)->thumbnail($size, $mode)->save($cacheFile); header('Content-type: ' . contentType($cacheFile)); readfile($cacheFile);