]> git.p6c8.net - jirafeau_mojo42.git/blob - admin.php
Translated using Weblate (Slovak)
[jirafeau_mojo42.git] / admin.php
1 <?php
2 /*
3 * Jirafeau, your web file repository
4 * Copyright (C) 2015 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 /* Disable admin interface if we have a empty admin password. */
36 if (empty($cfg['admin_password']) && empty($cfg['admin_http_auth_user']))
37 {
38 require (JIRAFEAU_ROOT . 'lib/template/header.php');
39 echo '<div class="error"><p>'.
40 t('Sorry, the admin interface is not enabled.') .
41 '</p></div>';
42 require (JIRAFEAU_ROOT.'lib/template/footer.php');
43 exit;
44 }
45
46 /* Check session. */
47 session_start();
48
49 /* Unlog if asked. */
50 if (isset ($_POST['action']) && (strcmp ($_POST['action'], 'logout') == 0))
51 $_SESSION['admin_auth'] = false;
52
53 /* Check classic admin password authentification. */
54 if (isset ($_POST['admin_password']) && empty($cfg['admin_http_auth_user']))
55 {
56 if (strcmp ($cfg['admin_password'], $_POST['admin_password']) == 0)
57 $_SESSION['admin_auth'] = true;
58 else
59 {
60 $_SESSION['admin_auth'] = false;
61 require (JIRAFEAU_ROOT . 'lib/template/header.php');
62 echo '<div class="error"><p>'.
63 t('Wrong password.') . '</p></div>';
64 require (JIRAFEAU_ROOT.'lib/template/footer.php');
65 exit;
66 }
67 }
68 /* Ask for classic admin password authentification. */
69 elseif ((!isset ($_SESSION['admin_auth']) || $_SESSION['admin_auth'] != true)
70 && empty($cfg['admin_http_auth_user']))
71 {
72 require (JIRAFEAU_ROOT . 'lib/template/header.php'); ?>
73 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
74 <fieldset>
75 <table>
76 <tr>
77 <td class = "label"><label for = "enter_password">
78 <?php echo t('Administration password') . ':';?></label>
79 </td>
80 <td class = "field"><input type = "password"
81 name = "admin_password" id = "admin_password"
82 size = "40" />
83 </td>
84 </tr>
85 <tr class = "nav">
86 <td></td>
87 <td class = "nav next">
88 <input type = "submit" name = "key" value =
89 "<?php echo t('Login'); ?>" />
90 </td>
91 </tr>
92 </table>
93 </fieldset>
94 </form>
95 <?php
96 require (JIRAFEAU_ROOT.'lib/template/footer.php');
97 exit;
98 }
99 /* Check authenticated user if HTTP authentification is enable. */
100 elseif ((!isset ($_SESSION['admin_auth']) || $_SESSION['admin_auth'] != true)
101 && !empty($cfg['admin_http_auth_user']))
102 {
103 if ($cfg['admin_http_auth_user'] == $_SERVER['PHP_AUTH_USER'])
104 $_SESSION['admin_auth'] = true;
105 }
106
107 /* Be sure that no one can access further without admin_auth. */
108 if (!isset ($_SESSION['admin_auth']) || $_SESSION['admin_auth'] != true)
109 {
110 $_SESSION['admin_auth'] = false;
111 require (JIRAFEAU_ROOT . 'lib/template/header.php');
112 echo '<div class="error"><p>'.
113 t('Sorry, you are not authenticated on admin interface.') .
114 '</p></div>';
115 require (JIRAFEAU_ROOT.'lib/template/footer.php');
116 exit;
117 }
118
119 /* Operations may take a long time.
120 * Be sure PHP's safe mode is off.
121 */
122 @set_time_limit(0);
123 /* Remove errors. */
124 @error_reporting(0);
125
126 /* Show admin interface if not downloading a file. */
127 if (!(isset ($_POST['action']) && strcmp ($_POST['action'], 'download') == 0))
128 {
129 require (JIRAFEAU_ROOT . 'lib/template/header.php');
130 ?><h2><?php echo t('Admin interface'); ?></h2><?php
131 ?><h2>(version <?php echo JIRAFEAU_VERSION ?>)</h2><?php
132
133 ?><div id = "admin">
134 <fieldset><legend><?php echo t('Actions');?></legend>
135 <table>
136 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
137 <tr>
138 <input type = "hidden" name = "action" value = "clean"/>
139 <td class = "info">
140 <?php echo t('Clean expired files'); ?>
141 </td>
142 <td></td>
143 <td>
144 <input type = "submit" value = "<?php echo t('Clean'); ?>" />
145 </td>
146 </tr>
147 </form>
148 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
149 <tr>
150 <input type = "hidden" name = "action" value = "clean_async"/>
151 <td class = "info">
152 <?php echo t('Clean old unfinished transfers'); ?>
153 </td>
154 <td></td>
155 <td>
156 <input type = "submit" value = "<?php echo t('Clean'); ?>" />
157 </td>
158 </tr>
159 </form>
160 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
161 <tr>
162 <input type = "hidden" name = "action" value = "list"/>
163 <td class = "info">
164 <?php echo t('List all files'); ?>
165 </td>
166 <td></td>
167 <td>
168 <input type = "submit" value = "<?php echo t('List'); ?>" />
169 </td>
170 </tr>
171 </form>
172 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
173 <tr>
174 <input type = "hidden" name = "action" value = "search_by_name"/>
175 <td class = "info">
176 <?php echo t('Search files by name'); ?>
177 </td>
178 <td>
179 <input type = "text" name = "name" id = "name"/>
180 </td>
181 <td>
182 <input type = "submit" value = "<?php echo t('Search'); ?>" />
183 </td>
184 </tr>
185 </form>
186 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
187 <tr>
188 <input type = "hidden" name = "action" value = "search_by_file_hash"/>
189 <td class = "info">
190 <?php echo t('Search files by file hash'); ?>
191 </td>
192 <td>
193 <input type = "text" name = "hash" id = "hash"/>
194 </td>
195 <td>
196 <input type = "submit" value = "<?php echo t('Search'); ?>" />
197 </td>
198 </tr>
199 </form>
200 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
201 <tr>
202 <input type = "hidden" name = "action" value = "search_link"/>
203 <td class = "info">
204 <?php echo t('Search a specific link'); ?>
205 </td>
206 <td>
207 <input type = "text" name = "link" id = "link"/>
208 </td>
209 <td>
210 <input type = "submit" value = "<?php echo t('Search'); ?>" />
211 </td>
212 </tr>
213 </form>
214 </table>
215 <form action = "<?php echo basename(__FILE__); ?>" method = "post">
216 <input type = "hidden" name = "action" value = "logout" />
217 <input type = "submit" value = "<?php echo t('Logout'); ?>" />
218 </form>
219 </fieldset></div><?php
220 }
221
222 /* Check for actions */
223 if (isset ($_POST['action']))
224 {
225 if (strcmp ($_POST['action'], 'clean') == 0)
226 {
227 $total = jirafeau_admin_clean ();
228 echo '<div class="message">' . NL;
229 echo '<p>';
230 echo t('Number of cleaned files') . ' : ' . $total;
231 echo '</p></div>';
232 }
233 elseif (strcmp ($_POST['action'], 'clean_async') == 0)
234 {
235 $total = jirafeau_admin_clean_async ();
236 echo '<div class="message">' . NL;
237 echo '<p>';
238 echo t('Number of cleaned files') . ' : ' . $total;
239 echo '</p></div>';
240 }
241 elseif (strcmp ($_POST['action'], 'list') == 0)
242 {
243 jirafeau_admin_list ("", "", "");
244 }
245 elseif (strcmp ($_POST['action'], 'search_by_name') == 0)
246 {
247 jirafeau_admin_list ($_POST['name'], "", "");
248 }
249 elseif (strcmp ($_POST['action'], 'search_by_file_hash') == 0)
250 {
251 jirafeau_admin_list ("", $_POST['hash'], "");
252 }
253 elseif (strcmp ($_POST['action'], 'search_link') == 0)
254 {
255 jirafeau_admin_list ("", "", $_POST['link']);
256 }
257 elseif (strcmp ($_POST['action'], 'delete_link') == 0)
258 {
259 jirafeau_delete_link ($_POST['link']);
260 echo '<div class="message">' . NL;
261 echo '<p>' . t('Link deleted') . '</p></div>';
262 }
263 elseif (strcmp ($_POST['action'], 'delete_file') == 0)
264 {
265 $count = jirafeau_delete_file ($_POST['md5']);
266 echo '<div class="message">' . NL;
267 echo '<p>' . t('Deleted links') . ' : ' . $count . '</p></div>';
268 }
269 elseif (strcmp ($_POST['action'], 'download') == 0)
270 {
271 $l = jirafeau_get_link ($_POST['link']);
272 if (!count ($l))
273 return;
274 $p = s2p ($l['md5']);
275 header ('Content-Length: ' . $l['file_size']);
276 header ('Content-Type: ' . $l['mime_type']);
277 header ('Content-Disposition: attachment; filename="' .
278 $l['file_name'] . '"');
279 if (file_exists(VAR_FILES . $p . $l['md5']))
280 readfile (VAR_FILES . $p . $l['md5']);
281 exit;
282 }
283 }
284
285 require (JIRAFEAU_ROOT.'lib/template/footer.php');
286
287 ?>

patrick-canterino.de