update fix deadcode, security

This commit is contained in:
baodev0
2026-09-28 08:26:29 +07:00
parent 3af59bd9c5
commit 82080b5b84
452 changed files with 4857 additions and 26289 deletions
-61
View File
@@ -5,9 +5,7 @@ declare(strict_types=1);
namespace App\Services;
use App\Http\Facade\SignRSA;
use App\Http\Services\vCenter as VCenterService;
use App\Models\ModuleVmware;
use App\Support\TlsHttpClientFactory;
use Illuminate\Support\Facades\Log;
final class VmProvisionService
@@ -21,48 +19,6 @@ final class VmProvisionService
return config('vmware.template_password');
}
// -------------------------------------------------------------------------
// vCenter REST helpers (used by WaitVmReadyJob if still in flow)
// -------------------------------------------------------------------------
public function loginVCenter(\App\Models\vCenter $vcenter, VCenterService $service): void
{
if (!$service->loginServer($vcenter)) {
throw new \RuntimeException("vCenter login failed for host={$vcenter->host}");
}
}
/**
* @return array{tools_running:bool,ip_address:string|null,os_family:string|null}
*/
public function getVmGuestInfo(VCenterService $service, string $vmId): array
{
try {
$response = TlsHttpClientFactory::vCenter()
->withHeaders(['vmware-api-session-id' => $service->token])
->timeout(10)
->get("https://{$service->apiUri}/rest/vcenter/vm/{$vmId}/guest/identity");
if (!$response->successful()) {
return ['tools_running' => false, 'ip_address' => null, 'os_family' => null];
}
$value = $response->json('value', []);
$ip = trim((string) ($value['ip_address'] ?? ''));
return [
'tools_running' => $ip !== '' && $ip !== '0.0.0.0',
'ip_address' => $ip ?: null,
'os_family' => isset($value['family']) ? strtoupper((string) $value['family']) : null,
];
} catch (\Throwable $e) {
Log::warning('VmProvisionService::getVmGuestInfo error', [
'vm_id' => $vmId, 'error' => $e->getMessage(),
]);
return ['tools_running' => false, 'ip_address' => null, 'os_family' => null];
}
}
// -------------------------------------------------------------------------
// Password
// -------------------------------------------------------------------------
@@ -124,21 +80,4 @@ final class VmProvisionService
'module_vmware_id' => $moduleVmwareId,
]);
}
/**
* Update password + overwrite IP (used when real guest IP differs from pool IP).
*/
public function savePassword(int $moduleVmwareId, string $ip, string $plainPassword): void
{
ModuleVmware::findOrFail($moduleVmwareId)->update([
'ip' => $ip,
'password' => $this->encryptPassword($plainPassword),
'plain_password' => $plainPassword,
]);
Log::info('VmProvisionService::savePassword saved', [
'module_vmware_id' => $moduleVmwareId,
'ip' => $ip,
]);
}
}