]> git.p6c8.net - jirafeau_project.git/blob - index.php
New config option to preselect the checkbox for deleting the file after the first...
[jirafeau_project.git] / index.php
1 <?php
2 /*
3 * Jirafeau, your web file repository
4 * Copyright (C) 2013
5 * Jerome Jutteau <jerome@jutteau.fr>
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 session_start();
22 define('JIRAFEAU_ROOT', dirname(__FILE__) . '/');
23
24 require(JIRAFEAU_ROOT . 'lib/settings.php');
25 require(JIRAFEAU_ROOT . 'lib/functions.php');
26 require(JIRAFEAU_ROOT . 'lib/lang.php');
27
28 if ($cfg['download_password_requirement'] === "generated"){
29 $download_pass = jirafeau_gen_download_pass($cfg['download_password_gen_len'], $cfg['download_password_gen_chars']);
30 }
31
32 check_errors($cfg);
33 if (has_error()) {
34 require(JIRAFEAU_ROOT . 'lib/template/header.php');
35 show_errors();
36 require(JIRAFEAU_ROOT . 'lib/template/footer.php');
37 exit;
38 }
39 require(JIRAFEAU_ROOT . 'lib/template/header.php');
40
41 // Logout action
42 if (isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
43 jirafeau_session_end();
44 }
45
46 /* Check if user is allowed to upload. */
47 // First check: Is user already logged
48 if (jirafeau_user_session_logged()) {
49 }
50 // Second check: Challenge by IP NO PASSWORD
51 elseif (true === jirafeau_challenge_upload_ip_without_password($cfg, get_ip_address($cfg))) {
52 jirafeau_user_session_start();
53 $_SESSION['user_auth_type'] = JIRAFEAU_USER_AUTH_BY_IP_NO_PASSWORD;
54 }
55 // Third check: Challenge by IP
56 elseif (true === jirafeau_challenge_upload_ip($cfg, get_ip_address($cfg))) {
57 // Is an upload password required?
58 if (jirafeau_has_upload_password($cfg)) {
59 // Challenge by password
60 if (isset($_POST['upload_password'])) {
61 if (jirafeau_challenge_upload_password($cfg, $_POST['upload_password'])) {
62 jirafeau_user_session_start();
63 $_SESSION['user_auth_type'] = JIRAFEAU_USER_AUTH_BY_PASSWORD;
64 } else {
65 jirafeau_session_end();
66 jirafeau_fatal_error(t('BAD_PSW'), $cfg);
67 }
68 }
69
70 // Show login form if user session is not authorized yet
71 if (!jirafeau_user_session_logged()) {
72 ?>
73 <form method="post" class="form login">
74 <fieldset>
75 <table>
76 <tr>
77 <td class = "label"><label for = "enter_password">
78 <?php echo t('UP_PSW') . ':'; ?></label>
79 </td>
80 </tr><tr>
81 <td class = "field"><input type = "password"
82 name = "upload_password" id = "upload_password"
83 size = "40" autocomplete = "current-password" />
84 </td>
85 </tr>
86 <tr class = "nav">
87 <td class = "nav next">
88 <input type = "submit" name = "key" value = "<?php echo t('LOGIN'); ?>" />
89 </td>
90 </tr>
91 </table>
92 </fieldset>
93 </form>
94 <?php
95 require(JIRAFEAU_ROOT.'lib/template/footer.php');
96 exit;
97 }
98 }
99 } else {
100 jirafeau_fatal_error(t('ACCESS_KO'), $cfg);
101 }
102
103 ?>
104 <div id="upload_finished">
105 <p><?php echo t('FILE_UP') ?></p>
106
107 <div id="upload_finished_download_page">
108 <p>
109 <a id="upload_link" href=""><?php echo t('DL_PAGE') ?></a>
110 <a id="upload_link_email" href=""><img id="upload_image_email"/></a>
111 </p><p>
112 <code id=upload_link_text></code>
113 <button id="upload_link_button">&#128203;</button>
114 </p>
115 </div>
116
117 <?php if ($cfg['download_password_requirement'] === "generated"){
118 ?>
119 <div id="show_password">
120 <p><?php echo t('PSW') ?></p>
121
122 <div id="download_password">
123 <p>
124 <?php echo '<input id="output_key" value="' . $download_pass . '"/>'?>
125 <button id="password_copy_button">&#128203;</button>
126 </p>
127 </div>
128 </div>
129 <?php
130 }?>
131
132 <?php if ($cfg['preview'] == true) {
133 ?>
134 <div id="upload_finished_preview">
135 <p>
136 <a id="preview_link" href=""><?php echo t('VIEW_LINK') ?></a>
137 </p><p>
138 <code id=preview_link_text></code>
139 <button id="preview_link_button">&#128203;</button>
140 </p>
141 </div>
142 <?php
143 } ?>
144
145 <div id="upload_direct_download">
146 <p>
147 <a id="direct_link" href=""><?php echo t('DIRECT_DL') ?></a>
148 </p><p>
149 <code id=direct_link_text></code>
150 <button id="direct_link_button">&#128203;</button>
151 </p>
152 </div>
153
154 <div id="upload_delete">
155 <p>
156 <a id="delete_link" href=""><?php echo t('DELETE_LINK') ?></a>
157 </p><p>
158 <code id=delete_link_text></code>
159 <button id="delete_link_button">&#128203;</button>
160 </p>
161 </div>
162
163 <div id="upload_validity">
164 <p><?php echo t('VALID_UNTIL'); ?>:</p>
165 <p id="date"></p>
166 </div>
167 </div>
168
169 <div id="uploading">
170 <p>
171 <?php echo t('UP'); ?>
172 <div id="uploaded_percentage"></div>
173 <div id="uploaded_speed"></div>
174 <div id="uploaded_time"></div>
175 </p>
176 </div>
177
178 <div id="error_pop" class="error">
179 </div>
180
181 <div id="upload">
182 <form id="upload-form" onsubmit="
183 event.preventDefault();
184 document.getElementById('upload').style.display = 'none';
185 document.getElementById('uploading').style.display = '';
186 upload (<?php echo jirafeau_get_max_upload_chunk_size_bytes($cfg['max_upload_chunk_size_bytes']); ?>);
187 "><fieldset>
188 <legend>
189 <?php echo t('SEL_FILE'); ?>
190 </legend>
191 <p>
192 <input type="file" id="file_select" size="30"
193 onchange="control_selected_file_size(<?php echo $cfg['maximal_upload_size'] ?>, '<?php
194 if ($cfg['maximal_upload_size'] >= 1024) {
195 echo t('2_BIG') . ', ' . t('FILE_LIM') . " " . number_format($cfg['maximal_upload_size']/1024, 2) . " GB.";
196 } elseif ($cfg['maximal_upload_size'] > 0) {
197 echo t('2_BIG') . ', ' . t('FILE_LIM') . " " . $cfg['maximal_upload_size'] . " MB.";
198 }
199 ?>')"/>
200 </p>
201
202 <div id="options">
203 <table id="option_table">
204 <?php
205 if ($cfg['one_time_download']) {
206 echo '<tr><td>' . t('ONE_TIME_DL') . ':</td>';
207 echo '<td><input type="checkbox" id="one_time_download"';
208
209 if ($cfg['one_time_download_preselected']) {
210 echo ' checked';
211 }
212
213 echo ' /></td></tr>';
214 }
215 if ($cfg['download_password_requirement'] === 'generated'){
216 echo '<input type="hidden" name="key" id="input_key" value="' . $download_pass .'"/>';
217 }else{
218 echo '<tr><td><label for="input_key">' . t('PSW') . ':' . '</label></td>';
219 echo '<td><input type="password" name="key" id="input_key" autocomplete = "new-password"';
220 if ($cfg['download_password_policy'] === 'regex'){
221 echo ' pattern="' . substr($cfg['download_password_policy_regex'], 1, strlen($cfg['download_password_policy_regex']) - 2) . '"'; //remove php delimiters
222 }
223 if ($cfg['download_password_requirement'] === 'required'){
224 echo ' required';
225 }
226 echo '/></td></tr>';
227 }?>
228 <tr>
229 <td><label for="select_time"><?php echo t('TIME_LIM') . ':'; ?></label></td>
230 <td><select name="time" id="select_time">
231 <?php
232 $expirationTimeOptions = array(
233 array(
234 'value' => 'minute',
235 'label' => '1_MIN'
236 ),
237 array(
238 'value' => 'hour',
239 'label' => '1_H'
240 ),
241 array(
242 'value' => 'day',
243 'label' => '1_D'
244 ),
245 array(
246 'value' => 'week',
247 'label' => '1_W'
248 ),
249 array(
250 'value' => 'fortnight',
251 'label' => '2_W'
252 ),
253 array(
254 'value' => 'month',
255 'label' => '1_M'
256 ),
257 array(
258 'value' => 'quarter',
259 'label' => '1_Q'
260 ),
261 array(
262 'value' => 'year',
263 'label' => '1_Y'
264 ),
265 array(
266 'value' => 'none',
267 'label' => 'NONE'
268 )
269 );
270 foreach ($expirationTimeOptions as $expirationTimeOption) {
271 $selected = ($expirationTimeOption['value'] === $cfg['availability_default'])? 'selected="selected"' : '';
272 if (true === $cfg['availabilities'][$expirationTimeOption['value']]) {
273 echo '<option value="' . $expirationTimeOption['value'] . '" ' .
274 $selected . '>' . t($expirationTimeOption['label']) . '</option>';
275 }
276 }
277 ?>
278 </select></td>
279 </tr>
280
281 <?php
282 if ($cfg['maximal_upload_size'] >= 1024) {
283 echo '<p class="config">' . t('FILE_LIM');
284 echo " " . number_format($cfg['maximal_upload_size'] / 1024, 2) . " GB.</p>";
285 } elseif ($cfg['maximal_upload_size'] > 0) {
286 echo '<p class="config">' . t('FILE_LIM');
287 echo " " . $cfg['maximal_upload_size'] . " MB.</p>";
288 } else {
289 echo '<p class="config"></p>';
290 }
291 ?>
292
293 <p id="max_file_size" class="config"></p>
294 <p>
295 <input type="submit" id="send" value="<?php echo t('SEND'); ?>"/>
296 </p>
297 </table>
298 </div> </fieldset></form>
299
300 <?php
301 if (jirafeau_user_session_logged() && $_SESSION['user_auth_type'] == JIRAFEAU_USER_AUTH_BY_PASSWORD) {
302 ?>
303 <form method="post" class="form logout">
304 <input type = "hidden" name = "action" value = "logout"/>
305 <input type = "submit" value = "<?php echo t('LOGOUT'); ?>" />
306 </form>
307 <?php
308 }
309 ?>
310
311 </div>
312
313 <script type="text/javascript" lang="Javascript">
314 // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
315 document.getElementById('error_pop').style.display = 'none';
316 document.getElementById('uploading').style.display = 'none';
317 document.getElementById('upload_finished').style.display = 'none';
318 document.getElementById('options').style.display = 'none';
319 document.getElementById('send').style.display = 'none';
320 if (!check_html5_file_api ())
321 document.getElementById('max_file_size').innerHTML = '<?php
322 $max_size = jirafeau_get_max_upload_size();
323 if ($max_size > 0) {
324 echo t('NO_BROWSER_SUPPORT') . $max_size;
325 }
326 ?>';
327
328 addCopyListener('upload_link_button', 'upload_link');
329 addCopyListener('preview_link_button', 'preview_link');
330 addCopyListener('direct_link_button', 'direct_link');
331 addCopyListener('delete_link_button', 'delete_link');
332 addTextCopyListener('password_copy_button', 'output_key');
333 // @license-end
334 </script>
335 <?php require(JIRAFEAU_ROOT . 'lib/template/footer.php'); ?>

patrick-canterino.de