]>
git.p6c8.net - jirafeau.git/blob - f.php
7faf028fce49f8fb49c0504ef5cd6b1e1f6db945
3 * Jirafeau, your web file repository
4 * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
5 * Copyright (C) 2012 Jerome Jutteau <j.jutteau@gmail.com>
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/lang.php');
23 require (JIRAFEAU_ROOT
. 'lib/config.original.php');
24 require (JIRAFEAU_ROOT
. 'lib/settings.php');
25 require (JIRAFEAU_ROOT
. 'lib/functions.php');
27 if (!isset ($_GET['h']) ||
empty ($_GET['h']))
29 header ('Location: ' . $cfg['web_root']);
33 /* Operations may take a long time.
34 * Be sure PHP's safe mode is off.
40 $link_name = $_GET['h'];
42 if (!preg_match ('/[0-9a-zA-Z_-]+$/', $link_name))
44 require (JIRAFEAU_ROOT
.'lib/template/header.php');
45 echo '<div class="error"><p>' . t('Sorry, the requested file is not found') . '</p></div>';
46 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
50 $link = jirafeau_get_link ($link_name);
51 if (count ($link) == 0)
53 require (JIRAFEAU_ROOT
.'lib/template/header.php');
54 echo '<div class="error"><p>' . t('Sorry, the requested file is not found') .
56 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
61 if (isset ($_GET['d']) && !empty ($_GET['d']))
62 $delete_code = $_GET['d'];
65 if (isset ($_GET['k']) && !empty ($_GET['k']))
66 $crypt_key = $_GET['k'];
68 $button_download = false;
69 if (isset ($_GET['bd']) && !empty ($_GET['bd']))
70 $button_download = true;
72 $button_preview = false;
73 if (isset ($_GET['bp']) && !empty ($_GET['bp']))
74 $button_preview = true;
76 $p = s2p ($link['md5']);
77 if (!file_exists (VAR_FILES
. $p . $link['md5']))
79 jirafeau_delete_link ($link_name);
80 require (JIRAFEAU_ROOT
.'lib/template/header.php');
81 echo '<div class="error"><p>'.t('File not available.').
83 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
87 if (!empty ($delete_code) && $delete_code == $link['link_code'])
89 jirafeau_delete_link ($link_name);
90 require (JIRAFEAU_ROOT
.'lib/template/header.php');
91 echo '<div class="message"><p>'.t('File has been deleted.').
93 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
97 if ($link['time'] != JIRAFEAU_INFINITY
&& time () > $link['time'])
99 jirafeau_delete_link ($link_name);
100 require (JIRAFEAU_ROOT
.'lib/template/header.php');
101 echo '<div class="error"><p>'.
102 t('The time limit of this file has expired.') . ' ' .
103 t('File has been deleted.') .
105 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
109 if (empty ($crypt_key) && $link['crypted'])
111 require (JIRAFEAU_ROOT
.'lib/template/header.php');
112 echo '<div class="error"><p>' . t('Sorry, the requested file is not found') .
114 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
118 $password_challenged = false;
119 if (!empty ($link['key']))
121 if (!isset ($_POST['key']))
123 require (JIRAFEAU_ROOT
.'lib/template/header.php');
126 echo $cfg['web_root'] . '/f.php';
128 'method = "post" id = "submit">'; ?
>
129 <input type
= "hidden" name
= "jirafeau" value
= "<?php echo JIRAFEAU_VERSION ?>"/><?php
131 '<legend>' . t('Password protection') .
132 '</legend><table><tr><td>' .
133 t('Give the password of this file') . ' : ' .
134 '<input type = "password" name = "key" />' .
137 t('By using our services, you accept of our'). ' <a href="' . $cfg['web_root'] . '/tos.php' . '">' . t('Term Of Service') . '</a>' .
140 ?
><input type
="submit" id
= "submit_download" value
="<?php echo t('Download'); ?>"
141 onclick
="document.getElementById('submit').action='
143 echo $cfg['web_root'] . '/f.php?h=' . $link_name . '&bd=1';
144 if (!empty($crypt_key))
145 echo '&k=' . urlencode($crypt_key);
147 document.getElementById('submit_download').submit ();"/><?php
148 if ($cfg['download_page'] && $cfg['preview'])
150 ?
><input type
="submit" id
= "submit_preview" value
="<?php echo t('Preview'); ?>"
151 onclick
="document.getElementById('submit').action='
153 echo $cfg['web_root'] . '/f.php?h=' . $link_name . '&bp=1';
154 if (!empty($crypt_key))
155 echo '&k=' . urlencode($crypt_key);
157 document.getElementById('submit_preview').submit ();"/><?php
159 echo '</td></tr></table></fieldset></form></div>';
160 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
165 if ($link['key'] == md5 ($_POST['key']))
166 $password_challenged = true;
169 header ("Access denied");
170 require (JIRAFEAU_ROOT
.'lib/template/header.php');
171 echo '<div class="error"><p>' . t('Access denied') .
173 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
179 if ($cfg['download_page'] && !$password_challenged && !$button_download && !$button_preview)
181 require (JIRAFEAU_ROOT
.'lib/template/header.php');
184 echo $cfg['web_root'] . '/f.php';
186 'method = "post" id = "submit">'; ?
>
187 <input type
= "hidden" name
= "jirafeau" value
= "<?php echo JIRAFEAU_VERSION ?>"/><?php
188 echo '<fieldset><legend>' . $link['file_name'] . '</legend><table>' .
190 t('You are about to download') . ' "' . $link['file_name'] . '" (' . jirafeau_human_size($link['file_size']) . ')' .
193 t('By using our services, you accept of our'). ' <a href="' . $cfg['web_root'] . '/tos.php' . '">' . t('Term Of Service') . '</a>';
194 ?
></td
></tr
><tr
><td
><input type
="submit" id
= "submit_download" value
="<?php echo t('Download'); ?>"
195 onclick
="document.getElementById('submit').action='
197 echo $cfg['web_root'] . '/f.php?h=' . $link_name . '&bd=1';
198 if (!empty($crypt_key))
199 echo '&k=' . urlencode($crypt_key);
201 document.getElementById('submit_download').submit ();"/><?php
203 if ($cfg['download_page'] && $cfg['preview'])
205 ?
><input type
="submit" id
= "submit_preview" value
="<?php echo t('Preview'); ?>"
206 onclick
="document.getElementById('submit').action='
208 echo $cfg['web_root'] . '/f.php?h=' . $link_name . '&bp=1';
209 if (!empty($crypt_key))
210 echo '&k=' . urlencode($crypt_key);
212 document.getElementById('submit_preview').submit ();"/><?php
215 echo '</table></fieldset></form></div>';
216 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
220 header ('HTTP/1.0 200 OK');
221 header ('Content-Length: ' . $link['file_size']);
222 if (!jirafeau_is_viewable ($link['mime_type']) ||
!$cfg['preview'] ||
$button_download)
223 header ('Content-Disposition: attachment; filename="' .
224 $link['file_name'] . '"');
225 header ('Content-Type: ' . $link['mime_type']);
227 /* Read encrypted file. */
228 if ($link['crypted'])
231 $m = mcrypt_module_open('rijndael-256', '', 'ofb', '');
232 /* Extract key and iv. */
233 $md5_key = md5 ($crypt_key);
234 $iv = jirafeau_crypt_create_iv ($md5_key, mcrypt_enc_get_iv_size($m));
236 mcrypt_generic_init ($m, $md5_key, $iv);
238 $r = fopen (VAR_FILES
. $p . $link['md5'], 'r');
241 $dec = mdecrypt_generic($m, fread ($r, 1024));
247 mcrypt_generic_deinit($m);
248 mcrypt_module_close($m);
253 $r = fopen (VAR_FILES
. $p . $link['md5'], 'r');
256 print fread ($r, 1024);
262 if ($link['onetime'] == 'O')
263 jirafeau_delete_link ($link_name);
patrick-canterino.de