1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-10-27 04:12:28 +01:00

Support for server info and minor changes to API setup

This commit is contained in:
Dane Everitt 2016-10-20 16:42:54 -04:00
parent 5a03ce7e1a
commit 125856d92f
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 64 additions and 3 deletions

View File

@ -9,11 +9,13 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
* Return node configuration from remote API by using `/api/nodes/{id}/config` endpoint. Only accepts SSL connections.
* Support for filtering servers within Admin CP to narrow down results by name, email, allocation, or defined fields.
* Setup scripts (user, mail, env) now support argument flags for use in containers and other non-terminal environments.
* New API endpoints for individual users to control their servers with at `/api/me/*`.
### Changed
* Creating a user, server, or node now returns `HTTP/1.1 200` and a JSON element with the user/server/node's ID.
* Environment setting script is much more user friendly and does not require an excessive amount of clicking and typing.
* File upload method switched from BinaryJS to Socket.io implementation to fix bugs as well as be a little speedier and allow upload throttling.
* `Server::getbyUUID()` now accepts either the `uuidShort` or full-length `uuid` for server identification.
## v0.5.0-pre.2 (Bodacious Boreopterus)

View File

@ -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)

View File

@ -27,6 +27,8 @@ use Auth;
use Pterodactyl\Models\Subuser;
use Illuminate\Database\Eloquent\Model;
use Pterodactyl\Exception\DisplayException;
class Server extends Model
{
@ -104,7 +106,7 @@ class Server extends Model
* @param Illuminate\Database\Eloquent\Model\Server $server
* @return string
*/
protected static function getUserDaemonSecret(Server $server)
public static function getUserDaemonSecret(Server $server)
{
if (self::$user->id === $server->owner || self::$user->root_admin === 1) {
@ -174,7 +176,8 @@ class Server extends Model
$query = self::select('servers.*', 'services.file as a_serviceFile')
->join('services', 'services.id', '=', 'servers.service')
->where('uuidShort', $uuid);
->where('uuidShort', $uuid)
->orWhere('uuid', $uuid);
if (self::$user->root_admin !== 1) {
$query->whereIn('servers.id', Subuser::accessServers());
@ -182,6 +185,10 @@ class Server extends Model
$result = $query->first();
if (!$result) {
throw new DisplayException('No server was found belonging to this user.');
}
if(!is_null($result)) {
$result->daemonSecret = self::getUserDaemonSecret($result);
}