]> git.p6c8.net - jirafeau.git/blob - file.php
Fix previous commit by adding forgotten files
[jirafeau.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 _('File has been deleted.') .
85 '</p></div>';
86 require (JIRAFEAU_ROOT.'lib/template/footer.php');
87 exit;
88 }
89
90 if (!empty ($key))
91 {
92 if (!isset ($_POST['key']))
93 {
94 require (JIRAFEAU_ROOT.'lib/template/header.php');
95 ?><div id = "upload">
96 <form action =
97 "<?php echo $_SERVER['REQUEST_URI']; ?>" method =
98 "post"> <input type = "hidden" name = "jirafeau" value =
99 "<?php echo JIRAFEAU_VERSION; ?>" /><fieldset>
100 <legend><?php echo _('Password protection');
101 ?></legend> <table> <tr>
102 <td><?php echo _('Give the password of this file:');
103 ?><input type = "password" name =
104 "key" /></td> </tr> <tr> <td><input type =
105 "submit" value =
106 "<?php echo _('I have the right to download this file'); ?>"
107 /></td> </tr> </table> </fieldset> </form> </div>
108 <?php require (JIRAFEAU_ROOT.'lib/template/footer.php');
109 exit;
110 }
111 else
112 {
113 if ($key != md5 ($_POST['key']))
114 {
115 header ("HTTP/1.0 403 Forbidden");
116
117 require (JIRAFEAU_ROOT.'lib/template/header.php');
118 echo '<div class="error"><p>' . _('Error 403: Forbidden') .
119 '</p></div>';
120 require (JIRAFEAU_ROOT.'lib/template/footer.php');
121 exit;
122 }
123 }
124 }
125
126 header ('Content-Length: ' . $file_size);
127 header ('Content-Type: ' . $mime_type);
128 if (!jirafeau_is_viewable ($mime_type))
129 {
130 header ('Content-Disposition: attachment; filename="' .
131 $file_name . '"');
132 }
133 readfile (VAR_FILES.$md5);
134
135 if ($onetime == 'O')
136 jirafeau_delete ($link_name);
137 exit;
138 }
139 else
140 {
141 header ("HTTP/1.0 404 Not Found");
142
143 require (JIRAFEAU_ROOT.'lib/template/header.php');
144 echo '<div class="error"><p>' . _('Error 404: Not Found') .
145 '</p></div>';
146 require (JIRAFEAU_ROOT.'lib/template/footer.php');
147 exit;
148 }
149 }
150 else
151 {
152 header ('Location: '.$cfg['web_root']);
153 exit;
154 }
155
156 ?>

patrick-canterino.de