]>
git.p6c8.net - jirafeau_mojo42.git/blob - f.php
a97718f9387a4ddd11f8d0563ee58ef4a11a57b3
3 * Jirafeau, your web file repository
4 * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
5 * Copyright (C) 2015 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/settings.php');
23 require (JIRAFEAU_ROOT
. 'lib/functions.php');
24 require (JIRAFEAU_ROOT
. 'lib/lang.php');
26 if (!isset ($_GET['h']) ||
empty ($_GET['h']))
28 header ('Location: ' . $cfg['web_root']);
32 /* Operations may take a long time.
33 * Be sure PHP's safe mode is off.
39 $link_name = $_GET['h'];
41 if (!preg_match ('/[0-9a-zA-Z_-]+$/', $link_name))
43 require (JIRAFEAU_ROOT
.'lib/template/header.php');
44 echo '<div class="error"><p>' . t('Sorry, the requested file is not found') . '</p></div>';
45 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
49 $link = jirafeau_get_link ($link_name);
50 if (count ($link) == 0)
53 $alias = jirafeau_get_alias (md5 ($link_name));
54 if (count ($alias) > 0)
55 $link = jirafeau_get_link ($alias["destination"]);
57 if (count ($link) == 0)
59 require (JIRAFEAU_ROOT
.'lib/template/header.php');
60 echo '<div class="error"><p>' . t('Sorry, the requested file is not found') .
62 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
67 if (isset ($_GET['d']) && !empty ($_GET['d']) && $_GET['d'] != '1')
68 $delete_code = $_GET['d'];
71 if (isset ($_GET['k']) && !empty ($_GET['k']))
72 $crypt_key = $_GET['k'];
75 if (isset ($_GET['d']) && $_GET['d'] == '1')
79 if (isset ($_GET['p']) && !empty ($_GET['p']))
82 $p = s2p ($link['md5']);
83 if (!file_exists (VAR_FILES
. $p . $link['md5']))
85 jirafeau_delete_link ($link_name);
86 require (JIRAFEAU_ROOT
.'lib/template/header.php');
87 echo '<div class="error"><p>'.t('File not available.').
89 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
93 if (!empty ($delete_code) && $delete_code == $link['link_code'])
95 jirafeau_delete_link ($link_name);
96 require (JIRAFEAU_ROOT
.'lib/template/header.php');
97 echo '<div class="message"><p>'.t('File has been deleted.').
99 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
103 if ($link['time'] != JIRAFEAU_INFINITY
&& time () > $link['time'])
105 jirafeau_delete_link ($link_name);
106 require (JIRAFEAU_ROOT
.'lib/template/header.php');
107 echo '<div class="error"><p>'.
108 t('The time limit of this file has expired.') . ' ' .
109 t('File has been deleted.') .
111 require (JIRAFEAU_ROOT
. 'lib/template/footer.php');
115 if (empty ($crypt_key) && $link['crypted'])
117 require (JIRAFEAU_ROOT
.'lib/template/header.php');
118 echo '<div class="error"><p>' . t('Sorry, the requested file is not found') .
120 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
124 $password_challenged = false;
125 if (!empty ($link['key']))
127 if (!isset ($_POST['key']))
129 require (JIRAFEAU_ROOT
.'lib/template/header.php');
132 echo $cfg['web_root'] . '/f.php';
134 'method = "post" id = "submit_post">'; ?
>
135 <input type
= "hidden" name
= "jirafeau" value
= "<?php echo JIRAFEAU_VERSION ?>"/><?php
137 '<legend>' . t('Password protection') .
138 '</legend><table><tr><td>' .
139 t('Give the password of this file') . ' : ' .
140 '<input type = "password" name = "key" />' .
143 t('By using our services, you accept our'). ' <a href="' . $cfg['web_root'] . '/tos.php' . '">' . t('Term Of Service') . '</a>' .
146 if ($link['onetime'] == 'O')
148 echo '<tr><td id="self_destruct">' .
149 t('Warning, this file will self-destruct after being read') .
153 ?
><tr
><td
><input type
="submit" id
= "submit_download" value
="<?php echo t('Download'); ?>"
154 onclick
="document.getElementById('submit_post').action='
156 echo $cfg['web_root'] . '/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']))
163 ?
><input type
="submit" id
= "submit_preview" value
="<?php echo t('Preview'); ?>"
164 onclick
="document.getElementById('submit_post').action='
166 echo $cfg['web_root'] . '/f.php?h=' . $link_name . '&p=1';
167 if (!empty($crypt_key))
168 echo '&k=' . urlencode($crypt_key);
170 document.getElementById('submit_preview').submit ();"/><?php
172 echo '</td></tr></table></fieldset></form></div>';
173 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
178 if ($link['key'] == md5 ($_POST['key']))
179 $password_challenged = true;
183 require (JIRAFEAU_ROOT
.'lib/template/header.php');
184 echo '<div class="error"><p>' . t('Access denied') .
186 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
192 if (!$password_challenged && !$do_download && !$do_preview)
194 require (JIRAFEAU_ROOT
.'lib/template/header.php');
197 echo $cfg['web_root'] . '/f.php';
199 'method = "post" id = "submit_post">'; ?
>
200 <input type
= "hidden" name
= "jirafeau" value
= "<?php echo JIRAFEAU_VERSION ?>"/><?php
201 echo '<fieldset><legend>' . htmlspecialchars($link['file_name']) . '</legend><table>' .
203 t('You are about to download') . ' "' . htmlspecialchars($link['file_name']) . '" (' . jirafeau_human_size($link['file_size']) . ')' .
206 t('By using our services, you accept our'). ' <a href="' . $cfg['web_root'] . '/tos.php' . '">' . t('Term Of Service') . '</a>' .
209 if ($link['onetime'] == 'O')
211 echo '<tr><td id="self_destruct">' .
212 t('Warning, this file will self-destruct after being read') .
217 <tr
><td
><input type
="submit" id
= "submit_download" value
="<?php echo t('Download'); ?>"
218 onclick
="document.getElementById('submit_post').action='
220 echo $cfg['web_root'] . '/f.php?h=' . $link_name . '&d=1';
221 if (!empty($crypt_key))
222 echo '&k=' . urlencode($crypt_key);
224 document.getElementById('submit_post').submit ();"/><?php
226 if ($cfg['preview'] && jirafeau_is_viewable($link['mime_type']))
228 ?
><input type
="submit" id
= "submit_preview" value
="<?php echo t('Preview'); ?>"
229 onclick
="document.getElementById('submit_post').action='
231 echo $cfg['web_root'] . '/f.php?h=' . $link_name . '&p=1';
232 if (!empty($crypt_key))
233 echo '&k=' . urlencode($crypt_key);
235 document.getElementById('submit_post').submit ();"/><?php
238 echo '</table></fieldset></form></div>';
239 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
243 header ('HTTP/1.0 200 OK');
244 header ('Content-Length: ' . $link['file_size']);
245 if (!jirafeau_is_viewable ($link['mime_type']) ||
!$cfg['preview'] ||
$do_download)
246 header ('Content-Disposition: attachment; filename="' . $link['file_name'] . '"');
248 header ('Content-Disposition: filename="' . $link['file_name'] . '"');
249 header ('Content-Type: ' . $link['mime_type']);
250 header ('Content-MD5: ' . hex_to_base64($link['md5']));
252 /* Read encrypted file. */
253 if ($link['crypted'])
256 $m = mcrypt_module_open('rijndael-256', '', 'ofb', '');
257 /* Extract key and iv. */
258 $md5_key = md5 ($crypt_key);
259 $iv = jirafeau_crypt_create_iv ($md5_key, mcrypt_enc_get_iv_size($m));
261 mcrypt_generic_init ($m, $md5_key, $iv);
263 $r = fopen (VAR_FILES
. $p . $link['md5'], 'r');
266 $dec = mdecrypt_generic($m, fread ($r, 1024));
272 mcrypt_generic_deinit($m);
273 mcrypt_module_close($m);
278 $r = fopen (VAR_FILES
. $p . $link['md5'], 'r');
281 print fread ($r, 1024);
287 if ($link['onetime'] == 'O')
288 jirafeau_delete_link ($link_name);
patrick-canterino.de