scratch – Blame information for rev 48
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
28 | office | 1 | <?php |
2 | |||
3 | ########################################################################### |
||
4 | ## Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 ## |
||
5 | ########################################################################### |
||
6 | |||
37 | office | 7 | header('Content-Type: text/html; charset=utf-8'); |
8 | header('Cache-Control: no-cache, no-store, must-revalidate'); |
||
9 | header('Pragma: no-cache'); |
||
10 | header('Expires: 0'); |
||
11 | |||
28 | office | 12 | require_once('inc/pseudocrypt.php'); |
13 | require_once('inc/functions.php'); |
||
14 | require_once('config.php'); |
||
15 | |||
37 | office | 16 | if(!isset($_POST['fingerprint']) or empty($_POST['fingerprint']) or |
17 | !isset($_POST['action']) or empty($_POST['action'])) |
||
18 | return; |
||
19 | |||
20 | #### Check fingerprint consistency. |
||
21 | $fingerprint = strtoupper($_POST['fingerprint']); |
||
22 | if(strlen($fingerprint) !== 32) |
||
23 | return; |
||
24 | |||
25 | $action = strtoupper($_POST['action']); |
||
26 | |||
27 | #### Data must be sent in order to save a file. |
||
40 | office | 28 | if($action === 'SAVE' and !isset($_POST['data'])) |
37 | office | 29 | return; |
30 | |||
31 | #### Hash fingerprint. |
||
32 | $file = strtolower( |
||
33 | PseudoCrypt::hash( |
||
34 | preg_replace( |
||
35 | '/\D/', |
||
36 | '', |
||
37 | hash( |
||
38 | 'sha512', |
||
48 | office | 39 | $fingerprint, |
37 | office | 40 | ) |
48 | office | 41 | ), |
42 | $ASSET_HASH_SIZE |
||
43 | ). |
||
44 | '.html' |
||
37 | office | 45 | ); |
46 | |||
28 | office | 47 | #### Build the user path. |
48 | $userPath = join( |
||
49 | DIRECTORY_SEPARATOR, |
||
50 | array( |
||
51 | $STORE_FOLDER, |
||
37 | office | 52 | $file |
28 | office | 53 | ) |
54 | ); |
||
55 | |||
56 | #### Check for path traversals |
||
57 | $pathPart = pathinfo($userPath); |
||
58 | if (strcasecmp( |
||
59 | realpath($pathPart['dirname']), realpath($STORE_FOLDER)) != 0) |
||
60 | return; |
||
61 | |||
37 | office | 62 | switch($action) { |
63 | case 'SAVE': |
||
28 | office | 64 | #### Store the file. |
29 | office | 65 | atomized_put_contents($userPath, $_POST['data']); |
28 | office | 66 | break; |
37 | office | 67 | case 'LOAD': |
29 | office | 68 | if(!file_exists($userPath)) |
69 | return; |
||
70 | echo atomized_get_contents($userPath); |
||
28 | office | 71 | break; |
72 | } |
||
73 |