Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 33 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; under version 2 |
| 8 | * of the License (non-upgradable). |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | * |
| 19 | * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 20 | * |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | use oat\tao\model\websource\WebsourceManager; |
| 25 | |
| 26 | require_once '../vendor/autoload.php'; |
| 27 | |
| 28 | $rel = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '/getFile.php/') + strlen('/getFile.php/')); |
| 29 | $parts = explode('/', $rel, 4); |
| 30 | if (count($parts) < 3) { |
| 31 | header('HTTP/1.0 403 Forbidden'); |
| 32 | die(); |
| 33 | } |
| 34 | |
| 35 | list($ap, $timestamp, $token, $subPath) = $parts; |
| 36 | $parts = explode('*/', $subPath, 2); |
| 37 | // TODO add security check on url |
| 38 | if (count($parts) < 2) { |
| 39 | header('HTTP/1.0 403 Forbidden'); |
| 40 | die(); |
| 41 | } |
| 42 | list($subPath, $file) = $parts; |
| 43 | |
| 44 | $bootStrap = new oat\tao\model\mvc\Bootstrap('../config/generis.conf.php'); |
| 45 | $config = common_ext_ExtensionsManager::singleton()->getExtensionById('tao')->getConfig('websource_' . $ap); |
| 46 | common_Logger::singleton()->register(); |
| 47 | |
| 48 | $compiledPath = $config['options']['path']; |
| 49 | $secretPassphrase = $config['options']['secret']; |
| 50 | $ttl = $config['options']['ttl']; |
| 51 | |
| 52 | $correctToken = md5($timestamp . $subPath . $secretPassphrase); |
| 53 | |
| 54 | if (time() - $timestamp > $ttl || $token != $correctToken) { |
| 55 | header('HTTP/1.0 403 Forbidden'); |
| 56 | die(); |
| 57 | } |
| 58 | |
| 59 | $path = []; |
| 60 | foreach (explode('/', $subPath . $file) as $ele) { |
| 61 | $path[] = rawurldecode($ele); |
| 62 | } |
| 63 | $filename = $compiledPath . implode(DIRECTORY_SEPARATOR, $path); |
| 64 | if (strpos($filename, '?')) { |
| 65 | // A query string is provided with the file to be retrieved - clean up! |
| 66 | $parts = explode('?', $filename); |
| 67 | $filename = $parts[0]; |
| 68 | } |
| 69 | $cacheTtl = $ttl ? $ttl : (30 * 60); //30 min default |
| 70 | header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', $timestamp + $cacheTtl)); |
| 71 | |
| 72 | tao_helpers_Http::returnFile($filename); |
| 73 | |
| 74 | exit(); |