Support for server info and minor changes to API setup
This commit is contained in:
parent
5a03ce7e1a
commit
125856d92f
3 changed files with 64 additions and 3 deletions
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
namespace Pterodactyl\Http\Controllers\API\User;
|
||||
|
||||
use Log;
|
||||
use Pterodactyl\Models;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
@ -33,7 +34,58 @@ class ServerController extends BaseController
|
|||
|
||||
public function info(Request $request, $uuid)
|
||||
{
|
||||
// Will return server info including latest query and stats from daemon.
|
||||
$server = Models\Server::getByUUID($uuid);
|
||||
$node = Models\Node::findOrFail($server->node);
|
||||
$client = Models\Node::guzzleRequest($node->id);
|
||||
|
||||
try {
|
||||
$response = $client->request('GET', '/server', [
|
||||
'headers' => [
|
||||
'X-Access-Token' => $server->daemonSecret,
|
||||
'X-Access-Server' => $server->uuid
|
||||
]
|
||||
]);
|
||||
|
||||
$json = json_decode($response->getBody());
|
||||
$daemon = [
|
||||
'status' => $json->status,
|
||||
'stats' => $json->proc,
|
||||
'query' => $json->query
|
||||
];
|
||||
} catch (\Exception $ex) {
|
||||
$daemon = [
|
||||
'error' => 'An error was encountered while trying to connect to the daemon to collece information. It might be offline.'
|
||||
];
|
||||
Log::error($ex);
|
||||
}
|
||||
|
||||
$allocations = Models\Allocation::select('id', 'ip', 'port', 'ip_alias as alias')->where('assigned_to', $server->id)->get();
|
||||
foreach($allocations as &$allocation) {
|
||||
$allocation->default = ($allocation->id === $server->allocation);
|
||||
unset($allocation->id);
|
||||
}
|
||||
return [
|
||||
'uuidShort' => $server->uuidShort,
|
||||
'uuid' => $server->uuid,
|
||||
'name' => $server->name,
|
||||
'node' => $node->name,
|
||||
'limits' => [
|
||||
'memory' => $server->memory,
|
||||
'swap' => $server->swap,
|
||||
'disk' => $server->disk,
|
||||
'io' => $server->io,
|
||||
'cpu' => $server->cpu,
|
||||
'oom_disabled' => (bool) $server->oom_disabled
|
||||
],
|
||||
'allocations' => $allocations,
|
||||
'sftp' => [
|
||||
'username' => $server->username
|
||||
],
|
||||
'daemon' => [
|
||||
'token' => ($request->secure()) ? $server->daemonSecret : false,
|
||||
'response' => $daemon
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function power(Request $request, $uuid)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue