update rm deadcode
This commit is contained in:
@@ -6,6 +6,8 @@ namespace App\Services;
|
||||
|
||||
use App\Http\Facade\SignRSA;
|
||||
use App\Models\InfraManagement;
|
||||
use App\Support\PowerShellEscaper;
|
||||
use App\Support\SshHostKeyVerifier;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use phpseclib3\Net\SSH2;
|
||||
|
||||
@@ -207,6 +209,8 @@ final class VsphereHostSshService
|
||||
|
||||
$client = new SSH2($config['host'], $config['port'], self::CONNECT_TIMEOUT);
|
||||
|
||||
SshHostKeyVerifier::verify($client, $config['host']);
|
||||
|
||||
if (!$client->login($config['username'], $config['password'])) {
|
||||
throw new \RuntimeException(
|
||||
"SSH login failed: {$config['host']}:{$config['port']}"
|
||||
@@ -364,23 +368,14 @@ final class VsphereHostSshService
|
||||
*/
|
||||
private function windowsPowerShellCommand(string $workingDirectory, string $script, array $arguments): string
|
||||
{
|
||||
return sprintf(
|
||||
'powershell -ExecutionPolicy Bypass -NonInteractive -File "%s\\%s" %s',
|
||||
$workingDirectory,
|
||||
$script,
|
||||
implode(' ', array_map(
|
||||
fn (string $argument): string => $this->warg($argument),
|
||||
$arguments,
|
||||
)),
|
||||
);
|
||||
}
|
||||
$scriptPath = $workingDirectory . '\\' . $script;
|
||||
$psScript = '& ' . PowerShellEscaper::singleQuote($scriptPath) . ' ' . implode(' ', array_map(
|
||||
fn (string $argument): string => PowerShellEscaper::singleQuote($argument),
|
||||
$arguments,
|
||||
));
|
||||
|
||||
/**
|
||||
* Windows cmd.exe safe argument: wrap in double quotes, escape inner double quotes.
|
||||
*/
|
||||
private function warg(string $value): string
|
||||
{
|
||||
return '"' . str_replace('"', '\\"', $value) . '"';
|
||||
return 'powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand '
|
||||
. PowerShellEscaper::encodedCommand($psScript);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user