diff --git a/app/Http/Controllers/Api/Client/Servers/NetworkController.php b/app/Http/Controllers/Api/Client/Servers/NetworkController.php new file mode 100644 index 000000000..e7ecd1072 --- /dev/null +++ b/app/Http/Controllers/Api/Client/Servers/NetworkController.php @@ -0,0 +1,49 @@ +repository = $repository; + } + + /** + * Lists all of the allocations available to a server and wether or + * not they are currently assigned as the primary for this server. + * + * @param \Pterodactyl\Http\Requests\Api\Client\Servers\Network\GetNetworkRequest $request + * @return array + */ + public function index(GetNetworkRequest $request): array + { + $server = $request->getModel(Server::class); + + $allocations = $this->repository->findWhere([ + ['server_id', '=', $server->id], + ]); + + return $this->fractal->collection($allocations) + ->transformWith($this->getTransformer(AllocationTransformer::class)) + ->toArray(); + } +} diff --git a/app/Http/Requests/Api/Client/Servers/Network/GetNetworkRequest.php b/app/Http/Requests/Api/Client/Servers/Network/GetNetworkRequest.php new file mode 100644 index 000000000..14fd18337 --- /dev/null +++ b/app/Http/Requests/Api/Client/Servers/Network/GetNetworkRequest.php @@ -0,0 +1,20 @@ +user()->can('view-allocations', $this->getModel(Server::class)); + } +} diff --git a/app/Transformers/Api/Client/AllocationTransformer.php b/app/Transformers/Api/Client/AllocationTransformer.php new file mode 100644 index 000000000..055afdae3 --- /dev/null +++ b/app/Transformers/Api/Client/AllocationTransformer.php @@ -0,0 +1,36 @@ +loadMissing('server'); + + return [ + 'ip' => $model->ip, + 'alias' => $model->ip_alias, + 'port' => $model->port, + 'default' => $model->getRelation('server')->allocation_id === $model->id, + ]; + } +} diff --git a/routes/api-client.php b/routes/api-client.php index aca0fb329..0738c744f 100644 --- a/routes/api-client.php +++ b/routes/api-client.php @@ -46,4 +46,8 @@ Route::group(['prefix' => '/servers/{server}', 'middleware' => [AuthenticateServ ->where('file', '.*') ->name('api.client.servers.files.download'); }); + + Route::group(['prefix' => '/network'], function () { + Route::get('/', 'Servers\NetworkController@index')->name('api.client.servers.network'); + }); });