]>
git.p6c8.net - jirafeau_mojo42.git/blob - file.php
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>
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.
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.
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/>.
21 define('JIRAFEAU_ROOT', dirname(__FILE__
) . '/');
23 require(JIRAFEAU_ROOT
. 'lib/config.php');
24 require(JIRAFEAU_ROOT
. 'lib/settings.php');
25 require(JIRAFEAU_ROOT
. 'lib/functions.php');
27 if(isset($_GET['h']) && !empty($_GET['h'])) {
28 $link_name = $_GET['h'];
30 if(!ereg('[0-9a-f]{32}$', $link_name)) {
31 header("HTTP/1.0 404 Not Found");
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');
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]);
50 if(!file_exists(VAR_FILES
. $md5)) {
51 if (file_exists(VAR_FILES
. $md5 . '_count')) {
52 unlink(VAR_FILES
. $md5 . '_count');
55 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
56 echo '<div class="error"><p>' . _('File not available.') . '</p></div>';
57 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
62 if (file_exists(VAR_FILES
. $md5 . '_count')) {
63 $content = file(VAR_FILES
. $md5 . '_count');
64 $counter = trim($content[0], NL
);
67 if($time != JIRAFEAU_INFINITY
) {
73 $handle = fopen(VAR_FILES
. $md5 . '_count', 'w');
74 fwrite($handle, $counter);
77 elseif ($counter == 0) {
78 if (file_exists(VAR_FILES
. $md5 . '_count')) {
79 unlink(VAR_FILES
. $md5 . '_count');
81 $new_name = jirafeau_detect_collision($md5 . '_' . $file_name, VAR_TRASH
);
82 rename(VAR_FILES
. $md5, VAR_TRASH
. $new_name);
85 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
86 echo '<div class="error"><p>' . _('The time limit of this file has expired. It has been deleted.') . '</p></div>';
87 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
93 if(!isset($_POST['key'])) {
94 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
97 <form action
="<?php echo $_SERVER['REQUEST_URI']; ?>" method
="post">
98 <input type
="hidden" name
="jirafeau" value
="<?php echo JIRAFEAU_VERSION; ?>" />
100 <legend
><?php
echo _('Key protection'); ?
></legend
>
103 <td
><?php
echo _('Give the key of this file:'); ?
> <input type
="password" name
="key" /></td
>
106 <td
><input type
="submit" value
="<?php echo _('I have the right to download this file'); ?>" /></td
>
113 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
116 if($key != $_POST['key']) {
117 header("HTTP/1.0 403 Forbidden");
119 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
120 echo '<div class="error"><p>Error 403: Forbidden</p></div>';
121 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
127 header('Content-Length: ' . $file_size);
128 header('Content-Type: ' . $mime_type);
129 if(!jirafeau_is_viewable($mime_type)) {
130 header('Content-Disposition: attachment; filename="' . $file_name . '"');
132 readfile(VAR_FILES
. $md5);
134 if($onetime == 'O') {
139 $handle = fopen(VAR_FILES
. $md5 . '_count', 'w');
140 fwrite($handle, $counter);
143 elseif ($counter == 0) {
144 if (file_exists(VAR_FILES
. $md5 . '_count')) {
145 unlink(VAR_FILES
. $md5 . '_count');
147 $new_name = jirafeau_detect_collision($md5 . '_' . $file_name, VAR_TRASH
);
148 rename(VAR_FILES
. $md5, VAR_TRASH
. $new_name);
153 header("HTTP/1.0 404 Not Found");
155 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
156 echo '<div class="error"><p>Error 404: Not Found</p></div>';
157 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
161 header('Location: ' . $cfg['web_root']);
patrick-canterino.de