scratch – Blame information for rev 50

Subversion Repositories:
Rev:
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',
50 office 39 $fingerprint
37 office 40 )
48 office 41 ),
42 $ASSET_HASH_SIZE
49 office 43 )
37 office 44 );
45  
28 office 46 #### Build the user path.
47 $userPath = join(
48 DIRECTORY_SEPARATOR,
49 array(
50 $STORE_FOLDER,
37 office 51 $file
28 office 52 )
53 );
54  
55 #### Check for path traversals
49 office 56 $pathPart = pathinfo($userPath.'.html');
28 office 57 if (strcasecmp(
58 realpath($pathPart['dirname']), realpath($STORE_FOLDER)) != 0)
59 return;
60  
37 office 61 switch($action) {
62 case 'SAVE':
28 office 63 #### Store the file.
49 office 64 atomized_put_contents($userPath.'.html', $_POST['data']);
28 office 65 break;
37 office 66 case 'LOAD':
50 office 67 if(!file_exists($userPath.'.html'))
29 office 68 return;
49 office 69 echo atomized_get_contents($userPath.'.html');
28 office 70 break;
71 }
72