From 564d947f7e2de725e573892ac00c8dca50f851f1 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Mon, 9 Dec 2019 21:05:39 -0800 Subject: [PATCH] [#3c9g25] Add support for new endpoint to collect node information --- .../Nodes/SystemInformationController.php | 52 +++++++++++++++++++ .../Wings/DaemonConfigurationRepository.php | 19 +++++++ .../views/admin/nodes/view/index.blade.php | 7 +-- routes/admin.php | 1 + 4 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 app/Http/Controllers/Admin/Nodes/SystemInformationController.php diff --git a/app/Http/Controllers/Admin/Nodes/SystemInformationController.php b/app/Http/Controllers/Admin/Nodes/SystemInformationController.php new file mode 100644 index 000000000..4e1a3fe8f --- /dev/null +++ b/app/Http/Controllers/Admin/Nodes/SystemInformationController.php @@ -0,0 +1,52 @@ +repository = $repository; + } + + /** + * Returns system information from the Daemon. + * + * @param \Illuminate\Http\Request $request + * @param \Pterodactyl\Models\Node $node + * @return \Illuminate\Http\JsonResponse + * + * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException + */ + public function __invoke(Request $request, Node $node) + { + $data = $this->repository->setNode($node)->getSystemInformation(); + + return JsonResponse::create([ + 'version' => $data['version'] ?? '', + 'system' => [ + 'type' => Str::title($data['os'] ?? 'Unknown'), + 'arch' => $data['architecture'] ?? '--', + 'release' => $data['kernel_version'] ?? '--', + 'cpus' => $data['cpu_count'] ?? 0, + ], + ]); + } +} diff --git a/app/Repositories/Wings/DaemonConfigurationRepository.php b/app/Repositories/Wings/DaemonConfigurationRepository.php index 6d5982201..0579bcf0b 100644 --- a/app/Repositories/Wings/DaemonConfigurationRepository.php +++ b/app/Repositories/Wings/DaemonConfigurationRepository.php @@ -2,6 +2,25 @@ namespace Pterodactyl\Repositories\Wings; +use GuzzleHttp\Exception\TransferException; +use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException; + class DaemonConfigurationRepository extends DaemonRepository { + /** + * Returns system information from the wings instance. + * + * @return array + * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException + */ + public function getSystemInformation(): array + { + try { + $response = $this->getHttpClient()->get('/api/system'); + } catch (TransferException $exception) { + throw new DaemonConnectionException($exception); + } + + return json_decode($response->getBody()->__toString(), true); + } } diff --git a/resources/views/admin/nodes/view/index.blade.php b/resources/views/admin/nodes/view/index.blade.php index ac9e29530..566982d5c 100644 --- a/resources/views/admin/nodes/view/index.blade.php +++ b/resources/views/admin/nodes/view/index.blade.php @@ -153,14 +153,11 @@ (function getInformation() { $.ajax({ method: 'GET', - url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/v1', + url: '/admin/nodes/view/{{ $node->id }}/system-information', timeout: 5000, - headers: { - 'X-Access-Token': '{{ $node->daemonSecret }}' - }, }).done(function (data) { $('[data-attr="info-version"]').html(data.version); - $('[data-attr="info-system"]').html(data.system.type + '(' + data.system.arch + ') ' + data.system.release + ''); + $('[data-attr="info-system"]').html(data.system.type + ' (' + data.system.arch + ') ' + data.system.release + ''); $('[data-attr="info-cpus"]').html(data.system.cpus); }).fail(function (jqXHR) { diff --git a/routes/admin.php b/routes/admin.php index d36ec4468..598f46bbb 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -150,6 +150,7 @@ Route::group(['prefix' => 'nodes'], function () { Route::get('/view/{node}/configuration', 'Nodes\NodeViewController@configuration')->name('admin.nodes.view.configuration'); Route::get('/view/{node}/allocation', 'Nodes\NodeViewController@allocations')->name('admin.nodes.view.allocation'); Route::get('/view/{node}/servers', 'Nodes\NodeViewController@servers')->name('admin.nodes.view.servers'); + Route::get('/view/{node}/system-information', 'Nodes\SystemInformationController'); Route::get('/view/{node}/settings/token', 'NodesController@setToken')->name('admin.nodes.view.configuration.token'); Route::post('/new', 'NodesController@store');