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

patrick-canterino.de