Skip to content

Commit f54d4f9

Browse files
authored
Merge pull request pterodactyl#2 from pterodactyl/develop
Update From Upstream
2 parents d3a544a + d735909 commit f54d4f9

File tree

130 files changed

+1907
-816
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+1907
-816
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ RUN cp docker/default.conf /etc/nginx/conf.d/default.conf \
2525
&& cat docker/www.conf > /usr/local/etc/php-fpm.d/www.conf \
2626
&& rm /usr/local/etc/php-fpm.d/www.conf.default \
2727
&& cat docker/supervisord.conf > /etc/supervisord.conf \
28-
&& echo "* * * * * /usr/bin/php /app/artisan schedule:run >> /dev/null 2>&1" >> /var/spool/cron/crontabs/root \
28+
&& echo "* * * * * /usr/local/bin/php /app/artisan schedule:run >> /dev/null 2>&1" >> /var/spool/cron/crontabs/root \
2929
&& sed -i s/ssl_session_cache/#ssl_session_cache/g /etc/nginx/nginx.conf \
3030
&& mkdir -p /var/run/php /var/run/nginx
3131

3232
EXPOSE 80 443
3333

3434
ENTRYPOINT ["/bin/ash", "docker/entrypoint.sh"]
3535

36-
CMD [ "supervisord", "-n", "-c", "/etc/supervisord.conf" ]
36+
CMD [ "supervisord", "-n", "-c", "/etc/supervisord.conf" ]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ in becoming a sponsor?](https://github.com/sponsors/DaneEveritt)
3232
> DedicatedMC provides Raw Power hosting at affordable pricing, making sure to never compromise on your performance
3333
> and giving you the best performance money can buy.
3434
35+
#### [Skynode](https://www.skynode.pro/)
36+
> Skynode provides blazing fast game servers along with a top notch user experience. Whatever our clients are looking
37+
> for, we're able to provide it!
38+
39+
#### [XCORE-SERVER.de](https://xcore-server.de)
40+
> XCORE-SERVER.de offers High-End Servers for hosting and gaming since 2012. Fast, excellent and well known for eSports Gaming.
3541
3642
## Support & Documentation
3743
Support for using Pterodactyl can be found on our [Documentation Website](https://pterodactyl.io/project/introduction.html), [Guides Website](https://pterodactyl.io/community/about.html), or via our [Discord Chat](https://discord.gg/QRDZvVm).
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Pterodactyl\Console\Commands\Maintenance;
4+
5+
use Carbon\CarbonImmutable;
6+
use InvalidArgumentException;
7+
use Illuminate\Console\Command;
8+
use Pterodactyl\Repositories\Eloquent\BackupRepository;
9+
10+
class PruneOrphanedBackupsCommand extends Command
11+
{
12+
/**
13+
* @var string
14+
*/
15+
protected $signature = 'p:maintenance:prune-backups {--since-minutes=30}';
16+
17+
/**
18+
* @var string
19+
*/
20+
protected $description = 'Marks all backups that have not completed in the last "n" minutes as being failed.';
21+
22+
/**
23+
* @param \Pterodactyl\Repositories\Eloquent\BackupRepository $repository
24+
*/
25+
public function handle(BackupRepository $repository)
26+
{
27+
$since = $this->option('since-minutes');
28+
if (! is_digit($since)) {
29+
throw new InvalidArgumentException('The --since-minutes option must be a valid numeric digit.');
30+
}
31+
32+
$query = $repository->getBuilder()
33+
->whereNull('completed_at')
34+
->whereDate('created_at', '<=', CarbonImmutable::now()->subMinutes($since));
35+
36+
$count = $query->count();
37+
if (! $count) {
38+
$this->info('There are no orphaned backups to be marked as failed.');
39+
40+
return;
41+
}
42+
43+
$this->warn("Marking {$count} backups that have not been marked as completed in the last {$since} minutes as failed.");
44+
45+
$query->update([
46+
'is_successful' => false,
47+
'completed_at' => CarbonImmutable::now(),
48+
'updated_at' => CarbonImmutable::now(),
49+
]);
50+
}
51+
}

app/Console/Kernel.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ protected function commands()
2222
*/
2323
protected function schedule(Schedule $schedule)
2424
{
25+
// Execute scheduled commands for servers every minute, as if there was a normal cron running.
2526
$schedule->command('p:schedule:process')->everyMinute()->withoutOverlapping();
27+
28+
// Every 30 minutes, run the backup pruning command so that any abandoned backups can be removed
29+
// from the UI view for the server.
30+
$schedule->command('p:maintenance:prune-backups', [
31+
'--since-minutes' => '30',
32+
])->everyThirtyMinutes();
33+
34+
// Every day cleanup any internal backups of service files.
2635
$schedule->command('p:maintenance:clean-service-backups')->daily();
2736
}
2837
}

app/Contracts/Repository/ServerRepositoryInterface.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,6 @@ public function findWithVariables(int $id): Server;
6565
*/
6666
public function getPrimaryAllocation(Server $server, bool $refresh = false): Server;
6767

68-
/**
69-
* Return all of the server variables possible and default to the variable
70-
* default if there is no value defined for the specific server requested.
71-
*
72-
* @param int $id
73-
* @param bool $returnAsObject
74-
* @return array|object
75-
*
76-
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
77-
*/
78-
public function getVariablesWithValues(int $id, bool $returnAsObject = false);
79-
8068
/**
8169
* Return enough data to be used for the creation of a server via the daemon.
8270
*

app/Exceptions/Handler.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,21 @@ public function invalidJson($request, ValidationException $exception)
178178
return [str_replace('.', '_', $field) => $cleaned];
179179
})->toArray();
180180

181-
$errors = collect($exception->errors())->map(function ($errors, $field) use ($codes) {
181+
$errors = collect($exception->errors())->map(function ($errors, $field) use ($codes, $exception) {
182182
$response = [];
183183
foreach ($errors as $key => $error) {
184-
$response[] = [
185-
'code' => str_replace(self::PTERODACTYL_RULE_STRING, 'p_', array_get(
184+
$meta = [
185+
'source_field' => $field,
186+
'rule' => str_replace(self::PTERODACTYL_RULE_STRING, 'p_', array_get(
186187
$codes, str_replace('.', '_', $field) . '.' . $key
187188
)),
188-
'detail' => $error,
189-
'source' => ['field' => $field],
190189
];
190+
191+
$converted = self::convertToArray($exception)['errors'][0];
192+
$converted['detail'] = $error;
193+
$converted['meta'] = is_array($converted['meta']) ? array_merge($converted['meta'], $meta) : $meta;
194+
195+
$response[] = $converted;
191196
}
192197

193198
return $response;
@@ -209,10 +214,19 @@ public static function convertToArray(Throwable $exception, array $override = []
209214
{
210215
$error = [
211216
'code' => class_basename($exception),
212-
'status' => method_exists($exception, 'getStatusCode') ? strval($exception->getStatusCode()) : '500',
217+
'status' => method_exists($exception, 'getStatusCode')
218+
? strval($exception->getStatusCode())
219+
: ($exception instanceof ValidationException ? '422' : '500'),
213220
'detail' => 'An error was encountered while processing this request.',
214221
];
215222

223+
if ($exception instanceof ModelNotFoundException || $exception->getPrevious() instanceof ModelNotFoundException) {
224+
// Show a nicer error message compared to the standard "No query results for model"
225+
// response that is normally returned. If we are in debug mode this will get overwritten
226+
// with a more specific error message to help narrow down things.
227+
$error['detail'] = 'The requested resource could not be found on the server.';
228+
}
229+
216230
if (config('app.debug')) {
217231
$error = array_merge($error, [
218232
'detail' => $exception->getMessage(),

app/Http/Controllers/Admin/Servers/ServerViewController.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Contracts\View\Factory;
1010
use Pterodactyl\Exceptions\DisplayException;
1111
use Pterodactyl\Http\Controllers\Controller;
12+
use Pterodactyl\Services\Servers\EnvironmentService;
1213
use Pterodactyl\Repositories\Eloquent\NestRepository;
1314
use Pterodactyl\Repositories\Eloquent\NodeRepository;
1415
use Pterodactyl\Repositories\Eloquent\MountRepository;
@@ -56,6 +57,11 @@ class ServerViewController extends Controller
5657
*/
5758
private $nodeRepository;
5859

60+
/**
61+
* @var \Pterodactyl\Services\Servers\EnvironmentService
62+
*/
63+
private $environmentService;
64+
5965
/**
6066
* ServerViewController constructor.
6167
*
@@ -66,6 +72,7 @@ class ServerViewController extends Controller
6672
* @param \Pterodactyl\Repositories\Eloquent\NestRepository $nestRepository
6773
* @param \Pterodactyl\Repositories\Eloquent\NodeRepository $nodeRepository
6874
* @param \Pterodactyl\Repositories\Eloquent\ServerRepository $repository
75+
* @param \Pterodactyl\Services\Servers\EnvironmentService $environmentService
6976
*/
7077
public function __construct(
7178
Factory $view,
@@ -74,7 +81,8 @@ public function __construct(
7481
MountRepository $mountRepository,
7582
NestRepository $nestRepository,
7683
NodeRepository $nodeRepository,
77-
ServerRepository $repository
84+
ServerRepository $repository,
85+
EnvironmentService $environmentService
7886
) {
7987
$this->view = $view;
8088
$this->databaseHostRepository = $databaseHostRepository;
@@ -83,6 +91,7 @@ public function __construct(
8391
$this->nestRepository = $nestRepository;
8492
$this->nodeRepository = $nodeRepository;
8593
$this->repository = $repository;
94+
$this->environmentService = $environmentService;
8695
}
8796

8897
/**
@@ -138,12 +147,12 @@ public function build(Request $request, Server $server)
138147
*/
139148
public function startup(Request $request, Server $server)
140149
{
141-
$parameters = $this->repository->getVariablesWithValues($server->id, true);
142150
$nests = $this->nestRepository->getWithEggs();
151+
$variables = $this->environmentService->handle($server);
143152

144153
$this->plainInject([
145154
'server' => $server,
146-
'server_variables' => $parameters->data,
155+
'server_variables' => $variables,
147156
'nests' => $nests->map(function (Nest $item) {
148157
return array_merge($item->toArray(), [
149158
'eggs' => $item->eggs->keyBy('id')->toArray(),

app/Http/Controllers/Api/Client/Servers/DownloadBackupController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function __invoke(DownloadBackupRequest $request, Server $server, Backup
8282
throw new BadRequestHttpException;
8383
}
8484

85-
return JsonResponse::create([
85+
return new JsonResponse([
8686
'object' => 'signed_url',
8787
'attributes' => [
8888
'url' => $url,
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
4+
5+
use Carbon\CarbonImmutable;
6+
use Pterodactyl\Models\User;
7+
use Pterodactyl\Models\Server;
8+
use Illuminate\Http\JsonResponse;
9+
use Pterodactyl\Services\Nodes\NodeJWTService;
10+
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
11+
use Pterodactyl\Http\Requests\Api\Client\Servers\Files\UploadFileRequest;
12+
13+
class FileUploadController extends ClientApiController
14+
{
15+
/**
16+
* @var \Pterodactyl\Services\Nodes\NodeJWTService
17+
*/
18+
private $jwtService;
19+
20+
/**
21+
* FileUploadController constructor.
22+
*
23+
* @param \Pterodactyl\Services\Nodes\NodeJWTService $jwtService
24+
*/
25+
public function __construct(
26+
NodeJWTService $jwtService
27+
) {
28+
parent::__construct();
29+
30+
$this->jwtService = $jwtService;
31+
}
32+
33+
/**
34+
* Returns a url where files can be uploaded to.
35+
*
36+
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\Files\UploadFileRequest $request
37+
* @param \Pterodactyl\Models\Server $server
38+
*
39+
* @return \Illuminate\Http\JsonResponse
40+
*/
41+
public function __invoke(UploadFileRequest $request, Server $server)
42+
{
43+
return new JsonResponse([
44+
'object' => 'signed_url',
45+
'attributes' => [
46+
'url' => $this->getUploadUrl($server, $request->user()),
47+
],
48+
]);
49+
}
50+
51+
/**
52+
* Returns a url where files can be uploaded to.
53+
*
54+
* @param \Pterodactyl\Models\Server $server
55+
* @param \Pterodactyl\Models\User $user
56+
* @return string
57+
*/
58+
protected function getUploadUrl(Server $server, User $user)
59+
{
60+
$token = $this->jwtService
61+
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
62+
->setClaims([
63+
'server_uuid' => $server->uuid,
64+
])
65+
->handle($server->node, $user->id . $server->uuid);
66+
67+
return sprintf(
68+
'%s/upload/file?token=%s',
69+
$server->node->getConnectionAddress(),
70+
$token->__toString()
71+
);
72+
}
73+
}

0 commit comments

Comments
 (0)