49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Internal;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Facade\SignRSA;
|
|
use App\Models\vCenter;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class PortalMonitorVCenterController extends Controller
|
|
{
|
|
public function __invoke(): JsonResponse
|
|
{
|
|
$vcenter = vCenter::query()
|
|
->where('status', 1)
|
|
->orderBy('id')
|
|
->first();
|
|
|
|
if (!$vcenter) {
|
|
return response()->json([
|
|
'error' => true,
|
|
'message' => 'Active vCenter configuration is unavailable',
|
|
], 503);
|
|
}
|
|
|
|
$username = trim((string) $vcenter->user);
|
|
$password = SignRSA::DecryptFunc($vcenter->password);
|
|
$host = trim((string) $vcenter->host);
|
|
$port = 443;
|
|
|
|
if ($host === '' || $port < 1 || $username === '' || $password === '') {
|
|
return response()->json([
|
|
'error' => true,
|
|
'message' => 'Active vCenter configuration is incomplete',
|
|
], 503);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => [
|
|
'host' => $host,
|
|
'port' => $port,
|
|
'username' => $username,
|
|
'password' => $password,
|
|
],
|
|
])->header('Cache-Control', 'no-store, private');
|
|
}
|
|
}
|