]>
git.p6c8.net - jirafeau.git/blob - admin.php
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/config.original.php');
23 require (JIRAFEAU_ROOT
. 'lib/settings.php');
24 require (JIRAFEAU_ROOT
. 'lib/functions.php');
25 require (JIRAFEAU_ROOT
. 'lib/lang.php');
27 /* Check if installation is OK. */
28 if (file_exists (JIRAFEAU_ROOT
. 'install.php')
29 && !file_exists (JIRAFEAU_ROOT
. 'lib/config.local.php'))
31 header('Location: install.php');
35 /* If called from CLI, no password or graphical interface */
36 if (php_sapi_name() == "cli") {
37 if ((count($argv)>1) && $argv[1]=="clean_expired") {
38 $total = jirafeau_admin_clean ();
39 echo "$total expired files deleted.";
41 elseif ((count($argv)>1) && $argv[1]=="clean_async") {
42 $total = jirafeau_admin_clean_async ();
43 echo "$total old unfinished transfers deleted.";
47 die("No command found. Should be admin.php <clean_expired|clean_async>.");
52 /* Disable admin interface if we have a empty admin password. */
53 if (empty($cfg['admin_password']) && empty($cfg['admin_http_auth_user']))
55 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
56 echo '<div class="error"><p>'.
57 t('Sorry, the admin interface is not enabled.') .
59 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
67 if (isset ($_POST['action']) && (strcmp ($_POST['action'], 'logout') == 0))
68 $_SESSION['admin_auth'] = false;
70 /* Check classic admin password authentification. */
71 if (isset ($_POST['admin_password']) && empty($cfg['admin_http_auth_user']))
73 if ($cfg['admin_password'] === $_POST['admin_password'] ||
74 $cfg['admin_password'] === hash('sha256', $_POST['admin_password']))
75 $_SESSION['admin_auth'] = true;
78 $_SESSION['admin_auth'] = false;
79 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
80 echo '<div class="error"><p>'.
81 t('Wrong password.') . '</p></div>';
82 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
86 /* Ask for classic admin password authentification. */
87 elseif ((!isset ($_SESSION['admin_auth']) ||
$_SESSION['admin_auth'] != true)
88 && empty($cfg['admin_http_auth_user']))
90 require (JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
>
91 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
95 <td
class = "label"><label
for = "enter_password">
96 <?php
echo t('Administration password') . ':';?
></label
>
98 <td
class = "field"><input type
= "password"
99 name
= "admin_password" id
= "admin_password"
105 <td
class = "nav next">
106 <input type
= "submit" name
= "key" value
=
107 "<?php echo t('Login'); ?>" />
114 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
117 /* Check authenticated user if HTTP authentification is enable. */
118 elseif ((!isset ($_SESSION['admin_auth']) ||
$_SESSION['admin_auth'] != true)
119 && !empty($cfg['admin_http_auth_user']))
121 if ($cfg['admin_http_auth_user'] == $_SERVER['PHP_AUTH_USER'])
122 $_SESSION['admin_auth'] = true;
125 /* Be sure that no one can access further without admin_auth. */
126 if (!isset ($_SESSION['admin_auth']) ||
$_SESSION['admin_auth'] != true)
128 $_SESSION['admin_auth'] = false;
129 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
130 echo '<div class="error"><p>'.
131 t('Sorry, you are not authenticated on admin interface.') .
133 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
137 /* Operations may take a long time.
138 * Be sure PHP's safe mode is off.
144 /* Show admin interface if not downloading a file. */
145 if (!(isset ($_POST['action']) && strcmp ($_POST['action'], 'download') == 0))
147 require (JIRAFEAU_ROOT
. 'lib/template/header.php');
148 ?
><h2
><?php
echo t('Admin interface'); ?
></h2
><?php
149 ?
><h2
>(version
<?php
echo JIRAFEAU_VERSION ?
>)</h2
><?php
152 <fieldset
><legend
><?php
echo t('Actions');?
></legend
>
154 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
156 <input type
= "hidden" name
= "action" value
= "clean"/>
158 <?php
echo t('Clean expired files'); ?
>
162 <input type
= "submit" value
= "<?php echo t('Clean'); ?>" />
166 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
168 <input type
= "hidden" name
= "action" value
= "clean_async"/>
170 <?php
echo t('Clean old unfinished transfers'); ?
>
174 <input type
= "submit" value
= "<?php echo t('Clean'); ?>" />
178 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
180 <input type
= "hidden" name
= "action" value
= "list"/>
182 <?php
echo t('List all files'); ?
>
186 <input type
= "submit" value
= "<?php echo t('List'); ?>" />
190 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
192 <input type
= "hidden" name
= "action" value
= "search_by_name"/>
194 <?php
echo t('Search files by name'); ?
>
197 <input type
= "text" name
= "name" id
= "name"/>
200 <input type
= "submit" value
= "<?php echo t('Search'); ?>" />
204 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
206 <input type
= "hidden" name
= "action" value
= "search_by_file_hash"/>
208 <?php
echo t('Search files by file hash'); ?
>
211 <input type
= "text" name
= "hash" id
= "hash"/>
214 <input type
= "submit" value
= "<?php echo t('Search'); ?>" />
218 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
220 <input type
= "hidden" name
= "action" value
= "search_link"/>
222 <?php
echo t('Search a specific link'); ?
>
225 <input type
= "text" name
= "link" id
= "link"/>
228 <input type
= "submit" value
= "<?php echo t('Search'); ?>" />
233 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
234 <input type
= "hidden" name
= "action" value
= "logout" />
235 <input type
= "submit" value
= "<?php echo t('Logout'); ?>" />
237 </fieldset
></div
><?php
240 /* Check for actions */
241 if (isset ($_POST['action']))
243 if (strcmp ($_POST['action'], 'clean') == 0)
245 $total = jirafeau_admin_clean ();
246 echo '<div class="message">' . NL
;
248 echo t('Number of cleaned files') . ' : ' . $total;
251 elseif (strcmp ($_POST['action'], 'clean_async') == 0)
253 $total = jirafeau_admin_clean_async ();
254 echo '<div class="message">' . NL
;
256 echo t('Number of cleaned files') . ' : ' . $total;
259 elseif (strcmp ($_POST['action'], 'list') == 0)
261 jirafeau_admin_list ("", "", "");
263 elseif (strcmp ($_POST['action'], 'search_by_name') == 0)
265 jirafeau_admin_list ($_POST['name'], "", "");
267 elseif (strcmp ($_POST['action'], 'search_by_file_hash') == 0)
269 jirafeau_admin_list ("", $_POST['hash'], "");
271 elseif (strcmp ($_POST['action'], 'search_link') == 0)
273 jirafeau_admin_list ("", "", $_POST['link']);
275 elseif (strcmp ($_POST['action'], 'delete_link') == 0)
277 jirafeau_delete_link ($_POST['link']);
278 echo '<div class="message">' . NL
;
279 echo '<p>' . t('Link deleted') . '</p></div>';
281 elseif (strcmp ($_POST['action'], 'delete_file') == 0)
283 $count = jirafeau_delete_file ($_POST['md5']);
284 echo '<div class="message">' . NL
;
285 echo '<p>' . t('Deleted links') . ' : ' . $count . '</p></div>';
287 elseif (strcmp ($_POST['action'], 'download') == 0)
289 $l = jirafeau_get_link ($_POST['link']);
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']);
303 require (JIRAFEAU_ROOT
.'lib/template/footer.php');
patrick-canterino.de