]>
git.p6c8.net - jirafeau.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'];
31 if(isset($_GET['d']) && !empty($_GET['d']))
32 $delete_code = $_GET['d'];
34 if(!ereg('[0-9a-f]{32}$', $link_name)) {
35 header("HTTP/1.0 404 Not Found");
37 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
38 echo '<div class="error"><p>Error 404: Not Found</p></div>';
39 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
43 $link_file = VAR_LINKS
. $link_name;
44 if(file_exists($link_file)) {
45 $content = file($link_file);
46 $file_name = trim($content[0]);
47 $mime_type = trim($content[1]);
48 $file_size = trim($content[2]);
49 $key = trim($content[3], NL
);
50 $time = trim($content[4]);
51 $md5 = trim($content[5]);
52 $onetime = trim($content[6]);
53 $link_code = trim($content[9]);
57 if(!file_exists(VAR_FILES
. $md5)) {
58 jirafeau_delete($link_name);
59 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
60 echo '<div class="error"><p>' . _('File not available.') . '</p></div>';
61 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
65 if(!empty($delete_code) && $delete_code == $link_code) {
66 jirafeau_delete($link_name);
67 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
68 echo '<div class="message"><p>' . _('File has been deleted.') . '</p></div>';
69 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
73 if($time != JIRAFEAU_INFINITY
&& time() > $time) {
74 jirafeau_delete($link_name);
75 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
76 echo '<div class="error"><p>' . _('The time limit of this file has expired. It has been deleted.') . '</p></div>';
77 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
82 if(!isset($_POST['key'])) {
83 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
86 <form action
="<?php echo $_SERVER['REQUEST_URI']; ?>" method
="post">
87 <input type
="hidden" name
="jirafeau" value
="<?php echo JIRAFEAU_VERSION; ?>" />
89 <legend
><?php
echo _('Key protection'); ?
></legend
>
92 <td
><?php
echo _('Give the key of this file:'); ?
> <input type
="password" name
="key" /></td
>
95 <td
><input type
="submit" value
="<?php echo _('I have the right to download this file'); ?>" /></td
>
102 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
105 if($key != $_POST['key']) {
106 header("HTTP/1.0 403 Forbidden");
108 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
109 echo '<div class="error"><p>Error 403: Forbidden</p></div>';
110 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
116 header('Content-Length: ' . $file_size);
117 header('Content-Type: ' . $mime_type);
118 if(!jirafeau_is_viewable($mime_type)) {
119 header('Content-Disposition: attachment; filename="' . $file_name . '"');
121 readfile(VAR_FILES
. $md5);
123 if($onetime == 'O') {
124 jirafeau_delete($link_name);
128 header("HTTP/1.0 404 Not Found");
130 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
131 echo '<div class="error"><p>Error 404: Not Found</p></div>';
132 require(JIRAFEAU_ROOT
. 'lib/template/footer.php');
136 header('Location: ' . $cfg['web_root']);
patrick-canterino.de