Skip to content

Commit 7d1c233

Browse files
committed
Final adjustments to Daemon <-> Panel communication change
1 parent 8e2b77d commit 7d1c233

32 files changed

+527
-537
lines changed

app/Console/Commands/Server/RebuildServerCommand.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ public function handle()
104104
];
105105

106106
try {
107-
$this->daemonRepository->setNode($server->node_id)
108-
->setAccessServer($server->uuid)
109-
->setAccessToken($server->node->daemonSecret)
110-
->update($json);
107+
$this->daemonRepository->setNode($server->node_id)->setAccessServer($server->uuid)->update($json);
111108
} catch (RequestException $exception) {
112109
$this->output->error(trans('command/messages.server.rebuild_failed', [
113110
'name' => $server->name,

app/Contracts/Repository/Daemon/ServerRepositoryInterface.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ interface ServerRepositoryInterface extends BaseRepositoryInterface
3636
*/
3737
public function create($id, array $overrides = [], $start = false);
3838

39-
/**
40-
* Set an access token and associated permissions for a server.
41-
*
42-
* @param string $key
43-
* @param array $permissions
44-
* @return \Psr\Http\Message\ResponseInterface
45-
*/
46-
public function setSubuserKey($key, array $permissions);
47-
4839
/**
4940
* Update server details on the daemon.
5041
*
@@ -95,4 +86,12 @@ public function delete();
9586
* @return \Psr\Http\Message\ResponseInterface
9687
*/
9788
public function details();
89+
90+
/**
91+
* Revoke an access key on the daemon before the time is expired.
92+
*
93+
* @param string $key
94+
* @return \Psr\Http\Message\ResponseInterface
95+
*/
96+
public function revokeAccessKey($key);
9897
}

app/Contracts/Repository/DaemonKeyRepositoryInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626

2727
interface DaemonKeyRepositoryInterface extends RepositoryInterface
2828
{
29+
/**
30+
* String prepended to keys to identify that they are managed internally and not part of the user API.
31+
*/
32+
const INTERNAL_KEY_IDENTIFIER = 'i_';
33+
2934
/**
3035
* Gets the daemon keys associated with a specific server.
3136
*

app/Contracts/Repository/SubuserRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface SubuserRepositoryInterface extends RepositoryInterface
3030
* Return a subuser with the associated server relationship.
3131
*
3232
* @param int $id
33-
* @return \Illuminate\Database\Eloquent\Collection
33+
* @return \Pterodactyl\Models\Subuser
3434
*
3535
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
3636
*/

app/Exceptions/Service/Server/UserNotLinkedToServerException.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

app/Http/Controllers/API/Remote/ValidateKeyController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use Illuminate\Foundation\Testing\HttpException;
3131
use League\Fractal\Serializer\JsonApiSerializer;
3232
use Pterodactyl\Transformers\Daemon\ApiKeyTransformer;
33-
use Pterodactyl\Services\DaemonKeys\DaemonKeyUpdateService;
3433
use Pterodactyl\Contracts\Repository\DaemonKeyRepositoryInterface;
3534

3635
class ValidateKeyController extends Controller
@@ -78,7 +77,7 @@ public function __construct(
7877
*/
7978
public function index($token)
8079
{
81-
if (! starts_with($token, DaemonKeyUpdateService::INTERNAL_TOKEN_IDENTIFIER)) {
80+
if (! starts_with($token, DaemonKeyRepositoryInterface::INTERNAL_KEY_IDENTIFIER)) {
8281
throw new HttpException(501);
8382
}
8483

app/Http/Controllers/Base/IndexController.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@
2929
use GuzzleHttp\Exception\RequestException;
3030
use Pterodactyl\Http\Controllers\Controller;
3131
use Symfony\Component\HttpKernel\Exception\HttpException;
32-
use Pterodactyl\Services\Servers\ServerAccessHelperService;
32+
use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
3333
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
3434
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
3535

3636
class IndexController extends Controller
3737
{
3838
/**
39-
* @var \Pterodactyl\Services\Servers\ServerAccessHelperService
39+
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
4040
*/
41-
protected $serverAccessHelper;
41+
protected $daemonRepository;
4242

4343
/**
44-
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
44+
* @var \Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService
4545
*/
46-
protected $daemonRepository;
46+
protected $keyProviderService;
4747

4848
/**
4949
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
@@ -53,17 +53,17 @@ class IndexController extends Controller
5353
/**
5454
* IndexController constructor.
5555
*
56+
* @param \Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService $keyProviderService
5657
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonRepository
57-
* @param \Pterodactyl\Services\Servers\ServerAccessHelperService $serverAccessHelper
5858
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
5959
*/
6060
public function __construct(
61+
DaemonKeyProviderService $keyProviderService,
6162
DaemonServerRepositoryInterface $daemonRepository,
62-
ServerAccessHelperService $serverAccessHelper,
6363
ServerRepositoryInterface $repository
6464
) {
65-
$this->serverAccessHelper = $serverAccessHelper;
6665
$this->daemonRepository = $daemonRepository;
66+
$this->keyProviderService = $keyProviderService;
6767
$this->repository = $repository;
6868
}
6969

@@ -93,7 +93,7 @@ public function getIndex(Request $request)
9393
public function status(Request $request, $uuid)
9494
{
9595
$server = $this->repository->findFirstWhere([['uuidShort', '=', $uuid]]);
96-
$token = $this->serverAccessHelper->handle($server, $request->user());
96+
$token = $this->keyProviderService->handle($server->id, $request->user()->id);
9797

9898
if (! $server->installed) {
9999
return response()->json(['status' => 20]);

app/Http/Middleware/SubuserAccessAuthenticate.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
use Illuminate\Http\Request;
2929
use Illuminate\Contracts\Session\Session;
3030
use Illuminate\Auth\AuthenticationException;
31-
use Pterodactyl\Services\Servers\ServerAccessHelperService;
32-
use Pterodactyl\Exceptions\Service\Server\UserNotLinkedToServerException;
31+
use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
32+
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
3333

3434
class SubuserAccessAuthenticate
3535
{
3636
/**
37-
* @var \Pterodactyl\Services\Servers\ServerAccessHelperService
37+
* @var \Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService
3838
*/
39-
protected $accessHelperService;
39+
protected $keyProviderService;
4040

4141
/**
4242
* @var \Illuminate\Contracts\Session\Session
@@ -46,33 +46,36 @@ class SubuserAccessAuthenticate
4646
/**
4747
* SubuserAccessAuthenticate constructor.
4848
*
49-
* @param \Pterodactyl\Services\Servers\ServerAccessHelperService $accessHelperService
50-
* @param \Illuminate\Contracts\Session\Session $session
49+
* @param \Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService $keyProviderService
50+
* @param \Illuminate\Contracts\Session\Session $session
5151
*/
5252
public function __construct(
53-
ServerAccessHelperService $accessHelperService,
53+
DaemonKeyProviderService $keyProviderService,
5454
Session $session
5555
) {
56-
$this->accessHelperService = $accessHelperService;
56+
$this->keyProviderService = $keyProviderService;
5757
$this->session = $session;
5858
}
5959

6060
/**
61+
* Determine if a subuser has permissions to access a server, if so set thier access token.
62+
*
6163
* @param \Illuminate\Http\Request $request
6264
* @param \Closure $next
6365
* @return mixed
6466
*
6567
* @throws \Illuminate\Auth\AuthenticationException
68+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
6669
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
6770
*/
6871
public function handle(Request $request, Closure $next)
6972
{
7073
$server = $this->session->get('server_data.model');
7174

7275
try {
73-
$token = $this->accessHelperService->handle($server, $request->user());
76+
$token = $this->keyProviderService->handle($server->id, $request->user()->id);
7477
$this->session->now('server_data.token', $token);
75-
} catch (UserNotLinkedToServerException $exception) {
78+
} catch (RecordNotFoundException $exception) {
7679
throw new AuthenticationException('This account does not have permission to access this server.');
7780
}
7881

app/Jobs/Schedule/RunTaskJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ public function handle(
110110
case 'power':
111111
$this->powerRepository->setNode($server->node_id)
112112
->setAccessServer($server->uuid)
113-
->setAccessToken($server->daemonSecret)
113+
->setAccessToken($server->accessToken->secret)
114114
->sendSignal($task->payload);
115115
break;
116116
case 'command':
117117
$this->commandRepository->setNode($server->node_id)
118118
->setAccessServer($server->uuid)
119-
->setAccessToken($server->daemonSecret)
119+
->setAccessToken($server->accessToken->secret)
120120
->send($task->payload);
121121
break;
122122
default:

app/Models/Permission.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
namespace Pterodactyl\Models;
2626

2727
use Sofa\Eloquence\Eloquence;
28+
use Sofa\Eloquence\Validable;
2829
use Illuminate\Database\Eloquent\Model;
2930
use Sofa\Eloquence\Contracts\CleansAttributes;
31+
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
3032

31-
class Permission extends Model implements CleansAttributes
33+
class Permission extends Model implements CleansAttributes, ValidableContract
3234
{
33-
use Eloquence;
35+
use Eloquence, Validable;
3436

3537
/**
3638
* Should timestamps be used on this model.
@@ -62,6 +64,22 @@ class Permission extends Model implements CleansAttributes
6264
'subuser_id' => 'integer',
6365
];
6466

67+
/**
68+
* @var array
69+
*/
70+
protected static $applicationRules = [
71+
'subuser_id' => 'required',
72+
'permission' => 'required',
73+
];
74+
75+
/**
76+
* @var array
77+
*/
78+
protected static $dataIntegrityRules = [
79+
'subuser_id' => 'numeric|min:1',
80+
'permission' => 'string',
81+
];
82+
6583
/**
6684
* A list of all permissions available for a user.
6785
*

0 commit comments

Comments
 (0)