diff --git a/app/Contracts/Repository/ApiKeyRepositoryInterface.php b/app/Contracts/Repository/ApiKeyRepositoryInterface.php index bfebbddb60..3a2dba43b1 100644 --- a/app/Contracts/Repository/ApiKeyRepositoryInterface.php +++ b/app/Contracts/Repository/ApiKeyRepositoryInterface.php @@ -13,9 +13,9 @@ interface ApiKeyRepositoryInterface extends RepositoryInterface public function getAccountKeys(User $user): Collection; /** - * Get all the application API keys that exist for a specific user. + * Get all the application API keys that exist. */ - public function getApplicationKeys(User $user): Collection; + public function getApplicationKeys(): Collection; /** * Delete an account API key from the panel for a specific user. @@ -23,7 +23,7 @@ public function getApplicationKeys(User $user): Collection; public function deleteAccountKey(User $user, string $identifier): int; /** - * Delete an application API key from the panel for a specific user. + * Delete an application API key from the panel. */ - public function deleteApplicationKey(User $user, string $identifier): int; + public function deleteApplicationKey(string $identifier): int; } diff --git a/app/Http/Controllers/Admin/ApiController.php b/app/Http/Controllers/Admin/ApiController.php index 02ad6e540d..05074f3723 100644 --- a/app/Http/Controllers/Admin/ApiController.php +++ b/app/Http/Controllers/Admin/ApiController.php @@ -34,7 +34,7 @@ public function __construct( public function index(Request $request): View { return $this->view->make('admin.api.index', [ - 'keys' => $this->repository->getApplicationKeys($request->user()), + 'keys' => $this->repository->getApplicationKeys(), ]); } @@ -80,7 +80,7 @@ public function store(StoreApplicationApiKeyRequest $request): RedirectResponse */ public function delete(Request $request, string $identifier): Response { - $this->repository->deleteApplicationKey($request->user(), $identifier); + $this->repository->deleteApplicationKey($identifier); return response('', 204); } diff --git a/app/Http/Controllers/Admin/NodeAutoDeployController.php b/app/Http/Controllers/Admin/NodeAutoDeployController.php index ac0684a9c9..ac6fd5ea80 100644 --- a/app/Http/Controllers/Admin/NodeAutoDeployController.php +++ b/app/Http/Controllers/Admin/NodeAutoDeployController.php @@ -32,8 +32,9 @@ public function __construct( public function __invoke(Request $request, Node $node): JsonResponse { /** @var \Pterodactyl\Models\ApiKey|null $key */ - $key = $this->repository->getApplicationKeys($request->user()) + $key = $this->repository->getApplicationKeys() ->filter(function (ApiKey $key) { + if ($key->user->id != $request->user()->id) return false; foreach ($key->getAttributes() as $permission => $value) { if ($permission === 'r_nodes' && $value === 1) { return true; diff --git a/app/Repositories/Eloquent/ApiKeyRepository.php b/app/Repositories/Eloquent/ApiKeyRepository.php index eb1a362aed..19bcce2797 100644 --- a/app/Repositories/Eloquent/ApiKeyRepository.php +++ b/app/Repositories/Eloquent/ApiKeyRepository.php @@ -28,12 +28,13 @@ public function getAccountKeys(User $user): Collection } /** - * Get all the application API keys that exist for a specific user. + * Get all the application API keys that exist. */ - public function getApplicationKeys(User $user): Collection + public function getApplicationKeys(): Collection { - return $this->getBuilder()->where('user_id', $user->id) + return $this->getBuilder() ->where('key_type', ApiKey::TYPE_APPLICATION) + ->with('user') ->get($this->getColumns()); } @@ -49,11 +50,11 @@ public function deleteAccountKey(User $user, string $identifier): int } /** - * Delete an application API key from the panel for a specific user. + * Delete an application API key from the panel. */ - public function deleteApplicationKey(User $user, string $identifier): int + public function deleteApplicationKey(string $identifier): int { - return $this->getBuilder()->where('user_id', $user->id) + return $this->getBuilder() ->where('key_type', ApiKey::TYPE_APPLICATION) ->where('identifier', $identifier) ->delete(); diff --git a/resources/views/admin/api/index.blade.php b/resources/views/admin/api/index.blade.php index d863c5779a..cdd72d0f3c 100644 --- a/resources/views/admin/api/index.blade.php +++ b/resources/views/admin/api/index.blade.php @@ -1,103 +1,113 @@ @extends('layouts.admin') @section('title') - Application API +Application API @endsection @section('content-header') -

Application APIControl access credentials for managing this Panel via the API.

- +

Application APIControl access credentials for managing this Panel via the API.

+ @endsection @section('content') -
-
-
-
-

Credentials List

- -
-
- - - - - - - - - @foreach($keys as $key) - - - - - - - - @endforeach -
KeyMemoLast UsedCreated
{{ $key->identifier }}{{ decrypt($key->token) }}{{ $key->memo }} - @if(!is_null($key->last_used_at)) - @datetimeHuman($key->last_used_at) - @else - — - @endif - @datetimeHuman($key->created_at) - - - -
+
+
+
+
+

Credentials List

+
+
+ + + + + + + + + + @foreach($keys as $key) + + + + + + + + + @endforeach +
KeyMemoLast UsedCreatedCreated by
+ @if(Auth::user()->id != $key->user->id) + {{ $key->identifier . str_repeat('*', strlen(decrypt($key->token)))}} + @else + {{$key->identifier . decrypt($key->token)}} + @endif + {{ $key->memo }} + @if(!is_null($key->last_used_at)) + @datetimeHuman($key->last_used_at) + @else + — + @endif + @datetimeHuman($key->created_at) + {{ $key->user->username }} + + + + +
+
+
@endsection @section('footer-scripts') - @parent - -@endsection + }); + +@endsection \ No newline at end of file