1
0
mirror of https://github.com/mailcow/mailcow-dockerized.git synced 2024-11-28 08:52:00 +02:00
mailcow-dockerized/data/web/resource.php
Vincent Simon deac5ad2fe [Web] Fix resource.php and /cache/ warning message
If http://mail.example.tld/cache/ or http://mail.example.tld/resource.php are called without the required parameters it returns one or two warnings
2022-03-20 22:05:28 +01:00

38 lines
898 B
PHP

<?php
if (!isset($_GET['file']) ) {
http_response_code(404);
exit;
}
$pathinfo = pathinfo($_GET['file']);
if (!array_key_exists('extension', $pathinfo)) {
http_response_code(404);
exit;
}
$extension = strtolower($pathinfo['extension']);
$filepath = '/tmp/' . $pathinfo['basename'];
$content = '';
if (file_exists($filepath)) {
$secondsToCache = 31536000;
$expires = gmdate('D, d M Y H:i:s', time() + $secondsToCache) . ' GMT';
if ($extension === 'js') {
header('Content-Type: application/javascript');
} elseif ($extension === 'css') {
header('Content-Type: text/css');
} else {
//currently just css and js should be supported!
exit();
}
header("Expires: $expires");
header('Pragma: cache');
header('Cache-Control: max-age=' . $secondsToCache);
$content = file_get_contents($filepath);
}
echo $content;