forked from coollabsio/coolify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fully functional terminal for command center
- Loading branch information
1 parent
fcfbba4
commit c2ea899
Showing
15 changed files
with
624 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Project\Shared; | ||
|
||
use App\Models\Server; | ||
use Livewire\Attributes\On; | ||
use Livewire\Component; | ||
|
||
class Terminal extends Component | ||
{ | ||
#[On('send-terminal-command')] | ||
public function sendTerminalCommand($isContainer, $identifier, $serverUuid) | ||
{ | ||
$server = Server::whereUuid($serverUuid)->firstOrFail(); | ||
|
||
if (auth()->user()) { | ||
$teams = auth()->user()->teams->pluck('id'); | ||
if (! $teams->contains($server->team_id) && ! $teams->contains(0)) { | ||
throw new \Exception('User is not part of the team that owns this server'); | ||
} | ||
} | ||
|
||
if ($isContainer) { | ||
$status = getContainerStatus($server, $identifier); | ||
if ($status !== 'running') { | ||
return handleError(new \Exception('Container is not running'), $this); | ||
} | ||
$command = generateSshCommand($server, "docker exec -it {$identifier} sh -c 'if [ -f ~/.profile ]; then . ~/.profile; fi; if [ -n \"\$SHELL\" ]; then exec \$SHELL; else sh; fi'"); | ||
} else { | ||
$command = generateSshCommand($server, "sh -c 'if [ -f ~/.profile ]; then . ~/.profile; fi; if [ -n \"\$SHELL\" ]; then exec \$SHELL; else sh; fi'"); | ||
} | ||
|
||
// ssh command is sent back to frontend then to websocket | ||
// this is done because the websocket connection is not available here | ||
// a better solution would be to remove websocket on NodeJS and work with something like | ||
// 1. Laravel Pusher/Echo connection (not possible without a sdk) | ||
// 2. Ratchet / Revolt / ReactPHP / Event Loop (possible but hard to implement and huge dependencies) | ||
// 3. Just found out about this https://github.com/sirn-se/websocket-php, perhaps it can be used | ||
$this->dispatch('send-back-command', $command); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.project.shared.terminal'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.