misc_pterodactyl-panel/app/Http/Controllers/API/User/ServerController.php

85 lines
2.6 KiB
PHP
Raw Normal View History

<?php
/**
* Pterodactyl - Panel
2017-01-24 22:57:08 +00:00
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
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-12-07 22:46:38 +00:00
namespace Pterodactyl\Http\Controllers\API\User;
use Fractal;
use Illuminate\Http\Request;
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;
use Pterodactyl\Repositories\old_Daemon\CommandRepository;
class ServerController extends Controller
{
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
*/
public function index(Request $request, $uuid)
{
$this->authorize('user.server-view', $request->apiKey());
$server = Server::byUuid($uuid);
$fractal = Fractal::create()->item($server);
if ($request->input('include')) {
$fractal->parseIncludes(explode(',', $request->input('include')));
}
return $fractal->transformWith(new ServerTransformer)
->withResourceName('server')
->toArray();
}
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
*/
public function power(Request $request, $uuid)
{
$this->authorize('user.server-power', $request->apiKey());
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 19:52:53 +00:00
return response('', 204)->header('Content-Type', 'application/json');
}
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
*/
public function command(Request $request, $uuid)
{
$this->authorize('user.server-command', $request->apiKey());
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 19:52:53 +00:00
return response('', 204)->header('Content-Type', 'application/json');
}
}