Skip to content

Commit 975597b

Browse files
committed
Implement changes to administrative user revocation, closes pterodactyl#733
1 parent 20beb2f commit 975597b

File tree

19 files changed

+458
-125
lines changed

19 files changed

+458
-125
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1010
* `[beta.2]` — Fixes a bug that would throw a red page of death when submitting an invalid egg variable value for a server in the Admin CP.
1111
* `[beta.2]` — Someone found a `@todo` that I never `@todid` and thus database hosts could not be created without being linked to a node. This is fixed...
1212
* `[beta.2]` — Fixes bug that caused incorrect rendering of CPU usage on server graphs due to missing variable.
13+
* `[beta.2]` — Fixes bug causing schedules to be un-deletable.
14+
15+
### Changed
16+
* Revoking the administrative status for an admin will revoke all authentication tokens currently assigned to their account.
1317

1418
## v0.7.0-beta.2 (Derelict Dermodactylus)
1519
### Fixed

app/Contracts/Repository/Daemon/ServerRepositoryInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ public function details();
7878
/**
7979
* Revoke an access key on the daemon before the time is expired.
8080
*
81-
* @param string $key
81+
* @param string|array $key
8282
* @return \Psr\Http\Message\ResponseInterface
83+
*
84+
* @throws \GuzzleHttp\Exception\RequestException
8385
*/
8486
public function revokeAccessKey($key);
8587
}

app/Contracts/Repository/DaemonKeyRepositoryInterface.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525
namespace Pterodactyl\Contracts\Repository;
2626

27+
use Pterodactyl\Models\User;
2728
use Pterodactyl\Models\DaemonKey;
29+
use Illuminate\Support\Collection;
2830

2931
interface DaemonKeyRepositoryInterface extends RepositoryInterface
3032
{
@@ -59,4 +61,22 @@ public function getServerKeys($server);
5961
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
6062
*/
6163
public function getKeyWithServer($key);
64+
65+
/**
66+
* Get all of the keys for a specific user including the information needed
67+
* from their server relation for revocation on the daemon.
68+
*
69+
* @param \Pterodactyl\Models\User $user
70+
* @return \Illuminate\Support\Collection
71+
*/
72+
public function getKeysForRevocation(User $user): Collection;
73+
74+
/**
75+
* Delete an array of daemon keys from the database. Used primarily in
76+
* conjunction with getKeysForRevocation.
77+
*
78+
* @param array $ids
79+
* @return bool|int
80+
*/
81+
public function deleteKeys(array $ids);
6282
}

app/Exceptions/Http/Connection/DaemonConnectionException.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Exceptions\Http\Connection;
114

app/Http/Controllers/Admin/UserController.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Http\Controllers\Admin;
114

@@ -160,10 +153,30 @@ public function store(UserFormRequest $request)
160153
*
161154
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
162155
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
156+
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
163157
*/
164158
public function update(UserFormRequest $request, User $user)
165159
{
166-
$this->updateService->handle($user->id, $request->normalize());
160+
$this->updateService->setUserLevel(User::USER_LEVEL_ADMIN);
161+
$data = $this->updateService->handle($user, $request->normalize());
162+
163+
if (! empty($data->get('exceptions'))) {
164+
foreach ($data->get('exceptions') as $node => $exception) {
165+
/** @var \GuzzleHttp\Exception\RequestException $exception */
166+
/** @var \GuzzleHttp\Psr7\Response|null $response */
167+
$response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null;
168+
$message = trans('admin/server.exceptions.daemon_exception', [
169+
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
170+
]);
171+
172+
$this->alert->danger(trans('exceptions.users.node_revocation_failed', [
173+
'node' => $node,
174+
'error' => $message,
175+
'link' => route('admin.nodes.view', $node),
176+
]))->flash();
177+
}
178+
}
179+
167180
$this->alert->success($this->translator->trans('admin/user.notices.account_updated'))->flash();
168181

169182
return redirect()->route('admin.users.view', $user->id);

app/Http/Controllers/Base/AccountController.php

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>
5-
* Some Modifications (c) 2015 Dylan Seidt <dylan.seidt@gmail.com>.
6-
*
7-
* Permission is hereby granted, free of charge, to any person obtaining a copy
8-
* of this software and associated documentation files (the "Software"), to deal
9-
* in the Software without restriction, including without limitation the rights
10-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
* copies of the Software, and to permit persons to whom the Software is
12-
* furnished to do so, subject to the following conditions:
13-
*
14-
* The above copyright notice and this permission notice shall be included in all
15-
* copies or substantial portions of the Software.
16-
*
17-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23-
* SOFTWARE.
24-
*/
252

263
namespace Pterodactyl\Http\Controllers\Base;
274

5+
use Pterodactyl\Models\User;
286
use Prologue\Alerts\AlertsMessageBag;
297
use Pterodactyl\Http\Controllers\Controller;
308
use Pterodactyl\Services\Users\UserUpdateService;
@@ -48,10 +26,8 @@ class AccountController extends Controller
4826
* @param \Prologue\Alerts\AlertsMessageBag $alert
4927
* @param \Pterodactyl\Services\Users\UserUpdateService $updateService
5028
*/
51-
public function __construct(
52-
AlertsMessageBag $alert,
53-
UserUpdateService $updateService
54-
) {
29+
public function __construct(AlertsMessageBag $alert, UserUpdateService $updateService)
30+
{
5531
$this->alert = $alert;
5632
$this->updateService = $updateService;
5733
}
@@ -74,6 +50,7 @@ public function index()
7450
*
7551
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
7652
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
53+
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
7754
*/
7855
public function update(AccountDataFormRequest $request)
7956
{
@@ -86,7 +63,8 @@ public function update(AccountDataFormRequest $request)
8663
$data = $request->only(['name_first', 'name_last', 'username']);
8764
}
8865

89-
$this->updateService->handle($request->user()->id, $data);
66+
$this->updateService->setUserLevel(User::USER_LEVEL_USER);
67+
$this->updateService->handle($request->user(), $data);
9068
$this->alert->success(trans('base.account.details_updated'))->flash();
9169

9270
return redirect()->route('account');

app/Http/Middleware/AdminAuthenticate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class AdminAuthenticate
2121
* @param \Illuminate\Http\Request $request
2222
* @param \Closure $next
2323
* @return mixed
24+
*
25+
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
2426
*/
2527
public function handle(Request $request, Closure $next)
2628
{

app/Http/Middleware/DaemonAuthenticate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function __construct(NodeRepositoryInterface $repository)
4646
* @param \Illuminate\Http\Request $request
4747
* @param \Closure $next
4848
* @return mixed
49+
*
50+
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
4951
*/
5052
public function handle(Request $request, Closure $next)
5153
{

app/Http/Middleware/Server/AuthenticateAsSubuser.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ public function __construct(DaemonKeyProviderService $keyProviderService, Sessio
4747
* @param \Closure $next
4848
* @return mixed
4949
*
50-
* @throws \Illuminate\Auth\AuthenticationException
5150
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
52-
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
51+
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
5352
*/
5453
public function handle(Request $request, Closure $next)
5554
{

app/Http/Requests/Admin/UserFormRequest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ class UserFormRequest extends AdminFormRequest
1919
public function rules()
2020
{
2121
if ($this->method() === 'PATCH') {
22-
return User::getUpdateRulesForId($this->route()->parameter('user')->id);
22+
$rules = User::getUpdateRulesForId($this->route()->parameter('user')->id);
23+
24+
return array_merge($rules, [
25+
'ignore_connection_error' => 'sometimes|nullable|boolean',
26+
]);
2327
}
2428

2529
return User::getCreateRules();
@@ -30,7 +34,7 @@ public function normalize($only = [])
3034
if ($this->method === 'PATCH') {
3135
return array_merge(
3236
$this->intersect('password'),
33-
$this->only(['email', 'username', 'name_first', 'name_last', 'root_admin'])
37+
$this->only(['email', 'username', 'name_first', 'name_last', 'root_admin', 'ignore_connection_error'])
3438
);
3539
}
3640

0 commit comments

Comments
 (0)