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

patrick-canterino.de