]> git.p6c8.net - jirafeau_project.git/blob - index.php
795c804a0d754ef50af380e6844bda7480ba2870
[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 // First check: Challenge by IP
38 if (true === jirafeau_challenge_upload_ip($cfg['upload_ip'], get_ip_address($cfg))) {
39 // Is an upload password required?
40 if (jirafeau_has_upload_password($cfg)) {
41 session_start();
42
43 // Logout action
44 if (isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
45 session_unset();
46 }
47
48 // Challenge by password
49 // …save successful logins in session
50 if (isset($_POST['upload_password'])) {
51 if (jirafeau_challenge_upload_password($cfg, $_POST['upload_password'])) {
52 $_SESSION['upload_auth'] = true;
53 $_SESSION['user_upload_password'] = $_POST['upload_password'];
54 } else {
55 $_SESSION['admin_auth'] = false;
56 jirafeau_fatal_error(t('Wrong password.'), $cfg);
57 }
58 }
59
60 // Show login form if user session is not authorized yet
61 if (true === empty($_SESSION['upload_auth'])) {
62 ?>
63 <form method="post" class="form login">
64 <fieldset>
65 <table>
66 <tr>
67 <td class = "label"><label for = "enter_password">
68 <?php echo t('Upload password') . ':'; ?></label>
69 </td>
70 </tr><tr>
71 <td class = "field"><input type = "password"
72 name = "upload_password" id = "upload_password"
73 size = "40" />
74 </td>
75 </tr>
76 <tr class = "nav">
77 <td class = "nav next">
78 <input type = "submit" name = "key" value =
79 "<?php echo t('Login'); ?>" />
80 </td>
81 </tr>
82 </table>
83 </fieldset>
84 </form>
85 <?php
86 require(JIRAFEAU_ROOT.'lib/template/footer.php');
87 exit;
88 }
89 }
90 }
91 else {
92 jirafeau_fatal_error(t('Access denied'), $cfg);
93 }
94
95 ?>
96 <div id="upload_finished">
97 <p><?php echo t('File uploaded !') ?></p>
98
99 <div id="upload_finished_download_page">
100 <p>
101 <a id="upload_link" href=""><?php echo t('Download page') ?></a>
102 <a id="upload_link_email" href=""><img id="upload_image_email"/></a>
103 <button id="upload_link_button"></button>
104 </p>
105 </div>
106
107 <?php if ($cfg['preview'] == true) {
108 ?>
109 <div id="upload_finished_preview">
110 <p>
111 <a id="preview_link" href=""><?php echo t('View link') ?></a>
112 <button id="preview_link_button"></button>
113 </p>
114 </div>
115 <?php
116 } ?>
117
118 <div id="upload_direct_download">
119 <p>
120 <a id="direct_link" href=""><?php echo t('Direct download link') ?></a>
121 <button id="direct_link_button"></button>
122 </p>
123 </div>
124
125 <div id="upload_delete">
126 <p>
127 <a id="delete_link" href=""><?php echo t('Delete link') ?></a>
128 <button id="delete_link_button"></button>
129 </p>
130 </div>
131
132 <div id="upload_validity">
133 <p><?php echo t('This file is valid until the following date'); ?>:</p>
134 <p id="date"></p>
135 </div>
136 </div>
137
138 <div id="uploading">
139 <p>
140 <?php echo t('Uploading ...'); ?>
141 <div id="uploaded_percentage"></div>
142 <div id="uploaded_speed"></div>
143 <div id="uploaded_time"></div>
144 </p>
145 </div>
146
147 <div id="error_pop" class="error">
148 </div>
149
150 <div id="upload">
151 <fieldset>
152 <legend>
153 <?php echo t('Select a file'); ?>
154 </legend>
155 <p>
156 <input type="file" id="file_select" size="30"
157 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"; ?>')"/>
158 </p>
159
160 <div id="options">
161 <table id="option_table">
162 <tr>
163 <td><?php echo t('One time download'); ?>:</td>
164 <td><input type="checkbox" id="one_time_download" /></td>
165 </tr>
166 <tr>
167 <td><label for="input_key"><?php echo t('Password') . ':'; ?></label></td>
168 <td><input type="text" name="key" id="input_key" /></td>
169 </tr>
170 <tr>
171 <td><label for="select_time"><?php echo t('Time limit') . ':'; ?></label></td>
172 <td><select name="time" id="select_time">
173 <?php
174 $expirationTimeOptions = array(
175 array(
176 'value' => 'minute',
177 'label' => 'One minute'
178 ),
179 array(
180 'value' => 'hour',
181 'label' => 'One hour'
182 ),
183 array(
184 'value' => 'day',
185 'label' => 'One day'
186 ),
187 array(
188 'value' => 'week',
189 'label' => 'One week'
190 ),
191 array(
192 'value' => 'month',
193 'label' => 'One month'
194 ),
195 array(
196 'value' => 'quarter',
197 'label' => 'One quarter'
198 ),
199 array(
200 'value' => 'year',
201 'label' => 'One year'
202 ),
203 array(
204 'value' => 'none',
205 'label' => 'None'
206 )
207 );
208 foreach ($expirationTimeOptions as $expirationTimeOption) {
209 $selected = ($expirationTimeOption['value'] === $cfg['availability_default'])? 'selected="selected"' : '';
210 if (true === $cfg['availabilities'][$expirationTimeOption['value']]) {
211 echo '<option value="' . $expirationTimeOption['value'] . '" ' .
212 $selected . '>' . t($expirationTimeOption['label']) . '</option>';
213 }
214 }
215 ?>
216 </select></td>
217 </tr>
218
219 <?php
220 if ($cfg['maximal_upload_size'] > 0) {
221 echo '<p class="config">' . t('File size is limited to');
222 echo " " . $cfg['maximal_upload_size'] . " MB</p>";
223 }
224 ?>
225
226 <p id="max_file_size" class="config"></p>
227 <p>
228 <?php
229 if (jirafeau_has_upload_password($cfg) && $_SESSION['upload_auth']) {
230 ?>
231 <input type="hidden" id="upload_password" name="upload_password" value="<?php echo $_SESSION['user_upload_password'] ?>"/>
232 <?php
233
234 } else {
235 ?>
236 <input type="hidden" id="upload_password" name="upload_password" value=""/>
237 <?php
238
239 }
240 ?>
241 <input type="submit" id="send" value="<?php echo t('Send'); ?>"
242 onclick="
243 document.getElementById('upload').style.display = 'none';
244 document.getElementById('uploading').style.display = '';
245 upload (<?php echo jirafeau_get_max_upload_size_bytes(); ?>);
246 "/>
247 </p>
248 </table>
249 </div> </fieldset>
250
251 <?php
252 if (jirafeau_has_upload_password($cfg)) {
253 ?>
254 <form method="post" class="form logout">
255 <input type = "hidden" name = "action" value = "logout"/>
256 <input type = "submit" value = "<?php echo t('Logout'); ?>" />
257 </form>
258 <?php
259
260 }
261 ?>
262
263 </div>
264
265 <script type="text/javascript" lang="Javascript">
266 document.getElementById('error_pop').style.display = 'none';
267 document.getElementById('uploading').style.display = 'none';
268 document.getElementById('upload_finished').style.display = 'none';
269 document.getElementById('options').style.display = 'none';
270 document.getElementById('send').style.display = 'none';
271 if (!check_html5_file_api ())
272 document.getElementById('max_file_size').innerHTML = '<?php
273 echo t('You browser may not support HTML5 so the maximum file size is ') . jirafeau_get_max_upload_size();
274 ?>';
275
276 addCopyListener('upload_link_button', 'upload_link');
277 addCopyListener('preview_link_button', 'preview_link');
278 addCopyListener('direct_link_button', 'direct_link');
279 addCopyListener('delete_link_button', 'delete_link');
280 </script>
281 <?php require(JIRAFEAU_ROOT . 'lib/template/footer.php'); ?>

patrick-canterino.de