]>
git.p6c8.net - jirafeau_mojo42.git/blob - admin.php
e4321dbce9a59160851608d06908aca88d1a050f
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')) {
29 header('Location: install.php');
33 /* If called from CLI, no password or graphical interface */
34 if (php_sapi_name() == "cli") {
35 if ((count($argv)>1) && $argv[1]=="clean_expired") {
36 $total = jirafeau_admin_clean();
37 echo "$total expired files deleted.";
38 } elseif ((count($argv)>1) && $argv[1]=="clean_async") {
39 $total = jirafeau_admin_clean_async();
40 echo "$total old unfinished transfers deleted.";
42 die("No command found. Should be admin.php <clean_expired|clean_async>.");
45 /* Disable admin interface if we have a empty admin password. */
46 if (empty($cfg['admin_password']) && empty($cfg['admin_http_auth_user'])) {
47 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
48 echo '<div class="error"><p>'.
49 t('Sorry, the admin interface is not enabled.') .
51 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
59 if (isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
60 $_SESSION['admin_auth'] = false;
63 /* Check classic admin password authentification. */
64 if (isset($_POST['admin_password']) && empty($cfg['admin_http_auth_user'])) {
65 if ($cfg['admin_password'] === $_POST['admin_password'] ||
66 $cfg['admin_password'] === hash('sha256', $_POST['admin_password'])) {
67 $_SESSION['admin_auth'] = true;
69 $_SESSION['admin_auth'] = false;
70 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
71 echo '<div class="error"><p>'.
72 t('Wrong password.') . '</p></div>';
73 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
77 /* Ask for classic admin password authentification. */
78 elseif ((!isset($_SESSION['admin_auth']) ||
$_SESSION['admin_auth'] != true)
79 && empty($cfg['admin_http_auth_user'])) {
80 require(JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
>
81 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
85 <td
class = "label"><label
for = "enter_password">
86 <?php
echo t('Administration password') . ':'; ?
></label
>
88 <td
class = "field"><input type
= "password"
89 name
= "admin_password" id
= "admin_password"
95 <td
class = "nav next">
96 <input type
= "submit" name
= "key" value
=
97 "<?php echo t('Login'); ?>" />
104 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
107 /* Check authenticated user if HTTP authentification is enable. */
108 elseif ((!isset($_SESSION['admin_auth']) ||
$_SESSION['admin_auth'] != true)
109 && !empty($cfg['admin_http_auth_user'])) {
110 if ($cfg['admin_http_auth_user'] == $_SERVER['PHP_AUTH_USER']) {
111 $_SESSION['admin_auth'] = true;
115 /* Be sure that no one can access further without admin_auth. */
116 if (!isset($_SESSION['admin_auth']) ||
$_SESSION['admin_auth'] != true) {
117 $_SESSION['admin_auth'] = false;
118 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
119 echo '<div class="error"><p>'.
120 t('Sorry, you are not authenticated on admin interface.') .
122 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
126 /* Operations may take a long time.
127 * Be sure PHP's safe mode is off.
133 /* Show admin interface if not downloading a file. */
134 if (!(isset($_POST['action']) && strcmp($_POST['action'], 'download') == 0)) {
135 require(JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
><h2
><?php
echo t('Admin interface'); ?
></h2
><?php
136 ?
><h2
>(version
<?php
echo JIRAFEAU_VERSION ?
>)</h2
><?php
139 <fieldset
><legend
><?php
echo t('Actions'); ?
></legend
>
141 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
143 <input type
= "hidden" name
= "action" value
= "clean"/>
145 <?php
echo t('Clean expired files'); ?
>
149 <input type
= "submit" value
= "<?php echo t('Clean'); ?>" />
153 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
155 <input type
= "hidden" name
= "action" value
= "clean_async"/>
157 <?php
echo t('Clean old unfinished transfers'); ?
>
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
= "list"/>
169 <?php
echo t('List all files'); ?
>
173 <input type
= "submit" value
= "<?php echo t('List'); ?>" />
177 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
179 <input type
= "hidden" name
= "action" value
= "search_by_name"/>
181 <?php
echo t('Search files by name'); ?
>
184 <input type
= "text" name
= "name" id
= "name"/>
187 <input type
= "submit" value
= "<?php echo t('Search'); ?>" />
191 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
193 <input type
= "hidden" name
= "action" value
= "search_by_file_hash"/>
195 <?php
echo t('Search files by file hash'); ?
>
198 <input type
= "text" name
= "hash" id
= "hash"/>
201 <input type
= "submit" value
= "<?php echo t('Search'); ?>" />
205 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
207 <input type
= "hidden" name
= "action" value
= "search_link"/>
209 <?php
echo t('Search a specific link'); ?
>
212 <input type
= "text" name
= "link" id
= "link"/>
215 <input type
= "submit" value
= "<?php echo t('Search'); ?>" />
220 <form action
= "<?php echo basename(__FILE__); ?>" method
= "post">
221 <input type
= "hidden" name
= "action" value
= "logout" />
222 <input type
= "submit" value
= "<?php echo t('Logout'); ?>" />
224 </fieldset
></div
><?php
228 /* Check for actions */
229 if (isset($_POST['action'])) {
230 if (strcmp($_POST['action'], 'clean') == 0) {
231 $total = jirafeau_admin_clean();
232 echo '<div class="message">' . NL
;
234 echo t('Number of cleaned files') . ' : ' . $total;
236 } elseif (strcmp($_POST['action'], 'clean_async') == 0) {
237 $total = jirafeau_admin_clean_async();
238 echo '<div class="message">' . NL
;
240 echo t('Number of cleaned files') . ' : ' . $total;
242 } elseif (strcmp($_POST['action'], 'list') == 0) {
243 jirafeau_admin_list("", "", "");
244 } elseif (strcmp($_POST['action'], 'search_by_name') == 0) {
245 jirafeau_admin_list($_POST['name'], "", "");
246 } elseif (strcmp($_POST['action'], 'search_by_file_hash') == 0) {
247 jirafeau_admin_list("", $_POST['hash'], "");
248 } elseif (strcmp($_POST['action'], 'search_link') == 0) {
249 jirafeau_admin_list("", "", $_POST['link']);
250 } elseif (strcmp($_POST['action'], 'delete_link') == 0) {
251 jirafeau_delete_link($_POST['link']);
252 echo '<div class="message">' . NL
;
253 echo '<p>' . t('Link deleted') . '</p></div>';
254 } elseif (strcmp($_POST['action'], 'delete_file') == 0) {
255 $count = jirafeau_delete_file($_POST['md5']);
256 echo '<div class="message">' . NL
;
257 echo '<p>' . t('Deleted links') . ' : ' . $count . '</p></div>';
258 } elseif (strcmp($_POST['action'], 'download') == 0) {
259 $l = jirafeau_get_link($_POST['link']);
264 header('Content-Length: ' . $l['file_size']);
265 header('Content-Type: ' . $l['mime_type']);
266 header('Content-Disposition: attachment; filename="' .
267 $l['file_name'] . '"');
268 if (file_exists(VAR_FILES
. $p . $l['md5'])) {
269 readfile(VAR_FILES
. $p . $l['md5']);
275 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
patrick-canterino.de