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

patrick-canterino.de