Add ssh multiplexing

This commit is contained in:
Andras Bacsai 2023-03-27 20:18:20 +02:00
parent 50bc6b0a48
commit e7592949f7
2 changed files with 5 additions and 2 deletions

View File

@ -7,6 +7,7 @@
use Illuminate\Process\ProcessResult; use Illuminate\Process\ProcessResult;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Process; use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Storage;
use Spatie\Activitylog\Models\Activity; use Spatie\Activitylog\Models\Activity;
class RunRemoteProcess class RunRemoteProcess
@ -69,13 +70,15 @@ protected function getCommand(): string
$command = $this->activity->getExtraProperty('command'); $command = $this->activity->getExtraProperty('command');
$delimiter = 'EOF-COOLIFY-SSH'; $delimiter = 'EOF-COOLIFY-SSH';
Storage::disk('local')->makeDirectory('.ssh');
$ssh_command = "ssh " $ssh_command = "ssh "
. "-i {$private_key_location} " . "-i {$private_key_location} "
. '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ' . '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '
. '-o PasswordAuthentication=no ' . '-o PasswordAuthentication=no '
. '-o RequestTTY=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} " . "-p {$port} "
. "{$user}@{$destination} " . "{$user}@{$destination} "
. " 'bash -se' << \\$delimiter" . PHP_EOL . " 'bash -se' << \\$delimiter" . PHP_EOL

View File

@ -20,7 +20,7 @@ function remoteProcess(
checkTeam($found_server->team_id); checkTeam($found_server->team_id);
$temp_file = 'id.rsa_'.'root'.'@'.$found_server->ip; $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; $private_key_location = '/var/www/html/storage/app/'.$temp_file;
return resolve(DispatchRemoteProcess::class, [ return resolve(DispatchRemoteProcess::class, [