]>
git.p6c8.net - jirafeau_project.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
="<?php echo 'f.php?h=' . $link_name . '&d=' . $delete_code; ?>" 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'); ?>"/>
107 </fieldset
></form
></div
><?php
109 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
113 if ($link['time'] != JIRAFEAU_INFINITY
&& time() > $link['time']) {
114 jirafeau_delete_link($link_name);
115 require(JIRAFEAU_ROOT
.'lib/template/header.php');
116 echo '<div class="error"><p>'.
117 t('FILE_EXPIRED') . ' ' .
120 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
124 if (empty($crypt_key) && $link['crypted']) {
125 require(JIRAFEAU_ROOT
.'lib/template/header.php');
126 echo '<div class="error"><p>' . t('FILE_404') .
128 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
132 $password_challenged = false;
133 if (!empty($link['key'])) {
134 if (!isset($_POST['key'])) {
135 require(JIRAFEAU_ROOT
.'lib/template/header.php');
137 '<form action="f.php" method="post" id="submit_post" class="form login">'; ?
>
138 <input type
= "hidden" name
= "jirafeau" value
= "<?php echo JIRAFEAU_VERSION ?>"/><?php
140 '<legend>' . t('PSW_PROTEC') .
141 '</legend><table><tr><td>' .
142 t('GIMME_PSW') . ' : ' .
143 '<input type = "password" name = "key" autocomplete = "current-password"/>' .
146 t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' .
149 if ($link['onetime'] == 'O') {
150 echo '<tr><td id="self_destruct">' .
153 } ?
><tr
><td
><input type
="submit" id
= "submit_download" value
="<?php echo t('DL'); ?>"
154 onclick
="document.getElementById('submit_post').action='<?php
155 echo 'f.php?h=' . $link_name . '&d=1';
156 if (!empty($crypt_key)) {
157 echo '&k=' . urlencode($crypt_key);
159 document.getElementById('submit_download').submit ();"/><?php
160 if ($cfg['preview'] && jirafeau_is_viewable($link['mime_type'])) {
161 ?
><input type
="submit" id
= "submit_preview" value
="<?php echo t('PREVIEW'); ?>"
162 onclick
="document.getElementById('submit_post').action='<?php
163 echo 'f.php?h=' . $link_name . '&p=1';
164 if (!empty($crypt_key)) {
165 echo '&k=' . urlencode($crypt_key);
167 document.getElementById('submit_preview').submit ();"/><?php
169 echo '</td></tr></table></fieldset></form></div>';
170 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
173 if ($link['key'] == md5($_POST['key'])) {
174 $password_challenged = true;
177 require(JIRAFEAU_ROOT
.'lib/template/header.php');
178 echo '<div class="error"><p>' . t('ACCESS_KO') .
180 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
186 if (!$password_challenged && !$do_download && !$do_preview) {
187 require(JIRAFEAU_ROOT
.'lib/template/header.php');
189 '<form action="f.php" method="post" id="submit_post" class="form download">'; ?
>
190 <input type
= "hidden" name
= "jirafeau" value
= "<?php echo JIRAFEAU_VERSION ?>"/><?php
191 echo '<fieldset><legend>' . jirafeau_escape($link['file_name']) . '</legend><table>' .
193 t('NOW_DOWNLOADING') . ' "' . jirafeau_escape($link['file_name']) . '" (' . jirafeau_human_size($link['file_size']) . ').' .
196 t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' .
199 if ($link['onetime'] == 'O') {
200 echo '<tr><td id="self_destruct">' .
204 <tr
><td
><input type
="submit" id
= "submit_download" value
="<?php echo t('DL'); ?>"
205 onclick
="document.getElementById('submit_post').action='<?php
206 echo 'f.php?h=' . $link_name . '&d=1';
207 if (!empty($crypt_key)) {
208 echo '&k=' . urlencode($crypt_key);
210 document.getElementById('submit_post').submit ();"/><?php
212 if ($cfg['preview'] && jirafeau_is_viewable($link['mime_type'])) {
213 ?
><input type
="submit" id
= "submit_preview" value
="<?php echo t('PREVIEW'); ?>"
214 onclick
="document.getElementById('submit_post').action='<?php
215 echo 'f.php?h=' . $link_name . '&p=1';
216 if (!empty($crypt_key)) {
217 echo '&k=' . urlencode($crypt_key);
219 document.getElementById('submit_post').submit ();"/><?php
222 echo '</table></fieldset></form></div>';
223 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
227 header('HTTP/1.0 200 OK');
228 header('Content-Length: ' . $link['file_size']);
229 if (!jirafeau_is_viewable($link['mime_type']) ||
!$cfg['preview'] ||
$do_download) {
230 header('Content-Disposition: attachment; filename="' . $link['file_name'] . '"');
232 header('Content-Disposition: filename="' . $link['file_name'] . '"');
234 header('Content-Type: ' . $link['mime_type']);
235 if ($cfg['file_hash'] == "md5") {
236 header('Content-MD5: ' . hex_to_base64($link['hash']));
238 if ($cfg['litespeed_workaround']) {
239 // Work around that LiteSpeed truncates large files.
240 // See https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:config:internal-redirect
241 if ($_GET['litespeed_workaround'] == 'phase2') {
242 $file_web_path = preg_replace('#^' . $_SERVER['DOCUMENT_ROOT'] . '#', '', VAR_FILES
);
243 header('X-LiteSpeed-Location: ' . $file_web_path . $p . $link['hash']);
245 // Since Content-Type isn't forwarded by LiteSpeed, first
246 // redirect to the same URL but append the file name.
247 header('Location: ' . $_SERVER['PHP_SELF'] . '/' . $link['file_name'] . '?' .
248 $_SERVER['QUERY_STRING'] . '&litespeed_workaround=phase2');
251 /* Read encrypted file (Sodium mode). */
252 elseif ($link['crypted']) {
253 jirafeau_decrypt_file(VAR_FILES
. $p . $link['hash'], 'php://output', $crypt_key);
255 /* Read encrypted file (legacy mode using mcrypt). */
256 elseif ($link['crypted_legacy']) {
257 jirafeau_decrypt_file_legacy(VAR_FILES
. $p . $link['hash'], 'php://output', $crypt_key);
261 if ($cfg['use_xsendfile']) {
262 $file_web_path = preg_replace('#^' . $_SERVER['DOCUMENT_ROOT'] . '#', '', VAR_FILES
);
263 header('X-Sendfile: ' . $file_web_path . $p . $link['hash']);
265 $r = fopen(VAR_FILES
. $p . $link['hash'], 'r');
267 print fread($r, 1024);
273 if ($link['onetime'] == 'O') {
274 jirafeau_delete_link($link_name);
277 jirafeau_write_download_stats($link_name, get_ip_address($cfg));
patrick-canterino.de