2017-09-03 21:32:52 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-09-03 21:32:52 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* 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
|
2017-09-03 21:32:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Server\Files;
|
|
|
|
|
2017-10-28 02:42:53 +00:00
|
|
|
use Illuminate\View\View;
|
2017-09-03 21:41:03 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use GuzzleHttp\Exception\RequestException;
|
2017-09-03 21:32:52 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Pterodactyl\Traits\Controllers\JavascriptInjection;
|
2017-09-03 21:41:03 +00:00
|
|
|
use Pterodactyl\Http\Requests\Server\UpdateFileContentsFormRequest;
|
|
|
|
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
|
2017-10-28 02:42:53 +00:00
|
|
|
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
2017-09-03 21:32:52 +00:00
|
|
|
|
|
|
|
class FileActionsController extends Controller
|
|
|
|
{
|
|
|
|
use JavascriptInjection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface
|
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
protected $repository;
|
2017-09-03 21:32:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* FileActionsController constructor.
|
|
|
|
*
|
2017-10-28 02:42:53 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface $repository
|
2017-09-03 21:32:52 +00:00
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function __construct(FileRepositoryInterface $repository)
|
2017-09-03 21:32:52 +00:00
|
|
|
{
|
2017-10-28 02:42:53 +00:00
|
|
|
$this->repository = $repository;
|
2017-09-03 21:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display server file index list.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function index(Request $request): View
|
2017-09-03 21:32:52 +00:00
|
|
|
{
|
2017-10-28 02:42:53 +00:00
|
|
|
$server = $request->attributes->get('server');
|
2017-09-03 21:32:52 +00:00
|
|
|
$this->authorize('list-files', $server);
|
|
|
|
|
2017-10-28 02:42:53 +00:00
|
|
|
$this->setRequest($request)->injectJavascript([
|
2017-09-03 21:32:52 +00:00
|
|
|
'meta' => [
|
|
|
|
'directoryList' => route('server.files.directory-list', $server->uuidShort),
|
|
|
|
'csrftoken' => csrf_token(),
|
|
|
|
],
|
|
|
|
'permissions' => [
|
|
|
|
'moveFiles' => $request->user()->can('move-files', $server),
|
|
|
|
'copyFiles' => $request->user()->can('copy-files', $server),
|
|
|
|
'compressFiles' => $request->user()->can('compress-files', $server),
|
|
|
|
'decompressFiles' => $request->user()->can('decompress-files', $server),
|
|
|
|
'createFiles' => $request->user()->can('create-files', $server),
|
|
|
|
'downloadFiles' => $request->user()->can('download-files', $server),
|
|
|
|
'deleteFiles' => $request->user()->can('delete-files', $server),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
return view('server.files.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render page to manually create a file in the panel.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function create(Request $request): View
|
2017-09-03 21:32:52 +00:00
|
|
|
{
|
2017-10-28 02:42:53 +00:00
|
|
|
$this->authorize('create-files', $request->attributes->get('server'));
|
|
|
|
$this->setRequest($request)->injectJavascript();
|
2017-09-03 21:32:52 +00:00
|
|
|
|
|
|
|
return view('server.files.add', [
|
|
|
|
'directory' => (in_array($request->get('dir'), [null, '/', ''])) ? '' : trim($request->get('dir'), '/') . '/',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a form to allow for editing of a file.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Server\UpdateFileContentsFormRequest $request
|
|
|
|
* @param string $uuid
|
|
|
|
* @param string $file
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*
|
2018-01-01 19:21:10 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
2017-09-03 21:32:52 +00:00
|
|
|
*/
|
2018-01-01 19:21:10 +00:00
|
|
|
public function view(UpdateFileContentsFormRequest $request, string $uuid, string $file): View
|
2017-09-03 21:32:52 +00:00
|
|
|
{
|
2017-10-28 02:42:53 +00:00
|
|
|
$server = $request->attributes->get('server');
|
2017-09-03 21:32:52 +00:00
|
|
|
|
|
|
|
$dirname = pathinfo($file, PATHINFO_DIRNAME);
|
|
|
|
try {
|
2018-01-06 00:27:47 +00:00
|
|
|
$content = $this->repository->setServer($server)->setToken($request->attributes->get('server_token'))->getContent($file);
|
2017-09-03 21:32:52 +00:00
|
|
|
} catch (RequestException $exception) {
|
2017-10-28 02:42:53 +00:00
|
|
|
throw new DaemonConnectionException($exception);
|
2017-09-03 21:32:52 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 02:42:53 +00:00
|
|
|
$this->setRequest($request)->injectJavascript(['stat' => $request->attributes->get('file_stats')]);
|
2017-09-03 21:32:52 +00:00
|
|
|
|
|
|
|
return view('server.files.edit', [
|
|
|
|
'file' => $file,
|
2017-10-28 02:42:53 +00:00
|
|
|
'stat' => $request->attributes->get('file_stats'),
|
2017-09-03 21:32:52 +00:00
|
|
|
'contents' => $content,
|
|
|
|
'directory' => (in_array($dirname, ['.', './', '/'])) ? '/' : trim($dirname, '/') . '/',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|