]>
git.p6c8.net - jirafeau_mojo42.git/blob - admin.php
d602dcda96f989745df8f3ba820570c73648ca2e
3 * Jirafeau, your web file repository
4 * Copyright (C) 2015 Jerome Jutteau <j.jutteau@gmail.com>
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.
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.
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/>.
20 define ('JIRAFEAU_ROOT', dirname (__FILE__
) . '/');
22 require (JIRAFEAU_ROOT
. 'lib/settings.php');
23 require (JIRAFEAU_ROOT
. 'lib/functions.php');
24 require (JIRAFEAU_ROOT
. 'lib/lang.php');
26 /* Check if installation is OK. */
27 if (file_exists (JIRAFEAU_ROOT
. 'install.php')
28 && !file_exists (JIRAFEAU_ROOT
. 'lib/config.local.php'))
30 header('Location: install.php');
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.";
40 elseif ((count($argv)>1) && $argv[1]=="clean_async") {
41 $total = jirafeau_admin_clean_async ();
42 echo "$total old unfinished transfers deleted.";
46 die("No command found. Should be admin.php <clean_expired|clean_async>.");
51 /* Disable admin interface if we have a empty admin password. */
52 if (empty($cfg['admin_password']) && empty($cfg['admin_http_auth_user']))
54 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
55 echo '<div class="error"><p>'.
56 t('Sorry, the admin interface is not enabled.') .
58 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
66 if (isset ($_POST['action']) && (strcmp ($_POST['action'], 'logout') == 0))
67 $_SESSION['admin_auth'] = false;
69 /* Check classic admin password authentification. */
70 if (isset ($_POST['admin_password']) && empty($cfg['admin_http_auth_user']))
72 if ($cfg['admin_password'] === $_POST['admin_password'] ||
73 $cfg['admin_password'] === hash('sha256', $_POST['admin_password']))
74 $_SESSION['admin_auth'] = true;
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');
85 /* Ask for classic admin password authentification. */
86 elseif ((!isset ($_SESSION['admin_auth']) ||
$_SESSION['admin_auth'] != true)
87 && empty($cfg['admin_http_auth_user']))
89 require (JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
>
90 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
94 <td
class = "label"><label
for = "enter_password">
95 <?php
echo t('Administration password') . ':';?
></label
>
97 <td
class = "field"><input type
= "password"
98 name
= "admin_password" id
= "admin_password"
104 <td
class = "nav next">
105 <input type
= "submit" name
= "key" value
=
106 "<?php echo t('Login'); ?>" />
113 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
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']))
120 if ($cfg['admin_http_auth_user'] == $_SERVER['PHP_AUTH_USER'])
121 $_SESSION['admin_auth'] = true;
124 /* Be sure that no one can access further without admin_auth. */
125 if (!isset ($_SESSION['admin_auth']) ||
$_SESSION['admin_auth'] != true)
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.') .
132 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
136 /* Operations may take a long time.
137 * Be sure PHP's safe mode is off.
143 /* Show admin interface if not downloading a file. */
144 if (!(isset ($_POST['action']) && strcmp ($_POST['action'], 'download') == 0))
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
151 <fieldset
><legend
><?php
echo t('Actions');?
></legend
>
153 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
155 <input type
= "hidden" name
= "action" value
= "clean"/>
157 <?php
echo t('Clean expired files'); ?
>
161 <input type
= "submit" value
= "<?php echo t('Clean'); ?>" />
165 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
167 <input type
= "hidden" name
= "action" value
= "clean_async"/>
169 <?php
echo t('Clean old unfinished transfers'); ?
>
173 <input type
= "submit" value
= "<?php echo t('Clean'); ?>" />
177 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
179 <input type
= "hidden" name
= "action" value
= "list"/>
181 <?php
echo t('List all files'); ?
>
185 <input type
= "submit" value
= "<?php echo t('List'); ?>" />
189 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
191 <input type
= "hidden" name
= "action" value
= "search_by_name"/>
193 <?php
echo t('Search files by name'); ?
>
196 <input type
= "text" name
= "name" id
= "name"/>
199 <input type
= "submit" value
= "<?php echo t('Search'); ?>" />
203 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
205 <input type
= "hidden" name
= "action" value
= "search_by_file_hash"/>
207 <?php
echo t('Search files by file hash'); ?
>
210 <input type
= "text" name
= "hash" id
= "hash"/>
213 <input type
= "submit" value
= "<?php echo t('Search'); ?>" />
217 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
219 <input type
= "hidden" name
= "action" value
= "search_link"/>
221 <?php
echo t('Search a specific link'); ?
>
224 <input type
= "text" name
= "link" id
= "link"/>
227 <input type
= "submit" value
= "<?php echo t('Search'); ?>" />
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'); ?>" />
236 </fieldset
></div
><?php
239 /* Check for actions */
240 if (isset ($_POST['action']))
242 if (strcmp ($_POST['action'], 'clean') == 0)
244 $total = jirafeau_admin_clean ();
245 echo '<div class="message">' . NL
;
247 echo t('Number of cleaned files') . ' : ' . $total;
250 elseif (strcmp ($_POST['action'], 'clean_async') == 0)
252 $total = jirafeau_admin_clean_async ();
253 echo '<div class="message">' . NL
;
255 echo t('Number of cleaned files') . ' : ' . $total;
258 elseif (strcmp ($_POST['action'], 'list') == 0)
260 jirafeau_admin_list ("", "", "");
262 elseif (strcmp ($_POST['action'], 'search_by_name') == 0)
264 jirafeau_admin_list ($_POST['name'], "", "");
266 elseif (strcmp ($_POST['action'], 'search_by_file_hash') == 0)
268 jirafeau_admin_list ("", $_POST['hash'], "");
270 elseif (strcmp ($_POST['action'], 'search_link') == 0)
272 jirafeau_admin_list ("", "", $_POST['link']);
274 elseif (strcmp ($_POST['action'], 'delete_link') == 0)
276 jirafeau_delete_link ($_POST['link']);
277 echo '<div class="message">' . NL
;
278 echo '<p>' . t('Link deleted') . '</p></div>';
280 elseif (strcmp ($_POST['action'], 'delete_file') == 0)
282 $count = jirafeau_delete_file ($_POST['md5']);
283 echo '<div class="message">' . NL
;
284 echo '<p>' . t('Deleted links') . ' : ' . $count . '</p></div>';
286 elseif (strcmp ($_POST['action'], 'download') == 0)
288 $l = jirafeau_get_link ($_POST['link']);
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']);
302 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
patrick-canterino.de