From 1f01c653f162809bdf5864f84506fc5dec0b9718 Mon Sep 17 00:00:00 2001 From: Gonzalo Chavez Date: Mon, 9 Nov 2020 20:35:57 -0300 Subject: [PATCH 1/8] Backup rotation for schedules. --- app/Jobs/Schedule/RunTaskJob.php | 2 +- .../Backups/InitiateBackupService.php | 31 +++++++++++++------ .../server/schedules/TaskDetailsModal.tsx | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/Jobs/Schedule/RunTaskJob.php b/app/Jobs/Schedule/RunTaskJob.php index 8784a37cb..ee3c3e16d 100644 --- a/app/Jobs/Schedule/RunTaskJob.php +++ b/app/Jobs/Schedule/RunTaskJob.php @@ -69,7 +69,7 @@ class RunTaskJob extends Job implements ShouldQueue $commandRepository->setServer($server)->send($this->task->payload); break; case 'backup': - $backupService->setIgnoredFiles(explode(PHP_EOL, $this->task->payload))->handle($server, null); + $backupService->setIgnoredFiles(explode(PHP_EOL, $this->task->payload))->handle($server, null, true); break; default: throw new InvalidArgumentException('Cannot run a task that points to a non-existent action.'); diff --git a/app/Services/Backups/InitiateBackupService.php b/app/Services/Backups/InitiateBackupService.php index ca8c3decd..9b6ae9a6f 100644 --- a/app/Services/Backups/InitiateBackupService.php +++ b/app/Services/Backups/InitiateBackupService.php @@ -13,6 +13,7 @@ use Pterodactyl\Repositories\Eloquent\BackupRepository; use Pterodactyl\Repositories\Wings\DaemonBackupRepository; use Pterodactyl\Exceptions\Service\Backup\TooManyBackupsException; use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException; +use Pterodactyl\Services\Backups\DeleteBackupService; class InitiateBackupService { @@ -41,24 +42,32 @@ class InitiateBackupService */ private $backupManager; + /** + * @var \Pterodactyl\Services\Backups\DeleteBackupService + */ + private $deleteBackupService; + /** * InitiateBackupService constructor. * * @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository * @param \Illuminate\Database\ConnectionInterface $connection * @param \Pterodactyl\Repositories\Wings\DaemonBackupRepository $daemonBackupRepository + * @param \Pterodactyl\Services\Backups\DeleteBackupService $deleteBackupService * @param \Pterodactyl\Extensions\Backups\BackupManager $backupManager */ public function __construct( BackupRepository $repository, ConnectionInterface $connection, DaemonBackupRepository $daemonBackupRepository, + DeleteBackupService $deleteBackupService, BackupManager $backupManager ) { $this->repository = $repository; $this->connection = $connection; $this->daemonBackupRepository = $daemonBackupRepository; $this->backupManager = $backupManager; + $this->deleteBackupService = $deleteBackupService; } /** @@ -96,13 +105,8 @@ class InitiateBackupService * @throws \Pterodactyl\Exceptions\Service\Backup\TooManyBackupsException * @throws \Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException */ - public function handle(Server $server, string $name = null): Backup + public function handle(Server $server, string $name = null, bool $override = null): Backup { - // Do not allow the user to continue if this server is already at its limit. - if (! $server->backup_limit || $server->backups()->where('is_successful', true)->count() >= $server->backup_limit) { - throw new TooManyBackupsException($server->backup_limit); - } - $previous = $this->repository->getBackupsGeneratedDuringTimespan($server->id, 10); if ($previous->count() >= 2) { throw new TooManyRequestsHttpException( @@ -111,6 +115,17 @@ class InitiateBackupService ); } + if (! $server->backup_limit || $server->backups()->where('is_successful', true)->count() >= $server->backup_limit) { + if($override){ + // Remove latest backup + $last_backup = $server->backups()->where('is_successful', true)->oldest()->first(); + $this->deleteBackupService->handle($last_backup); + }else{ + // Do not allow the user to continue if this server is already at its limit. + throw new TooManyBackupsException($server->backup_limit); + } + } + return $this->connection->transaction(function () use ($server, $name) { /** @var \Pterodactyl\Models\Backup $backup */ $backup = $this->repository->create([ @@ -121,9 +136,7 @@ class InitiateBackupService 'disk' => $this->backupManager->getDefaultAdapter(), ], true, true); - $this->daemonBackupRepository->setServer($server) - ->setBackupAdapter($this->backupManager->getDefaultAdapter()) - ->backup($backup); + $this->daemonBackupRepository->setServer($server)->setBackupAdapter($this->backupManager->getDefaultAdapter())->backup($backup); return $backup; }); diff --git a/resources/scripts/components/server/schedules/TaskDetailsModal.tsx b/resources/scripts/components/server/schedules/TaskDetailsModal.tsx index e1fca0cb0..5ff75555d 100644 --- a/resources/scripts/components/server/schedules/TaskDetailsModal.tsx +++ b/resources/scripts/components/server/schedules/TaskDetailsModal.tsx @@ -91,7 +91,7 @@ const TaskDetailsForm = ({ isEditingTask }: { isEditingTask: boolean }) => { From 1eaf486eaa944f30741a95db997bbea725ec5b13 Mon Sep 17 00:00:00 2001 From: Gonzalo Chavez Date: Mon, 9 Nov 2020 21:14:47 -0300 Subject: [PATCH 2/8] Backup Rotation - Minor Changes --- app/Services/Backups/InitiateBackupService.php | 11 +++++++---- .../components/server/schedules/TaskDetailsModal.tsx | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Services/Backups/InitiateBackupService.php b/app/Services/Backups/InitiateBackupService.php index 9b6ae9a6f..3246328c9 100644 --- a/app/Services/Backups/InitiateBackupService.php +++ b/app/Services/Backups/InitiateBackupService.php @@ -105,7 +105,7 @@ class InitiateBackupService * @throws \Pterodactyl\Exceptions\Service\Backup\TooManyBackupsException * @throws \Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException */ - public function handle(Server $server, string $name = null, bool $override = null): Backup + public function handle(Server $server, string $name = null, bool $override = false): Backup { $previous = $this->repository->getBackupsGeneratedDuringTimespan($server->id, 10); if ($previous->count() >= 2) { @@ -115,12 +115,13 @@ class InitiateBackupService ); } + // Check if the server has reached or exceeded it's backup limit if (! $server->backup_limit || $server->backups()->where('is_successful', true)->count() >= $server->backup_limit) { - if($override){ + if($override) { // Remove latest backup $last_backup = $server->backups()->where('is_successful', true)->oldest()->first(); $this->deleteBackupService->handle($last_backup); - }else{ + } else { // Do not allow the user to continue if this server is already at its limit. throw new TooManyBackupsException($server->backup_limit); } @@ -136,7 +137,9 @@ class InitiateBackupService 'disk' => $this->backupManager->getDefaultAdapter(), ], true, true); - $this->daemonBackupRepository->setServer($server)->setBackupAdapter($this->backupManager->getDefaultAdapter())->backup($backup); + $this->daemonBackupRepository->setServer($server) + ->setBackupAdapter($this->backupManager->getDefaultAdapter()) + ->backup($backup); return $backup; }); diff --git a/resources/scripts/components/server/schedules/TaskDetailsModal.tsx b/resources/scripts/components/server/schedules/TaskDetailsModal.tsx index 5ff75555d..65c647219 100644 --- a/resources/scripts/components/server/schedules/TaskDetailsModal.tsx +++ b/resources/scripts/components/server/schedules/TaskDetailsModal.tsx @@ -91,7 +91,7 @@ const TaskDetailsForm = ({ isEditingTask }: { isEditingTask: boolean }) => { From 7b8322e9c9ff978d4a608a6c85dd0c59f5fb16a6 Mon Sep 17 00:00:00 2001 From: Gonzalo Chavez Date: Wed, 11 Nov 2020 10:52:28 -0300 Subject: [PATCH 3/8] Backup Rotation - Minor changes --- app/Services/Backups/InitiateBackupService.php | 16 ++++++++-------- .../server/schedules/TaskDetailsModal.tsx | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Services/Backups/InitiateBackupService.php b/app/Services/Backups/InitiateBackupService.php index 3246328c9..aa53b88ae 100644 --- a/app/Services/Backups/InitiateBackupService.php +++ b/app/Services/Backups/InitiateBackupService.php @@ -116,16 +116,16 @@ class InitiateBackupService } // Check if the server has reached or exceeded it's backup limit - if (! $server->backup_limit || $server->backups()->where('is_successful', true)->count() >= $server->backup_limit) { - if($override) { - // Remove latest backup - $last_backup = $server->backups()->where('is_successful', true)->oldest()->first(); - $this->deleteBackupService->handle($last_backup); - } else { - // Do not allow the user to continue if this server is already at its limit. + if (!$server->backup_limit || $server->backups()->where('is_successful', true)->count() >= $server->backup_limit) { + // Do not allow the user to continue if this server is already at its limit and can't override. + if (!$override || $server->backup_limit <= 0) { throw new TooManyBackupsException($server->backup_limit); } - } + + // Remove latest backup + $lastBackup = $server->backups()->where('is_successful', true)->orderByDesc('created_at')->first(); + $this->deleteBackupService->handle($lastBackup); + } return $this->connection->transaction(function () use ($server, $name) { /** @var \Pterodactyl\Models\Backup $backup */ diff --git a/resources/scripts/components/server/schedules/TaskDetailsModal.tsx b/resources/scripts/components/server/schedules/TaskDetailsModal.tsx index 65c647219..08f33b161 100644 --- a/resources/scripts/components/server/schedules/TaskDetailsModal.tsx +++ b/resources/scripts/components/server/schedules/TaskDetailsModal.tsx @@ -91,7 +91,7 @@ const TaskDetailsForm = ({ isEditingTask }: { isEditingTask: boolean }) => { From e6a4a179226b1e745134624019b56c55235f411d Mon Sep 17 00:00:00 2001 From: Gonzalo Chavez Date: Wed, 11 Nov 2020 16:02:39 -0300 Subject: [PATCH 4/8] Backup Rotation - Comment change --- app/Services/Backups/InitiateBackupService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Services/Backups/InitiateBackupService.php b/app/Services/Backups/InitiateBackupService.php index aa53b88ae..89caf8cdc 100644 --- a/app/Services/Backups/InitiateBackupService.php +++ b/app/Services/Backups/InitiateBackupService.php @@ -122,7 +122,7 @@ class InitiateBackupService throw new TooManyBackupsException($server->backup_limit); } - // Remove latest backup + // Remove oldest backup $lastBackup = $server->backups()->where('is_successful', true)->orderByDesc('created_at')->first(); $this->deleteBackupService->handle($lastBackup); } From ebc8d40db83d7da7d900278584211186ddc43af3 Mon Sep 17 00:00:00 2001 From: Gonzalo Chavez Date: Wed, 11 Nov 2020 16:03:57 -0300 Subject: [PATCH 5/8] Backup Rotation - Variable name changed --- app/Services/Backups/InitiateBackupService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Services/Backups/InitiateBackupService.php b/app/Services/Backups/InitiateBackupService.php index 89caf8cdc..5c34961a4 100644 --- a/app/Services/Backups/InitiateBackupService.php +++ b/app/Services/Backups/InitiateBackupService.php @@ -123,8 +123,8 @@ class InitiateBackupService } // Remove oldest backup - $lastBackup = $server->backups()->where('is_successful', true)->orderByDesc('created_at')->first(); - $this->deleteBackupService->handle($lastBackup); + $oldestBackup = $server->backups()->where('is_successful', true)->orderByDesc('created_at')->first(); + $this->deleteBackupService->handle($oldestBackup); } return $this->connection->transaction(function () use ($server, $name) { From 4b1f3200049a5948a0df8dfb5c971b63ae0e4ee3 Mon Sep 17 00:00:00 2001 From: Josh Miles <19347018+j00005h@users.noreply.github.com> Date: Mon, 16 Nov 2020 13:51:02 +0000 Subject: [PATCH 6/8] Update index.blade.php --- resources/views/admin/nodes/view/index.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/admin/nodes/view/index.blade.php b/resources/views/admin/nodes/view/index.blade.php index 993f233dc..13d62e9ee 100644 --- a/resources/views/admin/nodes/view/index.blade.php +++ b/resources/views/admin/nodes/view/index.blade.php @@ -51,7 +51,7 @@ - Total CPU Cores + Total CPU Threads From b97ebcbe392b96d3d689fd91d4de84036a548490 Mon Sep 17 00:00:00 2001 From: danny6167 Date: Fri, 4 Dec 2020 19:18:08 +0800 Subject: [PATCH 7/8] Allow 0 in first octet of database client IP address Fixes #2779 Allow user to enter database connection IP address that contains a a 0 in the first octet. Fixes #2779 --- .../components/server/databases/CreateDatabaseButton.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/scripts/components/server/databases/CreateDatabaseButton.tsx b/resources/scripts/components/server/databases/CreateDatabaseButton.tsx index 2ce843365..d70faffba 100644 --- a/resources/scripts/components/server/databases/CreateDatabaseButton.tsx +++ b/resources/scripts/components/server/databases/CreateDatabaseButton.tsx @@ -24,7 +24,7 @@ const schema = object().shape({ .matches(/^[A-Za-z0-9_\-.]{3,48}$/, 'Database name should only contain alphanumeric characters, underscores, dashes, and/or periods.'), connectionsFrom: string() .required('A connection value must be provided.') - .matches(/^([1-9]{1,3}|%)(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?$/, 'A valid connection address must be provided.'), + .matches(/^([0-9]{1,3}|%)(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?$/, 'A valid connection address must be provided.'), }); export default () => { From ce0e9b7ded579c620593fe71745e5e6995fec8c3 Mon Sep 17 00:00:00 2001 From: Omar Kamel <30291302+TekExplorer@users.noreply.github.com> Date: Sun, 6 Dec 2020 13:17:47 -0500 Subject: [PATCH 8/8] Correct JDBC typo from `JBDC CONNECTION STRING` > `JDBC CONNECTION STRING` --- resources/scripts/components/server/databases/DatabaseRow.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/scripts/components/server/databases/DatabaseRow.tsx b/resources/scripts/components/server/databases/DatabaseRow.tsx index 3eeaa981e..952a7b746 100644 --- a/resources/scripts/components/server/databases/DatabaseRow.tsx +++ b/resources/scripts/components/server/databases/DatabaseRow.tsx @@ -131,7 +131,7 @@ export default ({ database, className }: Props) => {
- +