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

patrick-canterino.de