diff --git a/app/Livewire/Boarding/Index.php b/app/Livewire/Boarding/Index.php index 147a1ad6f..bb01160f4 100644 --- a/app/Livewire/Boarding/Index.php +++ b/app/Livewire/Boarding/Index.php @@ -73,6 +73,8 @@ class Index extends Component } $this->privateKeyName = generate_random_name(); $this->remoteServerName = generate_random_name(); + $this->remoteServerPort = $this->remoteServerPort; + $this->remoteServerUser = $this->remoteServerUser; if (isDev()) { $this->privateKey = '-----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW @@ -173,6 +175,8 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== } $this->selectedExistingPrivateKey = $this->createdServer->privateKey->id; $this->serverPublicKey = $this->createdServer->privateKey->publicKey(); + $this->remoteServerPort = $this->createdServer->port; + $this->remoteServerUser = $this->createdServer->user; $this->currentState = 'validate-server'; } @@ -269,7 +273,7 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== public function validateServer() { try { - config()->set('coolify.mux_enabled', false); + config()->set('coolify.mux_enabled', true); // EC2 does not have `uptime` command, lol instant_remote_process(['ls /'], $this->createdServer, true); @@ -277,9 +281,13 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== $this->createdServer->settings()->update([ 'is_reachable' => true, ]); + $this->serverReachable = true; } catch (\Throwable $e) { $this->serverReachable = false; - $this->createdServer->delete(); + $this->createdServer->settings()->update([ + 'is_reachable' => false, + ]); + return handleError(error: $e, livewire: $this); } @@ -296,6 +304,9 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== ]); $this->getProxyType(); } catch (\Throwable $e) { + $this->createdServer->settings()->update([ + 'is_usable' => false, + ]); return handleError(error: $e, livewire: $this); } } @@ -349,6 +360,33 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== ); } + public function saveAndValidateServer() + { + $this->validate([ + 'remoteServerPort' => 'required|integer|min:1|max:65535', + 'remoteServerUser' => 'required|string', + ]); + + if (!$this->createdServer) { + $this->createdServer = Server::create([ + 'name' => $this->remoteServerName ?? 'New Server', + 'ip' => $this->remoteServerHost, + 'port' => $this->remoteServerPort, + 'user' => $this->remoteServerUser, + 'team_id' => currentTeam()->id, + 'timezone' => 'UTC', + ]); + } else { + $this->createdServer->update([ + 'port' => $this->remoteServerPort, + 'user' => $this->remoteServerUser, + 'timezone' => 'UTC', + ]); + } + + $this->validateServer(); + } + private function createNewPrivateKey() { $this->privateKeyName = generate_random_name(); diff --git a/app/Models/Server.php b/app/Models/Server.php index c72c7cc95..d30cdc9d6 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -112,6 +112,11 @@ class Server extends BaseModel 'proxy', ]; + protected $fillable = [ + 'port', + 'user', + ]; + protected $guarded = []; public static function isReachable() @@ -143,7 +148,11 @@ class Server extends BaseModel public function settings() { - return $this->hasOne(ServerSetting::class); + return $this->hasOne(ServerSetting::class)->withDefault([ + 'force_disabled' => false, + 'is_reachable' => false, + 'is_usable' => false, + ]); } public function setupDefault404Redirect() diff --git a/resources/views/livewire/boarding/index.blade.php b/resources/views/livewire/boarding/index.blade.php index cd7ef4c86..4b1da05da 100644 --- a/resources/views/livewire/boarding/index.blade.php +++ b/resources/views/livewire/boarding/index.blade.php @@ -64,9 +64,9 @@

Please check the connection details below and correct them if they are incorrect.

- +
- +

Non-root user is experimental: docs @@ -88,7 +88,7 @@ - + Check again

@@ -236,9 +236,9 @@ Advanced Settings
- +
- +
Non-root user is experimental: docs.