Files

88 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2022-11-30 12:33:23 +00:00
<?php
/*
* This file is part of Chevereto.
*
* (c) Rodolfo Berrios <rodolfo@chevereto.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2025-05-13 16:49:51 +00:00
use Chevere\ThrowableHandler\ThrowableHandler;
2024-12-05 13:33:13 +00:00
use function Chevereto\Legacy\getCheveretoEnv;
2022-11-30 12:33:23 +00:00
use function Chevereto\Legacy\loaderHandler;
if (PHP_SAPI !== 'cli') {
header('HTTP/1.0 403 Forbidden');
2024-10-24 14:11:04 +00:00
echo '403 Forbidden';
exit(255);
2022-11-30 12:33:23 +00:00
}
$opts = getopt('C:') ?: [];
if ($opts === []) {
2024-10-24 14:11:04 +00:00
echo 'Missing -C command' . PHP_EOL;
exit(255);
}
$access = $opts['C'];
$options = [
2025-05-13 16:49:51 +00:00
'bulk-importer',
'cache-view',
'cache-flush',
2024-10-24 14:11:04 +00:00
'cron',
'decrypt-secrets',
2025-05-13 16:49:51 +00:00
'encrypt-secrets',
2024-10-24 14:11:04 +00:00
'htaccess-checksum',
'htaccess-enforce',
'install',
'js',
2025-05-13 16:49:51 +00:00
'langs',
2024-10-24 14:11:04 +00:00
'password-reset',
'setting-get',
'setting-update',
2025-12-09 16:07:48 +00:00
'database-migrate',
2024-10-24 14:11:04 +00:00
'version',
2026-04-08 17:03:15 +00:00
'version-installed',
2025-12-09 16:07:48 +00:00
'stats',
'stats-rebuild',
2024-10-24 14:11:04 +00:00
];
2025-12-09 16:07:48 +00:00
$aliases = [
'update' => 'database-migrate',
];
if (array_key_exists($access, $aliases)) {
$originalAccess = $access;
$access = $aliases[$access];
echo <<<PLAIN
Note: The "{$originalAccess}" command is now aliased to "{$access}"
PLAIN;
}
2024-10-24 14:11:04 +00:00
if (! in_array($access, $options, true)) {
2025-12-09 16:07:48 +00:00
echo <<<PLAIN
Invalid command
PLAIN;
2024-10-24 14:11:04 +00:00
exit(255);
2022-11-30 12:33:23 +00:00
}
2025-05-13 16:49:51 +00:00
if (defined('APP_BIN_LEGACY')) {
2025-12-09 16:07:48 +00:00
echo <<<PLAIN
Note: This CLI is migrating to app/bin/cli
PLAIN;
2025-05-13 16:49:51 +00:00
}
2025-12-09 16:07:48 +00:00
$access = $aliases[$access] ?? $access;
2022-11-30 12:33:23 +00:00
define('ACCESS', $access);
require_once __DIR__ . '/../load/php-boot.php';
2025-05-13 16:49:51 +00:00
set_error_handler(ThrowableHandler::ERROR_AS_EXCEPTION);
set_exception_handler(ThrowableHandler::CONSOLE);
2022-11-30 12:33:23 +00:00
require_once loaderHandler(
2024-12-05 13:33:13 +00:00
getCheveretoEnv(),
2025-05-26 15:08:35 +00:00
$_COOKIE,
2022-11-30 12:33:23 +00:00
$_FILES,
$_GET,
$_POST,
$_REQUEST,
$_SERVER,
$_SESSION ?? []
);