'required|string', 'password' => 'required|string', 'server' => 'required|string', ]; protected $vpnManager; public function boot(VpnManager $vpnManager) { $this->vpnManager = $vpnManager; } public function mount() { $this->refreshStatus(); } public function render() { return view('livewire.vpn-management'); } public function refreshStatus() { $this->vpnStatus = $this->vpnManager->getVpnStatus(); $this->lastUpdate = $this->vpnManager->getLastUpdate(); $this->emit('vpnStatusUpdated', $this->vpnStatus); } public function updateCredentials() { $this->validate(); try { $success = $this->vpnManager->updateCredentials( $this->username, $this->password, $this->server ); if ($success) { $this->successMessage = 'Credenziali VPN aggiornate con successo!'; $this->errorMessage = ''; $this->password = ''; // Clear password field for security // Emit event for JavaScript notification $this->emit('showToast', 'success', 'Credenziali VPN aggiornate con successo!'); Log::info('VPN credentials updated successfully'); } else { $this->errorMessage = 'Errore nell\'aggiornamento delle credenziali VPN.'; $this->successMessage = ''; $this->emit('showToast', 'error', 'Errore nell\'aggiornamento delle credenziali VPN.'); } } catch (\Exception $e) { $this->errorMessage = 'Errore: ' . $e->getMessage(); $this->successMessage = ''; $this->emit('showToast', 'error', 'Errore: ' . $e->getMessage()); Log::error('Error updating VPN credentials: ' . $e->getMessage()); } } public function connectVpn() { try { $result = $this->vpnManager->connectVpn(); if ($result) { $this->emit('showToast', 'success', 'Comando di connessione VPN inviato!'); Log::info('VPN connection command sent'); // Refresh status after a delay $this->emit('refreshStatusDelayed'); } else { $this->emit('showToast', 'error', 'Errore nel lancio della connessione VPN'); Log::error('Failed to send VPN connection command'); } } catch (\Exception $e) { $this->emit('showToast', 'error', 'Errore: ' . $e->getMessage()); Log::error('Error connecting VPN: ' . $e->getMessage()); } } public function disconnectVpn() { try { $result = $this->vpnManager->disconnectVpn(); if ($result) { $this->emit('showToast', 'success', 'Comando di disconnessione VPN inviato!'); Log::info('VPN disconnection command sent'); // Refresh status after a delay $this->emit('refreshStatusDelayed'); } else { $this->emit('showToast', 'error', 'Errore nella disconnessione VPN'); Log::error('Failed to send VPN disconnection command'); } } catch (\Exception $e) { $this->emit('showToast', 'error', 'Errore: ' . $e->getMessage()); Log::error('Error disconnecting VPN: ' . $e->getMessage()); } } public function getStatusBadgeClass() { return match($this->vpnStatus) { 'connected' => 'badge badge-success', 'disconnected' => 'badge badge-danger', 'error' => 'badge badge-danger', default => 'badge badge-warning' }; } public function getStatusBadgeText() { return match($this->vpnStatus) { 'connected' => 'ON', 'disconnected' => 'OFF', 'error' => 'ERR', default => '?' }; } public function getStatusIconClass() { return match($this->vpnStatus) { 'connected' => 'info-box-icon bg-success', 'disconnected' => 'info-box-icon bg-danger', 'error' => 'info-box-icon bg-danger', default => 'info-box-icon bg-warning' }; } public function getStatusIcon() { return match($this->vpnStatus) { 'connected' => 'fas fa-check', 'disconnected' => 'fas fa-times', 'error' => 'fas fa-exclamation-triangle', default => 'fas fa-question' }; } public function getStatusText() { return match($this->vpnStatus) { 'connected' => 'Connesso', 'disconnected' => 'Disconnesso', 'error' => 'Errore', default => 'Sconosciuto' }; } }