refactor: dynamicize jumphost credentials from database and restrict CORS allowed origins

This commit is contained in:
pbao9
2026-05-12 15:37:19 +07:00
parent 760b58e08d
commit cfffff96bf
2 changed files with 32 additions and 6 deletions
+26 -5
View File
@@ -10,6 +10,7 @@ use Exception;
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Client\ConnectionException;
use App\Http\Facade\SignRSA;
use App\Models\InfraManagement;
use Illuminate\Support\Str;
use phpseclib3\Net\SSH2;
@@ -397,17 +398,37 @@ class vCenter
}
private function LoginAuth()
{
try {
$connection = new SSH2('10.10.10.173', 22);
$infra = InfraManagement::where('type', 'jumphost')
->where('status', true)
->first();
if ($connection->login('administrator', 'Thegioiso@123**$$8899TgTk2')) {
$connection->setTimeout(0); // No timeout
if (!$infra) {
Log::error('SSH Login Failed: No active jumphost configuration found in InfraManagement.');
return false;
}
$sshHost = $infra->host;
$sshPort = 22;
if (isset($infra->meta_data['port'])) {
$sshPort = $infra->meta_data['port'];
}
$sshUser = $infra->username;
$sshPass = SignRSA::DecryptFunc($infra->password);
$connection = new SSH2($sshHost, $sshPort);
if ($connection->login($sshUser, $sshPass)) {
$connection->setTimeout(0);
return $connection;
}
Log::error('SSH Login Failed: Invalid credentials for jumphost.');
return false;
} catch (Exception $error) {
return $error->getCode();
Log::error('SSH Login Failed: ' . $error->getMessage());
return false;
}
}
+6 -1
View File
@@ -18,7 +18,12 @@ return [
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins' => [
'http://localhost:3000',
'http://localhost:5173',
'http://localhost:5174',
'https://portal.tgs.com.vn',
],
'allowed_origins_patterns' => [],