]> git.p6c8.net - jirafeau.git/blob - f.php
[BUGFIX] avoid running admin cli if installation not finished
[jirafeau.git] / f.php
1 <?php
2 /*
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 *
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.
11 *
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.
16 *
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/>.
19 */
20 define('JIRAFEAU_ROOT', dirname(__FILE__) . '/');
21
22 require(JIRAFEAU_ROOT . 'lib/settings.php');
23 require(JIRAFEAU_ROOT . 'lib/functions.php');
24 require(JIRAFEAU_ROOT . 'lib/lang.php');
25
26 if (!isset($_GET['h']) || empty($_GET['h'])) {
27 header('Location: ./');
28 exit;
29 }
30
31 /* Operations may take a long time.
32 * Be sure PHP's safe mode is off.
33 */
34 @set_time_limit(0);
35
36 $link_name = $_GET['h'];
37
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');
42 exit;
43 }
44
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') .
49 '</p></div>';
50 require(JIRAFEAU_ROOT.'lib/template/footer.php');
51 exit;
52 }
53
54 $delete_code = '';
55 if (isset($_GET['d']) && !empty($_GET['d']) && $_GET['d'] != '1') {
56 $delete_code = $_GET['d'];
57 }
58
59 $crypt_key = '';
60 if (isset($_GET['k']) && !empty($_GET['k'])) {
61 $crypt_key = $_GET['k'];
62 }
63
64 $do_download = false;
65 if (isset($_GET['d']) && $_GET['d'] == '1') {
66 $do_download = true;
67 }
68
69 $do_preview = false;
70 if (isset($_GET['p']) && !empty($_GET['p'])) {
71 $do_preview = true;
72 }
73
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').
79 '</p></div>';
80 require(JIRAFEAU_ROOT.'lib/template/footer.php');
81 exit;
82 }
83
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').
89 '</p></div>';
90 } else { ?>
91 <div>
92 <form action="f.php" method="post" id="submit_delete_post" class="form login">
93 <input type="hidden" name="do_delete" value=1/>
94 <fieldset>
95 <legend> <?php echo t('CONFIRM_DEL') ?> </legend>
96 <table>
97 <tr><td>
98 <?php echo t('GONNA_DEL') . ' "' . jirafeau_escape($link['file_name']) . '" (' . jirafeau_human_size($link['file_size']) . ').' ?>
99 </td></tr>
100 <tr><td>
101 <?php echo t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' ?>
102 </td></tr>
103 <tr><td>
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 . '&amp;d=' . $delete_code . "';"; ?>
106 document.getElementById('submit_delete').submit ();"/>
107 </td></tr>
108 </table>
109 </fieldset></form></div><?php
110 }
111 require(JIRAFEAU_ROOT.'lib/template/footer.php');
112 exit;
113 }
114
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') . ' ' .
120 t('FILE_DELETED') .
121 '</p></div>';
122 require(JIRAFEAU_ROOT . 'lib/template/footer.php');
123 exit;
124 }
125
126 if (empty($crypt_key) && $link['crypted']) {
127 require(JIRAFEAU_ROOT.'lib/template/header.php');
128 echo '<div class="error"><p>' . t('FILE_404') .
129 '</p></div>';
130 require(JIRAFEAU_ROOT.'lib/template/footer.php');
131 exit;
132 }
133
134 $password_challenged = false;
135 if (!empty($link['key'])) {
136 if (!isset($_POST['key'])) {
137 require(JIRAFEAU_ROOT.'lib/template/header.php');
138 echo '<div>' .
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
141 echo '<fieldset>' .
142 '<legend>' . t('PSW_PROTEC') .
143 '</legend><table><tr><td>' .
144 t('GIMME_PSW') . ' : ' .
145 '<input type = "password" name = "key" />' .
146 '</td></tr>' .
147 '<tr><td>' .
148 t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' .
149 '</td></tr>';
150
151 if ($link['onetime'] == 'O') {
152 echo '<tr><td id="self_destruct">' .
153 t('AUTO_DESTRUCT') .
154 '</td></tr>';
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 . '&amp;d=1';
158 if (!empty($crypt_key)) {
159 echo '&amp;k=' . urlencode($crypt_key);
160 } ?>';
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 . '&amp;p=1';
166 if (!empty($crypt_key)) {
167 echo '&amp;k=' . urlencode($crypt_key);
168 } ?>';
169 document.getElementById('submit_preview').submit ();"/><?php
170 }
171 echo '</td></tr></table></fieldset></form></div>';
172 require(JIRAFEAU_ROOT.'lib/template/footer.php');
173 exit;
174 } else {
175 if ($link['key'] == md5($_POST['key'])) {
176 $password_challenged = true;
177 } else {
178 sleep(2);
179 require(JIRAFEAU_ROOT.'lib/template/header.php');
180 echo '<div class="error"><p>' . t('ACCESS_KO') .
181 '</p></div>';
182 require(JIRAFEAU_ROOT.'lib/template/footer.php');
183 exit;
184 }
185 }
186 }
187
188 if (!$password_challenged && !$do_download && !$do_preview) {
189 require(JIRAFEAU_ROOT.'lib/template/header.php');
190 echo '<div>' .
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>' .
194 '<tr><td>' .
195 t('NOW_DOWNLOADING') . ' "' . jirafeau_escape($link['file_name']) . '" (' . jirafeau_human_size($link['file_size']) . ').' .
196 '</td></tr>' .
197 '<tr><td>' .
198 t('USING_SERVICE'). ' <a href="tos.php" target="_blank" rel="noopener noreferrer">' . t('TOS') . '</a>.' .
199 '</td></tr>';
200
201 if ($link['onetime'] == 'O') {
202 echo '<tr><td id="self_destruct">' .
203 t('AUTO_DESTRUCT') .
204 '</td></tr>';
205 } ?>
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 . '&amp;d=1';
209 if (!empty($crypt_key)) {
210 echo '&amp;k=' . urlencode($crypt_key);
211 } ?>';
212 document.getElementById('submit_post').submit ();"/><?php
213
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 . '&amp;p=1';
218 if (!empty($crypt_key)) {
219 echo '&amp;k=' . urlencode($crypt_key);
220 } ?>';
221 document.getElementById('submit_post').submit ();"/><?php
222 }
223 echo '</td></tr>';
224 echo '</table></fieldset></form></div>';
225 require(JIRAFEAU_ROOT.'lib/template/footer.php');
226 exit;
227 }
228
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'] . '"');
233 } else {
234 header('Content-Disposition: filename="' . $link['file_name'] . '"');
235 }
236 header('Content-Type: ' . $link['mime_type']);
237 if ($cfg['file_hash'] == "md5") {
238 header('Content-MD5: ' . hex_to_base64($link['hash']));
239 }
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']);
246 } else {
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');
251 }
252 }
253 /* Read encrypted file. */
254 elseif ($link['crypted']) {
255 /* Init module */
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));
260 /* Init module. */
261 mcrypt_generic_init($m, $hash_key, $iv);
262 /* Decrypt file. */
263 $r = fopen(VAR_FILES . $p . $link['hash'], 'r');
264 while (!feof($r)) {
265 $dec = mdecrypt_generic($m, fread($r, 1024));
266 print $dec;
267 }
268 fclose($r);
269 /* Cleanup. */
270 mcrypt_generic_deinit($m);
271 mcrypt_module_close($m);
272 }
273 /* Read file. */
274 else {
275 $r = fopen(VAR_FILES . $p . $link['hash'], 'r');
276 while (!feof($r)) {
277 print fread($r, 1024);
278 }
279 fclose($r);
280 }
281
282 if ($link['onetime'] == 'O') {
283 jirafeau_delete_link($link_name);
284 }
285 exit;
286
287 ?>

patrick-canterino.de