diff --git a/app/Http/Controllers/Api/Client/Servers/BackupController.php b/app/Http/Controllers/Api/Client/Servers/BackupController.php index 5ba8475ed..c18aac3ac 100644 --- a/app/Http/Controllers/Api/Client/Servers/BackupController.php +++ b/app/Http/Controllers/Api/Client/Servers/BackupController.php @@ -80,7 +80,7 @@ class BackupController extends ClientApiController public function store(StoreBackupRequest $request, Server $server) { /** @var \Pterodactyl\Models\Backup $backup */ - $backup = $server->audit(AuditLog::ACTION_SERVER_BACKUP_STARTED, function (AuditLog $model, Server $server) use ($request) { + $backup = $server->audit(AuditLog::SERVER__BACKUP_STARTED, function (AuditLog $model, Server $server) use ($request) { $backup = $this->initiateBackupService ->setIgnoredFiles( explode(PHP_EOL, $request->input('ignored') ?? '') @@ -125,7 +125,9 @@ class BackupController extends ClientApiController */ public function delete(DeleteBackupRequest $request, Server $server, Backup $backup) { - $server->audit(AuditLog::ACTION_SERVER_BACKUP_DELETED, function () use ($backup) { + $server->audit(AuditLog::SERVER__BACKUP_DELETED, function (AuditLog $audit) use ($backup) { + $audit->metadata = ['backup_uuid' => $backup->uuid]; + $this->deleteBackupService->handle($backup); }); diff --git a/app/Http/Controllers/Api/Client/Servers/FileController.php b/app/Http/Controllers/Api/Client/Servers/FileController.php index 2a2d96e06..df0fdded6 100644 --- a/app/Http/Controllers/Api/Client/Servers/FileController.php +++ b/app/Http/Controllers/Api/Client/Servers/FileController.php @@ -110,7 +110,7 @@ class FileController extends ClientApiController */ public function download(GetFileContentsRequest $request, Server $server) { - $token = $server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_DOWNLOAD, function (AuditLog $audit, Server $server) use ($request) { + $token = $server->audit(AuditLog::SERVER__FILESYSTEM_DOWNLOAD, function (AuditLog $audit, Server $server) use ($request) { $audit->metadata = ['file' => $request->get('file')]; return $this->jwtService @@ -145,7 +145,7 @@ class FileController extends ClientApiController */ public function write(WriteFileContentRequest $request, Server $server): JsonResponse { - $server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) { + $server->audit(AuditLog::SERVER__FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) { $audit->subaction = 'write_content'; $audit->metadata = ['file' => $request->get('file')]; @@ -168,7 +168,7 @@ class FileController extends ClientApiController */ public function create(CreateFolderRequest $request, Server $server): JsonResponse { - $server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) { + $server->audit(AuditLog::SERVER__FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) { $audit->subaction = 'create_folder'; $audit->metadata = ['file' => $request->input('root', '/') . $request->input('name')]; @@ -191,7 +191,7 @@ class FileController extends ClientApiController */ public function rename(RenameFileRequest $request, Server $server): JsonResponse { - $server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_RENAME, function (AuditLog $audit, Server $server) use ($request) { + $server->audit(AuditLog::SERVER__FILESYSTEM_RENAME, function (AuditLog $audit, Server $server) use ($request) { $audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('files')]; $this->fileRepository @@ -213,7 +213,7 @@ class FileController extends ClientApiController */ public function copy(CopyFileRequest $request, Server $server): JsonResponse { - $server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) { + $server->audit(AuditLog::SERVER__FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) { $audit->subaction = 'copy_file'; $audit->metadata = ['file' => $request->input('location')]; @@ -234,7 +234,7 @@ class FileController extends ClientApiController */ public function compress(CompressFilesRequest $request, Server $server): array { - $file = $server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_COMPRESS, function (AuditLog $audit, Server $server) use ($request) { + $file = $server->audit(AuditLog::SERVER__FILESYSTEM_COMPRESS, function (AuditLog $audit, Server $server) use ($request) { // Allow up to five minutes for this request to process before timing out. set_time_limit(300); @@ -260,7 +260,7 @@ class FileController extends ClientApiController */ public function decompress(DecompressFilesRequest $request, Server $server): JsonResponse { - $file = $server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_DECOMPRESS, function (AuditLog $audit, Server $server) use ($request) { + $file = $server->audit(AuditLog::SERVER__FILESYSTEM_DECOMPRESS, function (AuditLog $audit, Server $server) use ($request) { // Allow up to five minutes for this request to process before timing out. set_time_limit(300); @@ -284,7 +284,7 @@ class FileController extends ClientApiController */ public function delete(DeleteFileRequest $request, Server $server): JsonResponse { - $server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_DELETE, function (AuditLog $audit, Server $server) use ($request) { + $server->audit(AuditLog::SERVER__FILESYSTEM_DELETE, function (AuditLog $audit, Server $server) use ($request) { $audit->metadata = ['root' => $request->input('root'), 'files' => $request->input('files')]; $this->fileRepository->setServer($server) @@ -326,7 +326,7 @@ class FileController extends ClientApiController */ public function pull(PullFileRequest $request, Server $server): JsonResponse { - $server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_PULL, function (AuditLog $audit, Server $server) use ($request) { + $server->audit(AuditLog::SERVER__FILESYSTEM_PULL, function (AuditLog $audit, Server $server) use ($request) { $audit->metadata = ['directory' => $request->input('directory'), 'url' => $request->input('url')]; $this->fileRepository->setServer($server)->pull($request->input('url'), $request->input('directory')); diff --git a/app/Http/Controllers/Api/Remote/Backups/BackupStatusController.php b/app/Http/Controllers/Api/Remote/Backups/BackupStatusController.php index 8880c2405..fd53103c8 100644 --- a/app/Http/Controllers/Api/Remote/Backups/BackupStatusController.php +++ b/app/Http/Controllers/Api/Remote/Backups/BackupStatusController.php @@ -59,8 +59,8 @@ class BackupStatusController extends Controller } $action = $request->input('successful') - ? AuditLog::ACTION_SERVER_BACKUP_COMPELTED - : AuditLog::ACTION_SERVER_BACKUP_FAILED; + ? AuditLog::SERVER__BACKUP_COMPELTED + : AuditLog::SERVER__BACKUP_FAILED; $model->server->audit($action, function (AuditLog $audit) use ($model, $request) { $audit->metadata = ['backup_uuid' => $model->uuid]; diff --git a/app/Models/AuditLog.php b/app/Models/AuditLog.php index e5a9204e8..8126f9f19 100644 --- a/app/Models/AuditLog.php +++ b/app/Models/AuditLog.php @@ -25,25 +25,20 @@ class AuditLog extends Model { const UPDATED_AT = null; - const ACTION_USER_AUTH_LOGIN = 'user:auth.login'; - const ACTION_USER_AUTH_FAILED = 'user:auth.failed'; - const ACTION_USER_AUTH_PASSWORD_CHANGED = 'user:auth.password-changed'; - - const ACTION_SERVER_FILESYSTEM_DOWNLOAD = 'server:filesystem.download'; - const ACTION_SERVER_FILESYSTEM_WRITE = 'server:filesystem.write'; - const ACTION_SERVER_FILESYSTEM_DELETE = 'server:filesystem.delete'; - const ACTION_SERVER_FILESYSTEM_RENAME = 'server:filesystem.rename'; - const ACTION_SERVER_FILESYSTEM_COMPRESS = 'server:filesystem.compress'; - const ACTION_SERVER_FILESYSTEM_DECOMPRESS = 'server:filesystem.decompress'; - const ACTION_SERVER_FILESYSTEM_PULL = 'server:filesystem.pull'; - - const ACTION_SERVER_BACKUP_STARTED = 'server:backup.started'; - const ACTION_SERVER_BACKUP_FAILED = 'server:backup.failed'; - const ACTION_SERVER_BACKUP_COMPELTED = 'server:backup.completed'; - const ACTION_SERVER_BACKUP_DELETED = 'server:backup.deleted'; - const ACTION_SERVER_BACKUP_RESTORE_STARTED = 'server:backup.restore.started'; - const ACTION_SERVER_BACKUP_RESTORE_COMPLETED = 'server:backup.restore.completed'; - const ACTION_SERVER_BACKUP_RESTORE_FAILED = 'server:backup.restore.failed'; + const SERVER__FILESYSTEM_DOWNLOAD = 'server:filesystem.download'; + const SERVER__FILESYSTEM_WRITE = 'server:filesystem.write'; + const SERVER__FILESYSTEM_DELETE = 'server:filesystem.delete'; + const SERVER__FILESYSTEM_RENAME = 'server:filesystem.rename'; + const SERVER__FILESYSTEM_COMPRESS = 'server:filesystem.compress'; + const SERVER__FILESYSTEM_DECOMPRESS = 'server:filesystem.decompress'; + const SERVER__FILESYSTEM_PULL = 'server:filesystem.pull'; + const SERVER__BACKUP_STARTED = 'server:backup.started'; + const SERVER__BACKUP_FAILED = 'server:backup.failed'; + const SERVER__BACKUP_COMPELTED = 'server:backup.completed'; + const SERVER__BACKUP_DELETED = 'server:backup.deleted'; + const SERVER__BACKUP_RESTORE_STARTED = 'server:backup.restore.started'; + const SERVER__BACKUP_RESTORE_COMPLETED = 'server:backup.restore.completed'; + const SERVER__BACKUP_RESTORE_FAILED = 'server:backup.restore.failed'; /** * @var string[]