]> git.p6c8.net - jirafeau_mojo42.git/blob - pub/file.php
Initial commit: Jiraph 0.5 (stable) project
[jirafeau_mojo42.git] / pub / file.php
1 <?php
2 /*
3 * Jyraphe, your web file repository
4 * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 define('JYRAPHE_ROOT', dirname(__FILE__) . '/');
21
22 require(JYRAPHE_ROOT . 'lib/config.php');
23 require(JYRAPHE_ROOT . 'lib/settings.php');
24 require(JYRAPHE_ROOT . 'lib/functions.php');
25
26 if(isset($_GET['h']) && !empty($_GET['h'])) {
27 $link_name = $_GET['h'];
28
29 if(!ereg('^[OR][0-9a-f]{32}$', $link_name)) {
30 header("HTTP/1.0 404 Not Found");
31
32 require(JYRAPHE_ROOT . 'lib/template/header.php');
33 echo '<div class="error"><p>Error 404: Not Found</p></div>';
34 require(JYRAPHE_ROOT . 'lib/template/footer.php');
35 exit;
36 }
37
38 $link_file = VAR_LINKS . $link_name;
39 if(file_exists($link_file)) {
40 $content = file($link_file);
41 $file_name = trim($content[0]);
42 $mime_type = trim($content[1]);
43 $file_size = trim($content[2]);
44 $key = trim($content[3], NL);
45 $time = trim($content[4]);
46
47 if($time != JYRAPHE_INFINITY) {
48 if(time() > $time) {
49 unlink($link_file);
50 $new_name = jyraphe_detect_collision($file_name, VAR_TRASH);
51 rename(VAR_FILES . $file_name, VAR_TRASH . $new_name);
52
53 require(JYRAPHE_ROOT . 'lib/template/header.php');
54 echo '<div class="error"><p>' . _('The time limit of this file has expired. It has been deleted.') . '</p></div>';
55 require(JYRAPHE_ROOT . 'lib/template/footer.php');
56 exit;
57
58 }
59 }
60
61 if(!empty($key)) {
62 if(!isset($_POST['key'])) {
63 require(JYRAPHE_ROOT . 'lib/template/header.php');
64 ?>
65 <div id="upload">
66 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
67 <input type="hidden" name="jyraphe" value="<?php echo JYRAPHE_VERSION; ?>" />
68 <fieldset>
69 <legend><?php echo _('Key protection'); ?></legend>
70 <table>
71 <tr>
72 <td><?php echo _('Give the key of this file:'); ?> <input type="password" name="key" /></td>
73 </tr>
74 <tr>
75 <td><input type="submit" value="<?php echo _('I have the right to download this file'); ?>" /></td>
76 </tr>
77 </table>
78 </fieldset>
79 </form>
80 </div>
81 <?php
82 require(JYRAPHE_ROOT . 'lib/template/footer.php');
83 exit;
84 } else {
85 if($key != $_POST['key']) {
86 header("HTTP/1.0 403 Forbidden");
87
88 require(JYRAPHE_ROOT . 'lib/template/header.php');
89 echo '<div class="error"><p>Error 403: Forbidden</p></div>';
90 require(JYRAPHE_ROOT . 'lib/template/footer.php');
91 exit;
92 }
93 }
94 }
95
96 header('Content-Length: ' . $file_size);
97 header('Content-Type: ' . $mime_type);
98 if(!jyraphe_is_viewable($mime_type)) {
99 header('Content-Disposition: attachment; filename="' . $file_name . '"');
100 }
101 readfile(VAR_FILES . $file_name);
102
103 if($link_name[0] == 'O') {
104 unlink($link_file);
105 $new_name = jyraphe_detect_collision($file_name, VAR_TRASH);
106 rename(VAR_FILES . $file_name, VAR_TRASH . $new_name);
107 }
108 exit;
109 } else {
110 header("HTTP/1.0 404 Not Found");
111
112 require(JYRAPHE_ROOT . 'lib/template/header.php');
113 echo '<div class="error"><p>Error 404: Not Found</p></div>';
114 require(JYRAPHE_ROOT . 'lib/template/footer.php');
115 exit;
116 }
117 } else {
118 header('Location: ' . $cfg['web_root']);
119 exit;
120 }
121
122 ?>

patrick-canterino.de