2016-10-14 20:22:23 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
2017-01-24 17:57:08 -05:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
2016-10-14 20:22:23 -04:00
|
|
|
*
|
2017-09-25 21:43:01 -05:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2016-10-14 20:22:23 -04:00
|
|
|
*/
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-10-14 20:22:23 -04:00
|
|
|
namespace Pterodactyl\Http\Controllers\API\User;
|
|
|
|
|
2017-04-02 13:19:39 -04:00
|
|
|
use Fractal;
|
2016-10-14 20:22:23 -04:00
|
|
|
use Illuminate\Http\Request;
|
2017-04-02 13:19:39 -04:00
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-04-09 19:16:39 -04:00
|
|
|
use Pterodactyl\Transformers\User\ServerTransformer;
|
2017-08-05 17:26:30 -05:00
|
|
|
use Pterodactyl\Repositories\old_Daemon\PowerRepository;
|
2017-07-19 20:49:41 -05:00
|
|
|
use Pterodactyl\Repositories\old_Daemon\CommandRepository;
|
2016-10-14 20:22:23 -04:00
|
|
|
|
2017-04-02 13:19:39 -04:00
|
|
|
class ServerController extends Controller
|
2016-10-14 20:22:23 -04:00
|
|
|
{
|
2017-04-02 15:52:53 -04:00
|
|
|
/**
|
|
|
|
* Controller to handle base request for individual server information.
|
|
|
|
*
|
2017-08-21 22:10:48 -05:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param string $uuid
|
2017-04-02 15:52:53 -04:00
|
|
|
* @return array
|
|
|
|
*/
|
2017-04-02 13:19:39 -04:00
|
|
|
public function index(Request $request, $uuid)
|
2016-10-14 20:22:23 -04:00
|
|
|
{
|
2017-04-09 18:59:54 -04:00
|
|
|
$this->authorize('user.server-view', $request->apiKey());
|
2017-04-09 13:15:15 -04:00
|
|
|
|
2017-04-02 13:19:39 -04:00
|
|
|
$server = Server::byUuid($uuid);
|
|
|
|
$fractal = Fractal::create()->item($server);
|
|
|
|
|
2017-04-02 16:51:56 -04:00
|
|
|
if ($request->input('include')) {
|
2017-04-07 20:28:58 -04:00
|
|
|
$fractal->parseIncludes(explode(',', $request->input('include')));
|
2017-04-02 13:19:39 -04:00
|
|
|
}
|
|
|
|
|
2017-04-02 16:51:56 -04:00
|
|
|
return $fractal->transformWith(new ServerTransformer)
|
|
|
|
->withResourceName('server')
|
|
|
|
->toArray();
|
2017-04-02 13:19:39 -04:00
|
|
|
}
|
|
|
|
|
2017-04-02 15:52:53 -04:00
|
|
|
/**
|
|
|
|
* Controller to handle request for server power toggle.
|
|
|
|
*
|
2017-08-21 22:10:48 -05:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param string $uuid
|
2017-04-02 15:52:53 -04:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2017-04-02 13:19:39 -04:00
|
|
|
public function power(Request $request, $uuid)
|
|
|
|
{
|
2017-04-09 18:59:54 -04:00
|
|
|
$this->authorize('user.server-power', $request->apiKey());
|
2017-04-09 13:15:15 -04:00
|
|
|
|
2017-04-02 15:52:53 -04:00
|
|
|
$server = Server::byUuid($uuid);
|
|
|
|
$request->user()->can('power-' . $request->input('action'), $server);
|
|
|
|
|
2017-04-15 13:52:43 -04:00
|
|
|
$repo = new PowerRepository($server, $request->user());
|
2017-04-02 15:52:53 -04:00
|
|
|
$repo->do($request->input('action'));
|
2017-04-02 13:19:39 -04:00
|
|
|
|
2017-04-02 15:52:53 -04:00
|
|
|
return response('', 204)->header('Content-Type', 'application/json');
|
2017-04-02 13:19:39 -04:00
|
|
|
}
|
|
|
|
|
2017-04-02 15:52:53 -04:00
|
|
|
/**
|
|
|
|
* Controller to handle base request for individual server information.
|
|
|
|
*
|
2017-08-21 22:10:48 -05:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param string $uuid
|
2017-04-02 15:52:53 -04:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2017-04-02 13:19:39 -04:00
|
|
|
public function command(Request $request, $uuid)
|
|
|
|
{
|
2017-04-09 18:59:54 -04:00
|
|
|
$this->authorize('user.server-command', $request->apiKey());
|
2017-04-09 13:15:15 -04:00
|
|
|
|
2017-04-02 15:52:53 -04:00
|
|
|
$server = Server::byUuid($uuid);
|
|
|
|
$request->user()->can('send-command', $server);
|
|
|
|
|
2017-04-15 13:52:43 -04:00
|
|
|
$repo = new CommandRepository($server, $request->user());
|
2017-04-02 15:52:53 -04:00
|
|
|
$repo->send($request->input('command'));
|
2017-04-02 13:19:39 -04:00
|
|
|
|
2017-04-02 15:52:53 -04:00
|
|
|
return response('', 204)->header('Content-Type', 'application/json');
|
2016-10-14 20:22:23 -04:00
|
|
|
}
|
|
|
|
}
|