refactor: simplify Proxmox firewall request handling by hardcoding credentials and removing unnecessary logging, enhancing code clarity and maintainability
This commit is contained in:
@@ -213,15 +213,13 @@ class Firewall extends Component
|
||||
|
||||
protected function firewallRequest(string $url, string $method = 'get', array $data = []): \Illuminate\Http\Client\Response
|
||||
{
|
||||
// Get the Proxmox extension configuration
|
||||
$proxmox = new \Paymenter\Extensions\Servers\Proxmox\Proxmox();
|
||||
$baseUrl = $proxmox->config('host');
|
||||
$user = $proxmox->config('user');
|
||||
$token = $proxmox->config('token');
|
||||
$verifySsl = $proxmox->config('verify_ssl', true);
|
||||
$baseUrl = 'https://pve.virtnet.bond';
|
||||
$user = 'root@pam';
|
||||
$tokenId = 'firewall';
|
||||
$secret = '0a439967-0a44-4b94-8906-c36b3a40cf68';
|
||||
|
||||
$fullUrl = rtrim($baseUrl, '/') . '/api2/json' . $url;
|
||||
$authHeader = 'PVEAPIToken=' . $user . '=' . $token;
|
||||
$authHeader = 'PVEAPIToken=' . $user . '!' . $tokenId . '=' . $secret;
|
||||
|
||||
$acceptHeader = str_contains($url, '/firewall/log')
|
||||
? 'application/json, text/plain, */*'
|
||||
@@ -230,11 +228,7 @@ class Firewall extends Component
|
||||
$request = Http::withHeaders([
|
||||
'Authorization' => $authHeader,
|
||||
'Accept' => $acceptHeader,
|
||||
]);
|
||||
|
||||
if (!$verifySsl) {
|
||||
$request = $request->withoutVerifying();
|
||||
}
|
||||
])->withoutVerifying();
|
||||
|
||||
$response = match($method) {
|
||||
'post' => $request->post($fullUrl, $data),
|
||||
@@ -306,30 +300,14 @@ class Firewall extends Component
|
||||
[$adapter . '.firewall' => $newState ? 1 : 0]
|
||||
);
|
||||
|
||||
Log::info('Adapter firewall toggle API call', [
|
||||
'vm_id' => $this->server->vm_id,
|
||||
'node' => $this->server->node->name,
|
||||
'adapter' => $adapter,
|
||||
'new_state' => $newState,
|
||||
'status' => $response->status(),
|
||||
'body' => $response->body(),
|
||||
'headers' => $response->headers(),
|
||||
'url' => '/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/config',
|
||||
]);
|
||||
|
||||
if ($response->successful()) {
|
||||
$this->adapterFirewallStates[$adapter] = $newState;
|
||||
$this->notify('Adapter firewall ' . ($newState ? 'enabled' : 'disabled'), 'success');
|
||||
} else {
|
||||
$this->error = 'Failed to toggle adapter firewall - Status: ' . $response->status() . ' - ' . $response->body();
|
||||
$this->error = 'Failed to toggle adapter firewall';
|
||||
$this->showErrorModal = true;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Adapter firewall toggle exception: ' . $e->getMessage(), [
|
||||
'vm_id' => $this->server->vm_id,
|
||||
'node' => $this->server->node->name,
|
||||
'adapter' => $adapter,
|
||||
]);
|
||||
$this->error = 'Failed to toggle adapter firewall: ' . $e->getMessage();
|
||||
$this->showErrorModal = true;
|
||||
} finally {
|
||||
@@ -377,28 +355,14 @@ class Firewall extends Component
|
||||
]
|
||||
);
|
||||
|
||||
Log::info('Firewall toggle API call', [
|
||||
'vm_id' => $this->server->vm_id,
|
||||
'node' => $this->server->node->name,
|
||||
'new_state' => $newState,
|
||||
'status' => $response->status(),
|
||||
'body' => $response->body(),
|
||||
'headers' => $response->headers(),
|
||||
'url' => '/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/firewall/options',
|
||||
]);
|
||||
|
||||
if ($response->successful()) {
|
||||
$this->firewallEnabled = $newState;
|
||||
$this->notify('Firewall ' . ($newState ? 'enabled' : 'disabled'), 'success');
|
||||
} else {
|
||||
$this->error = 'Failed to toggle firewall - Status: ' . $response->status() . ' - ' . $response->body();
|
||||
$this->error = 'Failed to toggle firewall';
|
||||
$this->showErrorModal = true;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Firewall toggle exception: ' . $e->getMessage(), [
|
||||
'vm_id' => $this->server->vm_id,
|
||||
'node' => $this->server->node->name,
|
||||
]);
|
||||
$this->error = 'Failed to toggle firewall: ' . $e->getMessage();
|
||||
$this->showErrorModal = true;
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user