add ?daemon=true option to API for servers
This commit is contained in:
parent
fbfaec6b20
commit
06756af994
3 changed files with 39 additions and 6 deletions
|
@ -7,14 +7,16 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
* Added support for file copying through the file manager. [#127](https://github.com/Pterodactyl/Panel/issues/127)
|
* 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.
|
* Creating new files and folders directly from the right-click dropdown menu in the file manager.
|
||||||
* Added support for setting custom `user_id` when using the API to create users.
|
* 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.
|
* 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
|
### Changed
|
||||||
* Support for sub-folders within the `getJavascript()` route for servers.
|
* 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`](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/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
|
### 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)
|
* 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)
|
||||||
|
|
|
@ -62,8 +62,7 @@ class ServerController extends BaseController
|
||||||
*/
|
*/
|
||||||
public function list(Request $request)
|
public function list(Request $request)
|
||||||
{
|
{
|
||||||
$servers = Models\Server::paginate(50);
|
return Models\Server::all()->toArray();
|
||||||
return $this->response->paginator($servers, new ServerTransformer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,9 +119,41 @@ class ServerController extends BaseController
|
||||||
if (!$query->first()) {
|
if (!$query->first()) {
|
||||||
throw new NotFoundHttpException('No server by that ID was found.');
|
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) {
|
} catch (NotFoundHttpException $ex) {
|
||||||
throw $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) {
|
} catch (\Exception $ex) {
|
||||||
throw new BadRequestHttpException('There was an issue with the fields passed in the request.');
|
throw new BadRequestHttpException('There was an issue with the fields passed in the request.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@
|
||||||
<div class="checkbox highlight">
|
<div class="checkbox highlight">
|
||||||
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
<label class="checkbox-custom highlight" data-initialize="checkbox">
|
||||||
<input class="sr-only" name="permissions[]" type="checkbox" value="api.servers.view"> <strong><span class="label label-default">GET</span> /servers/{id}</strong>
|
<input class="sr-only" name="permissions[]" type="checkbox" value="api.servers.view"> <strong><span class="label label-default">GET</span> /servers/{id}</strong>
|
||||||
<p class="text-muted"><small>Allows viewing details about a specific server.</small><p>
|
<p class="text-muted"><small><span class="label label-danger">Danger</span> Allows viewing details about a specific server including the <code>daemon_token</code> as current process information.</small><p>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="checkbox highlight">
|
<div class="checkbox highlight">
|
||||||
|
|
Loading…
Reference in a new issue