scratch – Diff between revs 110 and 111

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 110 Rev 111
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/autoload.php'); 9 require_once('vendor/autoload.php');
10 require_once('vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/FFMpeg.php'); 10 require_once('vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/FFMpeg.php');
11   11  
12 ### Load configuration. 12 ### Load configuration.
13 $config = spyc_load_file('config.yaml'); 13 $config = spyc_load_file('config.yaml');
14   14  
15 ### If no file has been specified for download then return. 15 ### If no file has been specified for download then return.
16 if (!isset($_GET['hash']) or empty($_GET['hash'])) { 16 if (!isset($_GET['hash']) or empty($_GET['hash'])) {
17 http_response_code(404); 17 http_response_code(404);
18 die('File not found.'); 18 die('File not found.');
19 } 19 }
20   20  
21 ### Find the requested file. 21 ### Find the requested file.
22 $file = array_shift( 22 $file = array_shift(
23 preg_grep( 23 preg_grep(
24 "/".$_GET['hash']."/", 24 "/".$_GET['hash']."/",
25 scandir($config['STORE_FOLDER']) 25 scandir($config['STORE_FOLDER'])
26 ) 26 )
27 ); 27 );
28   28  
29 if (!isset($file) or empty($file)) { 29 if (!isset($file) or empty($file)) {
30 http_response_code(404); 30 http_response_code(404);
31 die('File not found.'); 31 die('File not found.');
32 } 32 }
33   33  
34 ### Check the path for path traversals. 34 ### Check the path for path traversals.
35 $fileExtension = pathinfo($file, PATHINFO_EXTENSION); 35 $fileExtension = pathinfo($file, PATHINFO_EXTENSION);
36   36  
37 #### If the extension is not allowed then return. 37 #### If the extension is not allowed then return.
38 if (!isset($fileExtension) || 38 if (!isset($fileExtension) ||
39 !in_array(strtoupper($fileExtension), 39 !in_array(strtoupper($fileExtension),
40 array_map('strtoupper', $config['ALLOWED_FILE_EXTENSIONS']))) { 40 array_map('strtoupper', $config['ALLOWED_FILE_EXTENSIONS']))) {
41 http_response_code(403); 41 http_response_code(403);
42 die('File extension not allowed.'); 42 die('File extension not allowed.');
43 } 43 }
44   44  
45 #### Build the user path. 45 #### Build the user path.
46 $userPath = join( 46 $userPath = join(
47 DIRECTORY_SEPARATOR, 47 DIRECTORY_SEPARATOR,
48 array( 48 array(
49 $config['STORE_FOLDER'], 49 $config['STORE_FOLDER'],
50 $file 50 $file
51 ) 51 )
52 ); 52 );
53   53  
54 #### Check for path traversals 54 #### Check for path traversals
55 $pathPart = pathinfo($userPath); 55 $pathPart = pathinfo($userPath);
56 if (strcasecmp( 56 if (strcasecmp(
57 realpath($pathPart['dirname']), realpath($config['STORE_FOLDER'])) != 0) { 57 realpath($pathPart['dirname']), realpath($config['STORE_FOLDER'])) != 0) {
58 http_response_code(500); 58 http_response_code(500);
59 die('Internal server error.'); 59 die('Internal server error.');
60 } 60 }
61   61  
62 #### Check if the file exists. 62 #### Check if the file exists.
63 if (!file_exists($userPath)) { 63 if (!file_exists($userPath)) {
64 http_response_code(404); 64 http_response_code(404);
65 die('File not found.'); 65 die('File not found.');
66 } 66 }
67   67  
68 $GRAPH_URL = $config['URL_PATH'].'og/'.$_GET['hash']; 68 $GRAPH_URL = $config['URL_PATH'].'og/'.$_GET['hash'];
69 $CANON_URL = $config['URL_PATH'].'file.php?hash='.$_GET['hash']; 69 $CANON_URL = $config['URL_PATH'].'file.php?hash='.$_GET['hash'];
70 $BASIC_URL = $config['URL_PATH'].$_GET['hash']; 70 $BASIC_URL = $config['URL_PATH'].$_GET['hash'];
71   71  
72 switch(strtoupper($fileExtension)) { 72 switch(strtoupper($fileExtension)) {
73 case 'GIF': 73 case 'GIF':
74 list($width, $height) = getimagesize($userPath); 74 list($width, $height) = getimagesize($userPath);
75 echo <<<END 75 echo <<<END
76 <html> 76 <html>
77 <head> 77 <head>
78 <meta property="og:site_name" content="Scratch Copy"> 78 <meta property="og:site_name" content="Scratch Copy">
79 <meta property="og:url" content="$BASIC_URL"> 79 <meta property="og:url" content="$BASIC_URL">
80 <meta property="og:title" content="Scratch Copy"> 80 <meta property="og:title" content="Scratch Copy">
81 <meta property="og:type" content="video.other"> 81 <meta property="og:type" content="video.other">
82 <meta property="og:image" content="$BASIC_URL"> 82 <meta property="og:image" content="$BASIC_URL">
83 <meta property="og:image:width" content="$width"> 83 <meta property="og:image:width" content="$width">
84 <meta property="og:image:height" content="$height"> 84 <meta property="og:image:height" content="$height">
85 </head> 85 </head>
86   86  
87 <body> 87 <body>
88 <p> 88 <p>
89 <img src="$URL"> 89 <img src="$BASIC_URL">
90 </p> 90 </p>
91 </body> 91 </body>
92   92  
93 </html> 93 </html>
94 END; 94 END;
95 break; 95 break;
96 case 'MP4': 96 case 'MP4':
97 ### Create a thumbnail for the video. 97 ### Create a thumbnail for the video.
98 $file = strtolower( 98 $file = strtolower(
99 PseudoCrypt::hash( 99 PseudoCrypt::hash(
100 preg_replace( 100 preg_replace(
101 '/\D/', 101 '/\D/',
102 '', 102 '',
103 hash( 103 hash(
104 'sha512', 104 'sha512',
105 $_GET['hash'] 105 $_GET['hash']
106 ) 106 )
107 ), 107 ),
108 $config['ASSET_HASH_SIZE'] 108 $config['ASSET_HASH_SIZE']
109 ) 109 )
110 ); 110 );
111 111
112 #### Build the user path. 112 #### Build the user path.
113 $userPath = join( 113 $userPath = join(
114 DIRECTORY_SEPARATOR, 114 DIRECTORY_SEPARATOR,
115 array( 115 array(
116 $config['STORE_FOLDER'], 116 $config['STORE_FOLDER'],
117 $file 117 $file
118 ) 118 )
119 ); 119 );
120 120
121 ### Extract thumbnail. 121 ### Extract thumbnail.
122 $ffmpeg = FFMpeg\FFMpeg::create(); 122 $ffmpeg = FFMpeg\FFMpeg::create();
123 $video = $ffmpeg->open($CANON_URL); 123 $video = $ffmpeg->open($CANON_URL);
-   124 $frame = $video->frame(
124 $frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(42)); 125 FFMpeg\Coordinate\TimeCode::fromSeconds(
-   126 $config['VIDEO_PREVIEW_IMAGE_FRAME_SECOND']
-   127 )
-   128 );
125 $frame->save($userPath.'.'.'jpg'); 129 $frame->save($userPath.'.'.'jpg');
-   130
-   131 $PREVIEW_IMAGE_URL = $config['URL_PATH'].$file;
-   132 $FLOW_PLAYER_VIDEO_URL = $config['URL_PATH'].'flowplayer/flowplayer.swf?config={"clip":"'.$BASIC_URL.'"}';
-   133 $FLOW_PLAYER = $config['URL_PATH'].'flowplayer/flowplayer.swf';
-   134
126 echo <<<END 135 echo <<<END
127 <html> 136 <html>
128 <head> 137 <head>
129 <meta property="og:type" content="video.other"> 138 <meta property="og:type" content="video.other">
130 <meta property="og:title" content="Scratch Copy"> 139 <meta property="og:title" content="Scratch Copy">
131 <meta property="og:site_name" content="Scratch Copy"> 140 <meta property="og:site_name" content="Scratch Copy">
132 141
133 <meta property="og:url" content="$GRAPH_URL"> 142 <meta property="og:url" content="$GRAPH_URL">
134 143
135 <meta property="og:image" content="https://cpy.ro/$file"> 144 <meta property="og:image" content="$PREVIEW_IMAGE_URL">
136 <meta property="og:video" content='http://cpy.ro/flowplayer/flowplayer.swf?config={"clip":"$BASIC_URL"}'> 145 <meta property="og:video" content='$FLOW_PLAYER_VIDEO_URL'>
137 <meta property="og:video:secure_url" content='https://cpy.ro/flowplayer/flowplayer.swf?config={"clip":"$BASIC_URL"}'> 146 <meta property="og:video:secure_url" content='$FLOW_PLAYER_VIDEO_URL'>
138 <meta property="og:video:type" content="application/x-shockwave-flash"> 147 <meta property="og:video:type" content="application/x-shockwave-flash">
139 <meta property="og:video:width" content="425"> 148 <meta property="og:video:width" content="425">
140 <meta property="og:video:height" content="300"> 149 <meta property="og:video:height" content="300">
141 </head> 150 </head>
142   151  
143 <body> 152 <body>
144 <p> 153 <p>
145 <object width="425" height="300" id="Scratch Copy" name="Scratch Copy" data="https://cpy.ro/flowplayer/flowplayer.swf" type="application/x-shockwave-flash"><param name="movie" value="https://cpy.ro/flowplayer/flowplayer.swf" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="flashvars" value='config={"clip":"$BASIC_URL"}' /></object> 154 <object width="425" height="300" id="Scratch Copy" name="Scratch Copy" data="$FLOW_PLAYER" type="application/x-shockwave-flash"><param name="movie" value="$FLOW_PLAYER" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="flashvars" value='config={"clip":"$BASIC_URL"}' /></object>
146 </p> 155 </p>
147 </body> 156 </body>
148   157  
149 </html> 158 </html>
150 END; 159 END;
151 break; 160 break;
152 } 161 }
153   162  
154   163  
155   164  
156   165