update rm deadcode

This commit is contained in:
baodev0
2026-09-27 11:42:40 +07:00
parent 82a71244ca
commit 3af59bd9c5
129 changed files with 5194 additions and 2698 deletions
+3 -2
View File
@@ -3,6 +3,7 @@
namespace App\Http\Services\vCenter;
use Illuminate\Support\Facades\Http;
use App\Support\TlsHttpClientFactory;
use App\Http\Facade\SignRSA;
use App\Models\Vcenter;
use Exception;
@@ -23,7 +24,7 @@ class Client
$this->username = $vcenterModel->user;
$this->password = SignRSA::DecryptFunc($vcenterModel->password);
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withBasicAuth($this->username, $this->password)
->post("https://{$this->apiUri}/rest/com/vmware/cis/session", []);
@@ -48,7 +49,7 @@ class Client
public function checkApiExits(): bool
{
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->token
])
@@ -4,6 +4,9 @@ namespace App\Http\Services\vCenter\Concerns;
use App\Http\Facade\SignRSA;
use App\Models\InfraManagement;
use App\Support\PowerCliCertificatePolicy;
use App\Support\PowerShellEscaper;
use App\Support\SshHostKeyVerifier;
use Exception;
use Illuminate\Support\Facades\Log;
use phpseclib3\Net\SSH2;
@@ -19,6 +22,11 @@ use phpseclib3\Net\SSH2;
*/
trait ManagesSsh
{
private function powerCliCertificateLine(): string
{
return PowerCliCertificatePolicy::configurationLine();
}
// ─── Auth ────────────────────────────────────────────────────────────────
private function LoginAuth(): SSH2|false
@@ -41,6 +49,8 @@ trait ManagesSsh
$connection = new SSH2($sshHost, $sshPort);
SshHostKeyVerifier::verify($connection, $sshHost);
if ($connection->login($infra->username, SignRSA::DecryptFunc($infra->password))) {
$connection->setTimeout(0);
return $connection;
@@ -83,7 +93,7 @@ trait ManagesSsh
try {
$psCommand = 'powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "'
. 'Import-Module VMware.PowerCLI; '
. 'Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false -Scope Session; '
. $this->powerCliCertificateLine() . '; '
. '$cred = Import-Clixml -Path \'C:\secure\vcenter.cred\'; '
. 'Connect-VIServer -Server \'' . $this->apiUri . '\' -Credential $cred; '
. $cmd . '; '
@@ -113,8 +123,8 @@ trait ManagesSsh
return 'Login_Fail';
}
$action = 'powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass '
. '-Command "' . str_replace('"', '\"', $psCommand) . '"';
$action = 'powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand '
. PowerShellEscaper::encodedCommand($psCommand);
try {
$out = $auth->exec($action);
@@ -136,7 +146,6 @@ trait ManagesSsh
return 'Login_Fail';
}
$esc = fn(string $v) => str_replace("'", "''", $v);
$script = strtr(
<<<'PS'
$ProgressPreference = 'SilentlyContinue'
@@ -145,7 +154,7 @@ $WarningPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
Import-Module VMware.PowerCLI -ErrorAction Stop
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope Session -Confirm:$false | Out-Null
<CERT>
Connect-VIServer -Server '<SERVER>' -User '<USER>' -Password '<PASS>' | Out-Null
& {
@@ -153,15 +162,16 @@ Connect-VIServer -Server '<SERVER>' -User '<USER>' -Password '<PASS>' | Out-Null
} | Out-String
PS,
[
'<SERVER>' => $esc($this->apiUri ?? ''),
'<USER>' => $esc($this->username ?? ''),
'<PASS>' => $esc($this->password ?? ''),
'<CERT>' => $this->powerCliCertificateLine(),
'<SERVER>' => PowerShellEscaper::singleQuote($this->apiUri ?? ''),
'<USER>' => PowerShellEscaper::singleQuote($this->username ?? ''),
'<PASS>' => PowerShellEscaper::singleQuote($this->password ?? ''),
'<CMD>' => $cmd,
]
);
$encoded = base64_encode(mb_convert_encoding($script, 'UTF-16LE', 'UTF-8'));
$action = "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encoded";
$action = 'powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand '
. PowerShellEscaper::encodedCommand($script);
try {
$out = $auth->exec($action);
@@ -183,7 +193,6 @@ PS,
return 'Login_Fail';
}
$esc = fn(string $v) => str_replace("'", "''", $v);
$script = strtr(
<<<'PS'
$ProgressPreference = 'SilentlyContinue'
@@ -193,7 +202,7 @@ $ErrorActionPreference = 'Stop'
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Import-Module VMware.PowerCLI -ErrorAction Stop
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope Session -Confirm:$false | Out-Null
<CERT>
Connect-VIServer -Server '<SERVER>' -User '<USER>' -Password '<PASS>' | Out-Null
& {
@@ -201,15 +210,16 @@ Connect-VIServer -Server '<SERVER>' -User '<USER>' -Password '<PASS>' | Out-Null
}
PS,
[
'<SERVER>' => $esc($this->apiUri ?? ''),
'<USER>' => $esc($this->username ?? ''),
'<PASS>' => $esc($this->password ?? ''),
'<CERT>' => $this->powerCliCertificateLine(),
'<SERVER>' => PowerShellEscaper::singleQuote($this->apiUri ?? ''),
'<USER>' => PowerShellEscaper::singleQuote($this->username ?? ''),
'<PASS>' => PowerShellEscaper::singleQuote($this->password ?? ''),
'<CMD>' => $cmd,
]
);
$encoded = base64_encode(mb_convert_encoding($script, 'UTF-16LE', 'UTF-8'));
$action = "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encoded";
$action = 'powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand '
. PowerShellEscaper::encodedCommand($script);
try {
$out = $auth->exec($action);
@@ -3,6 +3,7 @@
namespace App\Http\Services\vCenter;
use Illuminate\Support\Facades\Http;
use App\Support\TlsHttpClientFactory;
use Illuminate\Support\Facades\Log;
class PowerManagementService
@@ -17,7 +18,7 @@ class PowerManagementService
public function SuspendVirtualMachine($vmware_id = ''): array|string
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -39,7 +40,7 @@ class PowerManagementService
public function RebootVirtualMachine($product, $vmware_id = ''): array|string
{
if ($this->client->loginServer($product->ipaddress->host->datacenter->vCenter)) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -61,7 +62,7 @@ class PowerManagementService
public function StartVirtualMachine($product, $vmware_id = ''): array|string
{
if ($this->client->loginServer($product->ipaddress->host->datacenter->vCenter)) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -83,7 +84,7 @@ class PowerManagementService
public function ShutdownGuestVirtualMachine($product, $vmware_id = ''): array|string
{
if ($this->client->loginServer($product->ipaddress->host->datacenter->vCenter)) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -106,7 +107,7 @@ class PowerManagementService
public function PowerOffVirtualMachine($vmware_id = ''): array|string
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -128,7 +129,7 @@ class PowerManagementService
public function DeleteVirtualMachine($vmware_id = ''): array|string
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -150,7 +151,7 @@ class PowerManagementService
public function GetConsoleTickets($vmware_id = ''): array|string
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -219,7 +220,7 @@ class PowerManagementService
return "Login_Again";
}
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -265,7 +266,7 @@ class PowerManagementService
return 'Login_Again';
}
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders(['vmware-api-session-id' => $this->client->token])
->timeout(8)
->get("https://{$this->client->apiUri}/rest/vcenter/vm/$vmId/power");
+63 -56
View File
@@ -7,6 +7,9 @@ use phpseclib3\Net\SSH2;
use Exception;
use App\Models\InfraManagement;
use App\Http\Facade\SignRSA;
use App\Support\PowerShellEscaper;
use App\Support\PowerCliCertificatePolicy;
use App\Support\SshHostKeyVerifier;
class PowerShellService
{
@@ -41,6 +44,8 @@ class PowerShellService
$connection = new SSH2($sshHost, $sshPort);
SshHostKeyVerifier::verify($connection, $sshHost);
if ($connection->login($sshUser, $sshPass)) {
$connection->setTimeout(0); // No timeout
return $connection;
@@ -72,9 +77,8 @@ class PowerShellService
return "Login_Fail";
}
// Action wrapper
$action = 'powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass '
. '-Command "' . str_replace('"', '\"', $psCommand) . '"';
$action = 'powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand '
. PowerShellEscaper::encodedCommand($psCommand);
try {
$out = $auth->exec($action);
@@ -91,6 +95,11 @@ class PowerShellService
return $this->CommandRSP($cmd);
}
private function powerCliCertificateLine(): string
{
return PowerCliCertificatePolicy::configurationLine();
}
protected function CommandRSP(string $cmd)
{
$auth = $this->LoginAuth();
@@ -98,12 +107,9 @@ class PowerShellService
return "Login_Fail";
}
$esc = fn(string $v) => str_replace("'", "''", $v);
// Get credentials from Client
$server = $esc($this->client->apiUri ?? '');
$user = $esc($this->client->getUsername() ?? '');
$pass = $esc($this->client->getPassword() ?? '');
$server = PowerShellEscaper::singleQuote($this->client->apiUri ?? '');
$user = PowerShellEscaper::singleQuote($this->client->getUsername() ?? '');
$pass = PowerShellEscaper::singleQuote($this->client->getPassword() ?? '');
$psTemplate = <<<'PS'
$ProgressPreference = 'SilentlyContinue'
@@ -112,7 +118,7 @@ $WarningPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
Import-Module VMware.PowerCLI -ErrorAction Stop
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope Session -Confirm:$false | Out-Null
<CERT>
Connect-VIServer -Server '<SERVER>' -User '<USER>' -Password '<PASS>' | Out-Null
& {
@@ -121,19 +127,19 @@ Connect-VIServer -Server '<SERVER>' -User '<USER>' -Password '<PASS>' | Out-Null
PS;
$psScript = strtr($psTemplate, [
'<CERT>' => $this->powerCliCertificateLine(),
'<SERVER>' => $server,
'<USER>' => $user,
'<PASS>' => $pass,
'<CMD>' => $cmd,
]);
$encoded = base64_encode(mb_convert_encoding($psScript, 'UTF-16LE', 'UTF-8'));
$action = "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encoded";
$action = 'powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand '
. PowerShellEscaper::encodedCommand($psScript);
try {
$out = $auth->exec($action);
$errOut = $auth->getStdError();
// PowerCLI banner is CLIXML informational records — not an error
$realErr = $errOut && !str_starts_with(trim($errOut), '#< CLIXML');
return $out . ($realErr ? "\n[STDERR]\n" . $errOut : '');
} catch (\Throwable $e) {
@@ -148,11 +154,9 @@ PS;
return "Login_Fail";
}
$esc = fn(string $v) => str_replace("'", "''", $v);
$server = $esc($this->client->apiUri ?? '');
$user = $esc($this->client->getUsername() ?? '');
$pass = $esc($this->client->getPassword() ?? '');
$server = PowerShellEscaper::singleQuote($this->client->apiUri ?? '');
$user = PowerShellEscaper::singleQuote($this->client->getUsername() ?? '');
$pass = PowerShellEscaper::singleQuote($this->client->getPassword() ?? '');
$psTemplate = <<<'PS'
$ProgressPreference = 'SilentlyContinue'
@@ -162,7 +166,7 @@ $ErrorActionPreference = 'Stop'
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Import-Module VMware.PowerCLI -ErrorAction Stop
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope Session -Confirm:$false | Out-Null
<CERT>
Connect-VIServer -Server '<SERVER>' -User '<USER>' -Password '<PASS>' | Out-Null
& {
@@ -171,14 +175,15 @@ Connect-VIServer -Server '<SERVER>' -User '<USER>' -Password '<PASS>' | Out-Null
PS;
$psScript = strtr($psTemplate, [
'<CERT>' => $this->powerCliCertificateLine(),
'<SERVER>' => $server,
'<USER>' => $user,
'<PASS>' => $pass,
'<CMD>' => $cmd,
]);
$encoded = base64_encode(mb_convert_encoding($psScript, 'UTF-16LE', 'UTF-8'));
$action = "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encoded";
$action = 'powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand '
. PowerShellEscaper::encodedCommand($psScript);
try {
$out = $auth->exec($action);
@@ -201,15 +206,14 @@ PS;
public function resetGuestPasswordViaPs1(string $vmName, string $guestUser, string $guestPassword, string $newPassword, string $targetUser = 'Administrator'): array|string
{
$psFile = "C:\\CLISave\\AssignIP\\SetGuestPwd.ps1";
$q = fn(string $v) => str_replace("'", "''", $v);
$args = " -VMName '" . $q($vmName) . "'";
$args .= " -GuestUser '" . $q($guestUser) . "'";
$args .= " -GuestPassword '" . $q($guestPassword) . "'";
$args .= " -TargetUser '" . $q($targetUser) . "'";
$args .= " -NewPassword '" . $q($newPassword) . "'";
$args = ' -VMName ' . PowerShellEscaper::singleQuote($vmName);
$args .= ' -GuestUser ' . PowerShellEscaper::singleQuote($guestUser);
$args .= ' -GuestPassword ' . PowerShellEscaper::singleQuote($guestPassword);
$args .= ' -TargetUser ' . PowerShellEscaper::singleQuote($targetUser);
$args .= ' -NewPassword ' . PowerShellEscaper::singleQuote($newPassword);
$cmd = "& '$psFile'$args | Out-String";
$cmd = '& ' . PowerShellEscaper::singleQuote($psFile) . "{$args} | Out-String";
$raw = $this->CommandRSP($cmd);
if ($raw === 'Login_Fail' || $raw === false || $raw === null) {
@@ -230,14 +234,13 @@ PS;
public function changeRDPPortWindows(string $vmName, string $guestUser, string $guestPassword, string $newPort): array|string
{
$psFile = "C:\\CLISave\\AssignIP\\change-rdp-port.ps1";
$q = fn(string $v) => str_replace("'", "''", $v);
$args = " -VMName '" . $q($vmName) . "'";
$args .= " -GuestUser '" . $q($guestUser) . "'";
$args .= " -GuestPassword '" . $q($guestPassword) . "'";
$args .= " -NewPort " . (int) $newPort;
$args = ' -VMName ' . PowerShellEscaper::singleQuote($vmName);
$args .= ' -GuestUser ' . PowerShellEscaper::singleQuote($guestUser);
$args .= ' -GuestPassword ' . PowerShellEscaper::singleQuote($guestPassword);
$args .= ' -NewPort ' . (int) $newPort;
$cmd = "& '$psFile'$args";
$cmd = '& ' . PowerShellEscaper::singleQuote($psFile) . $args;
$raw = $this->CommandChangePort($cmd, true);
@@ -286,8 +289,6 @@ PS;
string $dns = '8.8.8.8',
string $hostname = ''
): string {
$q = fn(string $v) => str_replace("'", "''", $v);
$isLinux = str_contains(strtolower($osType), 'linux')
|| str_contains(strtolower($osType), 'ubuntu')
|| str_contains(strtolower($osType), 'centos')
@@ -295,29 +296,35 @@ PS;
if ($isLinux) {
$psFile = "C:\\CLISave\\changeIPLinux.ps1";
$Command = "& '{$psFile}'"
. " -VMName '" . $q($vmName) . "'"
. " -IP '" . $q($ipAddress) . "'"
. " -Gateway '" . $q($gateway) . "'"
. " -DNS '" . $q($dns) . "'"
. " -GuestUser '" . $q($guestUser) . "'"
. " -GuestPassword '" . $q($guestPassword) . "'";
$Command = '& ' . PowerShellEscaper::singleQuote($psFile)
. ' -VMName ' . PowerShellEscaper::singleQuote($vmName)
. ' -IP ' . PowerShellEscaper::singleQuote($ipAddress)
. ' -Gateway ' . PowerShellEscaper::singleQuote($gateway)
. ' -DNS ' . PowerShellEscaper::singleQuote($dns)
. ' -GuestUser ' . PowerShellEscaper::singleQuote($guestUser)
. ' -GuestPassword ' . PowerShellEscaper::singleQuote($guestPassword);
Log::channel('Custom')->info('[changeIpVM:linux] ' . $Command);
Log::channel('Custom')->info('[changeIpVM:linux]', [
'script' => 'changeIPLinux.ps1',
'vmware_id' => $vmwareId,
]);
return (string) $this->CommandChangePort($Command, true);
}
$VirtualMachine = "VirtualMachine-$vmwareId";
$hn = strtolower($hostname ?: $vmName);
$Command = "\$vm = get-vm -Id '{$VirtualMachine}';"
. " \$hostname = '{$q($hn)}';"
. " \$ipadd = '{$q($ipAddress)}';"
. " \$gw = '{$q($gateway)}';"
. " \$password = \"'{$q($guestPassword)}'\"; "
. " cd /; C:\\CLISave\\changeWindows1line.ps1;";
$Command = '$vm = get-vm -Id ' . PowerShellEscaper::singleQuote($VirtualMachine) . ';'
. ' $hostname = ' . PowerShellEscaper::singleQuote($hn) . ';'
. ' $ipadd = ' . PowerShellEscaper::singleQuote($ipAddress) . ';'
. ' $gw = ' . PowerShellEscaper::singleQuote($gateway) . ';'
. ' $password = ' . PowerShellEscaper::singleQuote($guestPassword) . '; '
. ' cd /; C:\\CLISave\\changeWindows1line.ps1;';
Log::channel('Custom')->info('[changeIpVM:windows] ' . $Command);
Log::channel('Custom')->info('[changeIpVM:windows]', [
'script' => 'changeWindows1line.ps1',
'vmware_id' => $vmwareId,
]);
return (string) $this->CommandRSP($Command);
}
@@ -326,11 +333,11 @@ PS;
{
$ps = "(Get-ItemProperty 'HKLM:\\System\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp' -Name PortNumber).PortNumber";
$cmd = "Invoke-VMScript -VM '$vmwareId' "
. "-ScriptText \"$ps\" "
. "-ScriptType Powershell "
. "-GuestUser '$guestUser' "
. "-GuestPassword '$guestPassword'";
$cmd = 'Invoke-VMScript -VM ' . PowerShellEscaper::singleQuote($vmwareId)
. ' -ScriptText ' . PowerShellEscaper::singleQuote($ps)
. ' -ScriptType Powershell'
. ' -GuestUser ' . PowerShellEscaper::singleQuote($guestUser)
. ' -GuestPassword ' . PowerShellEscaper::singleQuote($guestPassword);
$output = $this->CommandRSP($cmd);
@@ -3,6 +3,7 @@
namespace App\Http\Services\vCenter;
use Illuminate\Support\Facades\Http;
use App\Support\TlsHttpClientFactory;
use Illuminate\Support\Facades\Log;
class ResourceService
@@ -17,7 +18,7 @@ class ResourceService
public function getAllDatacenter()
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -34,7 +35,7 @@ class ResourceService
public function getAllHost($datacenter = '')
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -53,7 +54,7 @@ class ResourceService
public function getAllFolder($datacenter = '')
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -80,7 +81,7 @@ class ResourceService
$params['filter.datacenters'] = $datacenter;
}
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -115,7 +116,7 @@ class ResourceService
$params['filter.datacenters'] = $datacenter;
}
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -171,7 +172,7 @@ class ResourceService
$params['filter.datacenters'] = $datacenter;
}
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -3,6 +3,7 @@
namespace App\Http\Services\vCenter;
use App\Support\Cache\CacheKey;
use App\Support\TlsHttpClientFactory;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
@@ -438,7 +439,7 @@ class SnapshotService
' . $soapBody . '
</soapenv:Envelope>';
curl_setopt_array($curl, array(
curl_setopt_array($curl, [
CURLOPT_URL => "https://$host/sdk",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
@@ -449,10 +450,8 @@ class SnapshotService
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => true // We need headers for cookie
));
] + TlsHttpClientFactory::vCenterCurlOptions());
$response = curl_exec($curl);
@@ -3,6 +3,7 @@
namespace App\Http\Services\vCenter;
use Illuminate\Support\Facades\Http;
use App\Support\TlsHttpClientFactory;
class TemplateService
{
@@ -16,7 +17,7 @@ class TemplateService
public function getAllTemplate()
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -32,7 +33,7 @@ class TemplateService
public function getTemplatebyID($template = '')
{
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -61,7 +62,7 @@ class TemplateService
public function getVersionDetail($version_id = '')
{
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -76,7 +77,7 @@ class TemplateService
public function getAllVersion($library = ''): bool|array|string
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -3,6 +3,7 @@
namespace App\Http\Services\vCenter;
use Illuminate\Support\Facades\Http;
use App\Support\TlsHttpClientFactory;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Str;
@@ -32,7 +33,7 @@ class VirtualMachineService
$params['filter.hosts'] = $host;
}
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -111,7 +112,7 @@ class VirtualMachineService
try {
Log::info('Bắt đầu clone VM với timeout 300 giây', ['template' => $template, 'target_name' => $body['spec']['name']]);
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->timeout(300)
->connectTimeout(30)
->withHeaders([
@@ -230,7 +231,7 @@ class VirtualMachineService
'hot_add_enabled' => true
]
];
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->timeout(30)
->withHeaders([
'vmware-api-session-id' => $this->client->token,
@@ -264,7 +265,7 @@ class VirtualMachineService
]
];
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->timeout(30)
->withHeaders([
'vmware-api-session-id' => $this->client->token,
@@ -299,7 +300,7 @@ class VirtualMachineService
]
];
$diskResponse = Http::withoutVerifying()
$diskResponse = TlsHttpClientFactory::vCenter()
->timeout(30)
->withHeaders([
'vmware-api-session-id' => $this->client->token,
@@ -318,7 +319,7 @@ class VirtualMachineService
$firstDisk = $diskData['value'][0];
$diskKey = $firstDisk['key'];
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->timeout(30)
->withHeaders([
'vmware-api-session-id' => $this->client->token,
@@ -340,7 +341,7 @@ class VirtualMachineService
public function CheckVirtualMachine($vmware_id = '')
{
if ($this->client->checkApiExits()) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -358,7 +359,7 @@ class VirtualMachineService
{
$check = $this->client->checkApiExits();
if ($check) {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -383,7 +384,7 @@ class VirtualMachineService
return null;
}
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -406,7 +407,7 @@ class VirtualMachineService
public function GetDetailVirtualMachine($vmware_id = ''): array
{
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -425,7 +426,7 @@ class VirtualMachineService
public function GetIPAddressVirtualMachine($vmware_id = ''): array
{
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -451,7 +452,7 @@ class VirtualMachineService
];
try {
$hardwareResponse = Http::withoutVerifying()
$hardwareResponse = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -480,7 +481,7 @@ class VirtualMachineService
}
}
$guestMemoryResponse = Http::withoutVerifying()
$guestMemoryResponse = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -494,7 +495,7 @@ class VirtualMachineService
: 0;
}
$guestCpuResponse = Http::withoutVerifying()
$guestCpuResponse = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -512,7 +513,7 @@ class VirtualMachineService
public function ConfigNetworkVirtualMachine($vmware_id = '', $config = []): int
{
return Http::withoutVerifying()
return TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -526,7 +527,7 @@ class VirtualMachineService
if ($check) {
try {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -552,7 +553,7 @@ class VirtualMachineService
}
try {
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -578,7 +579,7 @@ class VirtualMachineService
$vmId = $vmList[0]['vm'];
$detailResponse = Http::withoutVerifying()
$detailResponse = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -655,7 +656,7 @@ class VirtualMachineService
"size_MiB" => $ram * 1024,
]
];
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])
@@ -686,7 +687,7 @@ class VirtualMachineService
"count" => $cpu
]
];
$response = Http::withoutVerifying()
$response = TlsHttpClientFactory::vCenter()
->withHeaders([
'vmware-api-session-id' => $this->client->token
])