#!/usr/local/bin/php backendMode() !== 'da') { echo "DirectAdmin backend is not active; nothing to sync.\n"; exit(0); } $users = $targetUser !== '' ? [$targetUser] : users_with_rules(Settings::DATA_DIR); $service = new DirectAdminVacationSyncService( new RuleRepository(), new DirectAdminSyncRepository(), new MailboxDirectory(), new DirectAdminVacationApi() ); foreach ($users as $username) { $service->syncUser($username); echo "Synced {$username}\n"; } exit(0); } catch (Throwable $e) { fwrite(STDERR, "DirectAdmin vacation synchronization failed: " . $e->getMessage() . "\n"); exit(1); } /** @return string[] */ function users_with_rules(string $baseDir): array { $dir = rtrim($baseDir, '/') . '/users'; if (!is_dir($dir)) { return []; } $users = []; foreach (scandir($dir) ?: [] as $entry) { if ($entry === '.' || $entry === '..' || !preg_match('/^[A-Za-z0-9._-]+$/', $entry)) { continue; } if (is_file($dir . '/' . $entry . '/rules.json')) { $users[] = $entry; } } sort($users); return $users; }