]> git.p6c8.net - jirafeau_mojo42.git/blob - file.php
Fix php 5.3 support and prepare languages
[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 $link_name = $_GET['h'];
30
31 $delete_code = '';
32 if (isset ($_GET['d']) && !empty ($_GET['d']))
33 $delete_code = $_GET['d'];
34
35 if (!preg_match ('/[0-9a-f]{32}$/', $link_name))
36 {
37 header ("HTTP/1.0 404 Not Found");
38
39 require (JIRAFEAU_ROOT.'lib/template/header.php');
40 echo '<div class="error"><p>Error 404: Not Found</p></div>';
41 require (JIRAFEAU_ROOT.'lib/template/footer.php');
42 exit;
43 }
44
45 $link_file = VAR_LINKS.$link_name;
46 if (file_exists ($link_file))
47 {
48 $content = file ($link_file);
49 $file_name = trim ($content[0]);
50 $mime_type = trim ($content[1]);
51 $file_size = trim ($content[2]);
52 $key = trim ($content[3], NL);
53 $time = trim ($content[4]);
54 $md5 = trim ($content[5]);
55 $onetime = trim ($content[6]);
56 $link_code = trim ($content[9]);
57
58 if (!file_exists (VAR_FILES.$md5))
59 {
60 jirafeau_delete ($link_name);
61 require (JIRAFEAU_ROOT.'lib/template/header.php');
62 echo '<div class="error"><p>'._('File not available.').
63 '</p></div>';
64 require (JIRAFEAU_ROOT.'lib/template/footer.php');
65 exit;
66 }
67
68 if (!empty ($delete_code) && $delete_code == $link_code)
69 {
70 jirafeau_delete ($link_name);
71 require (JIRAFEAU_ROOT.'lib/template/header.php');
72 echo '<div class="message"><p>'._('File has been deleted.').
73 '</p></div>';
74 require (JIRAFEAU_ROOT.'lib/template/footer.php');
75 exit;
76 }
77
78 if ($time != JIRAFEAU_INFINITY && time ()> $time)
79 {
80 jirafeau_delete ($link_name);
81 require (JIRAFEAU_ROOT.'lib/template/header.php');
82 echo '<div class="error"><p>'.
83 _('The time limit of this file has expired.' .
84 'It has been deleted.') . '</p></div>';
85 require (JIRAFEAU_ROOT.'lib/template/footer.php');
86 exit;
87 }
88
89 if (!empty ($key))
90 {
91 if (!isset ($_POST['key']))
92 {
93 require (JIRAFEAU_ROOT.'lib/template/header.php');
94 ?><div id = "upload">
95 <form action =
96 "<?php echo $_SERVER['REQUEST_URI']; ?>" method =
97 "post"> <input type = "hidden" name = "jirafeau" value =
98 "<?php echo JIRAFEAU_VERSION; ?>" /><fieldset>
99 <legend><?php echo _('Key protection');
100 ?></legend> <table> <tr>
101 <td><?php echo _('Give the key of this file:');
102 ?><input type = "password" name =
103 "key" /></td> </tr> <tr> <td><input type =
104 "submit" value =
105 "<?php echo _('I have the right to download this file'); ?>"
106 /></td> </tr> </table> </fieldset> </form> </div>
107 <?php require (JIRAFEAU_ROOT.'lib/template/footer.php');
108 exit;
109 }
110 else
111 {
112 if ($key != md5 ($_POST['key']))
113 {
114 header ("HTTP/1.0 403 Forbidden");
115
116 require (JIRAFEAU_ROOT.'lib/template/header.php');
117 echo '<div class="error"><p>Error 403: Forbidden</p></div>';
118 require (JIRAFEAU_ROOT.'lib/template/footer.php');
119 exit;
120 }
121 }
122 }
123
124 header ('Content-Length: ' . $file_size);
125 header ('Content-Type: ' . $mime_type);
126 if (!jirafeau_is_viewable ($mime_type))
127 {
128 header ('Content-Disposition: attachment; filename="' .
129 $file_name . '"');
130 }
131 readfile (VAR_FILES.$md5);
132
133 if ($onetime == 'O')
134 jirafeau_delete ($link_name);
135 exit;
136 }
137 else
138 {
139 header ("HTTP/1.0 404 Not Found");
140
141 require (JIRAFEAU_ROOT.'lib/template/header.php');
142 echo '<div class="error"><p>Error 404: Not Found</p></div>';
143 require (JIRAFEAU_ROOT.'lib/template/footer.php');
144 exit;
145 }
146 }
147 else
148 {
149 header ('Location: '.$cfg['web_root']);
150 exit;
151 }
152
153 ?>

patrick-canterino.de