mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 08:42:38 -04:00
Add audit events for account actions, server and application settings, services, destinations, storage, backup schedules, and scheduled tasks. Track changed fields and skip unchanged saves without logging file content. Add regression coverage for audit events and changed-field detection.
85 lines
2.5 KiB
PHP
85 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Server\Security;
|
|
|
|
use App\Models\Server;
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
|
|
class TerminalAccess extends Component
|
|
{
|
|
use AuthorizesRequests;
|
|
|
|
public Server $server;
|
|
|
|
public array $parameters = [];
|
|
|
|
#[Validate(['boolean'])]
|
|
public bool $isTerminalEnabled = false;
|
|
|
|
public function mount(string $server_uuid)
|
|
{
|
|
try {
|
|
$this->server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail();
|
|
$this->authorize('update', $this->server);
|
|
$this->parameters = get_route_parameters();
|
|
$this->syncData();
|
|
|
|
} catch (\Throwable) {
|
|
return redirect()->route('server.index');
|
|
}
|
|
}
|
|
|
|
public function toggleTerminal($password, $selectedActions = [])
|
|
{
|
|
try {
|
|
$this->authorize('update', $this->server);
|
|
|
|
// Check if user is admin or owner
|
|
if (! auth()->user()->isAdmin()) {
|
|
throw new \Exception('Only team administrators and owners can modify terminal access.');
|
|
}
|
|
|
|
// Verify password
|
|
if (! verifyPasswordConfirmation($password, $this)) {
|
|
return 'The provided password is incorrect.';
|
|
}
|
|
|
|
// Toggle the terminal setting
|
|
$this->server->settings->is_terminal_enabled = ! $this->server->settings->is_terminal_enabled;
|
|
$this->server->settings->save();
|
|
|
|
// Update the local property
|
|
$this->isTerminalEnabled = $this->server->settings->is_terminal_enabled;
|
|
|
|
$status = $this->isTerminalEnabled ? 'enabled' : 'disabled';
|
|
auditLog("ui.server.terminal_access.{$status}", [
|
|
'team_id' => $this->server->team_id,
|
|
'server_uuid' => $this->server->uuid,
|
|
'server_name' => $this->server->name,
|
|
]);
|
|
$this->dispatch('success', "Terminal access has been {$status}.");
|
|
|
|
return true;
|
|
} catch (\Throwable $e) {
|
|
return handleError($e, $this);
|
|
}
|
|
}
|
|
|
|
private function syncData(bool $toModel = false): void
|
|
{
|
|
if ($toModel) {
|
|
$this->validate();
|
|
// No other fields to sync for terminal access
|
|
} else {
|
|
$this->isTerminalEnabled = $this->server->settings->is_terminal_enabled;
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.server.security.terminal-access');
|
|
}
|
|
}
|