]> git.p6c8.net - jirafeau_project.git/blob - index.php
Closes #6 can use several upload passwords in options
[jirafeau_project.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 <http://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 require (JIRAFEAU_ROOT . 'lib/template/header.php');
28
29 check_errors ($cfg);
30 if (has_error ())
31 {
32 show_errors ();
33 require (JIRAFEAU_ROOT . 'lib/template/footer.php');
34 exit;
35 }
36
37 /* Ask password if upload password is set. */
38 if (jirafeau_has_upload_password ($cfg))
39 {
40 session_start();
41
42 /* Unlog if asked. */
43 if (isset ($_POST['action']) && (strcmp ($_POST['action'], 'logout') == 0))
44 session_unset ();
45
46 /* Auth. */
47 if (isset ($_POST['upload_password']))
48 {
49 if (jirafeau_challenge_upload_password ($cfg, $_POST['upload_password']))
50 {
51 $_SESSION['upload_auth'] = true;
52 $_SESSION['user_upload_password'] = $_POST['upload_password'];
53 }
54 else
55 {
56 $_SESSION['admin_auth'] = false;
57 echo '<div class="error"><p>' . t('Wrong password.') . '</p></div>';
58 require (JIRAFEAU_ROOT.'lib/template/footer.php');
59 exit;
60 }
61 }
62
63 /* Show auth page. */
64 if (!isset ($_SESSION['upload_auth']) || $_SESSION['upload_auth'] != true)
65 {
66 ?>
67 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
68 <fieldset>
69 <table>
70 <tr>
71 <td class = "label"><label for = "enter_password">
72 <?php echo t('Upload password') . ':';?></label>
73 </td>
74 <td class = "field"><input type = "password"
75 name = "upload_password" id = "upload_password"
76 size = "40" />
77 </td>
78 </tr>
79 <tr class = "nav">
80 <td></td>
81 <td class = "nav next">
82 <input type = "submit" name = "key" value =
83 "<?php echo t('Login'); ?>" />
84 </td>
85 </tr>
86 </table>
87 </fieldset>
88 </form>
89 <?php
90 require (JIRAFEAU_ROOT.'lib/template/footer.php');
91 exit;
92 }
93 }
94
95 ?>
96 <div id="upload_finished">
97 <p>
98 <?php echo t('File uploaded! Copy the following URL to get it') ?>:
99 <br />
100 <a id="upload_link" href=""></a>
101 <br />
102 </p>
103
104 <p>
105 <?php echo t('Keep the following URL to delete it at any moment'); ?>:
106 <br />
107 <a id="delete_link" href=""></a>
108 </p>
109
110 <p id="validity">
111 <?php echo t('This file is valid until the following date'); ?>:
112 <br /><strong><div id="date"></div></strong>
113 </p>
114 </div>
115
116 <div id="uploading">
117 <p>
118 <?php echo t ('Uploading ...'); ?><div id="uploaded_percentage"></div>
119 </p>
120 </div>
121
122 <div id="upload">
123 <fieldset>
124 <legend>
125 <?php echo t('Select a file'); ?>
126 </legend>
127 <p>
128 <input type="file" id="file_select" size="30"
129 onchange="
130 document.getElementById('options').style.display = '';
131 document.getElementById('send').style.display = '';
132 "/>
133 </p>
134
135 <div id="options">
136 <table id="option_table">
137 <tr>
138 <td><?php echo t('One time download'); ?>:</td>
139 <td><input type="checkbox" id="one_time_download" /></td>
140 </tr>
141 <tr>
142 <td><label for="input_key"><?php echo t('Password') . ':'; ?></label></td>
143 <td><input type="text" name="key" id="input_key" /></td>
144 </tr>
145 <tr>
146 <td><label for="select_time"><?php echo t('Time limit') . ':'; ?></label></td>
147 <td><select name="time" id="select_time">
148 <option value="none"><?php echo t('None'); ?></option>
149 <option value = "minute"><?php echo t('One minute'); ?></option>
150 <option value = "hour"><?php echo t('One hour'); ?></option>
151 <option value = "day"><?php echo t('One day'); ?></option>
152 <option value = "week"><?php echo t('One week'); ?></option>
153 <option value = "month"><?php echo t('One month');?></option>
154 </select></td>
155 </tr>
156 <p id="max_file_size" class="config"></p>
157 <p>
158 <?php
159 if (jirafeau_has_upload_password ($cfg) && $_SESSION['upload_auth'])
160 {
161 ?>
162 <input type="hidden" id="upload_password" name="upload_password" value="<?php echo $_SESSION['user_upload_password'] ?>"/>
163 <?php
164 }
165 else
166 {
167 ?>
168 <input type="hidden" id="upload_password" name="upload_password" value=""/>
169 <?php
170 }
171 ?>
172 <input type="submit" id="send" value="<?php echo t('Send'); ?>"
173 onclick="
174 document.getElementById('upload').style.display = 'none';
175 document.getElementById('uploading').style.display = '';
176 upload ('<?php echo $cfg['web_root']; ?>', <?php echo jirafeau_get_max_upload_size_bytes (); ?>);
177 "/>
178 </p>
179 </table>
180 </div> </fieldset>
181
182 <?php
183 if (jirafeau_has_upload_password ($cfg))
184 {
185 ?>
186 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
187 <input type = "hidden" name = "action" value = "logout"/>
188 <input type = "submit" value = "<?php echo t('Logout'); ?>" />
189 </form>
190 <?php
191 }
192 ?>
193
194 </div>
195
196 <script lang="Javascript">
197 document.getElementById('uploading').style.display = 'none';
198 document.getElementById('upload_finished').style.display = 'none';
199 document.getElementById('options').style.display = 'none';
200 document.getElementById('send').style.display = 'none';
201 if (!check_html5_file_api ())
202 document.getElementById('max_file_size').innerHTML = '<?php
203 echo t('You browser may not support HTML5 so the maximum file size is ') . jirafeau_get_max_upload_size ();
204 ?>';
205 </script>
206 <?php require (JIRAFEAU_ROOT . 'lib/template/footer.php'); ?>

patrick-canterino.de