Reduce security and reliability risk across the Proxmox extension by removing password exposure from Livewire state, hardening console auth/cookie handling, and improving sanitized error paths. Improve firewall and router performance by adding safer lazy loading, bounded pagination, cross-server compatibility guards, and lower-overhead API workflows. Made-with: Cursor
105 lines
3.1 KiB
PHP
105 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace Paymenter\Extensions\Servers\Proxmox\Livewire;
|
|
|
|
use Paymenter\Extensions\Servers\Proxmox\Models\OS;
|
|
use Paymenter\Extensions\Servers\Proxmox\Models\Server;
|
|
use Paymenter\Extensions\Servers\Proxmox\Proxmox;
|
|
|
|
class Reinstall extends Component
|
|
{
|
|
public $os;
|
|
|
|
public bool $visible = false;
|
|
|
|
public $confirmReinstall = false;
|
|
|
|
public bool $isProtected = false;
|
|
public bool $protectionCheckFailed = false;
|
|
public $osList = [];
|
|
|
|
public function mount(Server $server): void
|
|
{
|
|
parent::mount($server);
|
|
$this->os = $server->os_id;
|
|
$this->checkProtectedStatus();
|
|
$this->loadOsList();
|
|
}
|
|
|
|
protected function checkProtectedStatus(): void
|
|
{
|
|
try {
|
|
$proxmox = new Proxmox;
|
|
$config = $proxmox->request('/nodes/' . $this->server->node->name . '/' . $this->server->node->vmType() . '/' . $this->server->vm_id . '/config')->json()['data'] ?? [];
|
|
// Protected can be 1, '1', true, or missing/null
|
|
$this->isProtected = isset($config['protection']) && ($config['protection'] == 1 || $config['protection'] === '1' || $config['protection'] === true);
|
|
$this->protectionCheckFailed = false;
|
|
} catch (\Throwable $e) {
|
|
// Fail closed for destructive operations when protection status cannot be verified
|
|
$this->isProtected = true;
|
|
$this->protectionCheckFailed = true;
|
|
}
|
|
}
|
|
|
|
public function reinstall()
|
|
{
|
|
// Check protected status again before proceeding
|
|
$this->checkProtectedStatus();
|
|
|
|
if ($this->isProtected) {
|
|
if ($this->protectionCheckFailed) {
|
|
$this->notify('Cannot reinstall: Unable to verify server protection status. Please try again.', 'error');
|
|
} else {
|
|
$this->notify('Cannot reinstall: This server is protected in Proxmox', 'error');
|
|
}
|
|
return;
|
|
}
|
|
|
|
$this->validate([
|
|
'os' => 'required',
|
|
]);
|
|
if (!$this->confirmReinstall) {
|
|
$this->notify('Please confirm the reinstall', 'error');
|
|
|
|
return;
|
|
}
|
|
try {
|
|
$proxmox = new Proxmox;
|
|
$proxmox->reinstall($this->server);
|
|
} catch (\Throwable $e) {
|
|
report($e);
|
|
$this->notify('Reinstall failed. Please try again in a moment.', 'error');
|
|
return;
|
|
}
|
|
|
|
$this->server->os_id = $this->os;
|
|
$this->server->save();
|
|
|
|
$this->redirect(route('proxmox.index'));
|
|
}
|
|
|
|
protected function loadOsList(): void
|
|
{
|
|
if (!$this->server->node) {
|
|
$this->osList = collect();
|
|
return;
|
|
}
|
|
|
|
$locationId = $this->server->node->location_id;
|
|
$isLxc = (bool) ($this->server->node->is_lxc ?? false);
|
|
|
|
$this->osList = OS::query()
|
|
->where('location_id', $locationId)
|
|
->where('is_lxc', $isLxc)
|
|
->get();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('proxmox::reinstall', [
|
|
'osList' => $this->osList,
|
|
'isProtected' => $this->isProtected,
|
|
]);
|
|
}
|
|
}
|