]> git.p6c8.net - jirafeau_project.git/blob - index.php
b8feabdc7c63e17f263b19db8fd4022844b8c2d8
[jirafeau_project.git] / index.php
1 <?php
2 /*
3 * Jirafeau, your web file repository
4 * Copyright (C) 2013
5 * Jerome Jutteau <j.jutteau@gmail.com>
6 * Jimmy Beauvois <jimmy.beauvois@gmail.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21 define('JIRAFEAU_ROOT', dirname(__FILE__) . '/');
22
23 require(JIRAFEAU_ROOT . 'lib/settings.php');
24 require(JIRAFEAU_ROOT . 'lib/functions.php');
25 require(JIRAFEAU_ROOT . 'lib/lang.php');
26
27 check_errors($cfg);
28 if (has_error()) {
29 show_errors();
30 require(JIRAFEAU_ROOT . 'lib/template/footer.php');
31 exit;
32 }
33
34 require(JIRAFEAU_ROOT . 'lib/template/header.php');
35
36 /* Check if user is allowed to upload. */
37 if (!jirafeau_challenge_upload_ip($cfg, get_ip_address($cfg))) {
38 echo '<div class="error"><p>' . t('Access denied') . '</p></div>';
39 require(JIRAFEAU_ROOT.'lib/template/footer.php');
40 exit;
41 }
42
43 /* Ask password if upload password is set. */
44 if (jirafeau_has_upload_password($cfg)) {
45 session_start();
46
47 /* Unlog if asked. */
48 if (isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
49 session_unset();
50 }
51
52 /* Auth. */
53 if (isset($_POST['upload_password'])) {
54 if (jirafeau_challenge_upload_password($cfg, $_POST['upload_password'])) {
55 $_SESSION['upload_auth'] = true;
56 $_SESSION['user_upload_password'] = $_POST['upload_password'];
57 } else {
58 $_SESSION['admin_auth'] = false;
59 echo '<div class="error"><p>' . t('Wrong password.') . '</p></div>';
60 require(JIRAFEAU_ROOT.'lib/template/footer.php');
61 exit;
62 }
63 }
64
65 /* Show auth page. */
66 if (!isset($_SESSION['upload_auth']) || $_SESSION['upload_auth'] != true) {
67 ?>
68 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
69 <fieldset>
70 <table>
71 <tr>
72 <td class = "label"><label for = "enter_password">
73 <?php echo t('Upload password') . ':'; ?></label>
74 </td>
75 <td class = "field"><input type = "password"
76 name = "upload_password" id = "upload_password"
77 size = "40" />
78 </td>
79 </tr>
80 <tr class = "nav">
81 <td></td>
82 <td class = "nav next">
83 <input type = "submit" name = "key" value =
84 "<?php echo t('Login'); ?>" />
85 </td>
86 </tr>
87 </table>
88 </fieldset>
89 </form>
90 <?php
91 require(JIRAFEAU_ROOT.'lib/template/footer.php');
92 exit;
93 }
94 }
95
96 ?>
97 <div id="upload_finished">
98 <p><?php echo t('File uploaded !') ?></p>
99
100 <div id="upload_finished_download_page">
101 <p>
102 <?php echo t('Download page') ?>
103 <a id="upload_link_email" href=""><img id="upload_image_email"/></a>
104 </p>
105 <p><a id="upload_link" href=""></a></p>
106 </div>
107
108 <?php if ($cfg['preview'] == true) {
109 ?>
110 <div id="upload_finished_preview">
111 <p><?php echo t('View link') ?>:</p>
112 <p><a id="preview_link" href=""></a></p>
113 </div>
114 <?php
115 } ?>
116
117 <div id="upload_direct_download">
118 <p><?php echo t('Direct download link') ?>:</p>
119 <p><a id="direct_link" href=""></a></p>
120 </div>
121
122 <div>
123 <p><?php echo t('Delete link') ?>:</p>
124 <p><a id="delete_link" href=""></a></p>
125 </div>
126
127 <div id="validity">
128 <p><?php echo t('This file is valid until the following date'); ?>:</p>
129 <p id="date"></p>
130 </div>
131 </div>
132
133 <div id="uploading">
134 <p>
135 <?php echo t('Uploading ...'); ?>
136 <div id="uploaded_percentage"></div>
137 <div id="uploaded_speed"></div>
138 <div id="uploaded_time"></div>
139 </p>
140 </div>
141
142 <div id="error_pop" class="error">
143 </div>
144
145 <div id="upload">
146 <fieldset>
147 <legend>
148 <?php echo t('Select a file'); ?>
149 </legend>
150 <p>
151 <input type="file" id="file_select" size="30"
152 onchange="control_selected_file_size(<?php echo $cfg['maximal_upload_size'] ?>, '<?php echo t('File is too big') . ', ' . t('File size is limited to') . " " . $cfg['maximal_upload_size'] . " MB"; ?>')"/>
153 </p>
154
155 <div id="options">
156 <table id="option_table">
157 <tr>
158 <td><?php echo t('One time download'); ?>:</td>
159 <td><input type="checkbox" id="one_time_download" /></td>
160 </tr>
161 <tr>
162 <td><label for="input_key"><?php echo t('Password') . ':'; ?></label></td>
163 <td><input type="text" name="key" id="input_key" /></td>
164 </tr>
165 <tr>
166 <td><label for="select_time"><?php echo t('Time limit') . ':'; ?></label></td>
167 <td><select name="time" id="select_time">
168 <?php
169 $expirationTimeOptions = array(
170 array(
171 'value' => 'minute',
172 'label' => 'One minute'
173 ),
174 array(
175 'value' => 'hour',
176 'label' => 'One hour'
177 ),
178 array(
179 'value' => 'day',
180 'label' => 'One day'
181 ),
182 array(
183 'value' => 'week',
184 'label' => 'One week'
185 ),
186 array(
187 'value' => 'month',
188 'label' => 'One month'
189 ),
190 array(
191 'value' => 'quarter',
192 'label' => 'One quarter'
193 ),
194 array(
195 'value' => 'year',
196 'label' => 'One year'
197 ),
198 array(
199 'value' => 'none',
200 'label' => 'None'
201 )
202 );
203 foreach ($expirationTimeOptions as $expirationTimeOption) {
204 $selected = ($expirationTimeOption['value'] === $cfg['availability_default'])? 'selected="selected"' : '';
205 if (true === $cfg['availabilities'][$expirationTimeOption['value']]) {
206 echo '<option value="' . $expirationTimeOption['value'] . '" ' .
207 $selected . '>' . t($expirationTimeOption['label']) . '</option>';
208 }
209 }
210 ?>
211 </select></td>
212 </tr>
213
214 <?php
215 if ($cfg['maximal_upload_size'] > 0) {
216 echo '<p class="config">' . t('File size is limited to');
217 echo " " . $cfg['maximal_upload_size'] . " MB</p>";
218 }
219 ?>
220
221 <p id="max_file_size" class="config"></p>
222 <p>
223 <?php
224 if (jirafeau_has_upload_password($cfg) && $_SESSION['upload_auth']) {
225 ?>
226 <input type="hidden" id="upload_password" name="upload_password" value="<?php echo $_SESSION['user_upload_password'] ?>"/>
227 <?php
228
229 } else {
230 ?>
231 <input type="hidden" id="upload_password" name="upload_password" value=""/>
232 <?php
233
234 }
235 ?>
236 <input type="submit" id="send" value="<?php echo t('Send'); ?>"
237 onclick="
238 document.getElementById('upload').style.display = 'none';
239 document.getElementById('uploading').style.display = '';
240 upload ('<?php echo $cfg['web_root']; ?>', <?php echo jirafeau_get_max_upload_size_bytes(); ?>);
241 "/>
242 </p>
243 </table>
244 </div> </fieldset>
245
246 <?php
247 if (jirafeau_has_upload_password($cfg)) {
248 ?>
249 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
250 <input type = "hidden" name = "action" value = "logout"/>
251 <input type = "submit" value = "<?php echo t('Logout'); ?>" />
252 </form>
253 <?php
254
255 }
256 ?>
257
258 </div>
259
260 <script type="text/javascript" lang="Javascript">
261 document.getElementById('error_pop').style.display = 'none';
262 document.getElementById('uploading').style.display = 'none';
263 document.getElementById('upload_finished').style.display = 'none';
264 document.getElementById('options').style.display = 'none';
265 document.getElementById('send').style.display = 'none';
266 if (!check_html5_file_api ())
267 document.getElementById('max_file_size').innerHTML = '<?php
268 echo t('You browser may not support HTML5 so the maximum file size is ') . jirafeau_get_max_upload_size();
269 ?>';
270 </script>
271 <?php require(JIRAFEAU_ROOT . 'lib/template/footer.php'); ?>

patrick-canterino.de