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

patrick-canterino.de