33namespace Pterodactyl \Http \Controllers \Api \Remote \Backups ;
44
55use Carbon \CarbonImmutable ;
6+ use Illuminate \Http \Request ;
67use Pterodactyl \Models \Backup ;
8+ use Pterodactyl \Models \Server ;
79use Pterodactyl \Models \AuditLog ;
810use Illuminate \Http \JsonResponse ;
911use League \Flysystem \AwsS3v3 \AwsS3Adapter ;
@@ -47,7 +49,7 @@ public function __construct(BackupRepository $repository, BackupManager $backupM
4749 *
4850 * @throws \Throwable
4951 */
50- public function __invoke (ReportBackupCompleteRequest $ request , string $ backup )
52+ public function index (ReportBackupCompleteRequest $ request , string $ backup )
5153 {
5254 /** @var \Pterodactyl\Models\Backup $model */
5355 $ model = Backup::query ()->where ('uuid ' , $ backup )->firstOrFail ();
@@ -63,6 +65,7 @@ public function __invoke(ReportBackupCompleteRequest $request, string $backup)
6365 : AuditLog::SERVER__BACKUP_FAILED ;
6466
6567 $ model ->server ->audit ($ action , function (AuditLog $ audit ) use ($ model , $ request ) {
68+ $ audit ->is_system = true ;
6669 $ audit ->metadata = ['backup_uuid ' => $ model ->uuid ];
6770
6871 $ successful = $ request ->input ('successful ' ) ? true : false ;
@@ -84,6 +87,39 @@ public function __invoke(ReportBackupCompleteRequest $request, string $backup)
8487 return new JsonResponse ([], JsonResponse::HTTP_NO_CONTENT );
8588 }
8689
90+ /**
91+ * Handles toggling the restoration status of a server. The server status field should be
92+ * set back to null, even if the restoration failed. This is not an unsolvable state for
93+ * the server, and the user can keep trying to restore, or just use the reinstall button.
94+ *
95+ * The only thing the successful field does is update the entry value for the audit logs
96+ * table tracking for this restoration.
97+ *
98+ * @param \Illuminate\Http\Request $request
99+ * @param string $backup
100+ * @return \Illuminate\Http\JsonResponse
101+ *
102+ * @throws \Throwable
103+ */
104+ public function restore (Request $ request , string $ backup )
105+ {
106+ /** @var \Pterodactyl\Models\Backup $model */
107+ $ model = Backup::query ()->where ('uuid ' , $ backup )->firstOrFail ();
108+ $ action = $ request ->get ('successful ' )
109+ ? AuditLog::SERVER__BACKUP_RESTORE_COMPLETED
110+ : AuditLog::SERVER__BACKUP_RESTORE_FAILED ;
111+
112+ // Just create a new audit entry for this event and update the server state
113+ // so that power actions, file management, and backups can resume as normal.
114+ $ model ->server ->audit ($ action , function (AuditLog $ audit , Server $ server ) use ($ backup , $ request ) {
115+ $ audit ->is_system = true ;
116+ $ audit ->metadata = ['backup_uuid ' => $ backup ];
117+ $ server ->update (['status ' => null ]);
118+ });
119+
120+ return new JsonResponse ([], JsonResponse::HTTP_NO_CONTENT );
121+ }
122+
87123 /**
88124 * Marks a multipart upload in a given S3-compatiable instance as failed or successful for
89125 * the given backup.
0 commit comments