mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-16 01:32:39 -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.
94 lines
3.9 KiB
PHP
94 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Auth\Events\Failed;
|
|
use Illuminate\Auth\Events\Login;
|
|
use Illuminate\Auth\Events\Logout;
|
|
use Illuminate\Auth\Events\PasswordReset;
|
|
use Illuminate\Auth\Events\Registered;
|
|
use Illuminate\Auth\Events\Verified;
|
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Laravel\Fortify\Events\RecoveryCodesGenerated;
|
|
use Laravel\Fortify\Events\TwoFactorAuthenticationConfirmed;
|
|
use Laravel\Fortify\Events\TwoFactorAuthenticationDisabled;
|
|
use Laravel\Fortify\Events\TwoFactorAuthenticationEnabled;
|
|
use SocialiteProviders\Authentik\AuthentikExtendSocialite;
|
|
use SocialiteProviders\Azure\AzureExtendSocialite;
|
|
use SocialiteProviders\Clerk\ClerkExtendSocialite;
|
|
use SocialiteProviders\Discord\DiscordExtendSocialite;
|
|
use SocialiteProviders\Google\GoogleExtendSocialite;
|
|
use SocialiteProviders\Infomaniak\InfomaniakExtendSocialite;
|
|
use SocialiteProviders\Manager\SocialiteWasCalled;
|
|
use SocialiteProviders\Zitadel\ZitadelExtendSocialite;
|
|
|
|
class EventServiceProvider extends ServiceProvider
|
|
{
|
|
protected $listen = [
|
|
SocialiteWasCalled::class => [
|
|
AzureExtendSocialite::class.'@handle',
|
|
AuthentikExtendSocialite::class.'@handle',
|
|
ClerkExtendSocialite::class.'@handle',
|
|
DiscordExtendSocialite::class.'@handle',
|
|
GoogleExtendSocialite::class.'@handle',
|
|
InfomaniakExtendSocialite::class.'@handle',
|
|
ZitadelExtendSocialite::class.'@handle',
|
|
],
|
|
];
|
|
|
|
public function boot(): void
|
|
{
|
|
Event::listen(Login::class, function (Login $event): void {
|
|
auditLog('auth.user.login_succeeded', $this->authContext($event->user));
|
|
});
|
|
Event::listen(Failed::class, function (Failed $event): void {
|
|
auditLog('auth.user.login_failed', [
|
|
'attempted_email' => data_get($event->credentials, 'email'),
|
|
'guard' => $event->guard,
|
|
], 'warning');
|
|
});
|
|
Event::listen(Logout::class, function (Logout $event): void {
|
|
auditLog('auth.user.logged_out', $this->authContext($event->user));
|
|
});
|
|
Event::listen(Registered::class, function (Registered $event): void {
|
|
auditLog('auth.user.registered', $this->authContext($event->user));
|
|
});
|
|
Event::listen(Verified::class, function (Verified $event): void {
|
|
auditLog('auth.user.email_verified', $this->authContext($event->user));
|
|
});
|
|
Event::listen(PasswordReset::class, function (PasswordReset $event): void {
|
|
auditLog('auth.user.password_reset', $this->authContext($event->user));
|
|
});
|
|
Event::listen(TwoFactorAuthenticationEnabled::class, function (TwoFactorAuthenticationEnabled $event): void {
|
|
auditLog('auth.user.two_factor_enabled', $this->authContext($event->user));
|
|
});
|
|
Event::listen(TwoFactorAuthenticationConfirmed::class, function (TwoFactorAuthenticationConfirmed $event): void {
|
|
auditLog('auth.user.two_factor_confirmed', $this->authContext($event->user));
|
|
});
|
|
Event::listen(TwoFactorAuthenticationDisabled::class, function (TwoFactorAuthenticationDisabled $event): void {
|
|
auditLog('auth.user.two_factor_disabled', $this->authContext($event->user));
|
|
});
|
|
Event::listen(RecoveryCodesGenerated::class, function (RecoveryCodesGenerated $event): void {
|
|
auditLog('auth.user.recovery_codes_regenerated', $this->authContext($event->user));
|
|
});
|
|
}
|
|
|
|
private function authContext(?object $user): array
|
|
{
|
|
return [
|
|
'team_id' => $user?->currentTeam()?->id,
|
|
'resource' => 'user',
|
|
'user_name' => $user?->name,
|
|
'actor_id' => $user?->id,
|
|
'actor_name' => $user?->name,
|
|
'actor_email' => $user?->email,
|
|
];
|
|
}
|
|
|
|
public function shouldDiscoverEvents(): bool
|
|
{
|
|
return true;
|
|
}
|
|
}
|