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, ]); } }