feat: implement global autoresponder plugin
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?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__);
|
||||
|
||||
foreach ([
|
||||
'Settings.php',
|
||||
'Http.php',
|
||||
'DirectAdminUser.php',
|
||||
'Lang.php',
|
||||
'LocalizedException.php',
|
||||
'CsrfGuard.php',
|
||||
'RuleRepository.php',
|
||||
'DirectAdminSyncRepository.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 {
|
||||
$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) {
|
||||
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>';
|
||||
}
|
||||
Reference in New Issue
Block a user