]> git.p6c8.net - jirafeau_project.git/blob - index.php
Security fix, bug fix and project name change.
[jirafeau_project.git] / index.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 define('DEBUG', true);
23
24 require(JIRAFEAU_ROOT . 'lib/config.php');
25 require(JIRAFEAU_ROOT . 'lib/settings.php');
26 require(JIRAFEAU_ROOT . 'lib/functions.php');
27
28 /* check if the destination dirs are writable */
29 $writable = is_writable(VAR_FILES) && is_writable(VAR_LINKS) && is_writable(VAR_TRASH);
30
31 $res = array();
32 if($writable && isset($_POST['jirafeau'])) {
33
34 $key = $_POST['key'];
35
36 $time = time();
37 switch($_POST['time']) {
38 case 'minute':
39 $time += JIRAFEAU_MINUTE;
40 break;
41 case 'hour':
42 $time += JIRAFEAU_HOUR;
43 break;
44 case 'day':
45 $time += JIRAFEAU_DAY;
46 break;
47 case 'week':
48 $time += JIRAFEAU_WEEK;
49 break;
50 case 'month':
51 $time += JIRAFEAU_MONTH;
52 break;
53 default:
54 $time = JIRAFEAU_INFINITY;
55 break;
56 }
57
58 $res = jirafeau_upload($_FILES['file'], isset($_POST['one_time_download']), $key, $time, $cfg);
59 }
60
61 require(JIRAFEAU_ROOT . 'lib/template/header.php');
62
63 /* Checking for errors. */
64 if(!is_writable(VAR_FILES)) {
65 add_error (_('The file directory is not writable!'), VAR_FILES);
66 }
67
68 if(!is_writable(VAR_LINKS)) {
69 add_error (_('The link directory is not writable!'), VAR_LINKS);
70 }
71
72 if(!is_writable(VAR_TRASH)) {
73 add_error (_('The trash directory is not writable!'), VAR_TRASH);
74 }
75
76 /* Check if the install.php script is still in the directory. */
77 if (file_exists(JIRAFEAU_ROOT . 'install.php')) {
78 add_error (_('Installer script still present'),
79 _('Please make sure to delete the installer script "install.php" before continuing.'));
80 }
81
82 if(!has_error() && !empty($res)) {
83 if($res['error']['has_error']) {
84 add_error (_('An error occurred.'), $res['error']['why']);
85 } else {
86 $link = $cfg['web_root'];
87 if($cfg['rewrite']) {
88 $link .= 'file-' . $res['link'];
89 } else {
90 $link .= 'file.php?h=' . $res['link']; // h because 'h' looks like a jirafeau ;)
91 }
92 echo '<div class="message">' . NL;
93 echo '<p>' . _('File uploaded! Copy the following URL to get it:') . '<br />' . NL;
94 echo '<a href="' . $link . '">' . $link . '</a>' . NL;
95
96 if($time != JIRAFEAU_INFINITY) {
97 echo '<br />' . _('This file is valid until the following date:') . '<br /><strong>' . strftime('%c' ,$time) . '</strong>';
98 }
99
100 echo '</p></div>';
101 }
102 }
103
104 if(has_error ()) {
105 show_errors ();
106 }
107
108 if(!has_error () && $writable) {
109 ?>
110
111 <div id="upload">
112 <form enctype="multipart/form-data" action="<?php echo $cfg['web_root']; ?>" method="post">
113 <div><input type="hidden" name="jirafeau" value="<?php echo JIRAFEAU_VERSION; ?>" /></div>
114 <fieldset>
115 <legend><?php echo _('Upload a file'); ?></legend>
116 <p><input type="file" name="file" size="30" /></p>
117 <p class="config"><?php printf(_('Maximum file size: %dMB'), jirafeau_get_max_upload_size()/(1024*1024)); ?></p>
118 <p><input type="submit" value="<?php echo _('Send in the binary chaos'); ?>" /></p>
119
120 <hr />
121
122 <div id="moreoptions">
123 <p><label><input type="checkbox" name="one_time_download" /> <?php echo _('One time download'); ?></label></p>
124 <p><label for="input_key"><?php echo _('File key:'); ?></label> <input type="text" name="key" id="input_key" /></p>
125 <p><label for="select_time"><?php echo _('Time limit:'); ?></label>
126 <select name="time" id="select_time">
127 <option value="none"><?php echo _('None'); ?></option>
128 <option value="minute"><?php echo _('One minute'); ?></option>
129 <option value="hour"><?php echo _('One hour'); ?></option>
130 <option value="day"><?php echo _('One day'); ?></option>
131 <option value="week"><?php echo _('One week'); ?></option>
132 <option value="month"><?php echo _('One month'); ?></option>
133 </select>
134 </p>
135 </div>
136 </fieldset>
137 </form>
138 </div>
139
140 <?php
141 }
142
143 require(JIRAFEAU_ROOT . 'lib/template/footer.php');
144 ?>

patrick-canterino.de