[3260] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @package Dotclear |
---|
| 4 | * @subpackage Core |
---|
| 5 | * |
---|
| 6 | * @copyright Olivier Meunier & Association Dotclear |
---|
| 7 | * @copyright GPL-2.0-only |
---|
| 8 | */ |
---|
[3260] | 9 | |
---|
| 10 | if (@is_dir('/usr/lib/clearbricks')) { |
---|
[3730] | 11 | define('CLEARBRICKS_PATH', '/usr/lib/clearbricks'); |
---|
| 12 | } elseif (is_dir(dirname(__FILE__) . '/libs/clearbricks')) { |
---|
| 13 | define('CLEARBRICKS_PATH', dirname(__FILE__) . '/libs/clearbricks'); |
---|
[3260] | 14 | } elseif (isset($_SERVER['CLEARBRICKS_PATH']) && is_dir($_SERVER['CLEARBRICKS_PATH'])) { |
---|
[3730] | 15 | define('CLEARBRICKS_PATH', $_SERVER['CLEARBRICKS_PATH']); |
---|
[3260] | 16 | } |
---|
| 17 | |
---|
| 18 | if (!defined('CLEARBRICKS_PATH') || !is_dir(CLEARBRICKS_PATH)) { |
---|
[3730] | 19 | exit('No clearbricks path defined'); |
---|
[3260] | 20 | } |
---|
| 21 | |
---|
[3730] | 22 | require CLEARBRICKS_PATH . '/_common.php'; |
---|
[3260] | 23 | |
---|
| 24 | if (isset($_SERVER['DC_RC_PATH'])) { |
---|
[3730] | 25 | define('DC_RC_PATH', $_SERVER['DC_RC_PATH']); |
---|
[3260] | 26 | } elseif (isset($_SERVER['REDIRECT_DC_RC_PATH'])) { |
---|
[3730] | 27 | define('DC_RC_PATH', $_SERVER['REDIRECT_DC_RC_PATH']); |
---|
[3260] | 28 | } else { |
---|
[3730] | 29 | define('DC_RC_PATH', dirname(__FILE__) . '/config.php'); |
---|
[3260] | 30 | } |
---|
| 31 | |
---|
| 32 | if (!is_file(DC_RC_PATH)) { |
---|
[3730] | 33 | trigger_error('Unable to open config file', E_USER_ERROR); |
---|
| 34 | exit; |
---|
[3260] | 35 | } |
---|
| 36 | |
---|
| 37 | require DC_RC_PATH; |
---|
| 38 | |
---|
| 39 | if (empty($_GET['vf'])) { |
---|
[3730] | 40 | header('Content-Type: text/plain'); |
---|
| 41 | http::head(404, 'Not Found'); |
---|
| 42 | exit; |
---|
[3260] | 43 | } |
---|
| 44 | |
---|
| 45 | // $_GET['v'] : version in url to bypass cache in case of dotclear upgrade or in dev mode |
---|
| 46 | // but don't care of value |
---|
[3730] | 47 | if (isset($_GET['v'])) { |
---|
[3260] | 48 | unset($_GET['v']); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | // Only $_GET['vf'] is allowed in URL |
---|
[3730] | 52 | if (count($_GET) > 1) { |
---|
[3260] | 53 | header('Content-Type: text/plain'); |
---|
[3730] | 54 | http::head(403, 'Forbidden'); |
---|
[3260] | 55 | exit; |
---|
| 56 | } |
---|
| 57 | |
---|
[3730] | 58 | $allow_types = array('png', 'jpg', 'jpeg', 'gif', 'css', 'js', 'swf', 'svg', 'html', 'xml', 'json', 'txt'); |
---|
[3260] | 59 | |
---|
| 60 | $vf = path::clean($_GET['vf']); |
---|
[3730] | 61 | $VF = path::real(DC_VAR . '/' . $vf); |
---|
[3260] | 62 | |
---|
| 63 | if ($VF === false || !is_file($VF) || !is_readable($VF)) { |
---|
[3730] | 64 | header('Content-Type: text/plain'); |
---|
| 65 | http::head(404, 'Not Found'); |
---|
| 66 | exit; |
---|
[3260] | 67 | } |
---|
| 68 | |
---|
[3730] | 69 | if (!in_array(files::getExtension($VF), $allow_types)) { |
---|
| 70 | header('Content-Type: text/plain'); |
---|
| 71 | http::head(404, 'Not Found'); |
---|
| 72 | exit; |
---|
[3260] | 73 | } |
---|
| 74 | |
---|
[3730] | 75 | http::$cache_max_age = 7 * 24 * 60 * 60; // One week cache for var files served by ?vf=… |
---|
| 76 | http::cache(array_merge(array($VF), get_included_files())); |
---|
[3260] | 77 | |
---|
[3730] | 78 | header('Content-Type: ' . files::getMimeType($VF)); |
---|
[3260] | 79 | readfile($VF); |
---|
| 80 | exit; |
---|