]> git.p6c8.net - jirafeau.git/blob - index.php
[FEATURE] Readme: Add link to contribution file
[jirafeau.git] / index.php
1 <?php
2 /*
3 * Jirafeau, your web file repository
4 * Copyright (C) 2013
5 * Jerome Jutteau <j.jutteau@gmail.com>
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 define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/');
22
23 require (JIRAFEAU_ROOT . 'lib/config.original.php');
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 {
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 if (!jirafeau_challenge_upload_ip ($cfg, get_ip_address($cfg)))
40 {
41 echo '<div class="error"><p>' . t('Access denied') . '</p></div>';
42 require (JIRAFEAU_ROOT.'lib/template/footer.php');
43 exit;
44 }
45
46 /* Ask password if upload password is set. */
47 if (jirafeau_has_upload_password ($cfg))
48 {
49 session_start();
50
51 /* Unlog if asked. */
52 if (isset ($_POST['action']) && (strcmp ($_POST['action'], 'logout') == 0))
53 session_unset ();
54
55 /* Auth. */
56 if (isset ($_POST['upload_password']))
57 {
58 if (jirafeau_challenge_upload_password ($cfg, $_POST['upload_password']))
59 {
60 $_SESSION['upload_auth'] = true;
61 $_SESSION['user_upload_password'] = $_POST['upload_password'];
62 }
63 else
64 {
65 $_SESSION['admin_auth'] = false;
66 echo '<div class="error"><p>' . t('Wrong password.') . '</p></div>';
67 require (JIRAFEAU_ROOT.'lib/template/footer.php');
68 exit;
69 }
70 }
71
72 /* Show auth page. */
73 if (!isset ($_SESSION['upload_auth']) || $_SESSION['upload_auth'] != true)
74 {
75 ?>
76 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
77 <fieldset>
78 <table>
79 <tr>
80 <td class = "label"><label for = "enter_password">
81 <?php echo t('Upload password') . ':';?></label>
82 </td>
83 <td class = "field"><input type = "password"
84 name = "upload_password" id = "upload_password"
85 size = "40" />
86 </td>
87 </tr>
88 <tr class = "nav">
89 <td></td>
90 <td class = "nav next">
91 <input type = "submit" name = "key" value =
92 "<?php echo t('Login'); ?>" />
93 </td>
94 </tr>
95 </table>
96 </fieldset>
97 </form>
98 <?php
99 require (JIRAFEAU_ROOT.'lib/template/footer.php');
100 exit;
101 }
102 }
103
104 ?>
105 <div id="upload_finished">
106 <p><?php echo t('File uploaded !') ?></p>
107
108 <div id="upload_finished_download_page">
109 <p>
110 <?php echo t('Download page') ?>
111 <a id="upload_link_email" href=""><img id="upload_image_email"/></a>
112 </p>
113 <p><a id="upload_link" href=""></a></p>
114 </div>
115
116 <?php if ($cfg['preview'] == true) { ?>
117 <div id="upload_finished_preview">
118 <p><?php echo t('View link') ?>:</p>
119 <p><a id="preview_link" href=""></a></p>
120 </div>
121 <?php } ?>
122
123 <div id="upload_direct_download">
124 <p><?php echo t('Direct download link') ?>:</p>
125 <p><a id="direct_link" href=""></a></p>
126 </div>
127
128 <div>
129 <p><?php echo t('Delete link') ?>:</p>
130 <p><a id="delete_link" href=""></a></p>
131 </div>
132
133 <div id="validity">
134 <p><?php echo t('This file is valid until the following date'); ?>:</p>
135 <p id="date"></p>
136 </div>
137 </div>
138
139 <div id="uploading">
140 <p>
141 <?php echo t ('Uploading ...'); ?>
142 <div id="uploaded_percentage"></div>
143 <div id="uploaded_speed"></div>
144 <div id="uploaded_time"></div>
145 </p>
146 </div>
147
148 <div id="error_pop" class="error">
149 </div>
150
151 <div id="upload">
152 <fieldset>
153 <legend>
154 <?php echo t('Select a file'); ?>
155 </legend>
156 <p>
157 <input type="file" id="file_select" size="30"
158 onchange="control_selected_file_size(<?php echo $cfg['maximal_upload_size'] ?>, '<?php echo t ('File is too big') . ', ' . t ('File size is limited to') . " " . $cfg['maximal_upload_size'] . " MB"; ?>')"/>
159 </p>
160
161 <div id="options">
162 <table id="option_table">
163 <tr>
164 <td><?php echo t('One time download'); ?>:</td>
165 <td><input type="checkbox" id="one_time_download" /></td>
166 </tr>
167 <tr>
168 <td><label for="input_key"><?php echo t('Password') . ':'; ?></label></td>
169 <td><input type="text" name="key" id="input_key" /></td>
170 </tr>
171 <tr>
172 <td><label for="select_time"><?php echo t('Time limit') . ':'; ?></label></td>
173 <td><select name="time" id="select_time">
174 <?php
175 $expirationTimeOptions = array(
176 array(
177 'value' => 'minute',
178 'label' => 'One minute'
179 ),
180 array(
181 'value' => 'hour',
182 'label' => 'One hour'
183 ),
184 array(
185 'value' => 'day',
186 'label' => 'One day'
187 ),
188 array(
189 'value' => 'week',
190 'label' => 'One week'
191 ),
192 array(
193 'value' => 'month',
194 'label' => 'One month'
195 ),
196 array(
197 'value' => 'quarter',
198 'label' => 'One quarter'
199 ),
200 array(
201 'value' => 'year',
202 'label' => 'One year'
203 ),
204 array(
205 'value' => 'none',
206 'label' => 'None'
207 )
208 );
209 foreach ($expirationTimeOptions as $expirationTimeOption) {
210 $selected = ($expirationTimeOption['value'] === $cfg['availability_default'])? 'selected="selected"' : '';
211 if(true === $cfg['availabilities'][$expirationTimeOption['value']]) {
212 echo '<option value="' . $expirationTimeOption['value'] . '" ' .
213 $selected . '>' . t($expirationTimeOption['label']) . '</option>';
214 }
215 }
216 ?>
217 </select></td>
218 </tr>
219
220 <?php
221 if ($cfg['maximal_upload_size'] > 0)
222 {
223 echo '<p class="config">' . t ('File size is limited to');
224 echo " " . $cfg['maximal_upload_size'] . " MB</p>";
225 }
226 ?>
227
228 <p id="max_file_size" class="config"></p>
229 <p>
230 <?php
231 if (jirafeau_has_upload_password ($cfg) && $_SESSION['upload_auth'])
232 {
233 ?>
234 <input type="hidden" id="upload_password" name="upload_password" value="<?php echo $_SESSION['user_upload_password'] ?>"/>
235 <?php
236 }
237 else
238 {
239 ?>
240 <input type="hidden" id="upload_password" name="upload_password" value=""/>
241 <?php
242 }
243 ?>
244 <input type="submit" id="send" value="<?php echo t('Send'); ?>"
245 onclick="
246 document.getElementById('upload').style.display = 'none';
247 document.getElementById('uploading').style.display = '';
248 upload ('<?php echo $cfg['web_root']; ?>', <?php echo jirafeau_get_max_upload_size_bytes (); ?>);
249 "/>
250 </p>
251 </table>
252 </div> </fieldset>
253
254 <?php
255 if (jirafeau_has_upload_password ($cfg))
256 {
257 ?>
258 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
259 <input type = "hidden" name = "action" value = "logout"/>
260 <input type = "submit" value = "<?php echo t('Logout'); ?>" />
261 </form>
262 <?php
263 }
264 ?>
265
266 </div>
267
268 <script type="text/javascript" lang="Javascript">
269 document.getElementById('error_pop').style.display = 'none';
270 document.getElementById('uploading').style.display = 'none';
271 document.getElementById('upload_finished').style.display = 'none';
272 document.getElementById('options').style.display = 'none';
273 document.getElementById('send').style.display = 'none';
274 if (!check_html5_file_api ())
275 document.getElementById('max_file_size').innerHTML = '<?php
276 echo t('You browser may not support HTML5 so the maximum file size is ') . jirafeau_get_max_upload_size ();
277 ?>';
278 </script>
279 <?php require (JIRAFEAU_ROOT . 'lib/template/footer.php'); ?>

patrick-canterino.de