Very rough go at getting API back into operational state.

Not spending a lot of time on this as its a pre-release and I have
plans to overhaul the API to actually work and be easy to maintain.
This commit is contained in:
Dane Everitt 2017-03-19 13:20:33 -04:00
parent 4e916cbf08
commit 5e27772fef
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
7 changed files with 189 additions and 333 deletions

View file

@ -25,15 +25,15 @@
namespace Pterodactyl\Http\Controllers\API\User;
use Log;
use Pterodactyl\Models;
use Illuminate\Http\Request;
use Pterodactyl\Models\Server;
use Pterodactyl\Http\Controllers\API\BaseController;
class ServerController extends BaseController
{
public function info(Request $request, $uuid)
{
$server = Models\Server::byUuid($uuid)->load('allocations');
$server = Server::byUuid($uuid)->load('allocations');
try {
$response = $server->guzzleClient()->request('GET', '/server');
@ -82,8 +82,14 @@ class ServerController extends BaseController
public function power(Request $request, $uuid)
{
$server = Models\Server::byUuid($uuid);
Auth::user()->can('power-' . $request->input('action'), $server);
$server = Server::byUuid($uuid);
$request->user()->can('power-' . $request->input('action'), $server);
if (empty($request->input('action'))) {
return $this->response()->error([
'error' => 'An action must be passed to this request.',
], 422);
}
$res = $server->guzzleClient()->request('PUT', '/server/power', [
'exceptions' => false,
@ -98,4 +104,29 @@ class ServerController extends BaseController
return $this->response->noContent();
}
public function command(Request $request, $uuid)
{
$server = Server::byUuid($uuid);
$request->user()->can('send-command', $server);
if (empty($request->input('command'))) {
return $this->response()->error([
'error' => 'A command must be passed to this request.',
], 422);
}
$res = $server->guzzleClient()->request('POST', '/server/command', [
'exceptions' => false,
'json' => [
'command' => $request->input('command'),
],
]);
if ($res->getStatusCode() !== 204) {
return $this->response->error(json_decode($res->getBody())->error, $res->getStatusCode());
}
return $this->response->noContent();
}
}