]>
git.p6c8.net - jirafeau_project.git/blob - admin.php
3 * Jirafeau, your web file repository
4 * Copyright (C) 2015 Jerome Jutteau <jerome@jutteau.fr>
5 * Copyright (C) 2023 Blackeye <blackeye@blackeyeprojects.de>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 define('JIRAFEAU_ROOT', dirname(__FILE__
) . '/');
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')) {
30 header('Location: install.php');
34 /* If called from CLI, no password or graphical interface */
35 if (php_sapi_name() == "cli") {
36 if ($cfg['installation_done'] == false) {
37 die("Installation not completed yet.\n");
39 if ((count($argv)>1) && $argv[1]=="clean_expired") {
40 $total = jirafeau_admin_clean();
41 echo "$total expired files deleted.\n";
42 } elseif ((count($argv)>1) && $argv[1]=="clean_async") {
43 $total = jirafeau_admin_clean_async();
44 echo "$total old unfinished transfers deleted.\n";
46 die("No command found. Should be admin.php <clean_expired|clean_async>.\n");
48 // Second check: Challenge by IP
49 } elseif (true === jirafeau_challenge_admin_ip($cfg, get_ip_address($cfg))) {
50 /* Disable admin interface if we have a empty admin password. */
51 if (empty($cfg['admin_password']) && empty($cfg['admin_http_auth_user'])) {
52 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
53 echo '<div class="error"><p>'.
56 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
60 /* Logout if requested. */
61 if (jirafeau_admin_session_logged() && isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
62 jirafeau_session_end();
65 if (!jirafeau_admin_session_logged()) {
66 /* Test HTTP authentication. */
67 if (!empty($cfg['admin_http_auth_user']) &&
68 ((is_array($cfg['admin_http_auth_user']) && in_array($_SERVER['PHP_AUTH_USER'], $cfg['admin_http_auth_user'])) ||
69 (($cfg['admin_http_auth_user'] == $_SERVER['PHP_AUTH_USER'])))) {
70 jirafeau_admin_session_start();
72 /* Test web password authentication. */
73 elseif (!empty($cfg['admin_password']) && isset($_POST['admin_password'])) {
74 if ($cfg['admin_password'] === hash('sha256', $_POST['admin_password'])) {
75 jirafeau_admin_session_start();
77 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
78 echo '<div class="error"><p>'. t('BAD_PSW') . '</p></div>';
79 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
83 /* Admin password prompt form. */
85 require(JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
>
86 <form method
="post" class="form login">
90 <td
class = "label"><label
for = "enter_password">
91 <?php
echo t('ADMIN_PSW') . ':'; ?
></label
>
95 <td
class = "field"><input type
= "password"
96 name
= "admin_password" id
= "admin_password"
97 size
= "40" autocomplete
= "current-password" />
101 <td
class = "nav next">
102 <input type
= "submit" name
= "key" value
=
103 "<?php echo t('LOGIN'); ?>" />
110 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
115 /* Operations may take a long time.
116 * Be sure PHP's safe mode is off.
120 /* Show admin interface if not downloading a file. */
121 if (!(isset($_POST['action']) && strcmp($_POST['action'], 'download') == 0)) {
122 require(JIRAFEAU_ROOT
. 'lib/template/header.php'); ?
><h2
><?php
echo t('ADMIN_INTERFACE'); ?
></h2
><?php
123 ?
><h2
>(version
<?php
echo JIRAFEAU_VERSION ?
>)</h2
><?php
125 if ($cfg['enable_crypt'] && !(extension_loaded('sodium'))) {
126 echo '<div class="error"><p>'.t('SODIUM_UNAVAILABLE').'</p></div>';
130 <fieldset
><legend
><?php
echo t('ACTIONS'); ?
></legend
>
134 <input type
= "hidden" name
= "action" value
= "clean"/>
135 <?php
echo jirafeau_admin_csrf_field() ?
>
137 <?php
echo t('CLEAN_EXPIRED'); ?
>
141 <input type
= "submit" value
= "<?php echo t('CLEAN'); ?>" />
147 <input type
= "hidden" name
= "action" value
= "clean_async"/>
148 <?php
echo jirafeau_admin_csrf_field() ?
>
150 <?php
echo t('CLEAN_INCOMPLETE'); ?
>
154 <input type
= "submit" value
= "<?php echo t('CLEAN'); ?>" />
160 <input type
= "hidden" name
= "action" value
= "list"/>
161 <?php
echo jirafeau_admin_csrf_field() ?
>
163 <?php
echo t('LS_FILES'); ?
>
167 <input type
= "submit" value
= "<?php echo t('LIST'); ?>" />
173 <input type
= "hidden" name
= "action" value
= "size"/>
174 <?php
echo jirafeau_admin_csrf_field() ?
>
176 <?php
echo t('SIZE_DATA'); ?
>
180 <input type
= "submit" value
= "<?php echo t('SIZE'); ?>" />
186 <input type
= "hidden" name
= "action" value
= "search_by_name"/>
187 <?php
echo jirafeau_admin_csrf_field() ?
>
189 <?php
echo t('SEARCH_NAME'); ?
>
192 <input type
= "text" name
= "name" id
= "name"/>
195 <input type
= "submit" value
= "<?php echo t('SEARCH'); ?>" />
201 <input type
= "hidden" name
= "action" value
= "search_by_file_hash"/>
202 <?php
echo jirafeau_admin_csrf_field() ?
>
204 <?php
echo t('SEARH_BY_HASH'); ?
>
207 <input type
= "text" name
= "hash" id
= "hash"/>
210 <input type
= "submit" value
= "<?php echo t('SEARCH'); ?>" />
216 <input type
= "hidden" name
= "action" value
= "search_link"/>
217 <?php
echo jirafeau_admin_csrf_field() ?
>
219 <?php
echo t('SEARCH_LINK'); ?
>
222 <input type
= "text" name
= "link" id
= "link"/>
225 <input type
= "submit" value
= "<?php echo t('SEARCH'); ?>" />
231 <input type
= "hidden" name
= "action" value
= "bug_report_info"/>
232 <?php
echo jirafeau_admin_csrf_field() ?
>
234 <?php
echo t('REPORTING_AN_ISSUE'); ?
>
238 <input type
= "submit" value
= "<?php echo t('INFO'); ?>" />
244 <input type
= "hidden" name
= "action" value
= "logout" />
245 <?php
echo jirafeau_admin_csrf_field() ?
>
246 <input type
= "submit" value
= "<?php echo t('LOGOUT'); ?>" />
248 </fieldset
></div
><?php
251 /* Check for actions */
252 if (isset($_POST['action'])) {
253 if (strcmp($_POST['action'], 'clean') == 0) {
254 $total = jirafeau_admin_clean();
255 echo '<div class="message">' . NL
;
257 echo t('CLEANED_FILES_CNT') . ' : ' . $total;
259 } elseif (strcmp($_POST['action'], 'clean_async') == 0) {
260 $total = jirafeau_admin_clean_async();
261 echo '<div class="message">' . NL
;
263 echo t('CLEANED_FILES_CNT') . ' : ' . $total;
265 } elseif (strcmp($_POST['action'], 'size') == 0) {
266 $size = jirafeau_dir_size($cfg['var_root']);
267 $human_size = jirafeau_human_size($size);
268 echo '<div class="message">' . NL
;
269 echo '<p>' . t('SIZE_DATA') . ': ' . $human_size .'</p>';
271 } elseif (strcmp($_POST['action'], 'list') == 0) {
272 jirafeau_admin_list("", "", "");
273 } elseif (strcmp($_POST['action'], 'search_by_name') == 0) {
274 jirafeau_admin_list($_POST['name'], "", "");
275 } elseif (strcmp($_POST['action'], 'search_by_file_hash') == 0) {
276 jirafeau_admin_list("", $_POST['hash'], "");
277 } elseif (strcmp($_POST['action'], 'search_link') == 0) {
278 jirafeau_admin_list("", "", $_POST['link']);
279 } elseif (strcmp($_POST['action'], 'delete_link') == 0) {
280 jirafeau_delete_link($_POST['link']);
281 echo '<div class="message">' . NL
;
282 echo '<p>' . t('LINK_DELETED') . '</p></div>';
283 } elseif (strcmp($_POST['action'], 'delete_file') == 0) {
284 $count = jirafeau_delete_file($_POST['hash']);
285 echo '<div class="message">' . NL
;
286 echo '<p>' . t('DELETED_LINKS') . ' : ' . $count . '</p></div>';
287 } elseif (strcmp($_POST['action'], 'download') == 0) {
288 $l = jirafeau_get_link($_POST['link']);
292 $p = s2p($l['hash']);
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['hash'])) {
298 $r = fopen(VAR_FILES
. $p . $l['hash'], 'r');
300 print fread($r, 1024);
305 } elseif (strcmp($_POST['action'], 'bug_report_info') == 0) {
306 echo jirafeau_admin_bug_report($cfg);
310 require(JIRAFEAU_ROOT
.'lib/template/footer.php');
312 require(JIRAFEAU_ROOT
. 'lib/template/header.php');
313 jirafeau_fatal_error(t('ACCESS_KO'), $cfg);
patrick-canterino.de