Files
2026-07-04 15:16:50 +02:00

69 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
if (!defined('IN_DA_PLUGIN') || IN_DA_PLUGIN !== true) {
http_response_code(403);
echo 'Forbidden';
exit;
}
define('PLUGIN_ROOT', dirname(__DIR__));
define('PLUGIN_EXEC_DIR', __DIR__);
require_once PLUGIN_EXEC_DIR . '/lib/PluginLogger.php';
PluginLogger::init(PLUGIN_ROOT . '/plugin.log');
foreach ([
'Settings.php',
'Http.php',
'DirectAdminUser.php',
'Lang.php',
'LocalizedException.php',
'CsrfGuard.php',
'RuleRepository.php',
'DirectAdminSyncRepository.php',
'DirectAdminVacationApi.php',
'DirectAdminVacationSyncService.php',
'RuleValidator.php',
'MailboxDirectory.php',
'AuditLog.php',
'AppContext.php',
] as $file) {
require_once PLUGIN_EXEC_DIR . '/lib/' . $file;
}
require_once PLUGIN_EXEC_DIR . '/handlers/_form_helpers.php';
try {
Http::bootstrapGlobals();
$settings = Settings::load(Settings::EXTERNAL_SETTINGS);
$user = DirectAdminUser::fromEnvironment($settings);
$lang = Lang::load($user->language(), $settings);
if (!$user->hasPluginAccess($settings)) {
http_response_code(403);
echo 'Plugin is not enabled for this account.';
exit;
}
$secret = $settings->loadOrCreateSecret();
$csrf = new CsrfGuard($secret, $user->username(), (string)($_SERVER['SESSION_ID'] ?? getenv('SESSION_ID') ?: ''));
$ctx = new AppContext($user, $settings, new RuleRepository(), $csrf, $lang, new AuditLog());
$action = basename((string)PLUGIN_ACTION);
$handlerPath = PLUGIN_EXEC_DIR . '/handlers/' . $action . '.php';
if (!is_file($handlerPath)) {
throw new RuntimeException('Missing handler: ' . $action);
}
$handler = require $handlerPath;
if (!is_callable($handler)) {
throw new RuntimeException('Invalid handler: ' . $action);
}
$handler($ctx);
} catch (Throwable $e) {
PluginLogger::exception($e, 'BOOTSTRAP');
http_response_code(500);
header('Content-Type: text/html; charset=UTF-8');
echo '<!doctype html><html><head><meta charset="utf-8"><title>Błąd</title></head><body>';
echo '<h1>Błąd pluginu</h1><p>' . htmlspecialchars($e->getMessage(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . '</p>';
echo '</body></html>';
}