scratch – Diff between revs 73 and 81

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 73 Rev 81
1 <?php 1 <?php
2   2  
3 ########################################################################### 3 ###########################################################################
4 ## Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 ## 4 ## Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 ##
5 ########################################################################### 5 ###########################################################################
6   6  
7 require_once('php/pseudocrypt.php'); 7 require_once('php/pseudocrypt.php');
8 require_once('php/functions.php'); 8 require_once('php/functions.php');
9 require_once('vendor/mustangostang/spyc/Spyc.php'); 9 require_once('vendor/mustangostang/spyc/Spyc.php');
10   10  
11 ### Load configuration. 11 ### Load configuration.
12 $config = spyc_load_file('config.yaml'); 12 $config = spyc_load_file('config.yaml');
13   13  
14 ### If no file has been specified for download then return. 14 ### If no file has been specified for download then return.
15 if (!isset($_GET['o']) or empty($_GET['o'])) { 15 if (!isset($_GET['hash']) or empty($_GET['hash'])) {
-   16 http_response_code(404);
16 header('File not found.', true, 404); 17 die('File not found.');
-   18 }
-   19  
-   20 ### If no timestamp has been provided then return.
-   21 if (!isset($_GET['timestamp']) or empty($_GET['timestamp'])) {
-   22 http_response_code(403);
17 return; 23 die('Forbidden.');
18 } 24 }
19   25  
20 ### Find the requested file. 26 ### Find the requested file.
21 $file = array_shift( 27 $file = array_shift(
22 preg_grep( 28 preg_grep(
23 "/$_GET[o]/", 29 "/".$_GET['hash']."/",
24 scandir($config['STORE_FOLDER']) 30 scandir($config['STORE_FOLDER'])
25 ) 31 )
26 ); 32 );
27   33  
28 if (!isset($file) or empty($file)) { 34 if (!isset($file) or empty($file)) {
29 header('File not found.', true, 404); 35 http_response_code(404);
30 return; 36 die('File not found.');
31 } 37 }
32   38  
33 ### Check the path for path traversals. 39 ### Check the path for path traversals.
34 $fileExtension = pathinfo($file, PATHINFO_EXTENSION); 40 $fileExtension = pathinfo($file, PATHINFO_EXTENSION);
35   41  
36 #### If the extension is not allowed then return. 42 #### If the extension is not allowed then return.
37 if (!isset($fileExtension) || 43 if (!isset($fileExtension) ||
38 !in_array(strtoupper($fileExtension), 44 !in_array(strtoupper($fileExtension),
39 array_map('strtoupper', $config['ALLOWED_FILE_EXTENSIONS']))) { 45 array_map('strtoupper', $config['ALLOWED_FILE_EXTENSIONS']))) {
-   46 http_response_code(403);
40 header('File extension not allowed.', true, 403); 47 die('File extension not allowed.');
41 return; -  
42 } 48 }
43   49  
44 #### Build the user path. 50 #### Build the user path.
45 $userPath = join( 51 $userPath = join(
46 DIRECTORY_SEPARATOR, 52 DIRECTORY_SEPARATOR,
47 array( 53 array(
48 $config['STORE_FOLDER'], 54 $config['STORE_FOLDER'],
49 $file 55 $file
50 ) 56 )
51 ); 57 );
52   58  
53 #### Check for path traversals 59 #### Check for path traversals
54 $pathPart = pathinfo($userPath); 60 $pathPart = pathinfo($userPath);
55 if (strcasecmp( 61 if (strcasecmp(
56 realpath($pathPart['dirname']), realpath($config['STORE_FOLDER'])) != 0) { 62 realpath($pathPart['dirname']), realpath($config['STORE_FOLDER'])) != 0) {
57 header('Internal server error.', true, 500); 63 http_response_code(500);
58 return; 64 die('Internal server error.');
59 } 65 }
-   66  
60   67 #### Check if the file exists.
-   68 if (!file_exists($userPath)) {
61 if (!file_exists($userPath)) { 69 http_response_code(404);
-   70 die('File not found.');
-   71 }
-   72  
-   73 ### Check if the timestamp matches.
-   74 if (filemtime($userPath) != $_GET['timestamp']) {
62 header('File not found.', true, 404); 75 http_response_code(403);
63 return; 76 die('Forbidden.');
64 } 77 }
65   78  
66 unlink($userPath); 79 unlink($userPath);
67   80