]> git.p6c8.net - jirafeau_project.git/blob - admin.php
Fix fr translation
[jirafeau_project.git] / admin.php
1 <?php
2 /*
3 * Jirafeau, your web file repository
4 * Copyright (C) 2012 Jerome Jutteau <j.jutteau@gmail.com>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/');
21
22 require (JIRAFEAU_ROOT . 'lib/config.original.php');
23 require (JIRAFEAU_ROOT . 'lib/settings.php');
24 require (JIRAFEAU_ROOT . 'lib/functions.php');
25 require (JIRAFEAU_ROOT . 'lib/lang.php');
26
27 /* Check if installation is OK. */
28 if (file_exists (JIRAFEAU_ROOT . 'install.php')
29 && !file_exists (JIRAFEAU_ROOT . 'lib/config.local.php'))
30 {
31 header('Location: install.php');
32 exit;
33 }
34
35 /* Check if the install.php script is still in the directory. */
36 if (file_exists (JIRAFEAU_ROOT . 'install.php'))
37 {
38 require (JIRAFEAU_ROOT . 'lib/template/header.php');
39 echo '<div class="error"><p>'.
40 t('Installer script still present') .
41 '</p></div>';
42 require (JIRAFEAU_ROOT.'lib/template/footer.php');
43 exit;
44 }
45
46 /* Disable admin interface if we have a empty admin password. */
47 if (!$cfg['admin_password'])
48 {
49 require (JIRAFEAU_ROOT . 'lib/template/header.php');
50 echo '<div class="error"><p>'.
51 t('Sorry, the admin interface is not enabled.') .
52 '</p></div>';
53 require (JIRAFEAU_ROOT.'lib/template/footer.php');
54 exit;
55 }
56
57 /* Check session. */
58 session_start();
59
60 /* Unlog if asked. */
61 if (isset ($_POST['action']) && (strcmp ($_POST['action'], 'logout') == 0))
62 $_SESSION['admin_auth'] = false;
63
64 /* Check password. */
65 if (isset ($_POST['admin_password']))
66 {
67 if (strcmp ($cfg['admin_password'], $_POST['admin_password']) == 0)
68 $_SESSION['admin_auth'] = true;
69 else
70 {
71 $_SESSION['admin_auth'] = false;
72 require (JIRAFEAU_ROOT . 'lib/template/header.php');
73 echo '<div class="error"><p>'.
74 t('Wrong password.') . '</p></div>';
75 require (JIRAFEAU_ROOT.'lib/template/footer.php');
76 exit;
77 }
78 }
79 /* Ask for password. */
80 elseif (!isset ($_SESSION['admin_auth']) || $_SESSION['admin_auth'] != true)
81 {
82 require (JIRAFEAU_ROOT . 'lib/template/header.php'); ?>
83 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
84 <fieldset>
85 <table>
86 <tr>
87 <td class = "label"><label for = "enter_password">
88 <?php echo t('Administration password') . ':';?></label>
89 </td>
90 <td class = "field"><input type = "password"
91 name = "admin_password" id = "admin_password"
92 size = "40" />
93 </td>
94 </tr>
95 <tr class = "nav">
96 <td></td>
97 <td class = "nav next">
98 <input type = "submit" name = "key" value =
99 "<?php echo t('Login'); ?>" />
100 </td>
101 </tr>
102 </table>
103 </fieldset>
104 </form>
105 <?php
106 require (JIRAFEAU_ROOT.'lib/template/footer.php');
107 exit;
108 }
109
110 /* Operations may take a long time.
111 * Be sure PHP's safe mode is off.
112 */
113 @set_time_limit(0);
114 /* Remove errors. */
115 @error_reporting(0);
116
117 /* Admin interface. */
118 require (JIRAFEAU_ROOT . 'lib/template/header.php');
119 ?><h2><?php echo t('Admin interface'); ?></h2><?php
120
121 /* Show admin interface. */
122 {
123 ?><div id = "install">
124 <fieldset><legend><?php echo t('Actions');?></legend>
125 <table>
126 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
127 <tr>
128 <input type = "hidden" name = "action" value = "clean"/>
129 <td class = "info">
130 <?php echo t('Clean expired files'); ?>
131 </td>
132 <td></td>
133 <td>
134 <input type = "submit" value = "<?php echo t('Clean'); ?>" />
135 </td>
136 </tr>
137 </form>
138 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
139 <tr>
140 <input type = "hidden" name = "action" value = "clean_async"/>
141 <td class = "info">
142 <?php echo t('Clean old unfinished transferts'); ?>
143 </td>
144 <td></td>
145 <td>
146 <input type = "submit" value = "<?php echo t('Clean'); ?>" />
147 </td>
148 </tr>
149 </form>
150 <?php
151 if ($cfg['enable_blocks'])
152 {
153 ?>
154 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
155 <tr>
156 <input type = "hidden" name = "action" value = "clean_block"/>
157 <td class = "info">
158 <?php echo t('Clean unused blocks'); ?>
159 </td>
160 <td></td>
161 <td>
162 <input type = "submit" value = "<?php echo t('Clean'); ?>" />
163 </td>
164 </tr>
165 </form>
166 <?php
167 }
168 ?>
169
170 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
171 <tr>
172 <input type = "hidden" name = "action" value = "list"/>
173 <td class = "info">
174 <?php echo t('List all files'); ?>
175 </td>
176 <td></td>
177 <td>
178 <input type = "submit" value = "<?php echo t('List'); ?>" />
179 </td>
180 </tr>
181 </form>
182 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
183 <tr>
184 <input type = "hidden" name = "action" value = "search_by_name"/>
185 <td class = "info">
186 <?php echo t('Search files by name'); ?>
187 </td>
188 <td>
189 <input type = "text" name = "name" id = "name"/>
190 </td>
191 <td>
192 <input type = "submit" value = "<?php echo t('Search'); ?>" />
193 </td>
194 </tr>
195 </form>
196 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
197 <tr>
198 <input type = "hidden" name = "action" value = "search_by_file_hash"/>
199 <td class = "info">
200 <?php echo t('Search files by file hash'); ?>
201 </td>
202 <td>
203 <input type = "text" name = "hash" id = "hash"/>
204 </td>
205 <td>
206 <input type = "submit" value = "<?php echo t('Search'); ?>" />
207 </td>
208 </tr>
209 </form>
210 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
211 <tr>
212 <input type = "hidden" name = "action" value = "search_link"/>
213 <td class = "info">
214 <?php echo t('Search a specific link'); ?>
215 </td>
216 <td>
217 <input type = "text" name = "link" id = "link"/>
218 </td>
219 <td>
220 <input type = "submit" value = "<?php echo t('Search'); ?>" />
221 </td>
222 </tr>
223 </form>
224 </table>
225 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
226 <input type = "hidden" name = "action" value = "logout"/>
227 <input type = "submit" value = "<?php echo t('Logout'); ?>" />
228 </form>
229 </fieldset></div><?php
230 }
231
232 /* Check for actions */
233 if (isset ($_POST['action']))
234 {
235 if (strcmp ($_POST['action'], 'clean') == 0)
236 {
237 $total = jirafeau_admin_clean ();
238 echo '<div class="message">' . NL;
239 echo '<p>';
240 echo t('Number of cleaned files') . ' : ' . $total;
241 echo '</p></div>';
242 }
243 elseif (strcmp ($_POST['action'], 'clean_async') == 0)
244 {
245 $total = jirafeau_admin_clean_async ();
246 echo '<div class="message">' . NL;
247 echo '<p>';
248 echo t('Number of cleaned files') . ' : ' . $total;
249 echo '</p></div>';
250 }
251 elseif (strcmp ($_POST['action'], 'clean_block') == 0)
252 {
253 $total = jirafeau_admin_clean_block ();
254 echo '<div class="message">' . NL;
255 echo '<p>';
256 echo t('Number of cleaned files') . ' : ' . $total;
257 echo '</p></div>';
258 }
259 elseif (strcmp ($_POST['action'], 'list') == 0)
260 {
261 jirafeau_admin_list ("", "", "");
262 }
263 elseif (strcmp ($_POST['action'], 'search_by_name') == 0)
264 {
265 jirafeau_admin_list ($_POST['name'], "", "");
266 }
267 elseif (strcmp ($_POST['action'], 'search_by_file_hash') == 0)
268 {
269 jirafeau_admin_list ("", $_POST['hash'], "");
270 }
271 elseif (strcmp ($_POST['action'], 'search_link') == 0)
272 {
273 jirafeau_admin_list ("", "", $_POST['link']);
274 }
275 elseif (strcmp ($_POST['action'], 'delete_link') == 0)
276 {
277 jirafeau_delete_link ($_POST['link']);
278 echo '<div class="message">' . NL;
279 echo '<p>' . t('Link deleted') . '</p></div>';
280 }
281 elseif (strcmp ($_POST['action'], 'delete_file') == 0)
282 {
283 $count = jirafeau_delete_file ($_POST['md5']);
284 echo '<div class="message">' . NL;
285 echo '<p>' . t('Deleted links') . ' : ' . $count . '</p></div>';
286 }
287 elseif (strcmp ($_POST['action'], 'download') == 0)
288 {
289 $l = jirafeau_get_link ($_POST['link']);
290 if (!count ($l))
291 return;
292 $p = s2p ($l['md5']);
293 header ('Content-Length: ' . $l['file_size']);
294 header ('Content-Type: ' . $l['mime_type']);
295 header ('Content-Disposition: attachment; filename="' .
296 $l['file_name'] . '"');
297 if (file_exists(VAR_FILES . $p . $l['md5']))
298 readfile (VAR_FILES . $p . $l['md5']);
299 }
300 }
301
302 require (JIRAFEAU_ROOT.'lib/template/footer.php');
303
304 ?>

patrick-canterino.de