Audit when a backup is successful or fails

This commit is contained in:
Dane Everitt 2021-01-17 15:22:02 -08:00
parent 291c65275a
commit bfc6f34c50
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -4,6 +4,7 @@ namespace Pterodactyl\Http\Controllers\Api\Remote\Backups;
use Carbon\CarbonImmutable; use Carbon\CarbonImmutable;
use Pterodactyl\Models\Backup; use Pterodactyl\Models\Backup;
use Pterodactyl\Models\AuditLog;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use League\Flysystem\AwsS3v3\AwsS3Adapter; use League\Flysystem\AwsS3v3\AwsS3Adapter;
use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Http\Controllers\Controller;
@ -44,7 +45,7 @@ class BackupStatusController extends Controller
* @param string $backup * @param string $backup
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
* *
* @throws \Exception * @throws \Throwable
*/ */
public function __invoke(ReportBackupCompleteRequest $request, string $backup) public function __invoke(ReportBackupCompleteRequest $request, string $backup)
{ {
@ -57,8 +58,14 @@ class BackupStatusController extends Controller
); );
} }
$successful = $request->input('successful') ? true : false; $action = $request->input('successful')
? AuditLog::ACTION_SERVER_BACKUP_COMPELTED
: AuditLog::ACTION_SERVER_BACKUP_FAILED;
$model->server->audit($action, function (AuditLog $audit) use ($model, $request) {
$audit->metadata = ['backup_uuid' => $model->uuid];
$successful = $request->input('successful') ? true : false;
$model->fill([ $model->fill([
'is_successful' => $successful, 'is_successful' => $successful,
'checksum' => $successful ? ($request->input('checksum_type') . ':' . $request->input('checksum')) : null, 'checksum' => $successful ? ($request->input('checksum_type') . ':' . $request->input('checksum')) : null,
@ -72,6 +79,7 @@ class BackupStatusController extends Controller
if ($adapter instanceof AwsS3Adapter) { if ($adapter instanceof AwsS3Adapter) {
$this->completeMultipartUpload($model, $adapter, $successful); $this->completeMultipartUpload($model, $adapter, $successful);
} }
});
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
} }