Add support for controlling server power from API.
This commit is contained in:
parent
745c735b32
commit
5a03ce7e1a
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,5 +13,6 @@ class VerifyCsrfToken extends BaseVerifier
|
||||||
*/
|
*/
|
||||||
protected $except = [
|
protected $except = [
|
||||||
'remote/*',
|
'remote/*',
|
||||||
|
'api/*'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue