]>
git.p6c8.net - jirafeau.git/blob - f.php
3 * Jirafeau, your web file repository
4 * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
5 * Copyright (C) 2015 Jerome Jutteau <jerome@jutteau.fr>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 define('JIRAFEAU_ROOT', dirname(__FILE__
) . '/');
22 require(JIRAFEAU_ROOT
. 'lib/settings.php');
23 require(JIRAFEAU_ROOT
. 'lib/functions.php');
24 require(JIRAFEAU_ROOT
. 'lib/lang.php');
26 if (!isset($_GET['h']) ||
empty($_GET['h'])) {
27 header('Location: ./');
31 /* Operations may take a long time.
32 * Be sure PHP's safe mode is off.
36 $link_name = $_GET['h'];
38 if (!preg_match('/[0-9a-zA-Z_-]+$/', $link_name)) {
39 require(JIRAFEAU_ROOT
.'lib/template/header.php');
40 echo '<div class="error"><p>' . t('FILE_404') . '</p></div>';
41 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
45 $link = jirafeau_get_link($link_name);
46 if (count($link) == 0) {
47 require(JIRAFEAU_ROOT
.'lib/template/header.php');
48 echo '<div class="error"><p>' . t('FILE_404') .
50 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
55 if (isset($_GET['d']) && !empty($_GET['d']) && $_GET['d'] != '1') {
56 $delete_code = $_GET['d'];
60 if (isset($_GET['k']) && !empty($_GET['k'])) {
61 $crypt_key = $_GET['k'];
65 if (isset($_GET['d']) && $_GET['d'] == '1') {
70 if (isset($_GET['p']) && !empty($_GET['p'])) {
74 $p = s2p($link['hash']);
75 if (!file_exists(VAR_FILES
. $p . $link['hash'])) {
76 jirafeau_delete_link($link_name);
77 require(JIRAFEAU_ROOT
.'lib/template/header.php');
78 echo '<div class="error"><p>'.t('FILE_NOT_AVAIL').
80 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
84 if (!empty($delete_code) && $delete_code == $link['link_code']) {
85 require(JIRAFEAU_ROOT
.'lib/template/header.php');
86 if (isset($_POST['do_delete'])) {
87 jirafeau_delete_link($link_name);
88 echo '<div class="message"><p>'.t('FILE_DELETED').
92 <form action
="f.php" method
="post" id
="submit_delete_post" class="form login">
93 <input type
="hidden" name
="do_delete" value
=1/>
95 <legend
> <?php
echo t('CONFIRM_DEL') ?
> </legend
>
98 <?php
echo t('GONNA_DEL') . ' "' . jirafeau_escape($link['file_name']) . '" (' . jirafeau_human_size($link['file_size']) . ').' ?
>
101 <?php
echo t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' ?
>
104 <input type
="submit" id
="submit_delete" value
="<?php echo t('DELETE'); ?>"
105 onclick
="document.getElementById('submit_delete_post').action='<?php echo 'f.php?h=' . $link_name . '&d=' . $delete_code . "';"; ?>
106 document.getElementById('submit_delete
').submit ();"/>
109 </fieldset></form></div><?php
111 require(JIRAFEAU_ROOT.'lib
/template
/footer
.php
');
115 if ($link['time
'] != JIRAFEAU_INFINITY && time() > $link['time
']) {
116 jirafeau_delete_link($link_name);
117 require(JIRAFEAU_ROOT.'lib
/template
/header
.php
');
118 echo '<div
class="error"><p
>'.
119 t('FILE_EXPIRED
') . ' ' .
122 require(JIRAFEAU_ROOT . 'lib
/template
/footer
.php
');
126 if (empty($crypt_key) && $link['crypted
']) {
127 require(JIRAFEAU_ROOT.'lib
/template
/header
.php
');
128 echo '<div
class="error"><p
>' . t('FILE_404
') .
130 require(JIRAFEAU_ROOT.'lib
/template
/footer
.php
');
134 $password_challenged = false;
135 if (!empty($link['key
'])) {
136 if (!isset($_POST['key
'])) {
137 require(JIRAFEAU_ROOT.'lib
/template
/header
.php
');
139 '<form action
="f.php" method
="post" id
="submit_post" class="form login">'; ?>
140 <input type = "hidden" name = "jirafeau" value = "<?php echo JIRAFEAU_VERSION ?>"/><?php
142 '<legend
>' . t('PSW_PROTEC
') .
143 '</legend
><table
><tr
><td
>' .
144 t('GIMME_PSW
') . ' : ' .
145 '<input type
= "password" name
= "key" autocomplete
= "current-password"/>' .
148 t('USING_SERVICE
'). ' <a href
="tos.php" target
="_blank" rel
="noopener noreferrer">' . t('TOS
') . '</a
>.' .
151 if ($link['onetime
'] == 'O
') {
152 echo '<tr
><td id
="self_destruct">' .
155 } ?><tr><td><input type="submit" id = "submit_download" value="<?php echo t('DL
'); ?>"
156 onclick="document.getElementById('submit_post
').action='<?php
157 echo 'f.php?h=' . $link_name . '&d=1';
158 if (!empty($crypt_key)) {
159 echo '&k=' . urlencode($crypt_key);
161 document.getElementById('submit_download
').submit ();"/><?php
162 if ($cfg['preview
'] && jirafeau_is_viewable($link['mime_type
'])) {
163 ?><input type="submit" id = "submit_preview" value="<?php echo t('PREVIEW
'); ?>"
164 onclick="document.getElementById('submit_post
').action='<?php
165 echo 'f.php?h=' . $link_name . '&p=1';
166 if (!empty($crypt_key)) {
167 echo '&k=' . urlencode($crypt_key);
169 document.getElementById('submit_preview
').submit ();"/><?php
171 echo '</td
></tr
></table
></fieldset
></form
></div
>';
172 require(JIRAFEAU_ROOT.'lib
/template
/footer
.php
');
175 if ($link['key
'] == md5($_POST['key
'])) {
176 $password_challenged = true;
179 require(JIRAFEAU_ROOT.'lib
/template
/header
.php
');
180 echo '<div
class="error"><p
>' . t('ACCESS_KO
') .
182 require(JIRAFEAU_ROOT.'lib
/template
/footer
.php
');
188 if (!$password_challenged && !$do_download && !$do_preview) {
189 require(JIRAFEAU_ROOT.'lib
/template
/header
.php
');
191 '<form action
="f.php" method
="post" id
="submit_post" class="form download">'; ?>
192 <input type = "hidden" name = "jirafeau" value = "<?php echo JIRAFEAU_VERSION ?>"/><?php
193 echo '<fieldset
><legend
>' . jirafeau_escape($link['file_name
']) . '</legend
><table
>' .
195 t('NOW_DOWNLOADING
') . ' "' . jirafeau_escape($link['file_name']) . '" (' . jirafeau_human_size($link['file_size
']) . ').' .
198 t('USING_SERVICE
'). ' <a href
="tos.php" target
="_blank" rel
="noopener noreferrer">' . t('TOS
') . '</a
>.' .
201 if ($link['onetime
'] == 'O
') {
202 echo '<tr
><td id
="self_destruct">' .
206 <tr><td><input type="submit" id = "submit_download" value="<?php echo t('DL
'); ?>"
207 onclick="document.getElementById('submit_post
').action='<?php
208 echo 'f.php?h=' . $link_name . '&d=1';
209 if (!empty($crypt_key)) {
210 echo '&k=' . urlencode($crypt_key);
212 document.getElementById('submit_post
').submit ();"/><?php
214 if ($cfg['preview
'] && jirafeau_is_viewable($link['mime_type
'])) {
215 ?><input type="submit" id = "submit_preview" value="<?php echo t('PREVIEW
'); ?>"
216 onclick="document.getElementById('submit_post
').action='<?php
217 echo 'f.php?h=' . $link_name . '&p=1';
218 if (!empty($crypt_key)) {
219 echo '&k=' . urlencode($crypt_key);
221 document.getElementById('submit_post
').submit ();"/><?php
224 echo '</table
></fieldset
></form
></div
>';
225 require(JIRAFEAU_ROOT.'lib
/template
/footer
.php
');
229 header('HTTP
/1.0 200 OK
');
230 header('Content
-Length
: ' . $link['file_size
']);
231 if (!jirafeau_is_viewable($link['mime_type
']) || !$cfg['preview
'] || $do_download) {
232 header('Content
-Disposition
: attachment
; filename
="' . $link['file_name'] . '"');
234 header('Content
-Disposition
: filename
="' . $link['file_name'] . '"');
236 header('Content
-Type
: ' . $link['mime_type
']);
237 if ($cfg['file_hash
'] == "md5") {
238 header('Content
-MD5
: ' . hex_to_base64($link['hash
']));
240 if ($cfg['litespeed_workaround
']) {
241 // Work around that LiteSpeed truncates large files.
242 // See https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:config:internal-redirect
243 if ($_GET['litespeed_workaround
'] == 'phase2
') {
244 $file_web_path = preg_replace('#^' . $_SERVER['DOCUMENT_ROOT'] . '#', '', VAR_FILES);
245 header('X-LiteSpeed-Location: ' . $file_web_path . $p . $link['hash']);
247 // Since Content-Type isn't forwarded by LiteSpeed, first
248 // redirect to the same URL but append the file name.
249 header('Location: ' . $_SERVER['PHP_SELF'] . '/' . $link['file_name'] . '?' .
250 $_SERVER['QUERY_STRING'] . '&litespeed_workaround=phase2');
253 /* Read encrypted file. */
254 elseif ($link['crypted']) {
256 $m = mcrypt_module_open('rijndael-256', '', 'ofb', '');
257 /* Extract key and iv. */
258 $hash_key = md5($crypt_key);
259 $iv = jirafeau_crypt_create_iv($hash_key, mcrypt_enc_get_iv_size($m));
261 mcrypt_generic_init($m, $hash_key, $iv);
263 $r = fopen(VAR_FILES
. $p . $link['hash'], 'r');
265 $dec = mdecrypt_generic($m, fread($r, 1024));
270 mcrypt_generic_deinit($m);
271 mcrypt_module_close($m);
275 $r = fopen(VAR_FILES
. $p . $link['hash'], 'r');
277 print fread($r, 1024);
282 if ($link['onetime'] == 'O') {
283 jirafeau_delete_link($link_name);
patrick-canterino.de