Merge branch 'develop' into matthewpi/security-keys-backport

This commit is contained in:
Matthew Penner 2023-01-17 15:33:53 -07:00
commit f631ac1946
No known key found for this signature in database
1153 changed files with 25099 additions and 37002 deletions

View file

@ -25,7 +25,7 @@ class AccountController extends ClientApiController
public function index(Request $request): array
{
return $this->fractal->item($request->user())
->transformWith($this->getTransformer(AccountTransformer::class))
->transformWith(AccountTransformer::class)
->toArray();
}

View file

@ -24,7 +24,7 @@ class ActivityLogController extends ClientApiController
->appends($request->query());
return $this->fractal->collection($activity)
->transformWith($this->getTransformer(ActivityLogTransformer::class))
->transformWith(ActivityLogTransformer::class)
->toArray();
}
}

View file

@ -18,7 +18,7 @@ class ApiKeyController extends ClientApiController
public function index(ClientApiRequest $request): array
{
return $this->fractal->collection($request->user()->apiKeys)
->transformWith($this->getTransformer(ApiKeyTransformer::class))
->transformWith(ApiKeyTransformer::class)
->toArray();
}
@ -44,7 +44,7 @@ class ApiKeyController extends ClientApiController
->log();
return $this->fractal->item($token->accessToken)
->transformWith($this->getTransformer(ApiKeyTransformer::class))
->transformWith(ApiKeyTransformer::class)
->addMeta(['secret_token' => $token->plainTextToken])
->toArray();
}

View file

@ -2,8 +2,7 @@
namespace Pterodactyl\Http\Controllers\Api\Client;
use Webmozart\Assert\Assert;
use Pterodactyl\Transformers\Api\Client\BaseClientTransformer;
use Pterodactyl\Transformers\Api\Transformer;
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
abstract class ClientApiController extends ApplicationApiController
@ -11,7 +10,7 @@ abstract class ClientApiController extends ApplicationApiController
/**
* Returns only the includes which are valid for the given transformer.
*/
protected function getIncludesForTransformer(BaseClientTransformer $transformer, array $merge = []): array
protected function getIncludesForTransformer(Transformer $transformer, array $merge = []): array
{
$filtered = array_filter($this->parseIncludes(), function ($datum) use ($transformer) {
return in_array($datum, $transformer->getAvailableIncludes());
@ -35,22 +34,4 @@ abstract class ClientApiController extends ApplicationApiController
return trim($item);
}, explode(',', $includes));
}
/**
* Return an instance of an application transformer.
*
* @template T of \Pterodactyl\Transformers\Api\Client\BaseClientTransformer
*
* @param class-string<T> $abstract
*
* @return T
*
* @noinspection PhpDocSignatureInspection
*/
public function getTransformer(string $abstract)
{
Assert::subclassOf($abstract, BaseClientTransformer::class);
return $abstract::fromRequest($this->request);
}
}

View file

@ -27,7 +27,7 @@ class ClientController extends ClientApiController
public function index(GetServersRequest $request): array
{
$user = $request->user();
$transformer = $this->getTransformer(ServerTransformer::class);
$transformer = new ServerTransformer();
// Start the query builder and ensure we eager load any requested relationships from the request.
$builder = QueryBuilder::for(
@ -40,6 +40,11 @@ class ClientController extends ClientApiController
AllowedFilter::custom('*', new MultiFieldServerFilter()),
]);
$loweredBindings = collect($builder->getBindings())
->map(fn ($f, $key) => is_string($f) ? strtolower($f) : $f)
->all();
$builder->setBindings($loweredBindings);
$type = $request->input('type');
// Either return all the servers the user has access to because they are an admin `?type=admin` or
// just return all the servers the user has access to because they are the owner or a subuser of the

View file

@ -17,7 +17,7 @@ class SSHKeyController extends ClientApiController
public function index(ClientApiRequest $request): array
{
return $this->fractal->collection($request->user()->sshKeys)
->transformWith($this->getTransformer(UserSSHKeyTransformer::class))
->transformWith(UserSSHKeyTransformer::class)
->toArray();
}
@ -38,7 +38,7 @@ class SSHKeyController extends ClientApiController
->log();
return $this->fractal->item($model)
->transformWith($this->getTransformer(UserSSHKeyTransformer::class))
->transformWith(UserSSHKeyTransformer::class)
->toArray();
}

View file

@ -48,7 +48,7 @@ class ActivityLogController extends ClientApiController
->appends($request->query());
return $this->fractal->collection($activity)
->transformWith($this->getTransformer(ActivityLogTransformer::class))
->transformWith(ActivityLogTransformer::class)
->toArray();
}
}

View file

@ -49,7 +49,7 @@ class BackupController extends ClientApiController
$limit = min($request->query('per_page') ?? 20, 50);
return $this->fractal->collection($server->backups()->paginate($limit))
->transformWith($this->getTransformer(BackupTransformer::class))
->transformWith(BackupTransformer::class)
->addMeta([
'backup_count' => $this->repository->getNonFailedBackups($server)->count(),
])
@ -84,7 +84,7 @@ class BackupController extends ClientApiController
->log();
return $this->fractal->item($backup)
->transformWith($this->getTransformer(BackupTransformer::class))
->transformWith(BackupTransformer::class)
->toArray();
}
@ -107,7 +107,7 @@ class BackupController extends ClientApiController
Activity::event($action)->subject($backup)->property('name', $backup->name)->log();
return $this->fractal->item($backup)
->transformWith($this->getTransformer(BackupTransformer::class))
->transformWith(BackupTransformer::class)
->toArray();
}
@ -123,7 +123,7 @@ class BackupController extends ClientApiController
}
return $this->fractal->item($backup)
->transformWith($this->getTransformer(BackupTransformer::class))
->transformWith(BackupTransformer::class)
->toArray();
}

View file

@ -35,7 +35,7 @@ class DatabaseController extends ClientApiController
public function index(GetDatabasesRequest $request, Server $server): array
{
return $this->fractal->collection($server->databases)
->transformWith($this->getTransformer(DatabaseTransformer::class))
->transformWith(DatabaseTransformer::class)
->toArray();
}
@ -57,7 +57,7 @@ class DatabaseController extends ClientApiController
return $this->fractal->item($database)
->parseIncludes(['password'])
->transformWith($this->getTransformer(DatabaseTransformer::class))
->transformWith(DatabaseTransformer::class)
->toArray();
}
@ -79,7 +79,7 @@ class DatabaseController extends ClientApiController
return $this->fractal->item($database)
->parseIncludes(['password'])
->transformWith($this->getTransformer(DatabaseTransformer::class))
->transformWith(DatabaseTransformer::class)
->toArray();
}

View file

@ -47,7 +47,7 @@ class FileController extends ClientApiController
->getDirectory($request->get('directory') ?? '/');
return $this->fractal->collection($contents)
->transformWith($this->getTransformer(FileObjectTransformer::class))
->transformWith(FileObjectTransformer::class)
->toArray();
}
@ -183,7 +183,7 @@ class FileController extends ClientApiController
->log();
return $this->fractal->item($file)
->transformWith($this->getTransformer(FileObjectTransformer::class))
->transformWith(FileObjectTransformer::class)
->toArray();
}

View file

@ -36,7 +36,7 @@ class NetworkAllocationController extends ClientApiController
public function index(GetNetworkRequest $request, Server $server): array
{
return $this->fractal->collection($server->allocations)
->transformWith($this->getTransformer(AllocationTransformer::class))
->transformWith(AllocationTransformer::class)
->toArray();
}
@ -60,7 +60,7 @@ class NetworkAllocationController extends ClientApiController
}
return $this->fractal->item($allocation)
->transformWith($this->getTransformer(AllocationTransformer::class))
->transformWith(AllocationTransformer::class)
->toArray();
}
@ -80,7 +80,7 @@ class NetworkAllocationController extends ClientApiController
->log();
return $this->fractal->item($allocation)
->transformWith($this->getTransformer(AllocationTransformer::class))
->transformWith(AllocationTransformer::class)
->toArray();
}
@ -104,7 +104,7 @@ class NetworkAllocationController extends ClientApiController
->log();
return $this->fractal->item($allocation)
->transformWith($this->getTransformer(AllocationTransformer::class))
->transformWith(AllocationTransformer::class)
->toArray();
}

View file

@ -35,7 +35,7 @@ class ResourceUtilizationController extends ClientApiController
});
return $this->fractal->item($stats)
->transformWith($this->getTransformer(StatsTransformer::class))
->transformWith(StatsTransformer::class)
->toArray();
}
}

View file

@ -2,7 +2,6 @@
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
use Exception;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
@ -41,7 +40,7 @@ class ScheduleController extends ClientApiController
$schedules = $server->schedules->loadMissing('tasks');
return $this->fractal->collection($schedules)
->transformWith($this->getTransformer(ScheduleTransformer::class))
->transformWith(ScheduleTransformer::class)
->toArray();
}
@ -73,7 +72,7 @@ class ScheduleController extends ClientApiController
->log();
return $this->fractal->item($model)
->transformWith($this->getTransformer(ScheduleTransformer::class))
->transformWith(ScheduleTransformer::class)
->toArray();
}
@ -89,7 +88,7 @@ class ScheduleController extends ClientApiController
$schedule->loadMissing('tasks');
return $this->fractal->item($schedule)
->transformWith($this->getTransformer(ScheduleTransformer::class))
->transformWith(ScheduleTransformer::class)
->toArray();
}
@ -132,7 +131,7 @@ class ScheduleController extends ClientApiController
->log();
return $this->fractal->item($schedule->refresh())
->transformWith($this->getTransformer(ScheduleTransformer::class))
->transformWith(ScheduleTransformer::class)
->toArray();
}
@ -178,7 +177,7 @@ class ScheduleController extends ClientApiController
$request->input('month'),
$request->input('day_of_week')
);
} catch (Exception $exception) {
} catch (\Exception $exception) {
throw new DisplayException('The cron data provided does not evaluate to a valid expression.');
}
}

View file

@ -64,7 +64,7 @@ class ScheduleTaskController extends ClientApiController
->log();
return $this->fractal->item($task)
->transformWith($this->getTransformer(TaskTransformer::class))
->transformWith(TaskTransformer::class)
->toArray();
}
@ -97,7 +97,7 @@ class ScheduleTaskController extends ClientApiController
->log();
return $this->fractal->item($task->refresh())
->transformWith($this->getTransformer(TaskTransformer::class))
->transformWith(TaskTransformer::class)
->toArray();
}

View file

@ -25,7 +25,7 @@ class ServerController extends ClientApiController
public function index(GetServerRequest $request, Server $server): array
{
return $this->fractal->item($server)
->transformWith($this->getTransformer(ServerTransformer::class))
->transformWith(ServerTransformer::class)
->addMeta([
'is_server_owner' => $request->user()->id === $server->owner_id,
'user_permissions' => $this->permissionsService->handle($server, $request->user()),

View file

@ -34,14 +34,22 @@ class SettingsController extends ClientApiController
*/
public function rename(RenameServerRequest $request, Server $server): JsonResponse
{
$name = $request->input('name');
$description = $request->input('description') ?? $server->description;
$this->repository->update($server->id, [
'name' => $request->input('name'),
'description' => $request->input('description') ?? '',
'name' => $name,
'description' => $description,
]);
if ($server->name !== $request->input('name')) {
if ($server->name !== $name) {
Activity::event('server:settings.rename')
->property(['old' => $server->name, 'new' => $request->input('name')])
->property(['old' => $server->name, 'new' => $name])
->log();
}
if ($server->description !== $description) {
Activity::event('server:settings.description')
->property(['old' => $server->description, 'new' => $description])
->log();
}

View file

@ -34,7 +34,7 @@ class StartupController extends ClientApiController
return $this->fractal->collection(
$server->variables()->where('user_viewable', true)->get()
)
->transformWith($this->getTransformer(EggVariableTransformer::class))
->transformWith(EggVariableTransformer::class)
->addMeta([
'startup_command' => $startup,
'docker_images' => $server->egg->docker_images,
@ -52,7 +52,6 @@ class StartupController extends ClientApiController
*/
public function update(UpdateStartupVariableRequest $request, Server $server): array
{
/** @var \Pterodactyl\Models\EggVariable $variable */
$variable = $server->variables()->where('env_variable', $request->input('key'))->first();
$original = $variable->server_value;
@ -62,6 +61,8 @@ class StartupController extends ClientApiController
throw new BadRequestHttpException('The environment variable you are trying to edit is read-only.');
}
/* @var \Pterodactyl\Models\EggVariable $variable */
// Revalidate the variable value using the egg variable specific validation rules for it.
$this->validate($request, ['value' => $variable->rules]);
@ -89,7 +90,7 @@ class StartupController extends ClientApiController
}
return $this->fractal->item($variable)
->transformWith($this->getTransformer(EggVariableTransformer::class))
->transformWith(EggVariableTransformer::class)
->addMeta([
'startup_command' => $startup,
'raw_startup_command' => $server->startup,

View file

@ -38,7 +38,7 @@ class SubuserController extends ClientApiController
public function index(GetSubuserRequest $request, Server $server): array
{
return $this->fractal->collection($server->subusers)
->transformWith($this->getTransformer(SubuserTransformer::class))
->transformWith(SubuserTransformer::class)
->toArray();
}
@ -50,7 +50,7 @@ class SubuserController extends ClientApiController
$subuser = $request->attributes->get('subuser');
return $this->fractal->item($subuser)
->transformWith($this->getTransformer(SubuserTransformer::class))
->transformWith(SubuserTransformer::class)
->toArray();
}
@ -76,7 +76,7 @@ class SubuserController extends ClientApiController
->log();
return $this->fractal->item($response)
->transformWith($this->getTransformer(SubuserTransformer::class))
->transformWith(SubuserTransformer::class)
->toArray();
}
@ -129,7 +129,7 @@ class SubuserController extends ClientApiController
$log->reset();
return $this->fractal->item($subuser->refresh())
->transformWith($this->getTransformer(SubuserTransformer::class))
->transformWith(SubuserTransformer::class)
->toArray();
}