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

patrick-canterino.de