Skip to content

Commit 06756af

Browse files
committed
add ?daemon=true option to API for servers
1 parent fbfaec6 commit 06756af

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
77

88
### Added
99
* Added support for file copying through the file manager. [#127](https://github.com/Pterodactyl/Panel/issues/127)
10-
* Added support for creating new files and folders directly from the right-click dropdown menu.
11-
* Added support for setting custom `user_id` when using the API to create users.
10+
* Creating new files and folders directly from the right-click dropdown menu in the file manager.
11+
* Support for setting custom `user_id` when using the API to create users.
1212
* Support for creating a new server through the API by passing a user ID rather than an email.
13+
* 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.
1314

1415
### Changed
1516
* Support for sub-folders within the `getJavascript()` route for servers.
1617
* 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.
1718
* 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.
19+
* 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.
1820

1921
### Fixed
2022
* 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)

app/Http/Controllers/API/ServerController.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ public function __construct()
6262
*/
6363
public function list(Request $request)
6464
{
65-
$servers = Models\Server::paginate(50);
66-
return $this->response->paginator($servers, new ServerTransformer);
65+
return Models\Server::all()->toArray();
6766
}
6867

6968
/**
@@ -120,9 +119,41 @@ public function view(Request $request, $id)
120119
if (!$query->first()) {
121120
throw new NotFoundHttpException('No server by that ID was found.');
122121
}
123-
return $query->first();
122+
123+
// Requested Daemon Stats
124+
$server = $query->first();
125+
if ($request->input('daemon') === 'true') {
126+
$node = Models\Node::findOrFail($server->node);
127+
$client = Models\Node::guzzleRequest($node->id);
128+
129+
$response = $client->request('GET', '/servers', [
130+
'headers' => [
131+
'X-Access-Token' => $node->daemonSecret
132+
]
133+
]);
134+
135+
$server->toArray();
136+
137+
// Only return the daemon token if the request is using HTTPS
138+
if ($request->secure()) {
139+
$server->daemon_token = $server->daemonSecret;
140+
}
141+
$server->daemon = json_decode($response->getBody())->{$server->uuid};
142+
143+
return $server;
144+
}
145+
146+
return $server;
147+
124148
} catch (NotFoundHttpException $ex) {
125149
throw $ex;
150+
} catch (\GuzzleHttp\Exception\TransferException $ex) {
151+
// Couldn't hit the daemon, return what we have though.
152+
$server->toArray();
153+
$server->daemon = [
154+
'error' => 'There was an error encountered while attempting to connect to the remote daemon.'
155+
];
156+
return $server;
126157
} catch (\Exception $ex) {
127158
throw new BadRequestHttpException('There was an issue with the fields passed in the request.');
128159
}

resources/views/admin/api/new.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
<div class="checkbox highlight">
9494
<label class="checkbox-custom highlight" data-initialize="checkbox">
9595
<input class="sr-only" name="permissions[]" type="checkbox" value="api.servers.view"> <strong><span class="label label-default">GET</span> /servers/{id}</strong>
96-
<p class="text-muted"><small>Allows viewing details about a specific server.</small><p>
96+
<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>
9797
</label>
9898
</div>
9999
<div class="checkbox highlight">

0 commit comments

Comments
 (0)