]> git.p6c8.net - jirafeau_project.git/blob - index.php
Updated CHANGELOG
[jirafeau_project.git] / index.php
1 <?php
2 /*
3 * Jirafeau, your web file repository
4 * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
5 * Copyright (C) 2015 Jerome Jutteau <jerome@jutteau.fr>
6 * Copyright (C) 2024 Jirafeau project <https://gitlab.com/jirafeau> (see AUTHORS.md)
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
105 <?php jirafeau_create_upload_finished_box($cfg['preview']); ?>
106
107 <div id="uploading">
108 <p>
109 <?php echo t('UP'); ?>
110 <div id="uploaded_percentage"></div>
111 <div id="uploaded_speed"></div>
112 <div id="uploaded_time"></div>
113 </p>
114 </div>
115
116 <div id="error_pop" class="error">
117 </div>
118
119 <div id="upload">
120 <form id="upload-form" onsubmit="
121 event.preventDefault();
122 document.getElementById('upload').style.display = 'none';
123 document.getElementById('uploading').style.display = '';
124 upload (<?php echo jirafeau_get_max_upload_chunk_size_bytes($cfg['max_upload_chunk_size_bytes']); ?>);
125 "><fieldset>
126 <legend>
127 <?php echo t('SEL_FILE'); ?>
128 </legend>
129 <p>
130 <input type="file" id="file_select" size="30"
131 onchange="control_selected_file_size(<?php echo $cfg['maximal_upload_size'] ?>, '<?php
132 if ($cfg['maximal_upload_size'] >= 1024) {
133 echo t('2_BIG') . ', ' . t('FILE_LIM') . " " . number_format($cfg['maximal_upload_size'] / 1024, 2) . " GB.";
134 } elseif ($cfg['maximal_upload_size'] > 0) {
135 echo t('2_BIG') . ', ' . t('FILE_LIM') . " " . $cfg['maximal_upload_size'] . " MB.";
136 }
137 ?>')"/>
138 </p>
139
140 <div id="options">
141 <table id="option_table">
142 <?php
143 if ($cfg['one_time_download']) {
144 echo '<tr><td>' . t('ONE_TIME_DL') . ':</td>';
145 echo '<td><input type="checkbox" id="one_time_download"';
146
147 if ($cfg['one_time_download_preselected']) {
148 echo ' checked';
149 }
150
151 echo ' /></td></tr>';
152 }
153 if ($cfg['download_password_requirement'] === 'generated') {
154 echo '<input type="hidden" name="key" id="input_key" value="' . $download_pass .'"/>';
155 } else {
156 echo '<tr><td><label for="input_key">' . t('PSW') . ':' . '</label></td>';
157 echo '<td><input type="password" name="key" id="input_key" autocomplete = "new-password"';
158 if ($cfg['download_password_policy'] === 'regex') {
159 echo ' pattern="' . substr($cfg['download_password_policy_regex'], 1, strlen($cfg['download_password_policy_regex']) - 2) . '"'; //remove php delimiters
160 }
161 if ($cfg['download_password_requirement'] === 'required') {
162 echo ' required';
163 }
164 echo '/></td></tr>';
165 }?>
166 <tr>
167 <td><label for="select_time"><?php echo t('TIME_LIM') . ':'; ?></label></td>
168 <td>
169 <?php jirafeau_create_selection_array($cfg); ?>
170 </td>
171 </tr>
172
173 <?php
174 if ($cfg['maximal_upload_size'] >= 1024) {
175 echo '<p class="config">' . t('FILE_LIM');
176 echo " " . number_format($cfg['maximal_upload_size'] / 1024, 2) . " GB.</p>";
177 } elseif ($cfg['maximal_upload_size'] > 0) {
178 echo '<p class="config">' . t('FILE_LIM');
179 echo " " . $cfg['maximal_upload_size'] . " MB.</p>";
180 } else {
181 echo '<p class="config"></p>';
182 }
183 ?>
184
185 <p id="max_file_size" class="config"></p>
186 <p>
187 <input type="submit" id="send" value="<?php echo t('SEND'); ?>"/>
188 </p>
189 </table>
190 </div> </fieldset></form>
191
192 <?php
193 if (jirafeau_user_session_logged() && $_SESSION['user_auth_type'] == JIRAFEAU_USER_AUTH_BY_PASSWORD) {
194 ?>
195 <form method="post" class="form logout">
196 <input type = "hidden" name = "action" value = "logout"/>
197 <input type = "submit" value = "<?php echo t('LOGOUT'); ?>" />
198 </form>
199 <?php
200 }
201 ?>
202
203 </div>
204
205 <script type="text/javascript" lang="Javascript">
206 // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
207 document.getElementById('error_pop').style.display = 'none';
208 document.getElementById('uploading').style.display = 'none';
209 document.getElementById('upload_finished').style.display = 'none';
210 document.getElementById('options').style.display = 'none';
211 document.getElementById('send').style.display = 'none';
212 if (!check_html5_file_api ())
213 document.getElementById('max_file_size').innerHTML = '<?php
214 $max_size = jirafeau_get_max_upload_size();
215 if ($max_size > 0) {
216 echo t('NO_BROWSER_SUPPORT') . $max_size;
217 }
218 ?>';
219
220 addCopyListener('upload_link_button', 'upload_link');
221 addCopyListener('preview_link_button', 'preview_link');
222 addCopyListener('direct_link_button', 'direct_link');
223 addCopyListener('delete_link_button', 'delete_link');
224 addTextCopyListener('password_copy_button', 'output_key');
225 // @license-end
226 </script>
227 <?php require(JIRAFEAU_ROOT . 'lib/template/footer.php'); ?>

patrick-canterino.de