From e7592949f742e8a9d816c2b6236226d22d411cc3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 27 Mar 2023 20:18:20 +0200 Subject: [PATCH] Add ssh multiplexing --- app/Actions/RemoteProcess/RunRemoteProcess.php | 5 ++++- bootstrap/helpers.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Actions/RemoteProcess/RunRemoteProcess.php b/app/Actions/RemoteProcess/RunRemoteProcess.php index 731eea533..9b4089970 100644 --- a/app/Actions/RemoteProcess/RunRemoteProcess.php +++ b/app/Actions/RemoteProcess/RunRemoteProcess.php @@ -7,6 +7,7 @@ use Illuminate\Process\ProcessResult; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Process; +use Illuminate\Support\Facades\Storage; use Spatie\Activitylog\Models\Activity; class RunRemoteProcess @@ -69,13 +70,15 @@ protected function getCommand(): string $command = $this->activity->getExtraProperty('command'); $delimiter = 'EOF-COOLIFY-SSH'; + Storage::disk('local')->makeDirectory('.ssh'); $ssh_command = "ssh " . "-i {$private_key_location} " . '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ' . '-o PasswordAuthentication=no ' . '-o RequestTTY=no ' - . "-o LogLevel=ERROR " + . '-o LogLevel=ERROR ' + . '-o ControlMaster=auto -o ControlPersist=yes -o ControlPath=/var/www/html/storage/app/.ssh/ssh_mux_%h_%p_%r ' . "-p {$port} " . "{$user}@{$destination} " . " 'bash -se' << \\$delimiter" . PHP_EOL diff --git a/bootstrap/helpers.php b/bootstrap/helpers.php index 6f9b04cad..494bb6470 100644 --- a/bootstrap/helpers.php +++ b/bootstrap/helpers.php @@ -20,7 +20,7 @@ function remoteProcess( checkTeam($found_server->team_id); $temp_file = 'id.rsa_'.'root'.'@'.$found_server->ip; - Storage::disk('local')->put($temp_file, $found_server->privateKeys->first()->private_key, 'private'); + Storage::disk('local')->put($temp_file, $found_server->privateKey->private_key, 'private'); $private_key_location = '/var/www/html/storage/app/'.$temp_file; return resolve(DispatchRemoteProcess::class, [