Revert "rector: arrrrr"

This reverts commit 16c0cd10d8.
This commit is contained in:
Andras Bacsai
2025-01-07 15:31:43 +01:00
parent da07b4fdcf
commit 1fe4dd722b
349 changed files with 3689 additions and 4184 deletions

View File

@@ -6,13 +6,12 @@ use App\Models\PrivateKey;
use App\Models\Server;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Process;
use RuntimeException;
class SshMultiplexingHelper
{
public static function serverSshConfiguration(Server $server)
{
$privateKey = PrivateKey::query()->findOrFail($server->private_key_id);
$privateKey = PrivateKey::findOrFail($server->private_key_id);
$sshKeyLocation = $privateKey->getKeyLocation();
$muxFilename = '/var/www/html/storage/app/ssh/mux/mux_'.$server->uuid;
@@ -36,9 +35,9 @@ class SshMultiplexingHelper
$checkCommand .= '-o ProxyCommand="cloudflared access ssh --hostname %h" ';
}
$checkCommand .= "{$server->user}@{$server->ip}";
$processResult = Process::run($checkCommand);
$process = Process::run($checkCommand);
if ($processResult->exitCode() !== 0) {
if ($process->exitCode() !== 0) {
return self::establishNewMultiplexedConnection($server);
}
@@ -61,9 +60,12 @@ class SshMultiplexingHelper
}
$establishCommand .= self::getCommonSshOptions($server, $sshKeyLocation, $connectionTimeout, $serverInterval);
$establishCommand .= "{$server->user}@{$server->ip}";
$processResult = Process::run($establishCommand);
$establishProcess = Process::run($establishCommand);
if ($establishProcess->exitCode() !== 0) {
return false;
}
return $processResult->exitCode() === 0;
return true;
}
public static function removeMuxFile(Server $server)
@@ -101,14 +103,15 @@ class SshMultiplexingHelper
}
$scp_command .= self::getCommonSshOptions($server, $sshKeyLocation, config('constants.ssh.connection_timeout'), config('constants.ssh.server_interval'), isScp: true);
$scp_command .= "{$source} {$server->user}@{$server->ip}:{$dest}";
return $scp_command."{$source} {$server->user}@{$server->ip}:{$dest}";
return $scp_command;
}
public static function generateSshCommand(Server $server, string $command)
{
if ($server->settings->force_disabled) {
throw new RuntimeException('Server is disabled.');
throw new \RuntimeException('Server is disabled.');
}
$sshConfig = self::serverSshConfiguration($server);
@@ -137,9 +140,11 @@ class SshMultiplexingHelper
$delimiter = base64_encode($delimiter);
$command = str_replace($delimiter, '', $command);
return $ssh_command.("{$server->user}@{$server->ip} 'bash -se' << \\$delimiter".PHP_EOL
$ssh_command .= "{$server->user}@{$server->ip} 'bash -se' << \\$delimiter".PHP_EOL
.$command.PHP_EOL
.$delimiter);
.$delimiter;
return $ssh_command;
}
private static function isMultiplexingEnabled(): bool
@@ -151,9 +156,9 @@ class SshMultiplexingHelper
{
$keyLocation = $privateKey->getKeyLocation();
$checkKeyCommand = "ls $keyLocation 2>/dev/null";
$processResult = Process::run($checkKeyCommand);
$keyCheckProcess = Process::run($checkKeyCommand);
if ($processResult->exitCode() !== 0) {
if ($keyCheckProcess->exitCode() !== 0) {
$privateKey->storeInFileSystem();
}
}