X-Git-Url: https://git.p6c8.net/jirafeau_project.git/blobdiff_plain/3d9792a36b5bb18d24216eea4b0ad402358db997..ca3530a0f3710ccd12247f008b3257d0c1ccd251:/admin.php
diff --git a/admin.php b/admin.php
old mode 100755
new mode 100644
index 56db0e5..f8270a2
--- a/admin.php
+++ b/admin.php
@@ -1,7 +1,9 @@
+ * Copyright (C) 2008 Julien "axolotl" BERNARD
+ * Copyright (C) 2015 Jerome Jutteau
+ * Copyright (C) 2024 Jirafeau project (see AUTHORS.md)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -14,289 +16,302 @@
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
+ * along with this program. If not, see .
*/
-
-define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/');
+session_start();
+define('JIRAFEAU_ROOT', dirname(__FILE__) . '/');
-require (JIRAFEAU_ROOT . 'lib/config.original.php');
-require (JIRAFEAU_ROOT . 'lib/settings.php');
-require (JIRAFEAU_ROOT . 'lib/functions.php');
-require (JIRAFEAU_ROOT . 'lib/lang.php');
+require(JIRAFEAU_ROOT . 'lib/settings.php');
+require(JIRAFEAU_ROOT . 'lib/functions.php');
+require(JIRAFEAU_ROOT . 'lib/lang.php');
/* Check if installation is OK. */
-if (file_exists (JIRAFEAU_ROOT . 'install.php')
- && !file_exists (JIRAFEAU_ROOT . 'lib/config.local.php'))
-{
- header('Location: install.php');
+if (file_exists(JIRAFEAU_ROOT . 'install.php')
+ && !file_exists(JIRAFEAU_ROOT . 'lib/config.local.php')) {
+ header('Location: install.php');
exit;
}
-/* Check if the install.php script is still in the directory. */
-if (file_exists (JIRAFEAU_ROOT . 'install.php'))
-{
- require (JIRAFEAU_ROOT . 'lib/template/header.php');
- echo '
'.
- t('Installer script still present') .
- '
';
- require (JIRAFEAU_ROOT.'lib/template/footer.php');
- exit;
-}
-
-/* Disable admin interface if we have a empty admin password. */
-if (!$cfg['admin_password'])
-{
- require (JIRAFEAU_ROOT . 'lib/template/header.php');
- echo '
'.
- t('Sorry, the admin interface is not enabled.') .
- '
';
- require (JIRAFEAU_ROOT.'lib/template/footer.php');
- exit;
+/* If called from CLI, no password or graphical interface */
+if (php_sapi_name() == "cli") {
+ if ($cfg['installation_done'] == false) {
+ die("Installation not completed yet.\n");
+ }
+ if ((count($argv) > 1) && $argv[1] == 'clean_expired') {
+ $total = jirafeau_admin_clean();
+ echo "$total expired files deleted.\n";
+ } elseif ((count($argv) > 1) && $argv[1] == 'clean_async') {
+ $total = jirafeau_admin_clean_async();
+ echo "$total old unfinished transfers deleted.\n";
+ } else {
+ die("No command found. Should be admin.php .\n");
+ }
}
-
-/* Check session. */
-session_start();
-
-/* Unlog if asked. */
-if (isset ($_POST['action']) && (strcmp ($_POST['action'], 'logout') == 0))
- $_SESSION['admin_auth'] = false;
-
-/* Check password. */
-if (isset ($_POST['admin_password']))
-{
- if (strcmp ($cfg['admin_password'], $_POST['admin_password']) == 0)
- $_SESSION['admin_auth'] = true;
- else
- {
- $_SESSION['admin_auth'] = false;
- require (JIRAFEAU_ROOT . 'lib/template/header.php');
+/* Second check: Challenge by IP */
+elseif (true === jirafeau_challenge_admin_ip($cfg, get_ip_address($cfg))) {
+ /* Disable admin interface if we have a empty admin password. */
+ if (empty($cfg['admin_password']) && empty($cfg['admin_http_auth_user'])) {
+ require(JIRAFEAU_ROOT . 'lib/template/header.php');
echo '