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

patrick-canterino.de