]>
git.p6c8.net - jirafeau.git/blob - admin.php
3 * Jirafeau, your web file repository
4 * Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
5 * Copyright (C) 2015 Jerome Jutteau <jerome@jutteau.fr>
6 * Copyright (C) 2024 Jirafeau project <https://gitlab.com/jirafeau> (see AUTHORS.md)
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 define('JIRAFEAU_ROOT', dirname(__FILE__
) . '/');
24 require(JIRAFEAU_ROOT
. 'lib/settings.php');
25 require(JIRAFEAU_ROOT
. 'lib/functions.php');
26 require(JIRAFEAU_ROOT
. 'lib/lang.php');
28 /* Check if installation is OK. */
29 if (file_exists(JIRAFEAU_ROOT
. 'install.php')
30 && !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 ($cfg['installation_done'] == false) {
38 die("Installation not completed yet.\n");
40 if ((count($argv) > 1) && $argv[1] == 'clean_expired') {
41 $total = jirafeau_admin_clean();
42 echo "$total expired files deleted.\n";
43 } elseif ((count($argv) > 1) && $argv[1] == 'clean_async') {
44 $total = jirafeau_admin_clean_async();
45 echo "$total old unfinished transfers deleted.\n";
47 die("No command found. Should be admin.php <clean_expired|clean_async>.\n");
50 /* Second check: Challenge by IP */
51 elseif (true === jirafeau_challenge_admin_ip($cfg, get_ip_address($cfg))) {
52 /* Disable admin interface if we have a empty admin password. */
53 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>'.
58 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
62 /* Logout if requested. */
63 if (jirafeau_admin_session_logged() && isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
64 jirafeau_session_end();
67 if (!jirafeau_admin_session_logged()) {
68 /* Test HTTP authentication. */
69 if (!empty($cfg['admin_http_auth_user']) &&
70 ((is_array($cfg['admin_http_auth_user']) && in_array($_SERVER['PHP_AUTH_USER'], $cfg['admin_http_auth_user'])) ||
71 (($cfg['admin_http_auth_user'] == $_SERVER['PHP_AUTH_USER'])))) {
72 jirafeau_admin_session_start();
74 /* Test web password authentication. */
75 elseif (!empty($cfg['admin_password']) && isset($_POST['admin_password'])) {
76 if ($cfg['admin_password'] === hash('sha256', $_POST['admin_password'])) {
77 jirafeau_admin_session_start();
79 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
80 echo '<div class="error"><p>'. t('BAD_PSW') . '</p></div>';
81 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
85 /* Admin password prompt form. */
87 require(JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
>
88 <form method
="post" class="form login">
92 <td
class = "label"><label
for = "enter_password">
93 <?php
echo t('ADMIN_PSW') . ':'; ?
></label
>
97 <td
class = "field"><input type
= "password"
98 name
= "admin_password" id
= "admin_password"
99 size
= "40" autocomplete
= "current-password" />
103 <td
class = "nav next">
104 <input type
= "submit" name
= "key" value
=
105 "<?php echo t('LOGIN'); ?>" />
112 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
117 /* Operations may take a long time.
118 * Be sure PHP's safe mode is off.
122 /* Show admin interface if not downloading a file. */
123 if (!(isset($_POST['action']) && strcmp($_POST['action'], 'download') == 0)) {
124 require(JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
><h2
><?php
echo t('ADMIN_INTERFACE'); ?
></h2
><?php
125 ?
><h2
>(version
<?php
echo JIRAFEAU_VERSION ?
>)</h2
><?php
127 if ($cfg['enable_crypt'] && !(extension_loaded('sodium'))) {
128 echo '<div class="error"><p>'.t('SODIUM_UNAVAILABLE').'</p></div>';
132 <fieldset
><legend
><?php
echo t('ACTIONS'); ?
></legend
>
136 <input type
= "hidden" name
= "action" value
= "clean"/>
137 <?php
echo jirafeau_admin_csrf_field() ?
>
139 <?php
echo t('CLEAN_EXPIRED'); ?
>
143 <input type
= "submit" value
= "<?php echo t('CLEAN'); ?>" />
149 <input type
= "hidden" name
= "action" value
= "clean_async"/>
150 <?php
echo jirafeau_admin_csrf_field() ?
>
152 <?php
echo t('CLEAN_INCOMPLETE'); ?
>
156 <input type
= "submit" value
= "<?php echo t('CLEAN'); ?>" />
162 <input type
= "hidden" name
= "action" value
= "list"/>
163 <?php
echo jirafeau_admin_csrf_field() ?
>
165 <?php
echo t('LS_FILES'); ?
>
169 <input type
= "submit" value
= "<?php echo t('LIST'); ?>" />
175 <input type
= "hidden" name
= "action" value
= "size"/>
176 <?php
echo jirafeau_admin_csrf_field() ?
>
178 <?php
echo t('SIZE_DATA'); ?
>
182 <input type
= "submit" value
= "<?php echo t('SIZE'); ?>" />
188 <input type
= "hidden" name
= "action" value
= "search_by_name"/>
189 <?php
echo jirafeau_admin_csrf_field() ?
>
191 <?php
echo t('SEARCH_NAME'); ?
>
194 <input type
= "text" name
= "name" id
= "name"/>
197 <input type
= "submit" value
= "<?php echo t('SEARCH'); ?>" />
203 <input type
= "hidden" name
= "action" value
= "search_by_file_hash"/>
204 <?php
echo jirafeau_admin_csrf_field() ?
>
206 <?php
echo t('SEARH_BY_HASH'); ?
>
209 <input type
= "text" name
= "hash" id
= "hash"/>
212 <input type
= "submit" value
= "<?php echo t('SEARCH'); ?>" />
218 <input type
= "hidden" name
= "action" value
= "search_link"/>
219 <?php
echo jirafeau_admin_csrf_field() ?
>
221 <?php
echo t('SEARCH_LINK'); ?
>
224 <input type
= "text" name
= "link" id
= "link"/>
227 <input type
= "submit" value
= "<?php echo t('SEARCH'); ?>" />
233 <input type
= "hidden" name
= "action" value
= "bug_report_info"/>
234 <?php
echo jirafeau_admin_csrf_field() ?
>
236 <?php
echo t('REPORTING_AN_ISSUE'); ?
>
240 <input type
= "submit" value
= "<?php echo t('INFO'); ?>" />
246 <input type
= "hidden" name
= "action" value
= "logout" />
247 <?php
echo jirafeau_admin_csrf_field() ?
>
248 <input type
= "submit" value
= "<?php echo t('LOGOUT'); ?>" />
250 </fieldset
></div
><?php
253 /* Check for actions */
254 if (isset($_POST['action'])) {
255 if (strcmp($_POST['action'], 'clean') == 0) {
256 $total = jirafeau_admin_clean();
257 echo '<div class="message">' . NL
;
259 echo t('CLEANED_FILES_CNT') . ' : ' . $total;
261 } elseif (strcmp($_POST['action'], 'clean_async') == 0) {
262 $total = jirafeau_admin_clean_async();
263 echo '<div class="message">' . NL
;
265 echo t('CLEANED_FILES_CNT') . ' : ' . $total;
267 } elseif (strcmp($_POST['action'], 'size') == 0) {
268 $size = jirafeau_dir_size($cfg['var_root']);
269 $human_size = jirafeau_human_size($size);
270 echo '<div class="message">' . NL
;
271 echo '<p>' . t('SIZE_DATA') . ': ' . $human_size .'</p>';
273 } elseif (strcmp($_POST['action'], 'list') == 0) {
274 jirafeau_admin_list("", "", "");
275 } elseif (strcmp($_POST['action'], 'search_by_name') == 0) {
276 jirafeau_admin_list($_POST['name'], "", "");
277 } elseif (strcmp($_POST['action'], 'search_by_file_hash') == 0) {
278 jirafeau_admin_list("", $_POST['hash'], "");
279 } elseif (strcmp($_POST['action'], 'search_link') == 0) {
280 jirafeau_admin_list("", "", $_POST['link']);
281 } elseif (strcmp($_POST['action'], 'delete_link') == 0) {
282 jirafeau_delete_link($_POST['link']);
283 echo '<div class="message">' . NL
;
284 echo '<p>' . t('LINK_DELETED') . '</p></div>';
285 } elseif (strcmp($_POST['action'], 'delete_file') == 0) {
286 $count = jirafeau_delete_file($_POST['hash']);
287 echo '<div class="message">' . NL
;
288 echo '<p>' . t('DELETED_LINKS') . ' : ' . $count . '</p></div>';
289 } elseif (strcmp($_POST['action'], 'download') == 0) {
290 $l = jirafeau_get_link($_POST['link']);
294 $p = s2p($l['hash']);
295 header('Content-Length: ' . $l['file_size']);
296 header('Content-Type: ' . $l['mime_type']);
297 header('Content-Disposition: attachment; filename="' .
298 $l['file_name'] . '"');
299 if (file_exists(VAR_FILES
. $p . $l['hash'])) {
300 $r = fopen(VAR_FILES
. $p . $l['hash'], 'r');
302 print fread($r, 1024);
307 } elseif (strcmp($_POST['action'], 'bug_report_info') == 0) {
308 echo jirafeau_admin_bug_report($cfg);
312 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
314 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
315 jirafeau_fatal_error(t('ACCESS_KO'), $cfg);
patrick-canterino.de