Add support for controlling server power from API.

This commit is contained in:
Dane Everitt 2016-10-20 13:39:39 -04:00
parent 745c735b32
commit 5a03ce7e1a
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 38 additions and 4 deletions

View File

@ -26,14 +26,37 @@ namespace Pterodactyl\Http\Controllers\API\User;
use Pterodactyl\Models; use Pterodactyl\Models;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class PowerController extends BaseController use Pterodactyl\Http\Controllers\API\BaseController;
class ServerController extends BaseController
{ {
public function __constructor()
public function info(Request $request, $uuid)
{ {
// Will return server info including latest query and stats from daemon.
} }
public function pass(Request $request, $uuid) public function power(Request $request, $uuid)
{ {
//$server = Models\Server::where('id', $id)->where(); $server = Models\Server::getByUUID($uuid);
$node = Models\Node::getByID($server->node);
$client = Models\Node::guzzleRequest($server->node);
$res = $client->request('PUT', '/server/power', [
'headers' => [
'X-Access-Server' => $server->uuid,
'X-Access-Token' => $server->daemonSecret
],
'exceptions' => false,
'json' => [
'action' => $request->input('action')
]
]);
if ($res->getStatusCode() !== 204) {
return $this->response->error(json_decode($res->getBody())->error, $res->getStatusCode());
}
return $this->response->noContent();
} }
} }

View File

@ -13,5 +13,6 @@ class VerifyCsrfToken extends BaseVerifier
*/ */
protected $except = [ protected $except = [
'remote/*', 'remote/*',
'api/*'
]; ];
} }

View File

@ -37,6 +37,16 @@ class APIRoutes
'as' => 'api.user', 'as' => 'api.user',
'uses' => 'Pterodactyl\Http\Controllers\API\User\InfoController@me' 'uses' => 'Pterodactyl\Http\Controllers\API\User\InfoController@me'
]); ]);
$api->get('/server/{uuid}', [
'as' => 'api.user.server',
'uses' => 'Pterodactyl\Http\Controllers\API\User\ServerController@info'
]);
$api->put('/server/{uuid}', [
'as' => 'api.user.server.power',
'uses' => 'Pterodactyl\Http\Controllers\API\User\ServerController@power'
]);
}); });
$api->version('v1', ['prefix' => 'api', 'middleware' => 'api.auth'], function ($api) { $api->version('v1', ['prefix' => 'api', 'middleware' => 'api.auth'], function ($api) {