]>
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>
6 * Copyright (C) 2024 Jirafeau project <https://gitlab.com/jirafeau> (see AUTHORS.md)
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 define('JIRAFEAU_ROOT', dirname(__FILE__
) . '/');
23 require(JIRAFEAU_ROOT
. 'lib/settings.php');
24 require(JIRAFEAU_ROOT
. 'lib/functions.php');
25 require(JIRAFEAU_ROOT
. 'lib/lang.php');
27 if (!isset($_GET['h']) ||
empty($_GET['h'])) {
28 header('Location: ./');
32 /* Operations may take a long time.
33 * Be sure PHP's safe mode is off.
37 $link_name = $_GET['h'];
39 if (!preg_match('/[0-9a-zA-Z_-]+$/', $link_name)) {
40 require(JIRAFEAU_ROOT
.'lib/template/header.php');
41 echo '<div class="error"><p>' . t('FILE_404') . '</p></div>';
42 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
46 $link = jirafeau_get_link($link_name);
47 if (count($link) == 0) {
48 require(JIRAFEAU_ROOT
.'lib/template/header.php');
49 echo '<div class="error"><p>' . t('FILE_404') .
51 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
56 if (isset($_GET['d']) && !empty($_GET['d']) && $_GET['d'] != '1') {
57 $delete_code = $_GET['d'];
61 if (isset($_GET['k']) && !empty($_GET['k'])) {
62 $crypt_key = $_GET['k'];
66 if (isset($_GET['d']) && $_GET['d'] == '1') {
71 if (isset($_GET['p']) && !empty($_GET['p'])) {
75 $p = s2p($link['hash']);
76 if (!file_exists(VAR_FILES
. $p . $link['hash'])) {
77 jirafeau_delete_link($link_name);
78 require(JIRAFEAU_ROOT
.'lib/template/header.php');
79 echo '<div class="error"><p>'.t('FILE_NOT_AVAIL').
81 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
85 if (!empty($delete_code) && $delete_code == $link['link_code']) {
86 require(JIRAFEAU_ROOT
.'lib/template/header.php');
87 if (isset($_POST['do_delete'])) {
88 jirafeau_delete_link($link_name);
89 echo '<div class="message"><p>'.t('FILE_DELETED').
93 <form action
="<?php echo 'f.php?h=' . $link_name . '&d=' . $delete_code; ?>" method
="post" id
="submit_delete_post" class="form login">
94 <input type
="hidden" name
="do_delete" value
="1" />
96 <legend
> <?php
echo t('CONFIRM_DEL') ?
> </legend
>
99 <?php
echo t('GONNA_DEL') . ' "' . jirafeau_escape($link['file_name']) . '" (' . jirafeau_human_size($link['file_size']) . ').' ?
>
102 <?php
echo t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' ?
>
105 <input type
="submit" id
="submit_delete" value
="<?php echo t('DELETE'); ?>"/>
108 </fieldset
></form
></div
><?php
110 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
114 if ($link['time'] != JIRAFEAU_INFINITY
&& time() > $link['time']) {
115 jirafeau_delete_link($link_name);
116 require(JIRAFEAU_ROOT
.'lib/template/header.php');
117 echo '<div class="error"><p>'.
118 t('FILE_EXPIRED') . ' ' .
121 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
125 if (empty($crypt_key) && $link['crypted']) {
126 require(JIRAFEAU_ROOT
.'lib/template/header.php');
127 echo '<div class="error"><p>' . t('FILE_404') .
129 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
133 $password_challenged = false;
134 if (!empty($link['key'])) {
135 if (!isset($_POST['key'])) {
136 require(JIRAFEAU_ROOT
.'lib/template/header.php');
138 '<form action="f.php" method="post" id="submit_post" class="form login">'; ?
>
139 <input type
= "hidden" name
= "jirafeau" value
= "<?php echo JIRAFEAU_VERSION ?>"/><?php
141 '<legend>' . t('PSW_PROTEC') .
142 '</legend><table><tr><td>' .
143 t('GIMME_PSW') . ' : ' .
144 '<input type = "password" name = "key" autocomplete = "current-password"/>' .
147 t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' .
150 if ($link['onetime'] == 'O') {
151 echo '<tr><td id="self_destruct">' .
154 } ?
><tr
><td
><input type
="submit" id
= "submit_download" value
="<?php echo t('DL'); ?>"
155 onclick
="document.getElementById('submit_post').action='<?php
156 echo 'f.php?h=' . $link_name . '&d=1';
157 if (!empty($crypt_key)) {
158 echo '&k=' . urlencode($crypt_key);
160 document.getElementById('submit_download').submit ();"/><?php
161 if ($cfg['preview'] && jirafeau_is_viewable($link['mime_type'])) {
162 ?
><input type
="submit" id
= "submit_preview" value
="<?php echo t('PREVIEW'); ?>"
163 onclick
="document.getElementById('submit_post').action='<?php
164 echo 'f.php?h=' . $link_name . '&p=1';
165 if (!empty($crypt_key)) {
166 echo '&k=' . urlencode($crypt_key);
168 document.getElementById('submit_preview').submit ();"/><?php
170 echo '</td></tr></table></fieldset></form></div>';
171 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
174 if ($link['key'] == md5($_POST['key'])) {
175 $password_challenged = true;
178 require(JIRAFEAU_ROOT
.'lib/template/header.php');
179 echo '<div class="error"><p>' . t('ACCESS_KO') .
181 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
187 if (!$password_challenged && !$do_download && !$do_preview) {
188 require(JIRAFEAU_ROOT
.'lib/template/header.php');
190 '<form action="f.php" method="post" id="submit_post" class="form download">'; ?
>
191 <input type
= "hidden" name
= "jirafeau" value
= "<?php echo JIRAFEAU_VERSION ?>"/><?php
192 echo '<fieldset><legend>' . jirafeau_escape($link['file_name']) . '</legend><table>' .
194 t('NOW_DOWNLOADING') . ' "' . jirafeau_escape($link['file_name']) . '" (' . jirafeau_human_size($link['file_size']) . ').' .
197 t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' .
200 if ($link['onetime'] == 'O') {
201 echo '<tr><td id="self_destruct">' .
205 <tr
><td
><input type
="submit" id
= "submit_download" value
="<?php echo t('DL'); ?>"
206 onclick
="document.getElementById('submit_post').action='<?php
207 echo 'f.php?h=' . $link_name . '&d=1';
208 if (!empty($crypt_key)) {
209 echo '&k=' . urlencode($crypt_key);
211 document.getElementById('submit_post').submit ();"/><?php
213 if ($cfg['preview'] && jirafeau_is_viewable($link['mime_type'])) {
214 ?
><input type
="submit" id
= "submit_preview" value
="<?php echo t('PREVIEW'); ?>"
215 onclick
="document.getElementById('submit_post').action='<?php
216 echo 'f.php?h=' . $link_name . '&p=1';
217 if (!empty($crypt_key)) {
218 echo '&k=' . urlencode($crypt_key);
220 document.getElementById('submit_post').submit ();"/><?php
223 echo '</table></fieldset></form></div>';
224 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
228 header('HTTP/1.0 200 OK');
229 header('Content-Length: ' . $link['file_size']);
230 if (!jirafeau_is_viewable($link['mime_type']) ||
!$cfg['preview'] ||
$do_download) {
231 header('Content-Disposition: attachment; filename="' . $link['file_name'] . '"');
233 header('Content-Disposition: filename="' . $link['file_name'] . '"');
235 header('Content-Type: ' . $link['mime_type']);
236 if ($cfg['file_hash'] == "md5") {
237 header('Content-MD5: ' . hex_to_base64($link['hash']));
239 if ($cfg['litespeed_workaround']) {
240 // Work around that LiteSpeed truncates large files.
241 // See https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:config:internal-redirect
242 if ($_GET['litespeed_workaround'] == 'phase2') {
243 $file_web_path = preg_replace('#^' . $_SERVER['DOCUMENT_ROOT'] . '#', '', VAR_FILES
);
244 header('X-LiteSpeed-Location: ' . $file_web_path . $p . $link['hash']);
246 // Since Content-Type isn't forwarded by LiteSpeed, first
247 // redirect to the same URL but append the file name.
248 header('Location: ' . $_SERVER['PHP_SELF'] . '/' . $link['file_name'] . '?' .
249 $_SERVER['QUERY_STRING'] . '&litespeed_workaround=phase2');
252 /* Read encrypted file (Sodium mode). */
253 elseif ($link['crypted']) {
254 jirafeau_decrypt_file(VAR_FILES
. $p . $link['hash'], 'php://output', $crypt_key);
256 /* Read encrypted file (legacy mode using mcrypt). */
257 elseif ($link['crypted_legacy']) {
258 jirafeau_decrypt_file_legacy(VAR_FILES
. $p . $link['hash'], 'php://output', $crypt_key);
262 if ($cfg['use_xsendfile']) {
263 $file_web_path = preg_replace('#^' . $_SERVER['DOCUMENT_ROOT'] . '#', '', VAR_FILES
);
264 header('X-Sendfile: ' . $file_web_path . $p . $link['hash']);
266 $r = fopen(VAR_FILES
. $p . $link['hash'], 'r');
268 print fread($r, 1024);
274 if ($link['onetime'] == 'O') {
275 jirafeau_delete_link($link_name);
278 jirafeau_write_download_stats($link_name, get_ip_address($cfg));
patrick-canterino.de