refactor: dynamicize jumphost credentials from database and restrict CORS allowed origins
This commit is contained in:
@@ -10,6 +10,7 @@ use Exception;
|
|||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Http\Client\ConnectionException;
|
use Illuminate\Http\Client\ConnectionException;
|
||||||
use App\Http\Facade\SignRSA;
|
use App\Http\Facade\SignRSA;
|
||||||
|
use App\Models\InfraManagement;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use phpseclib3\Net\SSH2;
|
use phpseclib3\Net\SSH2;
|
||||||
|
|
||||||
@@ -397,17 +398,37 @@ class vCenter
|
|||||||
}
|
}
|
||||||
private function LoginAuth()
|
private function LoginAuth()
|
||||||
{
|
{
|
||||||
|
|
||||||
try {
|
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')) {
|
if (!$infra) {
|
||||||
$connection->setTimeout(0); // No timeout
|
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;
|
return $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::error('SSH Login Failed: Invalid credentials for jumphost.');
|
||||||
return false;
|
return false;
|
||||||
} catch (Exception $error) {
|
} catch (Exception $error) {
|
||||||
return $error->getCode();
|
Log::error('SSH Login Failed: ' . $error->getMessage());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -18,7 +18,12 @@ return [
|
|||||||
|
|
||||||
'allowed_methods' => ['*'],
|
'allowed_methods' => ['*'],
|
||||||
|
|
||||||
'allowed_origins' => ['*'],
|
'allowed_origins' => [
|
||||||
|
'http://localhost:3000',
|
||||||
|
'http://localhost:5173',
|
||||||
|
'http://localhost:5174',
|
||||||
|
'https://portal.tgs.com.vn',
|
||||||
|
],
|
||||||
|
|
||||||
'allowed_origins_patterns' => [],
|
'allowed_origins_patterns' => [],
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user