diff --git a/CHANGELOG.md b/CHANGELOG.md index 092ecbfa7..9ca09f808 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,14 +7,16 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Added * Added support for file copying through the file manager. [#127](https://github.com/Pterodactyl/Panel/issues/127) -* Added support for creating new files and folders directly from the right-click dropdown menu. -* Added support for setting custom `user_id` when using the API to create users. +* Creating new files and folders directly from the right-click dropdown menu in the file manager. +* Support for setting custom `user_id` when using the API to create users. * Support for creating a new server through the API by passing a user ID rather than an email. +* Passing `?daemon=true` flag to [`/api/servers/:id`](https://pterodactyl.readme.io/v0.5.0/reference#single-server) will return the daemon stats as well as the `daemon_token` if using HTTPS. ### Changed * Support for sub-folders within the `getJavascript()` route for servers. * API route for [`/api/users`](https://pterodactyl.readme.io/v0.5.0/reference#users) now returns a non-paginated result set, and is a single array. * API route for [`/api/users/:id`](https://pterodactyl.readme.io/v0.5.0/reference#single-user) now returns a single array including an array of all servers the user is set as the owner of. +* API route for [`/api/servers`](https://pterodactyl.readme.io/v0.5.0/reference#servers) now returns a non-paginated result set, and is a single array. ### Fixed * File manager would do multiple up-down-up-down loading actions if you escaped renaming a file. Fixed the binding issue. [#122](https://github.com/Pterodactyl/Panel/issues/122) diff --git a/app/Http/Controllers/API/ServerController.php b/app/Http/Controllers/API/ServerController.php index a6d86cac4..adf4b95a3 100755 --- a/app/Http/Controllers/API/ServerController.php +++ b/app/Http/Controllers/API/ServerController.php @@ -62,8 +62,7 @@ class ServerController extends BaseController */ public function list(Request $request) { - $servers = Models\Server::paginate(50); - return $this->response->paginator($servers, new ServerTransformer); + return Models\Server::all()->toArray(); } /** @@ -120,9 +119,41 @@ class ServerController extends BaseController if (!$query->first()) { throw new NotFoundHttpException('No server by that ID was found.'); } - return $query->first(); + + // Requested Daemon Stats + $server = $query->first(); + if ($request->input('daemon') === 'true') { + $node = Models\Node::findOrFail($server->node); + $client = Models\Node::guzzleRequest($node->id); + + $response = $client->request('GET', '/servers', [ + 'headers' => [ + 'X-Access-Token' => $node->daemonSecret + ] + ]); + + $server->toArray(); + + // Only return the daemon token if the request is using HTTPS + if ($request->secure()) { + $server->daemon_token = $server->daemonSecret; + } + $server->daemon = json_decode($response->getBody())->{$server->uuid}; + + return $server; + } + + return $server; + } catch (NotFoundHttpException $ex) { throw $ex; + } catch (\GuzzleHttp\Exception\TransferException $ex) { + // Couldn't hit the daemon, return what we have though. + $server->toArray(); + $server->daemon = [ + 'error' => 'There was an error encountered while attempting to connect to the remote daemon.' + ]; + return $server; } catch (\Exception $ex) { throw new BadRequestHttpException('There was an issue with the fields passed in the request.'); } diff --git a/resources/views/admin/api/new.blade.php b/resources/views/admin/api/new.blade.php index 4f6343a74..11f6b22b9 100644 --- a/resources/views/admin/api/new.blade.php +++ b/resources/views/admin/api/new.blade.php @@ -93,7 +93,7 @@