forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pterodactyl#2 from pterodactyl/develop
Update From Upstream
- Loading branch information
Showing
130 changed files
with
1,907 additions
and
816 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/Console/Commands/Maintenance/PruneOrphanedBackupsCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Pterodactyl\Console\Commands\Maintenance; | ||
|
||
use Carbon\CarbonImmutable; | ||
use InvalidArgumentException; | ||
use Illuminate\Console\Command; | ||
use Pterodactyl\Repositories\Eloquent\BackupRepository; | ||
|
||
class PruneOrphanedBackupsCommand extends Command | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $signature = 'p:maintenance:prune-backups {--since-minutes=30}'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $description = 'Marks all backups that have not completed in the last "n" minutes as being failed.'; | ||
|
||
/** | ||
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository | ||
*/ | ||
public function handle(BackupRepository $repository) | ||
{ | ||
$since = $this->option('since-minutes'); | ||
if (! is_digit($since)) { | ||
throw new InvalidArgumentException('The --since-minutes option must be a valid numeric digit.'); | ||
} | ||
|
||
$query = $repository->getBuilder() | ||
->whereNull('completed_at') | ||
->whereDate('created_at', '<=', CarbonImmutable::now()->subMinutes($since)); | ||
|
||
$count = $query->count(); | ||
if (! $count) { | ||
$this->info('There are no orphaned backups to be marked as failed.'); | ||
|
||
return; | ||
} | ||
|
||
$this->warn("Marking {$count} backups that have not been marked as completed in the last {$since} minutes as failed."); | ||
|
||
$query->update([ | ||
'is_successful' => false, | ||
'completed_at' => CarbonImmutable::now(), | ||
'updated_at' => CarbonImmutable::now(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
app/Http/Controllers/Api/Client/Servers/FileUploadController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Pterodactyl\Http\Controllers\Api\Client\Servers; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Pterodactyl\Models\User; | ||
use Pterodactyl\Models\Server; | ||
use Illuminate\Http\JsonResponse; | ||
use Pterodactyl\Services\Nodes\NodeJWTService; | ||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController; | ||
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\UploadFileRequest; | ||
|
||
class FileUploadController extends ClientApiController | ||
{ | ||
/** | ||
* @var \Pterodactyl\Services\Nodes\NodeJWTService | ||
*/ | ||
private $jwtService; | ||
|
||
/** | ||
* FileUploadController constructor. | ||
* | ||
* @param \Pterodactyl\Services\Nodes\NodeJWTService $jwtService | ||
*/ | ||
public function __construct( | ||
NodeJWTService $jwtService | ||
) { | ||
parent::__construct(); | ||
|
||
$this->jwtService = $jwtService; | ||
} | ||
|
||
/** | ||
* Returns a url where files can be uploaded to. | ||
* | ||
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\UploadFileRequest $request | ||
* @param \Pterodactyl\Models\Server $server | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function __invoke(UploadFileRequest $request, Server $server) | ||
{ | ||
return new JsonResponse([ | ||
'object' => 'signed_url', | ||
'attributes' => [ | ||
'url' => $this->getUploadUrl($server, $request->user()), | ||
], | ||
]); | ||
} | ||
|
||
/** | ||
* Returns a url where files can be uploaded to. | ||
* | ||
* @param \Pterodactyl\Models\Server $server | ||
* @param \Pterodactyl\Models\User $user | ||
* @return string | ||
*/ | ||
protected function getUploadUrl(Server $server, User $user) | ||
{ | ||
$token = $this->jwtService | ||
->setExpiresAt(CarbonImmutable::now()->addMinutes(15)) | ||
->setClaims([ | ||
'server_uuid' => $server->uuid, | ||
]) | ||
->handle($server->node, $user->id . $server->uuid); | ||
|
||
return sprintf( | ||
'%s/upload/file?token=%s', | ||
$server->node->getConnectionAddress(), | ||
$token->__toString() | ||
); | ||
} | ||
} |
Oops, something went wrong.