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