An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
refactor(database): split import form into Livewire child
Andras Bacsai322bf7c1b2a0
diff --git a/app/Livewire/Project/Application/ServerStatusBadge.php b/app/Livewire/Project/Application/ServerStatusBadge.phpnew file mode 100644index 0000000000..459271e288--- /dev/null+++ b/app/Livewire/Project/Application/ServerStatusBadge.php@@ -0,0 +1,41 @@+<?php++namespace App\Livewire\Project\Application;++use App\Models\Application;+use Illuminate\Contracts\View\View;+use Illuminate\Support\Facades\Auth;+use Livewire\Component;++class ServerStatusBadge extends Component+{+ public Application $application;++ public function getListeners(): array+ {+ $user = Auth::user();+ if (! $user) {+ return [];+ }++ $team = $user->currentTeam();+ if (! $team) {+ return [];+ }++ return [+ "echo-private:team.{$team->id},ServiceStatusChanged" => 'refreshStatus',+ "echo-private:team.{$team->id},ServiceChecked" => 'refreshStatus',+ ];+ }++ public function refreshStatus(): void+ {+ $this->application->refresh();+ }++ public function render(): View+ {+ return view('livewire.project.application.server-status-badge');+ }+}diff --git a/app/Livewire/Project/Database/Import.php b/app/Livewire/Project/Database/Import.phpindex 304de62ef1..ea04658cfd 100644--- a/app/Livewire/Project/Database/Import.php+++ b/app/Livewire/Project/Database/Import.php@@ -2,22 +2,14 @@namespace App\Livewire\Project\Database;-use App\Models\S3Storage;-use App\Models\Server;-use App\Models\Service;use App\Models\ServiceDatabase;use App\Models\StandaloneClickhouse;use App\Models\StandaloneDragonfly;use App\Models\StandaloneKeydb;-use App\Models\StandaloneMariadb;-use App\Models\StandaloneMongodb;-use App\Models\StandaloneMysql;-use App\Models\StandalonePostgresql;use App\Models\StandaloneRedis;-use App\Support\ValidationPatterns;+use Illuminate\Contracts\View\View;use Illuminate\Foundation\Auth\Access\AuthorizesRequests;-use Illuminate\Support\Facades\Storage;-use Livewire\Attributes\Computed;+use Illuminate\Support\Facades\Auth;use Livewire\Attributes\Locked;use Livewire\Component;@@ -25,797 +17,134 @@ class Import extends Component{use AuthorizesRequests;- /**- * Validate that a string is safe for use as an S3 bucket name.- * Allows alphanumerics, dots, dashes, and underscores.- */- private function validateBucketName(string $bucket): bool- {- return preg_match('/^[a-zA-Z0-9.\-_]+$/', $bucket) === 1;- }-- /**- * Validate that a string is safe for use as an S3 path.- * Allows alphanumerics, dots, dashes, underscores, slashes, and common file characters.- */- private function validateS3Path(string $path): bool- {- // Must not be empty- if (empty($path)) {- return false;- }-- // Must not contain dangerous shell metacharacters or command injection patterns- $dangerousPatterns = [- '..', // Directory traversal- '$(', // Command substitution- '`', // Backtick command substitution- '|', // Pipe- ';', // Command separator- '&', // Background/AND- '>', // Redirect- '<', // Redirect- "\n", // Newline- "\r", // Carriage return- "\0", // Null byte- "'", // Single quote- '"', // Double quote- '\\', // Backslash- ];-- foreach ($dangerousPatterns as $pattern) {- if (str_contains($path, $pattern)) {- return false;- }- }-- // Allow alphanumerics, dots, dashes, underscores, slashes, spaces, plus, equals, at- return preg_match('/^[a-zA-Z0-9.\-_\/\s+@=]+$/', $path) === 1;- }-- /**- * Validate that a string is safe for use as a file path on the server.- */- private function validateServerPath(string $path): bool- {- // Must be an absolute path- if (! str_starts_with($path, '/')) {- return false;- }-- // Must not contain dangerous shell metacharacters or command injection patterns- $dangerousPatterns = [- '..', // Directory traversal- '$(', // Command substitution- '`', // Backtick command substitution- '|', // Pipe- ';', // Command separator- '&', // Background/AND- '>', // Redirect- '<', // Redirect- "\n", // Newline- "\r", // Carriage return- "\0", // Null byte- "'", // Single quote- '"', // Double quote- '\\', // Backslash- ];-- foreach ($dangerousPatterns as $pattern) {- if (str_contains($path, $pattern)) {- return false;- }- }-- // Allow alphanumerics, dots, dashes, underscores, slashes, and spaces- return preg_match('/^[a-zA-Z0-9.\-_\/\s]+$/', $path) === 1;- }-- public bool $unsupported = false;-- // Store IDs instead of models for proper Livewire serialization#[Locked]public ?int $resourceId = null;#[Locked]public ?string $resourceType = null;- #[Locked]- public ?int $serverId = null;-- // View-friendly properties to avoid computed property access in Blade- #[Locked]- public string $resourceUuid = '';-public string $resourceStatus = '';- #[Locked]- public string $resourceDbType = '';-- public array $parameters = [];-- public array $containers = [];-- public bool $scpInProgress = false;-- public bool $importRunning = false;-- public ?string $filename = null;-- public ?string $filesize = null;-- public bool $isUploading = false;-- public int $progress = 0;-- public bool $error = false;-- #[Locked]- public string $container;-- public array $importCommands = [];-- public bool $dumpAll = false;-- public string $restoreCommandText = '';-- public string $customLocation = '';-- public ?int $activityId = null;-- public string $postgresqlRestoreCommand = 'pg_restore -U $POSTGRES_USER -d ${POSTGRES_DB:-${POSTGRES_USER:-postgres}}';-- public string $mysqlRestoreCommand = 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE';-- public string $mariadbRestoreCommand = 'mariadb -u $MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE';-- public string $mongodbRestoreCommand = 'mongorestore --authenticationDatabase=admin --username $MONGO_INITDB_ROOT_USERNAME --password $MONGO_INITDB_ROOT_PASSWORD --uri mongodb://localhost:27017 --gzip --archive=';+ public string $resourceUuid = '';- // S3 Restore properties- public array $availableS3Storages = [];+ public bool $unsupported = false;- public ?int $s3StorageId = null;+ public function getListeners(): array+ {+ $listeners = ['databaseUpdated' => 'refreshStatus'];- public string $s3Path = '';+ $user = Auth::user();+ if (! $user) {+ return $listeners;+ }- public ?int $s3FileSize = null;+ $listeners["echo-private:user.{$user->id},DatabaseStatusChanged"] = 'refreshStatus';- #[Computed]- public function resource()- {- if ($this->resourceId === null || $this->resourceType === null) {- return null;+ $team = $user->currentTeam();+ if ($team) {+ $listeners["echo-private:team.{$team->id},ServiceChecked"] = 'refreshStatus';}- return $this->resourceType::find($this->resourceId);+ return $listeners;}- #[Computed]- public function server()+ public function mount(): void{- if ($this->serverId === null) {- return null;- }-- return Server::ownedByCurrentTeam()->find($this->serverId);- }+ $resource = $this->resolveResourceFromRoute();+ $this->authorize('view', $resource);- protected $listeners = [- 'slideOverClosed' => 'resetActivityId',- ];+ $this->resourceId = $resource->id;+ $this->resourceType = get_class($resource);- public function resetActivityId()- {- $this->activityId = null;+ $this->refreshStatus();}- public function mount()+ public function refreshStatus(): void{- $this->parameters = get_route_parameters();- $this->getContainers();- $this->loadAvailableS3Storages();+ $resource = $this->resolveStoredResource();+ $this->authorize('view', $resource);++ $resource->refresh();+ $this->resourceUuid = $resource->uuid;+ $this->resourceStatus = $resource->status ?? '';+ $this->unsupported = $this->isUnsupportedResource($resource);}- public function updatedDumpAll($value)+ public function render(): View{- $morphClass = $this->resource->getMorphClass();-- // Handle ServiceDatabase by checking the database type- if ($morphClass === ServiceDatabase::class) {- $dbType = $this->resource->databaseType();- if (str_contains($dbType, 'mysql')) {- $morphClass = 'mysql';- } elseif (str_contains($dbType, 'mariadb')) {- $morphClass = 'mariadb';- } elseif (str_contains($dbType, 'postgres')) {- $morphClass = 'postgresql';- }- }-- switch ($morphClass) {- case StandaloneMariadb::class:- case 'mariadb':- if ($value === true) {- $this->mariadbRestoreCommand = <<<'EOD'-for pid in $(mariadb -u root -p$MARIADB_ROOT_PASSWORD -N -e "SELECT id FROM information_schema.processlist WHERE user != 'root';"); do- mariadb -u root -p$MARIADB_ROOT_PASSWORD -e "KILL $pid" 2>/dev/null || true-done && \-mariadb -u root -p$MARIADB_ROOT_PASSWORD -N -e "SELECT CONCAT('DROP DATABASE IF EXISTS \`',schema_name,'\`;') FROM information_schema.schemata WHERE schema_name NOT IN ('information_schema','mysql','performance_schema','sys');" | mariadb -u root -p$MARIADB_ROOT_PASSWORD && \-mariadb -u root -p$MARIADB_ROOT_PASSWORD -e "CREATE DATABASE IF NOT EXISTS \`${MARIADB_DATABASE:-default}\`;" && \-(gunzip -cf $tmpPath 2>/dev/null || cat $tmpPath) | sed -e '/^CREATE DATABASE/d' -e '/^USE \`mysql\`/d' | mariadb -u root -p$MARIADB_ROOT_PASSWORD ${MARIADB_DATABASE:-default}-EOD;- $this->restoreCommandText = $this->mariadbRestoreCommand.' && (gunzip -cf <temp_backup_file> 2>/dev/null || cat <temp_backup_file>) | mariadb -u root -p$MARIADB_ROOT_PASSWORD ${MARIADB_DATABASE:-default}';- } else {- $this->mariadbRestoreCommand = 'mariadb -u $MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE';- }- break;- case StandaloneMysql::class:- case 'mysql':- if ($value === true) {- $this->mysqlRestoreCommand = <<<'EOD'-for pid in $(mysql -u root -p$MYSQL_ROOT_PASSWORD -N -e "SELECT id FROM information_schema.processlist WHERE user != 'root';"); do- mysql -u root -p$MYSQL_ROOT_PASSWORD -e "KILL $pid" 2>/dev/null || true-done && \-mysql -u root -p$MYSQL_ROOT_PASSWORD -N -e "SELECT CONCAT('DROP DATABASE IF EXISTS \`',schema_name,'\`;') FROM information_schema.schemata WHERE schema_name NOT IN ('information_schema','mysql','performance_schema','sys');" | mysql -u root -p$MYSQL_ROOT_PASSWORD && \-mysql -u root -p$MYSQL_ROOT_PASSWORD -e "CREATE DATABASE IF NOT EXISTS \`${MYSQL_DATABASE:-default}\`;" && \-(gunzip -cf $tmpPath 2>/dev/null || cat $tmpPath) | sed -e '/^CREATE DATABASE/d' -e '/^USE \`mysql\`/d' | mysql -u root -p$MYSQL_ROOT_PASSWORD ${MYSQL_DATABASE:-default}-EOD;- $this->restoreCommandText = $this->mysqlRestoreCommand.' && (gunzip -cf <temp_backup_file> 2>/dev/null || cat <temp_backup_file>) | mysql -u root -p$MYSQL_ROOT_PASSWORD ${MYSQL_DATABASE:-default}';- } else {- $this->mysqlRestoreCommand = 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE';- }- break;- case StandalonePostgresql::class:- case 'postgresql':- if ($value === true) {- $this->postgresqlRestoreCommand = <<<'EOD'-psql -U ${POSTGRES_USER} -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname IS NOT NULL AND pid <> pg_backend_pid()" && \-psql -U ${POSTGRES_USER} -t -c "SELECT datname FROM pg_database WHERE NOT datistemplate" | xargs -I {} dropdb -U ${POSTGRES_USER} --if-exists {} && \-createdb -U ${POSTGRES_USER} ${POSTGRES_DB:-${POSTGRES_USER:-postgres}}-EOD;- $this->restoreCommandText = $this->postgresqlRestoreCommand.' && (gunzip -cf <temp_backup_file> 2>/dev/null || cat <temp_backup_file>) | psql -U ${POSTGRES_USER} -d ${POSTGRES_DB:-${POSTGRES_USER:-postgres}}';- } else {- $this->postgresqlRestoreCommand = 'pg_restore -U ${POSTGRES_USER} -d ${POSTGRES_DB:-${POSTGRES_USER:-postgres}}';- }- break;- }-+ return view('livewire.project.database.import');}- public function getContainers()+ private function resolveResourceFromRoute(): object{- $this->containers = [];- $teamId = data_get(auth()->user()->currentTeam(), 'id');+ $parameters = get_route_parameters();+ $teamId = data_get(Auth::user()?->currentTeam(), 'id');+ $databaseUuid = data_get($parameters, 'database_uuid');+ $stackServiceUuid = data_get($parameters, 'stack_service_uuid');- // Try to find resource by route parameter- $databaseUuid = data_get($this->parameters, 'database_uuid');- $stackServiceUuid = data_get($this->parameters, 'stack_service_uuid');-- $resource = null;if ($databaseUuid) {- // Standalone database route$resource = getResourceByUuid($databaseUuid, $teamId);- if (is_null($resource)) {- abort(404);+ if ($resource) {+ return $resource;}- } elseif ($stackServiceUuid) {- // ServiceDatabase route - look up the service database- $serviceUuid = data_get($this->parameters, 'service_uuid');++ abort(404);+ }++ if ($stackServiceUuid) {$project = currentTeam()->projects()->select('id', 'uuid', 'team_id')- ->where('uuid', data_get($this->parameters, 'project_uuid'))+ ->where('uuid', data_get($parameters, 'project_uuid'))->firstOrFail();$environment = $project->environments()->select('id', 'uuid', 'name', 'project_id')- ->where('uuid', data_get($this->parameters, 'environment_uuid'))+ ->where('uuid', data_get($parameters, 'environment_uuid'))->firstOrFail();- $service = $environment->services()->whereUuid($serviceUuid)->firstOrFail();+ $service = $environment->services()->whereUuid(data_get($parameters, 'service_uuid'))->firstOrFail();$resource = $service->databases()->whereUuid($stackServiceUuid)->first();- if (is_null($resource)) {- abort(404);- }- } else {- abort(404);- }-- $this->authorize('view', $resource);-- // Store IDs for Livewire serialization- $this->resourceId = $resource->id;- $this->resourceType = get_class($resource);-- // Store view-friendly properties- $this->resourceStatus = $resource->status ?? '';-- // Handle ServiceDatabase server access differently- if ($resource->getMorphClass() === ServiceDatabase::class) {- $server = $resource->service?->server;- if (! $server) {- abort(404, 'Server not found for this service database.');- }- $this->serverId = $server->id;- $this->container = $resource->name.'-'.$resource->service->uuid;- $this->resourceUuid = $resource->uuid; // Use ServiceDatabase's own UUID-- // Determine database type for ServiceDatabase- $dbType = $resource->databaseType();- if (str_contains($dbType, 'postgres')) {- $this->resourceDbType = 'standalone-postgresql';- } elseif (str_contains($dbType, 'mysql')) {- $this->resourceDbType = 'standalone-mysql';- } elseif (str_contains($dbType, 'mariadb')) {- $this->resourceDbType = 'standalone-mariadb';- } elseif (str_contains($dbType, 'mongo')) {- $this->resourceDbType = 'standalone-mongodb';- } else {- $this->resourceDbType = $dbType;+ if ($resource) {+ return $resource;}- } else {- $server = $resource->destination?->server;- if (! $server) {- abort(404, 'Server not found for this database.');- }- $this->serverId = $server->id;- $this->container = $resource->uuid;- $this->resourceUuid = $resource->uuid;- $this->resourceDbType = $resource->type();- }-- if (str($resource->status)->startsWith('running')) {- $this->containers[] = $this->container;}- if (- $resource->getMorphClass() === StandaloneRedis::class ||- $resource->getMorphClass() === StandaloneKeydb::class ||- $resource->getMorphClass() === StandaloneDragonfly::class ||- $resource->getMorphClass() === StandaloneClickhouse::class- ) {- $this->unsupported = true;- }-- // Mark unsupported ServiceDatabase types (Redis, KeyDB, etc.)- if ($resource->getMorphClass() === ServiceDatabase::class) {- $dbType = $resource->databaseType();- if (str_contains($dbType, 'redis') || str_contains($dbType, 'keydb') ||- str_contains($dbType, 'dragonfly') || str_contains($dbType, 'clickhouse')) {- $this->unsupported = true;- }- }+ abort(404);}- public function checkFile()+ private function resolveStoredResource(): object{- if (filled($this->customLocation)) {- // Validate the custom location to prevent command injection- if (! $this->validateServerPath($this->customLocation)) {- $this->dispatch('error', 'Invalid file path. Path must be absolute and contain only safe characters (alphanumerics, dots, dashes, underscores, slashes).');-- return;- }-- if (! $this->server) {- $this->dispatch('error', 'Server not found. Please refresh the page.');-- return;- }-- try {- $escapedPath = escapeshellarg($this->customLocation);- $result = instant_remote_process(["ls -l {$escapedPath}"], $this->server, throwError: false);- if (blank($result)) {- $this->dispatch('error', 'The file does not exist or has been deleted.');-- return;- }- $this->filename = $this->customLocation;- $this->dispatch('success', 'The file exists.');- } catch (\Throwable $e) {- return handleError($e, $this);- }- }- }-- public function runImport(string $password = ''): bool|string- {- if (! verifyPasswordConfirmation($password, $this)) {- return 'The provided password is incorrect.';- }-- $this->authorize('update', $this->resource);-- if (! ValidationPatterns::isValidContainerName($this->container)) {- $this->dispatch('error', 'Invalid container name.');-- return true;- }-- if ($this->filename === '') {- $this->dispatch('error', 'Please select a file to import.');-- return true;- }-- if (! $this->server) {- $this->dispatch('error', 'Server not found. Please refresh the page.');-- return true;- }-- try {- $this->importRunning = true;- $this->importCommands = [];- $backupFileName = "upload/{$this->resourceUuid}/restore";-- // Check if an uploaded file exists first (takes priority over custom location)- if (Storage::exists($backupFileName)) {- $path = Storage::path($backupFileName);- $tmpPath = '/tmp/'.basename($backupFileName).'_'.$this->resourceUuid;- instant_scp($path, $tmpPath, $this->server);- Storage::delete($backupFileName);- $this->importCommands[] = "docker cp {$tmpPath} {$this->container}:{$tmpPath}";- } elseif (filled($this->customLocation)) {- // Validate the custom location to prevent command injection- if (! $this->validateServerPath($this->customLocation)) {- $this->dispatch('error', 'Invalid file path. Path must be absolute and contain only safe characters.');-- return true;- }- $tmpPath = '/tmp/restore_'.$this->resourceUuid;- $escapedCustomLocation = escapeshellarg($this->customLocation);- $this->importCommands[] = "docker cp {$escapedCustomLocation} {$this->container}:{$tmpPath}";- } else {- $this->dispatch('error', 'The file does not exist or has been deleted.');-- return true;- }-- // Copy the restore command to a script file- $scriptPath = "/tmp/restore_{$this->resourceUuid}.sh";-- $restoreCommand = $this->buildRestoreCommand($tmpPath);-- $restoreCommandBase64 = base64_encode($restoreCommand);- $this->importCommands[] = "echo \"{$restoreCommandBase64}\" | base64 -d > {$scriptPath}";- $this->importCommands[] = "chmod +x {$scriptPath}";- $this->importCommands[] = "docker cp {$scriptPath} {$this->container}:{$scriptPath}";-- $this->importCommands[] = "docker exec {$this->container} sh -c '{$scriptPath}'";- $this->importCommands[] = "docker exec {$this->container} sh -c 'echo \"Import finished with exit code $?\"'";-- if (! empty($this->importCommands)) {- $activity = remote_process($this->importCommands, $this->server, ignore_errors: true, callEventOnFinish: 'RestoreJobFinished', callEventData: [- 'scriptPath' => $scriptPath,- 'tmpPath' => $tmpPath,- 'container' => $this->container,- 'serverId' => $this->server->id,- ]);-- // Track the activity ID- $this->activityId = $activity->id;-- // Dispatch activity to the monitor and open slide-over- $this->dispatch('activityMonitor', $activity->id);- $this->dispatch('databaserestore');- }- } catch (\Throwable $e) {- handleError($e, $this);-- return true;- } finally {- $this->filename = null;- $this->importCommands = [];- }-- return true;- }-- public function loadAvailableS3Storages()- {- try {- $this->availableS3Storages = S3Storage::ownedByCurrentTeam(['id', 'name', 'description'])- ->where('is_usable', true)- ->get()- ->map(fn ($s) => ['id' => $s->id, 'name' => $s->name, 'description' => $s->description])- ->toArray();- } catch (\Throwable $e) {- $this->availableS3Storages = [];- }- }-- public function updatedS3Path($value)- {- // Reset validation state when path changes- $this->s3FileSize = null;-- // Ensure path starts with a slash- if ($value !== null && $value !== '') {- $this->s3Path = str($value)->trim()->start('/')->value();- }- }-- public function updatedS3StorageId()- {- // Reset validation state when storage changes- $this->s3FileSize = null;- }-- public function checkS3File()- {- if (! $this->s3StorageId) {- $this->dispatch('error', 'Please select an S3 storage.');-- return;- }-- if (blank($this->s3Path)) {- $this->dispatch('error', 'Please provide an S3 path.');-- return;+ if ($this->resourceId === null || $this->resourceType === null) {+ return $this->resolveResourceFromRoute();}- // Clean the path (remove leading slash if present)- $cleanPath = ltrim($this->s3Path, '/');-- // Validate the S3 path early to prevent command injection in subsequent operations- if (! $this->validateS3Path($cleanPath)) {- $this->dispatch('error', 'Invalid S3 path. Path must contain only safe characters (alphanumerics, dots, dashes, underscores, slashes).');-- return;+ $resource = $this->resourceType::find($this->resourceId);+ if ($resource) {+ return $resource;}- try {- $s3Storage = S3Storage::ownedByCurrentTeam()->findOrFail($this->s3StorageId);-- // Validate bucket name early- if (! $this->validateBucketName($s3Storage->bucket)) {- $this->dispatch('error', 'Invalid S3 bucket name. Bucket name must contain only alphanumerics, dots, dashes, and underscores.');-- return;- }-- // Test connection- $s3Storage->testConnection();-- // Build S3 disk configuration- $disk = Storage::build([- 'driver' => 's3',- 'region' => $s3Storage->region,- 'key' => $s3Storage->key,- 'secret' => $s3Storage->secret,- 'bucket' => $s3Storage->bucket,- 'endpoint' => $s3Storage->endpoint,- 'use_path_style_endpoint' => true,- ]);-- // Check if file exists- if (! $disk->exists($cleanPath)) {- $this->dispatch('error', 'File not found in S3. Please check the path.');-- return;- }-- // Get file size- $this->s3FileSize = $disk->size($cleanPath);-- $this->dispatch('success', 'File found in S3. Size: '.formatBytes($this->s3FileSize));- } catch (\Throwable $e) {- $this->s3FileSize = null;-- return handleError($e, $this);- }+ abort(404);}- public function restoreFromS3(string $password = ''): bool|string+ private function isUnsupportedResource(object $resource): bool{- if (! verifyPasswordConfirmation($password, $this)) {- return 'The provided password is incorrect.';- }-- $this->authorize('update', $this->resource);-- if (! ValidationPatterns::isValidContainerName($this->container)) {- $this->dispatch('error', 'Invalid container name.');-- return true;- }-- if (! $this->s3StorageId || blank($this->s3Path)) {- $this->dispatch('error', 'Please select S3 storage and provide a path first.');-- return true;- }-- if (is_null($this->s3FileSize)) {- $this->dispatch('error', 'Please check the file first by clicking "Check File".');-- return true;- }-- if (! $this->server) {- $this->dispatch('error', 'Server not found. Please refresh the page.');-- return true;- }-- try {- $this->importRunning = true;-- $s3Storage = S3Storage::ownedByCurrentTeam()->findOrFail($this->s3StorageId);-- $key = $s3Storage->key;- $secret = $s3Storage->secret;- $bucket = $s3Storage->bucket;- $endpoint = $s3Storage->endpoint;-- // Validate bucket name to prevent command injection- if (! $this->validateBucketName($bucket)) {- $this->dispatch('error', 'Invalid S3 bucket name. Bucket name must contain only alphanumerics, dots, dashes, and underscores.');-- return true;- }-- // Clean the S3 path- $cleanPath = ltrim($this->s3Path, '/');-- // Validate the S3 path to prevent command injection- if (! $this->validateS3Path($cleanPath)) {- $this->dispatch('error', 'Invalid S3 path. Path must contain only safe characters (alphanumerics, dots, dashes, underscores, slashes).');-- return true;- }-- // Get helper image- $helperImage = config('constants.coolify.helper_image');- $latestVersion = getHelperVersion();- $fullImageName = "{$helperImage}:{$latestVersion}";-- // Get the database destination network- if ($this->resource->getMorphClass() === ServiceDatabase::class) {- $destinationNetwork = $this->resource->service->destination->network ?? 'coolify';- } else {- $destinationNetwork = $this->resource->destination->network ?? 'coolify';- }-- // Generate unique names for this operation- $containerName = "s3-restore-{$this->resourceUuid}";- $helperTmpPath = '/tmp/'.basename($cleanPath);- $serverTmpPath = "/tmp/s3-restore-{$this->resourceUuid}-".basename($cleanPath);- $containerTmpPath = "/tmp/restore_{$this->resourceUuid}-".basename($cleanPath);- $scriptPath = "/tmp/restore_{$this->resourceUuid}.sh";-- // Prepare all commands in sequence- $commands = [];-- // 1. Clean up any existing helper container and temp files from previous runs- $commands[] = "docker rm -f {$containerName} 2>/dev/null || true";- $commands[] = "rm -f {$serverTmpPath} 2>/dev/null || true";- $commands[] = "docker exec {$this->container} rm -f {$containerTmpPath} {$scriptPath} 2>/dev/null || true";-- // 2. Start helper container on the database network- $commands[] = "docker run -d --network {$destinationNetwork} --name {$containerName} {$fullImageName} sleep 3600";-- // 3. Configure S3 access in helper container- $escapedEndpoint = escapeshellarg($endpoint);- $escapedKey = escapeshellarg($key);- $escapedSecret = escapeshellarg($secret);- $commands[] = "docker exec {$containerName} mc alias set s3temp {$escapedEndpoint} {$escapedKey} {$escapedSecret}";-- // 4. Check file exists in S3 (bucket and path already validated above)- $escapedBucket = escapeshellarg($bucket);- $escapedCleanPath = escapeshellarg($cleanPath);- $escapedS3Source = escapeshellarg("s3temp/{$bucket}/{$cleanPath}");- $commands[] = "docker exec {$containerName} mc stat {$escapedS3Source}";-- // 5. Download from S3 to helper container (progress shown by default)- $escapedHelperTmpPath = escapeshellarg($helperTmpPath);- $commands[] = "docker exec {$containerName} mc cp {$escapedS3Source} {$escapedHelperTmpPath}";-- // 6. Copy from helper to server, then immediately to database container- $commands[] = "docker cp {$containerName}:{$helperTmpPath} {$serverTmpPath}";- $commands[] = "docker cp {$serverTmpPath} {$this->container}:{$containerTmpPath}";-- // 7. Cleanup helper container and server temp file immediately (no longer needed)- $commands[] = "docker rm -f {$containerName} 2>/dev/null || true";- $commands[] = "rm -f {$serverTmpPath} 2>/dev/null || true";-- // 8. Build and execute restore command inside database container- $restoreCommand = $this->buildRestoreCommand($containerTmpPath);-- $restoreCommandBase64 = base64_encode($restoreCommand);- $commands[] = "echo \"{$restoreCommandBase64}\" | base64 -d > {$scriptPath}";- $commands[] = "chmod +x {$scriptPath}";- $commands[] = "docker cp {$scriptPath} {$this->container}:{$scriptPath}";-- // 9. Execute restore and cleanup temp files immediately after completion- $commands[] = "docker exec {$this->container} sh -c '{$scriptPath} && rm -f {$containerTmpPath} {$scriptPath}'";- $commands[] = "docker exec {$this->container} sh -c 'echo \"Import finished with exit code $?\"'";-- // Execute all commands with cleanup event (as safety net for edge cases)- $activity = remote_process($commands, $this->server, ignore_errors: true, callEventOnFinish: 'S3RestoreJobFinished', callEventData: [- 'containerName' => $containerName,- 'serverTmpPath' => $serverTmpPath,- 'scriptPath' => $scriptPath,- 'containerTmpPath' => $containerTmpPath,- 'container' => $this->container,- 'serverId' => $this->server->id,- ]);-- // Track the activity ID- $this->activityId = $activity->id;-- // Dispatch activity to the monitor and open slide-over- $this->dispatch('activityMonitor', $activity->id);- $this->dispatch('databaserestore');- $this->dispatch('info', 'Restoring database from S3. Progress will be shown in the activity monitor...');- } catch (\Throwable $e) {- $this->importRunning = false;- handleError($e, $this);-+ if (+ $resource instanceof StandaloneRedis ||+ $resource instanceof StandaloneKeydb ||+ $resource instanceof StandaloneDragonfly ||+ $resource instanceof StandaloneClickhouse+ ) {return true;}- return true;- }-- public function buildRestoreCommand(string $tmpPath): string- {- $morphClass = $this->resource->getMorphClass();-- // Handle ServiceDatabase by checking the database type- if ($morphClass === ServiceDatabase::class) {- $dbType = $this->resource->databaseType();- if (str_contains($dbType, 'mysql')) {- $morphClass = 'mysql';- } elseif (str_contains($dbType, 'mariadb')) {- $morphClass = 'mariadb';- } elseif (str_contains($dbType, 'postgres')) {- $morphClass = 'postgresql';- } elseif (str_contains($dbType, 'mongo')) {- $morphClass = 'mongodb';- }- }+ if ($resource instanceof ServiceDatabase) {+ $dbType = $resource->databaseType();- switch ($morphClass) {- case StandaloneMariadb::class:- case 'mariadb':- $restoreCommand = $this->mariadbRestoreCommand;- if ($this->dumpAll) {- $restoreCommand .= " && (gunzip -cf {$tmpPath} 2>/dev/null || cat {$tmpPath}) | mariadb -u root -p\$MARIADB_ROOT_PASSWORD \${MARIADB_DATABASE:-default}";- } else {- $restoreCommand .= " < {$tmpPath}";- }- break;- case StandaloneMysql::class:- case 'mysql':- $restoreCommand = $this->mysqlRestoreCommand;- if ($this->dumpAll) {- $restoreCommand .= " && (gunzip -cf {$tmpPath} 2>/dev/null || cat {$tmpPath}) | mysql -u root -p\$MYSQL_ROOT_PASSWORD \${MYSQL_DATABASE:-default}";- } else {- $restoreCommand .= " < {$tmpPath}";- }- break;- case StandalonePostgresql::class:- case 'postgresql':- $restoreCommand = $this->postgresqlRestoreCommand;- if ($this->dumpAll) {- $restoreCommand .= " && (gunzip -cf {$tmpPath} 2>/dev/null || cat {$tmpPath}) | psql -U \${POSTGRES_USER} -d \${POSTGRES_DB:-\${POSTGRES_USER:-postgres}}";- } else {- $restoreCommand .= " {$tmpPath}";- }- break;- case StandaloneMongodb::class:- case 'mongodb':- $restoreCommand = $this->mongodbRestoreCommand;- if ($this->dumpAll === false) {- $restoreCommand .= "{$tmpPath}";- }- break;- default:- $restoreCommand = '';+ return str_contains($dbType, 'redis') ||+ str_contains($dbType, 'keydb') ||+ str_contains($dbType, 'dragonfly') ||+ str_contains($dbType, 'clickhouse');}- return $restoreCommand;+ return false;}}diff --git a/app/Livewire/Project/Database/ImportForm.php b/app/Livewire/Project/Database/ImportForm.phpnew file mode 100644index 0000000000..1d394af879--- /dev/null+++ b/app/Livewire/Project/Database/ImportForm.php@@ -0,0 +1,821 @@+<?php++namespace App\Livewire\Project\Database;++use App\Models\S3Storage;+use App\Models\Server;+use App\Models\Service;+use App\Models\ServiceDatabase;+use App\Models\StandaloneClickhouse;+use App\Models\StandaloneDragonfly;+use App\Models\StandaloneKeydb;+use App\Models\StandaloneMariadb;+use App\Models\StandaloneMongodb;+use App\Models\StandaloneMysql;+use App\Models\StandalonePostgresql;+use App\Models\StandaloneRedis;+use App\Support\ValidationPatterns;+use Illuminate\Foundation\Auth\Access\AuthorizesRequests;+use Illuminate\Support\Facades\Storage;+use Livewire\Attributes\Computed;+use Livewire\Attributes\Locked;+use Livewire\Component;++class ImportForm extends Component+{+ use AuthorizesRequests;++ /**+ * Validate that a string is safe for use as an S3 bucket name.+ * Allows alphanumerics, dots, dashes, and underscores.+ */+ private function validateBucketName(string $bucket): bool+ {+ return preg_match('/^[a-zA-Z0-9.\-_]+$/', $bucket) === 1;+ }++ /**+ * Validate that a string is safe for use as an S3 path.+ * Allows alphanumerics, dots, dashes, underscores, slashes, and common file characters.+ */+ private function validateS3Path(string $path): bool+ {+ // Must not be empty+ if (empty($path)) {+ return false;+ }++ // Must not contain dangerous shell metacharacters or command injection patterns+ $dangerousPatterns = [+ '..', // Directory traversal+ '$(', // Command substitution+ '`', // Backtick command substitution+ '|', // Pipe+ ';', // Command separator+ '&', // Background/AND+ '>', // Redirect+ '<', // Redirect+ "\n", // Newline+ "\r", // Carriage return+ "\0", // Null byte+ "'", // Single quote+ '"', // Double quote+ '\\', // Backslash+ ];++ foreach ($dangerousPatterns as $pattern) {+ if (str_contains($path, $pattern)) {+ return false;+ }+ }++ // Allow alphanumerics, dots, dashes, underscores, slashes, spaces, plus, equals, at+ return preg_match('/^[a-zA-Z0-9.\-_\/\s+@=]+$/', $path) === 1;+ }++ /**+ * Validate that a string is safe for use as a file path on the server.+ */+ private function validateServerPath(string $path): bool+ {+ // Must be an absolute path+ if (! str_starts_with($path, '/')) {+ return false;+ }++ // Must not contain dangerous shell metacharacters or command injection patterns+ $dangerousPatterns = [+ '..', // Directory traversal+ '$(', // Command substitution+ '`', // Backtick command substitution+ '|', // Pipe+ ';', // Command separator+ '&', // Background/AND+ '>', // Redirect+ '<', // Redirect+ "\n", // Newline+ "\r", // Carriage return+ "\0", // Null byte+ "'", // Single quote+ '"', // Double quote+ '\\', // Backslash+ ];++ foreach ($dangerousPatterns as $pattern) {+ if (str_contains($path, $pattern)) {+ return false;+ }+ }++ // Allow alphanumerics, dots, dashes, underscores, slashes, and spaces+ return preg_match('/^[a-zA-Z0-9.\-_\/\s]+$/', $path) === 1;+ }++ public bool $unsupported = false;++ // Store IDs instead of models for proper Livewire serialization+ #[Locked]+ public ?int $resourceId = null;++ #[Locked]+ public ?string $resourceType = null;++ #[Locked]+ public ?int $serverId = null;++ // View-friendly properties to avoid computed property access in Blade+ #[Locked]+ public string $resourceUuid = '';++ public string $resourceStatus = '';++ #[Locked]+ public string $resourceDbType = '';++ public array $parameters = [];++ public array $containers = [];++ public bool $scpInProgress = false;++ public bool $importRunning = false;++ public ?string $filename = null;++ public ?string $filesize = null;++ public bool $isUploading = false;++ public int $progress = 0;++ public bool $error = false;++ #[Locked]+ public string $container;++ public array $importCommands = [];++ public bool $dumpAll = false;++ public string $restoreCommandText = '';++ public string $customLocation = '';++ public ?int $activityId = null;++ public string $postgresqlRestoreCommand = 'pg_restore -U $POSTGRES_USER -d ${POSTGRES_DB:-${POSTGRES_USER:-postgres}}';++ public string $mysqlRestoreCommand = 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE';++ public string $mariadbRestoreCommand = 'mariadb -u $MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE';++ public string $mongodbRestoreCommand = 'mongorestore --authenticationDatabase=admin --username $MONGO_INITDB_ROOT_USERNAME --password $MONGO_INITDB_ROOT_PASSWORD --uri mongodb://localhost:27017 --gzip --archive=';++ // S3 Restore properties+ public array $availableS3Storages = [];++ public ?int $s3StorageId = null;++ public string $s3Path = '';++ public ?int $s3FileSize = null;++ #[Computed]+ public function resource()+ {+ if ($this->resourceId === null || $this->resourceType === null) {+ return null;+ }++ return $this->resourceType::find($this->resourceId);+ }++ #[Computed]+ public function server()+ {+ if ($this->serverId === null) {+ return null;+ }++ return Server::ownedByCurrentTeam()->find($this->serverId);+ }++ protected $listeners = [+ 'slideOverClosed' => 'resetActivityId',+ ];++ public function resetActivityId()+ {+ $this->activityId = null;+ }++ public function mount()+ {+ $this->parameters = get_route_parameters();+ $this->getContainers();+ $this->loadAvailableS3Storages();+ }++ public function updatedDumpAll($value)+ {+ $morphClass = $this->resource->getMorphClass();++ // Handle ServiceDatabase by checking the database type+ if ($morphClass === ServiceDatabase::class) {+ $dbType = $this->resource->databaseType();+ if (str_contains($dbType, 'mysql')) {+ $morphClass = 'mysql';+ } elseif (str_contains($dbType, 'mariadb')) {+ $morphClass = 'mariadb';+ } elseif (str_contains($dbType, 'postgres')) {+ $morphClass = 'postgresql';+ }+ }++ switch ($morphClass) {+ case StandaloneMariadb::class:+ case 'mariadb':+ if ($value === true) {+ $this->mariadbRestoreCommand = <<<'EOD'+for pid in $(mariadb -u root -p$MARIADB_ROOT_PASSWORD -N -e "SELECT id FROM information_schema.processlist WHERE user != 'root';"); do+ mariadb -u root -p$MARIADB_ROOT_PASSWORD -e "KILL $pid" 2>/dev/null || true+done && \+mariadb -u root -p$MARIADB_ROOT_PASSWORD -N -e "SELECT CONCAT('DROP DATABASE IF EXISTS \`',schema_name,'\`;') FROM information_schema.schemata WHERE schema_name NOT IN ('information_schema','mysql','performance_schema','sys');" | mariadb -u root -p$MARIADB_ROOT_PASSWORD && \+mariadb -u root -p$MARIADB_ROOT_PASSWORD -e "CREATE DATABASE IF NOT EXISTS \`${MARIADB_DATABASE:-default}\`;" && \+(gunzip -cf $tmpPath 2>/dev/null || cat $tmpPath) | sed -e '/^CREATE DATABASE/d' -e '/^USE \`mysql\`/d' | mariadb -u root -p$MARIADB_ROOT_PASSWORD ${MARIADB_DATABASE:-default}+EOD;+ $this->restoreCommandText = $this->mariadbRestoreCommand.' && (gunzip -cf <temp_backup_file> 2>/dev/null || cat <temp_backup_file>) | mariadb -u root -p$MARIADB_ROOT_PASSWORD ${MARIADB_DATABASE:-default}';+ } else {+ $this->mariadbRestoreCommand = 'mariadb -u $MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE';+ }+ break;+ case StandaloneMysql::class:+ case 'mysql':+ if ($value === true) {+ $this->mysqlRestoreCommand = <<<'EOD'+for pid in $(mysql -u root -p$MYSQL_ROOT_PASSWORD -N -e "SELECT id FROM information_schema.processlist WHERE user != 'root';"); do+ mysql -u root -p$MYSQL_ROOT_PASSWORD -e "KILL $pid" 2>/dev/null || true+done && \+mysql -u root -p$MYSQL_ROOT_PASSWORD -N -e "SELECT CONCAT('DROP DATABASE IF EXISTS \`',schema_name,'\`;') FROM information_schema.schemata WHERE schema_name NOT IN ('information_schema','mysql','performance_schema','sys');" | mysql -u root -p$MYSQL_ROOT_PASSWORD && \+mysql -u root -p$MYSQL_ROOT_PASSWORD -e "CREATE DATABASE IF NOT EXISTS \`${MYSQL_DATABASE:-default}\`;" && \+(gunzip -cf $tmpPath 2>/dev/null || cat $tmpPath) | sed -e '/^CREATE DATABASE/d' -e '/^USE \`mysql\`/d' | mysql -u root -p$MYSQL_ROOT_PASSWORD ${MYSQL_DATABASE:-default}+EOD;+ $this->restoreCommandText = $this->mysqlRestoreCommand.' && (gunzip -cf <temp_backup_file> 2>/dev/null || cat <temp_backup_file>) | mysql -u root -p$MYSQL_ROOT_PASSWORD ${MYSQL_DATABASE:-default}';+ } else {+ $this->mysqlRestoreCommand = 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE';+ }+ break;+ case StandalonePostgresql::class:+ case 'postgresql':+ if ($value === true) {+ $this->postgresqlRestoreCommand = <<<'EOD'+psql -U ${POSTGRES_USER} -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname IS NOT NULL AND pid <> pg_backend_pid()" && \+psql -U ${POSTGRES_USER} -t -c "SELECT datname FROM pg_database WHERE NOT datistemplate" | xargs -I {} dropdb -U ${POSTGRES_USER} --if-exists {} && \+createdb -U ${POSTGRES_USER} ${POSTGRES_DB:-${POSTGRES_USER:-postgres}}+EOD;+ $this->restoreCommandText = $this->postgresqlRestoreCommand.' && (gunzip -cf <temp_backup_file> 2>/dev/null || cat <temp_backup_file>) | psql -U ${POSTGRES_USER} -d ${POSTGRES_DB:-${POSTGRES_USER:-postgres}}';+ } else {+ $this->postgresqlRestoreCommand = 'pg_restore -U ${POSTGRES_USER} -d ${POSTGRES_DB:-${POSTGRES_USER:-postgres}}';+ }+ break;+ }++ }++ public function getContainers()+ {+ $this->containers = [];+ $teamId = data_get(auth()->user()->currentTeam(), 'id');++ // Try to find resource by route parameter+ $databaseUuid = data_get($this->parameters, 'database_uuid');+ $stackServiceUuid = data_get($this->parameters, 'stack_service_uuid');++ $resource = null;+ if ($databaseUuid) {+ // Standalone database route+ $resource = getResourceByUuid($databaseUuid, $teamId);+ if (is_null($resource)) {+ abort(404);+ }+ } elseif ($stackServiceUuid) {+ // ServiceDatabase route - look up the service database+ $serviceUuid = data_get($this->parameters, 'service_uuid');+ $project = currentTeam()+ ->projects()+ ->select('id', 'uuid', 'team_id')+ ->where('uuid', data_get($this->parameters, 'project_uuid'))+ ->firstOrFail();+ $environment = $project->environments()+ ->select('id', 'uuid', 'name', 'project_id')+ ->where('uuid', data_get($this->parameters, 'environment_uuid'))+ ->firstOrFail();+ $service = $environment->services()->whereUuid($serviceUuid)->firstOrFail();+ $resource = $service->databases()->whereUuid($stackServiceUuid)->first();+ if (is_null($resource)) {+ abort(404);+ }+ } else {+ abort(404);+ }++ $this->authorize('view', $resource);++ // Store IDs for Livewire serialization+ $this->resourceId = $resource->id;+ $this->resourceType = get_class($resource);++ // Store view-friendly properties+ $this->resourceStatus = $resource->status ?? '';++ // Handle ServiceDatabase server access differently+ if ($resource->getMorphClass() === ServiceDatabase::class) {+ $server = $resource->service?->server;+ if (! $server) {+ abort(404, 'Server not found for this service database.');+ }+ $this->serverId = $server->id;+ $this->container = $resource->name.'-'.$resource->service->uuid;+ $this->resourceUuid = $resource->uuid; // Use ServiceDatabase's own UUID++ // Determine database type for ServiceDatabase+ $dbType = $resource->databaseType();+ if (str_contains($dbType, 'postgres')) {+ $this->resourceDbType = 'standalone-postgresql';+ } elseif (str_contains($dbType, 'mysql')) {+ $this->resourceDbType = 'standalone-mysql';+ } elseif (str_contains($dbType, 'mariadb')) {+ $this->resourceDbType = 'standalone-mariadb';+ } elseif (str_contains($dbType, 'mongo')) {+ $this->resourceDbType = 'standalone-mongodb';+ } else {+ $this->resourceDbType = $dbType;+ }+ } else {+ $server = $resource->destination?->server;+ if (! $server) {+ abort(404, 'Server not found for this database.');+ }+ $this->serverId = $server->id;+ $this->container = $resource->uuid;+ $this->resourceUuid = $resource->uuid;+ $this->resourceDbType = $resource->type();+ }++ if (str($resource->status)->startsWith('running')) {+ $this->containers[] = $this->container;+ }++ if (+ $resource->getMorphClass() === StandaloneRedis::class ||+ $resource->getMorphClass() === StandaloneKeydb::class ||+ $resource->getMorphClass() === StandaloneDragonfly::class ||+ $resource->getMorphClass() === StandaloneClickhouse::class+ ) {+ $this->unsupported = true;+ }++ // Mark unsupported ServiceDatabase types (Redis, KeyDB, etc.)+ if ($resource->getMorphClass() === ServiceDatabase::class) {+ $dbType = $resource->databaseType();+ if (str_contains($dbType, 'redis') || str_contains($dbType, 'keydb') ||+ str_contains($dbType, 'dragonfly') || str_contains($dbType, 'clickhouse')) {+ $this->unsupported = true;+ }+ }+ }++ public function checkFile()+ {+ if (filled($this->customLocation)) {+ // Validate the custom location to prevent command injection+ if (! $this->validateServerPath($this->customLocation)) {+ $this->dispatch('error', 'Invalid file path. Path must be absolute and contain only safe characters (alphanumerics, dots, dashes, underscores, slashes).');++ return;+ }++ if (! $this->server) {+ $this->dispatch('error', 'Server not found. Please refresh the page.');++ return;+ }++ try {+ $escapedPath = escapeshellarg($this->customLocation);+ $result = instant_remote_process(["ls -l {$escapedPath}"], $this->server, throwError: false);+ if (blank($result)) {+ $this->dispatch('error', 'The file does not exist or has been deleted.');++ return;+ }+ $this->filename = $this->customLocation;+ $this->dispatch('success', 'The file exists.');+ } catch (\Throwable $e) {+ return handleError($e, $this);+ }+ }+ }++ public function runImport(string $password = ''): bool|string+ {+ if (! verifyPasswordConfirmation($password, $this)) {+ return 'The provided password is incorrect.';+ }++ $this->authorize('update', $this->resource);++ if (! ValidationPatterns::isValidContainerName($this->container)) {+ $this->dispatch('error', 'Invalid container name.');++ return true;+ }++ if ($this->filename === '') {+ $this->dispatch('error', 'Please select a file to import.');++ return true;+ }++ if (! $this->server) {+ $this->dispatch('error', 'Server not found. Please refresh the page.');++ return true;+ }++ try {+ $this->importRunning = true;+ $this->importCommands = [];+ $backupFileName = "upload/{$this->resourceUuid}/restore";++ // Check if an uploaded file exists first (takes priority over custom location)+ if (Storage::exists($backupFileName)) {+ $path = Storage::path($backupFileName);+ $tmpPath = '/tmp/'.basename($backupFileName).'_'.$this->resourceUuid;+ instant_scp($path, $tmpPath, $this->server);+ Storage::delete($backupFileName);+ $this->importCommands[] = "docker cp {$tmpPath} {$this->container}:{$tmpPath}";+ } elseif (filled($this->customLocation)) {+ // Validate the custom location to prevent command injection+ if (! $this->validateServerPath($this->customLocation)) {+ $this->dispatch('error', 'Invalid file path. Path must be absolute and contain only safe characters.');++ return true;+ }+ $tmpPath = '/tmp/restore_'.$this->resourceUuid;+ $escapedCustomLocation = escapeshellarg($this->customLocation);+ $this->importCommands[] = "docker cp {$escapedCustomLocation} {$this->container}:{$tmpPath}";+ } else {+ $this->dispatch('error', 'The file does not exist or has been deleted.');++ return true;+ }++ // Copy the restore command to a script file+ $scriptPath = "/tmp/restore_{$this->resourceUuid}.sh";++ $restoreCommand = $this->buildRestoreCommand($tmpPath);++ $restoreCommandBase64 = base64_encode($restoreCommand);+ $this->importCommands[] = "echo \"{$restoreCommandBase64}\" | base64 -d > {$scriptPath}";+ $this->importCommands[] = "chmod +x {$scriptPath}";+ $this->importCommands[] = "docker cp {$scriptPath} {$this->container}:{$scriptPath}";++ $this->importCommands[] = "docker exec {$this->container} sh -c '{$scriptPath}'";+ $this->importCommands[] = "docker exec {$this->container} sh -c 'echo \"Import finished with exit code $?\"'";++ if (! empty($this->importCommands)) {+ $activity = remote_process($this->importCommands, $this->server, ignore_errors: true, callEventOnFinish: 'RestoreJobFinished', callEventData: [+ 'scriptPath' => $scriptPath,+ 'tmpPath' => $tmpPath,+ 'container' => $this->container,+ 'serverId' => $this->server->id,+ ]);++ // Track the activity ID+ $this->activityId = $activity->id;++ // Dispatch activity to the monitor and open slide-over+ $this->dispatch('activityMonitor', $activity->id);+ $this->dispatch('databaserestore');+ }+ } catch (\Throwable $e) {+ handleError($e, $this);++ return true;+ } finally {+ $this->filename = null;+ $this->importCommands = [];+ }++ return true;+ }++ public function loadAvailableS3Storages()+ {+ try {+ $this->availableS3Storages = S3Storage::ownedByCurrentTeam(['id', 'name', 'description'])+ ->where('is_usable', true)+ ->get()+ ->map(fn ($s) => ['id' => $s->id, 'name' => $s->name, 'description' => $s->description])+ ->toArray();+ } catch (\Throwable $e) {+ $this->availableS3Storages = [];+ }+ }++ public function updatedS3Path($value)+ {+ // Reset validation state when path changes+ $this->s3FileSize = null;++ // Ensure path starts with a slash+ if ($value !== null && $value !== '') {+ $this->s3Path = str($value)->trim()->start('/')->value();+ }+ }++ public function updatedS3StorageId()+ {+ // Reset validation state when storage changes+ $this->s3FileSize = null;+ }++ public function checkS3File()+ {+ if (! $this->s3StorageId) {+ $this->dispatch('error', 'Please select an S3 storage.');++ return;+ }++ if (blank($this->s3Path)) {+ $this->dispatch('error', 'Please provide an S3 path.');++ return;+ }++ // Clean the path (remove leading slash if present)+ $cleanPath = ltrim($this->s3Path, '/');++ // Validate the S3 path early to prevent command injection in subsequent operations+ if (! $this->validateS3Path($cleanPath)) {+ $this->dispatch('error', 'Invalid S3 path. Path must contain only safe characters (alphanumerics, dots, dashes, underscores, slashes).');++ return;+ }++ try {+ $s3Storage = S3Storage::ownedByCurrentTeam()->findOrFail($this->s3StorageId);++ // Validate bucket name early+ if (! $this->validateBucketName($s3Storage->bucket)) {+ $this->dispatch('error', 'Invalid S3 bucket name. Bucket name must contain only alphanumerics, dots, dashes, and underscores.');++ return;+ }++ // Test connection+ $s3Storage->testConnection();++ // Build S3 disk configuration+ $disk = Storage::build([+ 'driver' => 's3',+ 'region' => $s3Storage->region,+ 'key' => $s3Storage->key,+ 'secret' => $s3Storage->secret,+ 'bucket' => $s3Storage->bucket,+ 'endpoint' => $s3Storage->endpoint,+ 'use_path_style_endpoint' => true,+ ]);++ // Check if file exists+ if (! $disk->exists($cleanPath)) {+ $this->dispatch('error', 'File not found in S3. Please check the path.');++ return;+ }++ // Get file size+ $this->s3FileSize = $disk->size($cleanPath);++ $this->dispatch('success', 'File found in S3. Size: '.formatBytes($this->s3FileSize));+ } catch (\Throwable $e) {+ $this->s3FileSize = null;++ return handleError($e, $this);+ }+ }++ public function restoreFromS3(string $password = ''): bool|string+ {+ if (! verifyPasswordConfirmation($password, $this)) {+ return 'The provided password is incorrect.';+ }++ $this->authorize('update', $this->resource);++ if (! ValidationPatterns::isValidContainerName($this->container)) {+ $this->dispatch('error', 'Invalid container name.');++ return true;+ }++ if (! $this->s3StorageId || blank($this->s3Path)) {+ $this->dispatch('error', 'Please select S3 storage and provide a path first.');++ return true;+ }++ if (is_null($this->s3FileSize)) {+ $this->dispatch('error', 'Please check the file first by clicking "Check File".');++ return true;+ }++ if (! $this->server) {+ $this->dispatch('error', 'Server not found. Please refresh the page.');++ return true;+ }++ try {+ $this->importRunning = true;++ $s3Storage = S3Storage::ownedByCurrentTeam()->findOrFail($this->s3StorageId);++ $key = $s3Storage->key;+ $secret = $s3Storage->secret;+ $bucket = $s3Storage->bucket;+ $endpoint = $s3Storage->endpoint;++ // Validate bucket name to prevent command injection+ if (! $this->validateBucketName($bucket)) {+ $this->dispatch('error', 'Invalid S3 bucket name. Bucket name must contain only alphanumerics, dots, dashes, and underscores.');++ return true;+ }++ // Clean the S3 path+ $cleanPath = ltrim($this->s3Path, '/');++ // Validate the S3 path to prevent command injection+ if (! $this->validateS3Path($cleanPath)) {+ $this->dispatch('error', 'Invalid S3 path. Path must contain only safe characters (alphanumerics, dots, dashes, underscores, slashes).');++ return true;+ }++ // Get helper image+ $helperImage = config('constants.coolify.helper_image');+ $latestVersion = getHelperVersion();+ $fullImageName = "{$helperImage}:{$latestVersion}";++ // Get the database destination network+ if ($this->resource->getMorphClass() === ServiceDatabase::class) {+ $destinationNetwork = $this->resource->service->destination->network ?? 'coolify';+ } else {+ $destinationNetwork = $this->resource->destination->network ?? 'coolify';+ }++ // Generate unique names for this operation+ $containerName = "s3-restore-{$this->resourceUuid}";+ $helperTmpPath = '/tmp/'.basename($cleanPath);+ $serverTmpPath = "/tmp/s3-restore-{$this->resourceUuid}-".basename($cleanPath);+ $containerTmpPath = "/tmp/restore_{$this->resourceUuid}-".basename($cleanPath);+ $scriptPath = "/tmp/restore_{$this->resourceUuid}.sh";++ // Prepare all commands in sequence+ $commands = [];++ // 1. Clean up any existing helper container and temp files from previous runs+ $commands[] = "docker rm -f {$containerName} 2>/dev/null || true";+ $commands[] = "rm -f {$serverTmpPath} 2>/dev/null || true";+ $commands[] = "docker exec {$this->container} rm -f {$containerTmpPath} {$scriptPath} 2>/dev/null || true";++ // 2. Start helper container on the database network+ $commands[] = "docker run -d --network {$destinationNetwork} --name {$containerName} {$fullImageName} sleep 3600";++ // 3. Configure S3 access in helper container+ $escapedEndpoint = escapeshellarg($endpoint);+ $escapedKey = escapeshellarg($key);+ $escapedSecret = escapeshellarg($secret);+ $commands[] = "docker exec {$containerName} mc alias set s3temp {$escapedEndpoint} {$escapedKey} {$escapedSecret}";++ // 4. Check file exists in S3 (bucket and path already validated above)+ $escapedBucket = escapeshellarg($bucket);+ $escapedCleanPath = escapeshellarg($cleanPath);+ $escapedS3Source = escapeshellarg("s3temp/{$bucket}/{$cleanPath}");+ $commands[] = "docker exec {$containerName} mc stat {$escapedS3Source}";++ // 5. Download from S3 to helper container (progress shown by default)+ $escapedHelperTmpPath = escapeshellarg($helperTmpPath);+ $commands[] = "docker exec {$containerName} mc cp {$escapedS3Source} {$escapedHelperTmpPath}";++ // 6. Copy from helper to server, then immediately to database container+ $commands[] = "docker cp {$containerName}:{$helperTmpPath} {$serverTmpPath}";+ $commands[] = "docker cp {$serverTmpPath} {$this->container}:{$containerTmpPath}";++ // 7. Cleanup helper container and server temp file immediately (no longer needed)+ $commands[] = "docker rm -f {$containerName} 2>/dev/null || true";+ $commands[] = "rm -f {$serverTmpPath} 2>/dev/null || true";++ // 8. Build and execute restore command inside database container+ $restoreCommand = $this->buildRestoreCommand($containerTmpPath);++ $restoreCommandBase64 = base64_encode($restoreCommand);+ $commands[] = "echo \"{$restoreCommandBase64}\" | base64 -d > {$scriptPath}";+ $commands[] = "chmod +x {$scriptPath}";+ $commands[] = "docker cp {$scriptPath} {$this->container}:{$scriptPath}";++ // 9. Execute restore and cleanup temp files immediately after completion+ $commands[] = "docker exec {$this->container} sh -c '{$scriptPath} && rm -f {$containerTmpPath} {$scriptPath}'";+ $commands[] = "docker exec {$this->container} sh -c 'echo \"Import finished with exit code $?\"'";++ // Execute all commands with cleanup event (as safety net for edge cases)+ $activity = remote_process($commands, $this->server, ignore_errors: true, callEventOnFinish: 'S3RestoreJobFinished', callEventData: [+ 'containerName' => $containerName,+ 'serverTmpPath' => $serverTmpPath,+ 'scriptPath' => $scriptPath,+ 'containerTmpPath' => $containerTmpPath,+ 'container' => $this->container,+ 'serverId' => $this->server->id,+ ]);++ // Track the activity ID+ $this->activityId = $activity->id;++ // Dispatch activity to the monitor and open slide-over+ $this->dispatch('activityMonitor', $activity->id);+ $this->dispatch('databaserestore');+ $this->dispatch('info', 'Restoring database from S3. Progress will be shown in the activity monitor...');+ } catch (\Throwable $e) {+ $this->importRunning = false;+ handleError($e, $this);++ return true;+ }++ return true;+ }++ public function buildRestoreCommand(string $tmpPath): string+ {+ $morphClass = $this->resource->getMorphClass();++ // Handle ServiceDatabase by checking the database type+ if ($morphClass === ServiceDatabase::class) {+ $dbType = $this->resource->databaseType();+ if (str_contains($dbType, 'mysql')) {+ $morphClass = 'mysql';+ } elseif (str_contains($dbType, 'mariadb')) {+ $morphClass = 'mariadb';+ } elseif (str_contains($dbType, 'postgres')) {+ $morphClass = 'postgresql';+ } elseif (str_contains($dbType, 'mongo')) {+ $morphClass = 'mongodb';+ }+ }++ switch ($morphClass) {+ case StandaloneMariadb::class:+ case 'mariadb':+ $restoreCommand = $this->mariadbRestoreCommand;+ if ($this->dumpAll) {+ $restoreCommand .= " && (gunzip -cf {$tmpPath} 2>/dev/null || cat {$tmpPath}) | mariadb -u root -p\$MARIADB_ROOT_PASSWORD \${MARIADB_DATABASE:-default}";+ } else {+ $restoreCommand .= " < {$tmpPath}";+ }+ break;+ case StandaloneMysql::class:+ case 'mysql':+ $restoreCommand = $this->mysqlRestoreCommand;+ if ($this->dumpAll) {+ $restoreCommand .= " && (gunzip -cf {$tmpPath} 2>/dev/null || cat {$tmpPath}) | mysql -u root -p\$MYSQL_ROOT_PASSWORD \${MYSQL_DATABASE:-default}";+ } else {+ $restoreCommand .= " < {$tmpPath}";+ }+ break;+ case StandalonePostgresql::class:+ case 'postgresql':+ $restoreCommand = $this->postgresqlRestoreCommand;+ if ($this->dumpAll) {+ $restoreCommand .= " && (gunzip -cf {$tmpPath} 2>/dev/null || cat {$tmpPath}) | psql -U \${POSTGRES_USER} -d \${POSTGRES_DB:-\${POSTGRES_USER:-postgres}}";+ } else {+ $restoreCommand .= " {$tmpPath}";+ }+ break;+ case StandaloneMongodb::class:+ case 'mongodb':+ $restoreCommand = $this->mongodbRestoreCommand;+ if ($this->dumpAll === false) {+ $restoreCommand .= "{$tmpPath}";+ }+ break;+ default:+ $restoreCommand = '';+ }++ return $restoreCommand;+ }+}diff --git a/app/Livewire/Project/Service/ResourceCard.php b/app/Livewire/Project/Service/ResourceCard.phpnew file mode 100644index 0000000000..fd27f60c30--- /dev/null+++ b/app/Livewire/Project/Service/ResourceCard.php@@ -0,0 +1,66 @@+<?php++namespace App\Livewire\Project\Service;++use App\Models\Service;+use App\Models\ServiceApplication;+use App\Models\ServiceDatabase;+use Illuminate\Contracts\View\View;+use Illuminate\Foundation\Auth\Access\AuthorizesRequests;+use Illuminate\Support\Facades\Auth;+use Livewire\Component;++class ResourceCard extends Component+{+ use AuthorizesRequests;++ public Service $service;++ public ServiceApplication|ServiceDatabase $resource;++ public array $parameters = [];++ public function getListeners(): array+ {+ $user = Auth::user();+ if (! $user) {+ return [];+ }++ $team = $user->currentTeam();+ if (! $team) {+ return [];+ }++ return [+ "echo-private:team.{$team->id},ServiceChecked" => 'refreshResource',+ ];+ }++ public function refreshResource(): void+ {+ $this->resource->refresh();+ }++ public function restart(): void+ {+ try {+ $this->authorize('update', $this->service);+ $this->resource->restart();+ $message = $this->resource instanceof ServiceApplication+ ? 'Service application restarted successfully.'+ : 'Service database restarted successfully.';+ $this->dispatch('success', $message);+ } catch (\Throwable $e) {+ handleError($e, $this);+ }+ }++ public function render(): View+ {+ return view('livewire.project.service.resource-card', [+ 'isApplication' => $this->resource instanceof ServiceApplication,+ 'isDatabase' => $this->resource instanceof ServiceDatabase,+ ]);+ }+}diff --git a/resources/views/livewire/project/application/configuration.blade.php b/resources/views/livewire/project/application/configuration.blade.phpindex 848c46ff77..6986cef051 100644--- a/resources/views/livewire/project/application/configuration.blade.php+++ b/resources/views/livewire/project/application/configuration.blade.php@@ -27,21 +27,7 @@@endif<a class="sub-menu-item flex items-center gap-2" {{ wireNavigate() }} wire:current.exact="menu-item-active"href="{{ route('project.application.servers', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid, 'application_uuid' => $application->uuid]) }}"><span class="menu-item-label">Servers</span>- @if ($application->server_status == false)- <span title="One or more servers are unreachable or misconfigured.">- <svg class="w-4 h-4 text-error" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">- <path fill="currentColor"- d="M240.26 186.1L152.81 34.23a28.74 28.74 0 0 0-49.62 0L15.74 186.1a27.45 27.45 0 0 0 0 27.71A28.31 28.31 0 0 0 40.55 228h174.9a28.31 28.31 0 0 0 24.79-14.19a27.45 27.45 0 0 0 .02-27.71m-20.8 15.7a4.46 4.46 0 0 1-4 2.2H40.55a4.46 4.46 0 0 1-4-2.2a3.56 3.56 0 0 1 0-3.73L124 46.2a4.77 4.77 0 0 1 8 0l87.44 151.87a3.56 3.56 0 0 1 .02 3.73M116 136v-32a12 12 0 0 1 24 0v32a12 12 0 0 1-24 0m28 40a16 16 0 1 1-16-16a16 16 0 0 1 16 16" />- </svg>- </span>- @elseif ($application->additional_servers()->exists() && str($application->status)->contains('degraded'))- <span title="Application is in degraded state across multiple servers.">- <svg class="w-4 h-4 text-error" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">- <path fill="currentColor"- d="M240.26 186.1L152.81 34.23a28.74 28.74 0 0 0-49.62 0L15.74 186.1a27.45 27.45 0 0 0 0 27.71A28.31 28.31 0 0 0 40.55 228h174.9a28.31 28.31 0 0 0 24.79-14.19a27.45 27.45 0 0 0 .02-27.71m-20.8 15.7a4.46 4.46 0 0 1-4 2.2H40.55a4.46 4.46 0 0 1-4-2.2a3.56 3.56 0 0 1 0-3.73L124 46.2a4.77 4.77 0 0 1 8 0l87.44 151.87a3.56 3.56 0 0 1 .02 3.73M116 136v-32a12 12 0 0 1 24 0v32a12 12 0 0 1-24 0m28 40a16 16 0 1 1-16-16a16 16 0 0 1 16 16" />- </svg>- </span>- @endif+ <livewire:project.application.server-status-badge :application="$application" /></a><a @class(['sub-menu-item', 'menu-item-active' => str($currentRoute)->startsWith('project.application.scheduled-tasks')]) {{ wireNavigate() }}href="{{ route('project.application.scheduled-tasks.show', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid, 'application_uuid' => $application->uuid]) }}"><span class="menu-item-label">Scheduled Tasks</span></a>diff --git a/resources/views/livewire/project/application/server-status-badge.blade.php b/resources/views/livewire/project/application/server-status-badge.blade.phpnew file mode 100644index 0000000000..3413b3671c--- /dev/null+++ b/resources/views/livewire/project/application/server-status-badge.blade.php@@ -0,0 +1,17 @@+<span>+ @if ($application->server_status == false)+ <span title="One or more servers are unreachable or misconfigured.">+ <svg class="w-4 h-4 text-error" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">+ <path fill="currentColor"+ d="M240.26 186.1L152.81 34.23a28.74 28.74 0 0 0-49.62 0L15.74 186.1a27.45 27.45 0 0 0 0 27.71A28.31 28.31 0 0 0 40.55 228h174.9a28.31 28.31 0 0 0 24.79-14.19a27.45 27.45 0 0 0 .02-27.71m-20.8 15.7a4.46 4.46 0 0 1-4 2.2H40.55a4.46 4.46 0 0 1-4-2.2a3.56 3.56 0 0 1 0-3.73L124 46.2a4.77 4.77 0 0 1 8 0l87.44 151.87a3.56 3.56 0 0 1 .02 3.73M116 136v-32a12 12 0 0 1 24 0v32a12 12 0 0 1-24 0m28 40a16 16 0 1 1-16-16a16 16 0 0 1 16 16" />+ </svg>+ </span>+ @elseif ($application->additional_servers()->exists() && str($application->status)->contains('degraded'))+ <span title="Application is in degraded state across multiple servers.">+ <svg class="w-4 h-4 text-error" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">+ <path fill="currentColor"+ d="M240.26 186.1L152.81 34.23a28.74 28.74 0 0 0-49.62 0L15.74 186.1a27.45 27.45 0 0 0 0 27.71A28.31 28.31 0 0 0 40.55 228h174.9a28.31 28.31 0 0 0 24.79-14.19a27.45 27.45 0 0 0 .02-27.71m-20.8 15.7a4.46 4.46 0 0 1-4 2.2H40.55a4.46 4.46 0 0 1-4-2.2a3.56 3.56 0 0 1 0-3.73L124 46.2a4.77 4.77 0 0 1 8 0l87.44 151.87a3.56 3.56 0 0 1 .02 3.73M116 136v-32a12 12 0 0 1 24 0v32a12 12 0 0 1-24 0m28 40a16 16 0 1 1-16-16a16 16 0 0 1 16 16" />+ </svg>+ </span>+ @endif+</span>diff --git a/resources/views/livewire/project/database/import-form.blade.php b/resources/views/livewire/project/database/import-form.blade.phpnew file mode 100644index 0000000000..15306f9dfe--- /dev/null+++ b/resources/views/livewire/project/database/import-form.blade.php@@ -0,0 +1,228 @@+<div x-data="{+ error: $wire.entangle('error'),+ filesize: $wire.entangle('filesize'),+ filename: $wire.entangle('filename'),+ isUploading: $wire.entangle('isUploading'),+ progress: $wire.entangle('progress'),+ s3FileSize: $wire.entangle('s3FileSize'),+ s3StorageId: $wire.entangle('s3StorageId'),+ s3Path: $wire.entangle('s3Path'),+ restoreType: null+}">+ <script type="text/javascript" src="{{ URL::asset('js/dropzone.js') }}"></script>+ @script+ <script data-navigate-once>+ Dropzone.options.myDropzone = {+ chunking: true,+ method: "POST",+ maxFilesize: 1000000000,+ chunkSize: 10000000,+ createImageThumbnails: false,+ disablePreviews: true,+ parallelChunkUploads: false,+ init: function () {+ let button = this.element.querySelector('button');+ button.innerText = 'Select or drop a backup file here.'+ this.on('sending', function (file, xhr, formData) {+ const token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');+ formData.append("_token", token);+ });+ this.on("addedfile", file => {+ $wire.isUploading = true;+ $wire.customLocation = '';+ });+ this.on('uploadprogress', function (file, progress, bytesSent) {+ $wire.progress = progress;+ });+ this.on('complete', function (file) {+ $wire.filename = file.name;+ $wire.filesize = Number(file.size / 1024 / 1024).toFixed(2) + ' MB';+ $wire.isUploading = false;+ });+ this.on('error', function (file, message) {+ $wire.error = true;+ $wire.$dispatch('error', message.error)+ });+ }+ };+ </script>+ @endscript+ <div class="pt-2 rounded-sm alert-error">+ <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 stroke-current shrink-0" fill="none" viewBox="0 0 24 24">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"+ d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />+ </svg>+ <span>This is a destructive action, existing data will be replaced!</span>+ </div>+ {{-- Restore Command Configuration --}}+ @if ($resourceDbType === 'standalone-postgresql')+ @if ($dumpAll)+ <x-forms.textarea rows="6" readonly label="Custom Import Command"+ wire:model='restoreCommandText'></x-forms.textarea>+ @else+ <x-forms.input label="Custom Import Command" wire:model='postgresqlRestoreCommand'></x-forms.input>+ <div class="flex flex-col gap-1 pt-1">+ <span class="text-xs">You can add "--clean" to drop objects before creating them, avoiding+ conflicts.</span>+ <span class="text-xs">You can add "--verbose" to log more things.</span>+ </div>+ @endif+ <div class="w-64 pt-2">+ <x-forms.checkbox label="Backup includes all databases" wire:model.live='dumpAll'></x-forms.checkbox>+ </div>+ @elseif ($resourceDbType === 'standalone-mysql')+ @if ($dumpAll)+ <x-forms.textarea rows="14" readonly label="Custom Import Command"+ wire:model='restoreCommandText'></x-forms.textarea>+ @else+ <x-forms.input label="Custom Import Command" wire:model='mysqlRestoreCommand'></x-forms.input>+ @endif+ <div class="w-64 pt-2">+ <x-forms.checkbox label="Backup includes all databases" wire:model.live='dumpAll'></x-forms.checkbox>+ </div>+ @elseif ($resourceDbType === 'standalone-mariadb')+ @if ($dumpAll)+ <x-forms.textarea rows="14" readonly label="Custom Import Command"+ wire:model='restoreCommandText'></x-forms.textarea>+ @else+ <x-forms.input label="Custom Import Command" wire:model='mariadbRestoreCommand'></x-forms.input>+ @endif+ <div class="w-64 pt-2">+ <x-forms.checkbox label="Backup includes all databases" wire:model.live='dumpAll'></x-forms.checkbox>+ </div>+ @endif++ {{-- Restore Type Selection Boxes --}}+ <h3 class="pt-6">Choose Restore Method</h3>+ <div class="flex gap-4 pt-2">+ <div @click="restoreType = 'file'"+ class="flex-1 p-6 border-2 rounded-sm cursor-pointer transition-all"+ :class="restoreType === 'file' ? 'border-warning bg-warning/10' : 'border-neutral-200 dark:border-neutral-800 hover:border-warning/50'">+ <div class="flex flex-col gap-2">+ <svg xmlns="http://www.w3.org/2000/svg" class="w-8 h-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />+ </svg>+ <h4 class="text-lg font-bold">Restore from File</h4>+ <p class="text-sm text-neutral-600 dark:text-neutral-400">Upload a backup file or specify a file path on the server</p>+ </div>+ </div>++ @if (count($availableS3Storages) > 0)+ <div @click="restoreType = 's3'"+ class="flex-1 p-6 border-2 rounded-sm cursor-pointer transition-all"+ :class="restoreType === 's3' ? 'border-warning bg-warning/10' : 'border-neutral-200 dark:border-neutral-800 hover:border-warning/50'">+ <div class="flex flex-col gap-2">+ <svg xmlns="http://www.w3.org/2000/svg" class="w-8 h-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 15a4 4 0 004 4h9a5 5 0 10-.1-9.999 5.002 5.002 0 10-9.78 2.096A4.001 4.001 0 003 15z" />+ </svg>+ <h4 class="text-lg font-bold">Restore from S3</h4>+ <p class="text-sm text-neutral-600 dark:text-neutral-400">Download and restore a backup from S3 storage</p>+ </div>+ </div>+ @endif+ </div>++ {{-- File Restore Section --}}+ @can('update', $this->resource)+ <div x-show="restoreType === 'file'" class="pt-6">+ <h3>Backup File</h3>+ <form class="flex gap-2 items-end pt-2">+ <x-forms.input label="Location of the backup file on the server" placeholder="e.g. /home/user/backup.sql.gz"+ wire:model='customLocation' x-model="$wire.customLocation"></x-forms.input>+ <x-forms.button class="w-full" wire:click='checkFile' x-bind:disabled="!$wire.customLocation">Check File</x-forms.button>+ </form>+ <div class="pt-2 text-center text-xl font-bold">+ Or+ </div>+ <form action="/upload/backup/{{ $resourceUuid }}" class="dropzone" id="my-dropzone" wire:ignore>+ @csrf+ </form>+ <div x-show="isUploading">+ <progress max="100" x-bind:value="progress" class="progress progress-warning"></progress>+ </div>++ <div x-show="filename && !error" class="pt-6">+ <h3>File Information</h3>+ <div class="pt-2">Location: <span x-text="filename ?? 'N/A'"></span><span x-show="filesize" x-text="' / ' + filesize"></span></div>+ <div class="pt-2">+ <x-modal-confirmation title="Restore Database from File?" buttonTitle="Restore from File"+ submitAction="runImport" isErrorButton>+ <x-slot:button-title>+ Restore Database from File+ </x-slot:button-title>+ This will perform the following actions:+ <ul class="list-disc list-inside pt-2">+ <li>Copy backup file to database container</li>+ <li>Execute restore command</li>+ </ul>+ <div class="pt-2 font-bold text-error">WARNING: This will REPLACE all existing data!</div>+ </x-modal-confirmation>+ </div>+ </div>+ </div>+ @endcan++ {{-- S3 Restore Section --}}+ @if (count($availableS3Storages) > 0)+ @can('update', $this->resource)+ <div x-show="restoreType === 's3'" class="pt-6">+ <h3>Restore from S3</h3>+ <div class="flex flex-col gap-2 pt-2">+ <x-forms.select label="S3 Storage" wire:model.live="s3StorageId">+ <option value="">Select S3 Storage</option>+ @foreach ($availableS3Storages as $storage)+ <option value="{{ $storage['id'] }}">{{ $storage['name'] }}+ @if ($storage['description'])+ - {{ $storage['description'] }}+ @endif+ </option>+ @endforeach+ </x-forms.select>++ <x-forms.input label="S3 File Path (within bucket)"+ helper="Path to the backup file in your S3 bucket, e.g., /backups/database-2025-01-15.gz"+ placeholder="/backups/database-backup.gz" wire:model.blur='s3Path'+ wire:keydown.enter='checkS3File'></x-forms.input>++ <div class="flex gap-2">+ <x-forms.button class="w-full" wire:click='checkS3File' x-bind:disabled="!s3StorageId || !s3Path">+ Check File+ </x-forms.button>+ </div>++ @if ($s3FileSize)+ <div class="pt-6">+ <h3>File Information</h3>+ <div class="pt-2">Location: {{ $s3Path }} {{ formatBytes($s3FileSize ?? 0) }}</div>+ <div class="pt-2">+ <x-modal-confirmation title="Restore Database from S3?" buttonTitle="Restore from S3"+ submitAction="restoreFromS3" isErrorButton>+ <x-slot:button-title>+ Restore Database from S3+ </x-slot:button-title>+ This will perform the following actions:+ <ul class="list-disc list-inside pt-2">+ <li>Download backup from S3 storage</li>+ <li>Copy file into database container</li>+ <li>Execute restore command</li>+ </ul>+ <div class="pt-2 font-bold text-error">WARNING: This will REPLACE all existing data!</div>+ </x-modal-confirmation>+ </div>+ </div>+ @endif+ </div>+ </div>+ @endcan+ @endif++ {{-- Slide-over for activity monitor (all restore operations) --}}+ <x-slide-over @databaserestore.window="slideOverOpen = true" closeWithX fullScreen>+ <x-slot:title>Database Restore Output</x-slot:title>+ <x-slot:content>+ <div wire:ignore>+ <livewire:activity-monitor wire:key="database-restore-{{ $resourceUuid }}" header="Logs" fullHeight />+ </div>+ </x-slot:content>+ </x-slide-over>+</div>\ No newline at end of filediff --git a/resources/views/livewire/project/database/import.blade.php b/resources/views/livewire/project/database/import.blade.phpindex 666abb3b37..75de25f717 100644--- a/resources/views/livewire/project/database/import.blade.php+++ b/resources/views/livewire/project/database/import.blade.php@@ -1,237 +1,10 @@-<div x-data="{- error: $wire.entangle('error'),- filesize: $wire.entangle('filesize'),- filename: $wire.entangle('filename'),- isUploading: $wire.entangle('isUploading'),- progress: $wire.entangle('progress'),- s3FileSize: $wire.entangle('s3FileSize'),- s3StorageId: $wire.entangle('s3StorageId'),- s3Path: $wire.entangle('s3Path'),- restoreType: null-}">- <script type="text/javascript" src="{{ URL::asset('js/dropzone.js') }}"></script>- @script- <script data-navigate-once>- Dropzone.options.myDropzone = {- chunking: true,- method: "POST",- maxFilesize: 1000000000,- chunkSize: 10000000,- createImageThumbnails: false,- disablePreviews: true,- parallelChunkUploads: false,- init: function () {- let button = this.element.querySelector('button');- button.innerText = 'Select or drop a backup file here.'- this.on('sending', function (file, xhr, formData) {- const token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');- formData.append("_token", token);- });- this.on("addedfile", file => {- $wire.isUploading = true;- $wire.customLocation = '';- });- this.on('uploadprogress', function (file, progress, bytesSent) {- $wire.progress = progress;- });- this.on('complete', function (file) {- $wire.filename = file.name;- $wire.filesize = Number(file.size / 1024 / 1024).toFixed(2) + ' MB';- $wire.isUploading = false;- });- this.on('error', function (file, message) {- $wire.error = true;- $wire.$dispatch('error', message.error)- });- }- };- </script>- @endscript+<div><h2>Import Backup</h2>@if ($unsupported)<div>Database restore is not supported.</div>+ @elseif (str($resourceStatus)->startsWith('running'))+ <livewire:project.database.import-form wire:key="database-import-form-{{ $resourceUuid }}" />@else- <div class="pt-2 rounded-sm alert-error">- <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 stroke-current shrink-0" fill="none" viewBox="0 0 24 24">- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"- d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />- </svg>- <span>This is a destructive action, existing data will be replaced!</span>- </div>- @if (str($resourceStatus)->startsWith('running'))- {{-- Restore Command Configuration --}}- @if ($resourceDbType === 'standalone-postgresql')- @if ($dumpAll)- <x-forms.textarea rows="6" readonly label="Custom Import Command"- wire:model='restoreCommandText'></x-forms.textarea>- @else- <x-forms.input label="Custom Import Command" wire:model='postgresqlRestoreCommand'></x-forms.input>- <div class="flex flex-col gap-1 pt-1">- <span class="text-xs">You can add "--clean" to drop objects before creating them, avoiding- conflicts.</span>- <span class="text-xs">You can add "--verbose" to log more things.</span>- </div>- @endif- <div class="w-64 pt-2">- <x-forms.checkbox label="Backup includes all databases" wire:model.live='dumpAll'></x-forms.checkbox>- </div>- @elseif ($resourceDbType === 'standalone-mysql')- @if ($dumpAll)- <x-forms.textarea rows="14" readonly label="Custom Import Command"- wire:model='restoreCommandText'></x-forms.textarea>- @else- <x-forms.input label="Custom Import Command" wire:model='mysqlRestoreCommand'></x-forms.input>- @endif- <div class="w-64 pt-2">- <x-forms.checkbox label="Backup includes all databases" wire:model.live='dumpAll'></x-forms.checkbox>- </div>- @elseif ($resourceDbType === 'standalone-mariadb')- @if ($dumpAll)- <x-forms.textarea rows="14" readonly label="Custom Import Command"- wire:model='restoreCommandText'></x-forms.textarea>- @else- <x-forms.input label="Custom Import Command" wire:model='mariadbRestoreCommand'></x-forms.input>- @endif- <div class="w-64 pt-2">- <x-forms.checkbox label="Backup includes all databases" wire:model.live='dumpAll'></x-forms.checkbox>- </div>- @endif-- {{-- Restore Type Selection Boxes --}}- <h3 class="pt-6">Choose Restore Method</h3>- <div class="flex gap-4 pt-2">- <div @click="restoreType = 'file'"- class="flex-1 p-6 border-2 rounded-sm cursor-pointer transition-all"- :class="restoreType === 'file' ? 'border-warning bg-warning/10' : 'border-neutral-200 dark:border-neutral-800 hover:border-warning/50'">- <div class="flex flex-col gap-2">- <svg xmlns="http://www.w3.org/2000/svg" class="w-8 h-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />- </svg>- <h4 class="text-lg font-bold">Restore from File</h4>- <p class="text-sm text-neutral-600 dark:text-neutral-400">Upload a backup file or specify a file path on the server</p>- </div>- </div>-- @if (count($availableS3Storages) > 0)- <div @click="restoreType = 's3'"- class="flex-1 p-6 border-2 rounded-sm cursor-pointer transition-all"- :class="restoreType === 's3' ? 'border-warning bg-warning/10' : 'border-neutral-200 dark:border-neutral-800 hover:border-warning/50'">- <div class="flex flex-col gap-2">- <svg xmlns="http://www.w3.org/2000/svg" class="w-8 h-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 15a4 4 0 004 4h9a5 5 0 10-.1-9.999 5.002 5.002 0 10-9.78 2.096A4.001 4.001 0 003 15z" />- </svg>- <h4 class="text-lg font-bold">Restore from S3</h4>- <p class="text-sm text-neutral-600 dark:text-neutral-400">Download and restore a backup from S3 storage</p>- </div>- </div>- @endif- </div>-- {{-- File Restore Section --}}- @can('update', $this->resource)- <div x-show="restoreType === 'file'" class="pt-6">- <h3>Backup File</h3>- <form class="flex gap-2 items-end pt-2">- <x-forms.input label="Location of the backup file on the server" placeholder="e.g. /home/user/backup.sql.gz"- wire:model='customLocation' x-model="$wire.customLocation"></x-forms.input>- <x-forms.button class="w-full" wire:click='checkFile' x-bind:disabled="!$wire.customLocation">Check File</x-forms.button>- </form>- <div class="pt-2 text-center text-xl font-bold">- Or- </div>- <form action="/upload/backup/{{ $resourceUuid }}" class="dropzone" id="my-dropzone" wire:ignore>- @csrf- </form>- <div x-show="isUploading">- <progress max="100" x-bind:value="progress" class="progress progress-warning"></progress>- </div>-- <div x-show="filename && !error" class="pt-6">- <h3>File Information</h3>- <div class="pt-2">Location: <span x-text="filename ?? 'N/A'"></span><span x-show="filesize" x-text="' / ' + filesize"></span></div>- <div class="pt-2">- <x-modal-confirmation title="Restore Database from File?" buttonTitle="Restore from File"- submitAction="runImport" isErrorButton>- <x-slot:button-title>- Restore Database from File- </x-slot:button-title>- This will perform the following actions:- <ul class="list-disc list-inside pt-2">- <li>Copy backup file to database container</li>- <li>Execute restore command</li>- </ul>- <div class="pt-2 font-bold text-error">WARNING: This will REPLACE all existing data!</div>- </x-modal-confirmation>- </div>- </div>- </div>- @endcan-- {{-- S3 Restore Section --}}- @if (count($availableS3Storages) > 0)- @can('update', $this->resource)- <div x-show="restoreType === 's3'" class="pt-6">- <h3>Restore from S3</h3>- <div class="flex flex-col gap-2 pt-2">- <x-forms.select label="S3 Storage" wire:model.live="s3StorageId">- <option value="">Select S3 Storage</option>- @foreach ($availableS3Storages as $storage)- <option value="{{ $storage['id'] }}">{{ $storage['name'] }}- @if ($storage['description'])- - {{ $storage['description'] }}- @endif- </option>- @endforeach- </x-forms.select>-- <x-forms.input label="S3 File Path (within bucket)"- helper="Path to the backup file in your S3 bucket, e.g., /backups/database-2025-01-15.gz"- placeholder="/backups/database-backup.gz" wire:model.blur='s3Path'- wire:keydown.enter='checkS3File'></x-forms.input>-- <div class="flex gap-2">- <x-forms.button class="w-full" wire:click='checkS3File' x-bind:disabled="!s3StorageId || !s3Path">- Check File- </x-forms.button>- </div>-- @if ($s3FileSize)- <div class="pt-6">- <h3>File Information</h3>- <div class="pt-2">Location: {{ $s3Path }} {{ formatBytes($s3FileSize ?? 0) }}</div>- <div class="pt-2">- <x-modal-confirmation title="Restore Database from S3?" buttonTitle="Restore from S3"- submitAction="restoreFromS3" isErrorButton>- <x-slot:button-title>- Restore Database from S3- </x-slot:button-title>- This will perform the following actions:- <ul class="list-disc list-inside pt-2">- <li>Download backup from S3 storage</li>- <li>Copy file into database container</li>- <li>Execute restore command</li>- </ul>- <div class="pt-2 font-bold text-error">WARNING: This will REPLACE all existing data!</div>- </x-modal-confirmation>- </div>- </div>- @endif- </div>- </div>- @endcan- @endif-- {{-- Slide-over for activity monitor (all restore operations) --}}- <x-slide-over @databaserestore.window="slideOverOpen = true" closeWithX fullScreen>- <x-slot:title>Database Restore Output</x-slot:title>- <x-slot:content>- <div wire:ignore>- <livewire:activity-monitor wire:key="database-restore-{{ $resourceUuid }}" header="Logs" fullHeight />- </div>- </x-slot:content>- </x-slide-over>- @else- <div>Database must be running to restore a backup.</div>- @endif+ <div>Database must be running to restore a backup.</div>@endif-</div>\ No newline at end of file+</div>diff --git a/resources/views/livewire/project/service/configuration.blade.php b/resources/views/livewire/project/service/configuration.blade.phpindex ffe80b5956..35b2ffd20f 100644--- a/resources/views/livewire/project/service/configuration.blade.php+++ b/resources/views/livewire/project/service/configuration.blade.php@@ -43,134 +43,12 @@@endif@foreach ($applications as $application)- <div @class([- 'border-l border-dashed border-red-500' => str(- $application->status)->contains(['exited']),- 'border-l border-dashed border-success' => str(- $application->status)->contains(['running']),- 'border-l border-dashed border-warning' => str(- $application->status)->contains(['starting']),- 'flex gap-2 box-without-bg-without-border dark:bg-coolgray-100 bg-white dark:hover:text-neutral-300 group',- ])>- <div class="flex flex-row w-full">- <div class="flex flex-col flex-1">- <div class="pb-2">- @if ($application->human_name)- {{ Str::headline($application->human_name) }}- @else- {{ Str::headline($application->name) }}- @endif- <span class="text-xs">({{ $application->image }})</span>- </div>- @if ($application->configuration_required)- <span class="text-xs text-error">(configuration required)</span>- @endif- @if ($application->description)- <span class="text-xs">{{ Str::limit($application->description, 60) }}</span>- @endif- @if ($application->fqdn)- <span class="flex gap-1 text-xs">{{ Str::limit($application->fqdn, 60) }}- @can('update', $service)- <x-modal-input title="Edit Domains" :closeOutside="false">- <x-slot:content>- <span class="cursor-pointer">- <svg xmlns="http://www.w3.org/2000/svg"- class="w-4 h-4 dark:text-warning text-coollabs"- viewBox="0 0 24 24">- <g fill="none" stroke="currentColor"- stroke-linecap="round" stroke-linejoin="round"- stroke-width="2">- <path- d="m12 15l8.385-8.415a2.1 2.1 0 0 0-2.97-2.97L9 12v3h3zm4-10l3 3" />- <path d="M9 7.07A7 7 0 0 0 10 21a7 7 0 0 0 6.929-6" />- </g>- </svg>-- </span>- </x-slot:content>- <livewire:project.service.edit-domain- applicationId="{{ $application->id }}"- wire:key="edit-domain-{{ $application->id }}" />- </x-modal-input>- @endcan- </span>- @endif- <div class="pt-2 text-xs">{{ formatContainerStatus($application->status) }}</div>- </div>- <div class="flex items-center px-4">- <a class="mx-4 text-xs font-bold hover:underline" {{ wireNavigate() }}- href="{{ route('project.service.index', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid, 'service_uuid' => $service->uuid, 'stack_service_uuid' => $application->uuid]) }}">- Settings- </a>- @if (str($application->status)->contains('running'))- @can('update', $service)- <x-modal-confirmation title="Confirm Service Application Restart?"- buttonTitle="Restart"- submitAction="restartApplication({{ $application->id }})" :actions="[- 'The selected service application will be unavailable during the restart.',- 'If the service application is currently in use data could be lost.',- ]"- :confirmWithText="false" :confirmWithPassword="false"- step2ButtonText="Restart Service Container" />- @endcan- @endif- </div>- </div>- </div>+ <livewire:project.service.resource-card :service="$service" :resource="$application"+ :parameters="$parameters" wire:key="service-application-card-{{ $application->id }}" />@endforeach@foreach ($databases as $database)- <div @class([- 'border-l border-dashed border-red-500' => str($database->status)->contains(- ['exited']),- 'border-l border-dashed border-success' => str($database->status)->contains(- ['running']),- 'border-l border-dashed border-warning' => str($database->status)->contains(- ['restarting']),- 'flex gap-2 box-without-bg-without-border dark:bg-coolgray-100 bg-white dark:hover:text-neutral-300 group',- ])>- <div class="flex flex-row w-full">- <div class="flex flex-col flex-1">- <div class="pb-2">- @if ($database->human_name)- {{ Str::headline($database->human_name) }}- @else- {{ Str::headline($database->name) }}- @endif- <span class="text-xs">({{ $database->image }})</span>- </div>- @if ($database->configuration_required)- <span class="text-xs text-error">(configuration required)</span>- @endif- @if ($database->description)- <span class="text-xs">{{ Str::limit($database->description, 60) }}</span>- @endif- <div class="text-xs">{{ formatContainerStatus($database->status) }}</div>- </div>- <div class="flex items-center px-4">- @if ($database->isBackupSolutionAvailable() || $database->is_migrated)- <a class="mx-4 text-xs font-bold hover:underline" {{ wireNavigate() }}- href="{{ route('project.service.database.backups', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid, 'service_uuid' => $service->uuid, 'stack_service_uuid' => $database->uuid]) }}">- Backups- </a>- @endif- <a class="mx-4 text-xs font-bold hover:underline" {{ wireNavigate() }}- href="{{ route('project.service.index', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid, 'service_uuid' => $service->uuid, 'stack_service_uuid' => $database->uuid]) }}">- Settings- </a>- @if (str($database->status)->contains('running'))- @can('update', $service)- <x-modal-confirmation title="Confirm Service Database Restart?"- buttonTitle="Restart" submitAction="restartDatabase({{ $database->id }})"- :actions="[- 'This service database will be unavailable during the restart.',- 'If the service database is currently in use data could be lost.',- ]" :confirmWithText="false" :confirmWithPassword="false"- step2ButtonText="Restart Database" />- @endcan- @endif- </div>- </div>- </div>+ <livewire:project.service.resource-card :service="$service" :resource="$database"+ :parameters="$parameters" wire:key="service-database-card-{{ $database->id }}" />@endforeach</div>@elseif ($currentRoute === 'project.service.environment-variables')diff --git a/resources/views/livewire/project/service/resource-card.blade.php b/resources/views/livewire/project/service/resource-card.blade.phpnew file mode 100644index 0000000000..47fb009148--- /dev/null+++ b/resources/views/livewire/project/service/resource-card.blade.php@@ -0,0 +1,77 @@+<div @class([+ 'border-l border-dashed border-red-500' => str($resource->status)->contains(['exited']),+ 'border-l border-dashed border-success' => str($resource->status)->contains(['running']),+ 'border-l border-dashed border-warning' => str($resource->status)->contains(['starting', 'restarting']),+ 'flex gap-2 box-without-bg-without-border dark:bg-coolgray-100 bg-white dark:hover:text-neutral-300 group',+])>+ <div class="flex flex-row w-full">+ <div class="flex flex-col flex-1">+ <div class="pb-2">+ @if ($resource->human_name)+ {{ Str::headline($resource->human_name) }}+ @else+ {{ Str::headline($resource->name) }}+ @endif+ <span class="text-xs">({{ $resource->image }})</span>+ </div>+ @if ($resource->configuration_required)+ <span class="text-xs text-error">(configuration required)</span>+ @endif+ @if ($resource->description)+ <span class="text-xs">{{ Str::limit($resource->description, 60) }}</span>+ @endif+ @if ($isApplication && $resource->fqdn)+ <span class="flex gap-1 text-xs">{{ Str::limit($resource->fqdn, 60) }}+ @can('update', $service)+ <x-modal-input title="Edit Domains" :closeOutside="false">+ <x-slot:content>+ <span class="cursor-pointer">+ <svg xmlns="http://www.w3.org/2000/svg"+ class="w-4 h-4 dark:text-warning text-coollabs"+ viewBox="0 0 24 24">+ <g fill="none" stroke="currentColor" stroke-linecap="round"+ stroke-linejoin="round" stroke-width="2">+ <path d="m12 15l8.385-8.415a2.1 2.1 0 0 0-2.97-2.97L9 12v3h3zm4-10l3 3" />+ <path d="M9 7.07A7 7 0 0 0 10 21a7 7 0 0 0 6.929-6" />+ </g>+ </svg>+ </span>+ </x-slot:content>+ <livewire:project.service.edit-domain applicationId="{{ $resource->id }}"+ wire:key="edit-domain-{{ $resource->id }}" />+ </x-modal-input>+ @endcan+ </span>+ @endif+ <div @class(['pt-2' => $isApplication, 'text-xs'])>{{ formatContainerStatus($resource->status) }}</div>+ </div>+ <div class="flex items-center px-4">+ @if ($isDatabase && ($resource->isBackupSolutionAvailable() || $resource->is_migrated))+ <a class="mx-4 text-xs font-bold hover:underline" {{ wireNavigate() }}+ href="{{ route('project.service.database.backups', [...$parameters, 'stack_service_uuid' => $resource->uuid]) }}">+ Backups+ </a>+ @endif+ <a class="mx-4 text-xs font-bold hover:underline" {{ wireNavigate() }}+ href="{{ route('project.service.index', [...$parameters, 'stack_service_uuid' => $resource->uuid]) }}">+ Settings+ </a>+ @if (str($resource->status)->contains('running'))+ @can('update', $service)+ <x-modal-confirmation :title="$isApplication ? 'Confirm Service Application Restart?' : 'Confirm Service Database Restart?'"+ buttonTitle="Restart" submitAction="restart" :actions="$isApplication+ ? [+ 'The selected service application will be unavailable during the restart.',+ 'If the service application is currently in use data could be lost.',+ ]+ : [+ 'This service database will be unavailable during the restart.',+ 'If the service database is currently in use data could be lost.',+ ]"+ :confirmWithText="false" :confirmWithPassword="false"+ :step2ButtonText="$isApplication ? 'Restart Service Container' : 'Restart Database'" />+ @endcan+ @endif+ </div>+ </div>+</div>diff --git a/tests/Feature/DatabaseSslStatusRefreshTest.php b/tests/Feature/DatabaseSslStatusRefreshTest.phpindex 7efb037891..6e8216eedc 100644--- a/tests/Feature/DatabaseSslStatusRefreshTest.php+++ b/tests/Feature/DatabaseSslStatusRefreshTest.php@@ -1,9 +1,13 @@<?php+use App\Livewire\Project\Application\Configuration as ApplicationConfiguration;+use App\Livewire\Project\Application\ServerStatusBadge;use App\Livewire\Project\Database\Clickhouse\General as ClickhouseGeneral;use App\Livewire\Project\Database\Clickhouse\StatusInfo as ClickhouseStatusInfo;use App\Livewire\Project\Database\Dragonfly\General as DragonflyGeneral;use App\Livewire\Project\Database\Dragonfly\StatusInfo as DragonflyStatusInfo;+use App\Livewire\Project\Database\Import as DatabaseImport;+use App\Livewire\Project\Database\ImportForm as DatabaseImportForm;use App\Livewire\Project\Database\Keydb\General as KeydbGeneral;use App\Livewire\Project\Database\Keydb\StatusInfo as KeydbStatusInfo;use App\Livewire\Project\Database\Mariadb\General as MariadbGeneral;@@ -16,11 +20,15 @@ use App\Livewire\Project\Database\Postgresql\General as PostgresqlGeneral;use App\Livewire\Project\Database\Postgresql\StatusInfo as PostgresqlStatusInfo;use App\Livewire\Project\Database\Redis\General as RedisGeneral;use App\Livewire\Project\Database\Redis\StatusInfo as RedisStatusInfo;+use App\Livewire\Project\Service\Configuration as ServiceConfiguration;+use App\Livewire\Project\Service\ResourceCard as ServiceResourceCard;use App\Livewire\Server\Sentinel;use App\Livewire\Server\Show;use App\Models\Environment;use App\Models\Project;use App\Models\Server;+use App\Models\Service;+use App\Models\ServiceApplication;use App\Models\StandaloneDocker;use App\Models\StandaloneMysql;use App\Models\StandaloneRedis;@@ -52,6 +60,9 @@ dataset('database-general-forms-without-broadcasts', [KeydbGeneral::class,DragonflyGeneral::class,ClickhouseGeneral::class,+ DatabaseImportForm::class,+ ServiceConfiguration::class,+ ApplicationConfiguration::class,]);dataset('database-status-info-components', [@@ -65,6 +76,20 @@ dataset('database-status-info-components', [ClickhouseStatusInfo::class,]);+dataset('display-only-status-components', [+ RedisStatusInfo::class,+ PostgresqlStatusInfo::class,+ MysqlStatusInfo::class,+ MariadbStatusInfo::class,+ MongodbStatusInfo::class,+ KeydbStatusInfo::class,+ DragonflyStatusInfo::class,+ ClickhouseStatusInfo::class,+ DatabaseImport::class,+ ServiceResourceCard::class,+ ServerStatusBadge::class,+]);+it('does not subscribe the form to status broadcasts when display lives in a sibling', function (string $componentClass) {// Regression guard for coolify#6062 / #6354 / #9695:// Status broadcasts on the form would trigger a Livewire roundtrip that absorbs@@ -101,6 +126,80 @@ it('auto-refreshes status-info sibling on database status broadcasts', function->toHaveKey("echo-private:team.{$this->team->id},ServiceChecked");})->with('database-status-info-components');+it('keeps realtime status listeners on display-only components instead of form owners', function (string $componentClass) {+ $listeners = resolveLivewireListeners(app($componentClass));++ expect($listeners)->not->toBeEmpty();+})->with('display-only-status-components');++it('refreshes a service resource card without refreshing the service configuration form owner', function () {+ $server = Server::factory()->create(['team_id' => $this->team->id]);+ $destination = StandaloneDocker::where('server_id', $server->id)->first();+ $project = Project::factory()->create(['team_id' => $this->team->id]);+ $environment = Environment::factory()->create(['project_id' => $project->id]);+ $service = Service::create([+ 'name' => 'status-card-service',+ 'environment_id' => $environment->id,+ 'server_id' => $server->id,+ 'destination_id' => $destination->id,+ 'destination_type' => $destination->getMorphClass(),+ 'docker_compose_raw' => 'services: {}',+ ]);+ $serviceApplication = ServiceApplication::create([+ 'service_id' => $service->id,+ 'name' => 'web',+ 'image' => 'nginx:latest',+ 'status' => 'exited:unhealthy',+ ]);+ $parameters = [+ 'project_uuid' => $project->uuid,+ 'environment_uuid' => $environment->uuid,+ 'service_uuid' => $service->uuid,+ ];++ $component = Livewire::test(ServiceResourceCard::class, [+ 'service' => $service,+ 'resource' => $serviceApplication,+ 'parameters' => $parameters,+ ]);++ $serviceApplication->fill(['status' => 'running:healthy'])->save();++ $component->call('refreshResource');++ expect($component->instance()->resource->status)->toBe('running:healthy');+});++it('refreshes database import status from stored resource identity after the route context is gone', function () {+ $server = Server::factory()->create(['team_id' => $this->team->id]);+ $destination = StandaloneDocker::where('server_id', $server->id)->first();+ $project = Project::factory()->create(['team_id' => $this->team->id]);+ $environment = Environment::factory()->create(['project_id' => $project->id]);+ $database = StandaloneMysql::create([+ 'name' => 'import-status-mysql',+ 'image' => 'mysql:8',+ 'mysql_root_password' => 'password',+ 'mysql_user' => 'coolify',+ 'mysql_password' => 'password',+ 'mysql_database' => 'coolify',+ 'status' => 'exited:unhealthy',+ 'is_log_drain_enabled' => false,+ 'environment_id' => $environment->id,+ 'destination_id' => $destination->id,+ 'destination_type' => $destination->getMorphClass(),+ ]);++ $component = app(DatabaseImport::class);+ $component->resourceId = $database->id;+ $component->resourceType = StandaloneMysql::class;++ $database->fill(['status' => 'running:healthy'])->save();++ $component->refreshStatus();++ expect($component->resourceStatus)->toBe('running:healthy');+});+it('reloads the mysql status-info model when refresh is called so ssl controls follow the latest status', function () {$server = Server::factory()->create(['team_id' => $this->team->id]);$destination = StandaloneDocker::where('server_id', $server->id)->first();