]> git.p6c8.net - jirafeau_mojo42.git/blob - file.php
18bb459d6a04e5fddc35a6c8866a2ed8c15e66c9
[jirafeau_mojo42.git] / file.php
1 <?php
2 /*
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>
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/lang.php');
23 require (JIRAFEAU_ROOT . 'lib/config.php');
24 require (JIRAFEAU_ROOT . 'lib/settings.php');
25 require (JIRAFEAU_ROOT . 'lib/functions.php');
26
27 if (!isset ($_GET['h']) || empty ($_GET['h']))
28 {
29 header ('Location: ' . $cfg['web_root']);
30 exit;
31 }
32
33 $link_name = $_GET['h'];
34
35 if (!preg_match ('/[0-9a-f]{32}$/', $link_name))
36 {
37 require (JIRAFEAU_ROOT.'lib/template/header.php');
38 echo '<div class="error"><p>' . t('Sorry, the requested file is not found') . '</p></div>';
39 require (JIRAFEAU_ROOT.'lib/template/footer.php');
40 exit;
41 }
42
43 $link = jirafeau_get_link ($link_name);
44 if (count ($link) == 0)
45 {
46 require (JIRAFEAU_ROOT.'lib/template/header.php');
47 echo '<div class="error"><p>' . t('Sorry, the requested file is not found') .
48 '</p></div>';
49 require (JIRAFEAU_ROOT.'lib/template/footer.php');
50 exit;
51 }
52
53 $delete_code = '';
54 if (isset ($_GET['d']) && !empty ($_GET['d']))
55 $delete_code = $_GET['d'];
56
57 $button_download = false;
58 if (isset ($_GET['bd']) && !empty ($_GET['bd']))
59 $button_download = true;
60
61 $button_preview = false;
62 if (isset ($_GET['bp']) && !empty ($_GET['bp']))
63 $button_preview = true;
64
65 $p = s2p ($link['md5']);
66 if (!file_exists (VAR_FILES . $p . $link['md5']))
67 {
68 jirafeau_delete_link ($link_name);
69 require (JIRAFEAU_ROOT.'lib/template/header.php');
70 echo '<div class="error"><p>'.t('File not available.').
71 '</p></div>';
72 require (JIRAFEAU_ROOT.'lib/template/footer.php');
73 exit;
74 }
75
76 if (!empty ($delete_code) && $delete_code == $link['link_code'])
77 {
78 jirafeau_delete_link ($link_name);
79 require (JIRAFEAU_ROOT.'lib/template/header.php');
80 echo '<div class="message"><p>'.t('File has been deleted.').
81 '</p></div>';
82 require (JIRAFEAU_ROOT.'lib/template/footer.php');
83 exit;
84 }
85
86 if ($link['time'] != JIRAFEAU_INFINITY && time () > $link['time'])
87 {
88 jirafeau_delete_link ($link_name);
89 require (JIRAFEAU_ROOT.'lib/template/header.php');
90 echo '<div class="error"><p>'.
91 t('The time limit of this file has expired.') . ' ' .
92 t('File has been deleted.') .
93 '</p></div>';
94 require (JIRAFEAU_ROOT . 'lib/template/footer.php');
95 exit;
96 }
97
98 $password_challenged = false;
99 if (!empty ($link['key']))
100 {
101 if (!isset ($_POST['key']))
102 {
103 require (JIRAFEAU_ROOT.'lib/template/header.php');
104 echo '<div id = "upload">' .
105 '<form action = "' . $_SERVER['REQUEST_URI'] . '" ' .
106 'method = "post" id = "submit">'; ?>
107 <input type = "hidden" name = "jirafeau" value = "<?php echo JIRAFEAU_VERSION ?>"/><?php
108 echo '<fieldset>' .
109 '<legend>' . t('Password protection') .
110 '</legend><table><tr><td>' .
111 t('Give the password of this file') . ' : ' .
112 '<input type = "password" name = "key" />' .
113 '</td></tr>' .
114 '<tr><td>' .
115 t('By using our services, you accept of our'). ' <a href="' . $cfg['web_root'] . '/tos.php' . '">' . t('Term Of Service') . '</a>' .
116 '</td></tr>' .
117 '<tr><td>';
118 ?><input type="submit" id = "submit_download" value="<?php echo t('Download'); ?>"
119 onclick="document.getElementById('submit').action='<?php echo $_SERVER['REQUEST_URI'] ?>&amp;bd=1';
120 document.getElementById('submit_download').submit ();"/><?php
121
122 if ($cfg['download_page'] && $cfg['preview'])
123 {
124 ?><input type="submit" id = "submit_preview" value="<?php echo t('Preview'); ?>"
125 onclick="document.getElementById('submit').action='<?php echo $_SERVER['REQUEST_URI'] ?>&amp;bp=1';
126 document.getElementById('submit_preview').submit ();"/><?php
127 }
128 echo '</td></tr></table></fieldset></form></div>';
129 require (JIRAFEAU_ROOT.'lib/template/footer.php');
130 exit;
131 }
132 else
133 {
134 if ($link['key'] != md5 ($_POST['key']))
135 {
136 header ("Access denied");
137 require (JIRAFEAU_ROOT.'lib/template/header.php');
138 echo '<div class="error"><p>' . t('Access denied') .
139 '</p></div>';
140 require (JIRAFEAU_ROOT.'lib/template/footer.php');
141 exit;
142 }
143 else
144 $password_challenged = true;
145 }
146 }
147
148 if ($cfg['download_page'] && !$password_challenged && !$button_download && !$button_preview)
149 {
150 require (JIRAFEAU_ROOT.'lib/template/header.php');
151 echo '<div id = "upload">' .
152 '<form action = "' . $_SERVER['REQUEST_URI'] . '" ' .
153 'method = "post" id = "submit">'; ?>
154 <input type = "hidden" name = "jirafeau" value = "<?php echo JIRAFEAU_VERSION ?>"/><?php
155 echo '<fieldset><legend>' . $link['file_name'] . '</legend><table>' .
156 '<tr><td>' .
157 t('You are about to download') . ' "' . $link['file_name'] . '" (' . jirafeau_human_size($link['file_size']) . ')' .
158 '</td></tr>' .
159 '<tr><td>' .
160 t('By using our services, you accept of our'). ' <a href="' . $cfg['web_root'] . '/tos.php' . '">' . t('Term Of Service') . '</a>';
161 ?><input type="submit" id = "submit_download" value="<?php echo t('Download'); ?>"
162 onclick="document.getElementById('submit').action='<?php echo $_SERVER['REQUEST_URI'] ?>&amp;bd=1';
163 document.getElementById('submit_download').submit ();"/><?php
164
165 if ($cfg['download_page'] && $cfg['preview'])
166 {
167 ?><input type="submit" id = "submit_preview" value="<?php echo t('Preview'); ?>"
168 onclick="document.getElementById('submit').action='<?php echo $_SERVER['REQUEST_URI'] ?>&amp;bp=1';
169 document.getElementById('submit_preview').submit ();"/><?php
170 }
171 echo '</td></tr>';
172 echo '</table></fieldset></form></div>';
173 require (JIRAFEAU_ROOT.'lib/template/footer.php');
174 exit;
175 }
176
177 header ('Content-Length: ' . $link['file_size']);
178 header ('Content-Type: ' . $link['mime_type']);
179 if (!jirafeau_is_viewable ($link['mime_type']) || !$cfg['preview'] || $button_download)
180 {
181 header ('Content-Disposition: attachment; filename="' .
182 $link['file_name'] . '"');
183 }
184 readfile (VAR_FILES . $p . $link['md5']);
185
186 if ($link['onetime'] == 'O')
187 jirafeau_delete_link ($link_name);
188 exit;
189
190 ?>

patrick-canterino.de