]>
git.p6c8.net - jirafeau_mojo42.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/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');
56 if (isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
57 $_SESSION['admin_auth'] = false;
60 /* Check classic admin password authentification. */
61 if (isset($_POST['admin_password']) && empty($cfg['admin_http_auth_user'])) {
62 if ($cfg['admin_password'] === $_POST['admin_password'] ||
63 $cfg['admin_password'] === hash('sha256', $_POST['admin_password'])) {
64 $_SESSION['admin_auth'] = true;
66 $_SESSION['admin_auth'] = false;
67 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
68 echo '<div class="error"><p>'.
69 t('Wrong password.') . '</p></div>';
70 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
74 /* Ask for classic admin password authentification. */
75 elseif ((!isset($_SESSION['admin_auth']) ||
$_SESSION['admin_auth'] != true)
76 && empty($cfg['admin_http_auth_user'])) {
77 require(JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
>
78 <form method
="post" class="form login">
82 <td
class = "label"><label
for = "enter_password">
83 <?php
echo t('Administration password') . ':'; ?
></label
>
85 <td
class = "field"><input type
= "password"
86 name
= "admin_password" id
= "admin_password"
92 <td
class = "nav next">
93 <input type
= "submit" name
= "key" value
=
94 "<?php echo t('Login'); ?>" />
101 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
104 /* Check authenticated user if HTTP authentification is enable. */
105 elseif ((!isset($_SESSION['admin_auth']) ||
$_SESSION['admin_auth'] != true)
106 && !empty($cfg['admin_http_auth_user'])) {
107 if ($cfg['admin_http_auth_user'] == $_SERVER['PHP_AUTH_USER']) {
108 $_SESSION['admin_auth'] = true;
112 /* Be sure that no one can access further without admin_auth. */
113 if (!isset($_SESSION['admin_auth']) ||
$_SESSION['admin_auth'] != true) {
114 $_SESSION['admin_auth'] = false;
115 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
116 echo '<div class="error"><p>'.
117 t('Sorry, you are not authenticated on admin interface.') .
119 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
123 /* Operations may take a long time.
124 * Be sure PHP's safe mode is off.
130 /* Show admin interface if not downloading a file. */
131 if (!(isset($_POST['action']) && strcmp($_POST['action'], 'download') == 0)) {
132 require(JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
><h2
><?php
echo t('Admin interface'); ?
></h2
><?php
133 ?
><h2
>(version
<?php
echo JIRAFEAU_VERSION ?
>)</h2
><?php
136 <fieldset
><legend
><?php
echo t('Actions'); ?
></legend
>
140 <input type
= "hidden" name
= "action" value
= "clean"/>
142 <?php
echo t('Clean expired files'); ?
>
146 <input type
= "submit" value
= "<?php echo t('Clean'); ?>" />
152 <input type
= "hidden" name
= "action" value
= "clean_async"/>
154 <?php
echo t('Clean old unfinished transfers'); ?
>
158 <input type
= "submit" value
= "<?php echo t('Clean'); ?>" />
164 <input type
= "hidden" name
= "action" value
= "list"/>
166 <?php
echo t('List all files'); ?
>
170 <input type
= "submit" value
= "<?php echo t('List'); ?>" />
176 <input type
= "hidden" name
= "action" value
= "search_by_name"/>
178 <?php
echo t('Search files by name'); ?
>
181 <input type
= "text" name
= "name" id
= "name"/>
184 <input type
= "submit" value
= "<?php echo t('Search'); ?>" />
190 <input type
= "hidden" name
= "action" value
= "search_by_file_hash"/>
192 <?php
echo t('Search files by file hash'); ?
>
195 <input type
= "text" name
= "hash" id
= "hash"/>
198 <input type
= "submit" value
= "<?php echo t('Search'); ?>" />
204 <input type
= "hidden" name
= "action" value
= "search_link"/>
206 <?php
echo t('Search a specific link'); ?
>
209 <input type
= "text" name
= "link" id
= "link"/>
212 <input type
= "submit" value
= "<?php echo t('Search'); ?>" />
218 <input type
= "hidden" name
= "action" value
= "logout" />
219 <input type
= "submit" value
= "<?php echo t('Logout'); ?>" />
221 </fieldset
></div
><?php
225 /* Check for actions */
226 if (isset($_POST['action'])) {
227 if (strcmp($_POST['action'], 'clean') == 0) {
228 $total = jirafeau_admin_clean();
229 echo '<div class="message">' . NL
;
231 echo t('Number of cleaned files') . ' : ' . $total;
233 } elseif (strcmp($_POST['action'], 'clean_async') == 0) {
234 $total = jirafeau_admin_clean_async();
235 echo '<div class="message">' . NL
;
237 echo t('Number of cleaned files') . ' : ' . $total;
239 } elseif (strcmp($_POST['action'], 'list') == 0) {
240 jirafeau_admin_list("", "", "");
241 } elseif (strcmp($_POST['action'], 'search_by_name') == 0) {
242 jirafeau_admin_list($_POST['name'], "", "");
243 } elseif (strcmp($_POST['action'], 'search_by_file_hash') == 0) {
244 jirafeau_admin_list("", $_POST['hash'], "");
245 } elseif (strcmp($_POST['action'], 'search_link') == 0) {
246 jirafeau_admin_list("", "", $_POST['link']);
247 } elseif (strcmp($_POST['action'], 'delete_link') == 0) {
248 jirafeau_delete_link($_POST['link']);
249 echo '<div class="message">' . NL
;
250 echo '<p>' . t('Link deleted') . '</p></div>';
251 } elseif (strcmp($_POST['action'], 'delete_file') == 0) {
252 $count = jirafeau_delete_file($_POST['md5']);
253 echo '<div class="message">' . NL
;
254 echo '<p>' . t('Deleted links') . ' : ' . $count . '</p></div>';
255 } elseif (strcmp($_POST['action'], 'download') == 0) {
256 $l = jirafeau_get_link($_POST['link']);
261 header('Content-Length: ' . $l['file_size']);
262 header('Content-Type: ' . $l['mime_type']);
263 header('Content-Disposition: attachment; filename="' .
264 $l['file_name'] . '"');
265 if (file_exists(VAR_FILES
. $p . $l['md5'])) {
266 readfile(VAR_FILES
. $p . $l['md5']);
272 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
patrick-canterino.de