Add more front-end controllers, language file cleanup
This commit is contained in:
parent
4532811fcd
commit
54554465f2
59 changed files with 1100 additions and 336 deletions
76
app/Http/Controllers/Server/Files/DownloadController.php
Normal file
76
app/Http/Controllers/Server/Files/DownloadController.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Server\Files;
|
||||
|
||||
use Illuminate\Cache\Repository;
|
||||
use Illuminate\Contracts\Session\Session;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
|
||||
class DownloadController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Cache\Repository
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Session\Session
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* DownloadController constructor.
|
||||
*
|
||||
* @param \Illuminate\Cache\Repository $cache
|
||||
* @param \Illuminate\Contracts\Session\Session $session
|
||||
*/
|
||||
public function __construct(Repository $cache, Session $session)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a unique download link for a user to download a file from.
|
||||
*
|
||||
* @param string $uuid
|
||||
* @param string $file
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index($uuid, $file)
|
||||
{
|
||||
$server = $this->session->get('server_data.model');
|
||||
$this->authorize('download-files', $server);
|
||||
|
||||
$token = str_random(40);
|
||||
$this->cache->tags(['Server:Downloads'])->put($token, ['server' => $server->uuid, 'path' => $file], 5);
|
||||
|
||||
return redirect(sprintf(
|
||||
'%s://%s:%s/server/file/download/%s', $server->node->scheme, $server->node->fqdn, $server->node->daemonListen, $token
|
||||
));
|
||||
}
|
||||
}
|
161
app/Http/Controllers/Server/Files/FileActionsController.php
Normal file
161
app/Http/Controllers/Server/Files/FileActionsController.php
Normal file
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Server\Files;
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Contracts\Session\Session;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Log\Writer;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Http\Requests\Server\UpdateFileContentsFormRequest;
|
||||
use Pterodactyl\Traits\Controllers\JavascriptInjection;
|
||||
|
||||
class FileActionsController extends Controller
|
||||
{
|
||||
use JavascriptInjection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface
|
||||
*/
|
||||
protected $fileRepository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Session\Session
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Log\Writer
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
/**
|
||||
* FileActionsController constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface $fileRepository
|
||||
* @param \Illuminate\Contracts\Session\Session $session
|
||||
* @param \Illuminate\Log\Writer $writer
|
||||
*/
|
||||
public function __construct(FileRepositoryInterface $fileRepository, Session $session, Writer $writer)
|
||||
{
|
||||
$this->fileRepository = $fileRepository;
|
||||
$this->session = $session;
|
||||
$this->writer = $writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display server file index list.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\View\View
|
||||
*
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$server = $this->session->get('server_data.model');
|
||||
$this->authorize('list-files', $server);
|
||||
|
||||
$this->injectJavascript([
|
||||
'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
|
||||
*/
|
||||
public function create(Request $request)
|
||||
{
|
||||
$this->authorize('create-files', $this->session->get('server_data.model'));
|
||||
$this->injectJavascript();
|
||||
|
||||
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
|
||||
*
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function update(UpdateFileContentsFormRequest $request, $uuid, $file)
|
||||
{
|
||||
$server = $this->session->get('server_data.model');
|
||||
$this->authorize('edit-files', $server);
|
||||
|
||||
$dirname = pathinfo($file, PATHINFO_DIRNAME);
|
||||
try {
|
||||
$content = $this->fileRepository->setNode($server->node_id)
|
||||
->setAccessServer($server->uuid)
|
||||
->setAccessToken($this->session->get('server_data.token'))
|
||||
->getContent($file);
|
||||
} catch (RequestException $exception) {
|
||||
$response = $exception->getResponse();
|
||||
$this->writer->warning($exception);
|
||||
|
||||
throw new DisplayException(trans('exceptions.daemon_connection_failed', [
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]));
|
||||
}
|
||||
|
||||
$this->injectJavascript(['stat' => $request->getStats()]);
|
||||
|
||||
return view('server.files.edit', [
|
||||
'file' => $file,
|
||||
'stat' => $request->getStats(),
|
||||
'contents' => $content,
|
||||
'directory' => (in_array($dirname, ['.', './', '/'])) ? '/' : trim($dirname, '/') . '/',
|
||||
]);
|
||||
}
|
||||
}
|
166
app/Http/Controllers/Server/Files/RemoteRequestController.php
Normal file
166
app/Http/Controllers/Server/Files/RemoteRequestController.php
Normal file
|
@ -0,0 +1,166 @@
|
|||
<?php
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Server\Files;
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
use Illuminate\Contracts\Session\Session;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Log\Writer;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
|
||||
class RemoteRequestController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface
|
||||
*/
|
||||
protected $fileRepository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Session\Session
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Log\Writer
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
/**
|
||||
* RemoteRequestController constructor.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
* @param \Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface $fileRepository
|
||||
* @param \Illuminate\Contracts\Session\Session $session
|
||||
* @param \Illuminate\Log\Writer $writer
|
||||
*/
|
||||
public function __construct(
|
||||
ConfigRepository $config,
|
||||
FileRepositoryInterface $fileRepository,
|
||||
Session $session,
|
||||
Writer $writer
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->fileRepository = $fileRepository;
|
||||
$this->session = $session;
|
||||
$this->writer = $writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a listing of a servers file directory.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
|
||||
*
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function directory(Request $request)
|
||||
{
|
||||
$server = $this->session->get('server_data.model');
|
||||
$this->authorize('list-files', $server);
|
||||
|
||||
$requestDirectory = '/' . trim(urldecode($request->input('directory', '/')), '/');
|
||||
$directory = [
|
||||
'header' => $requestDirectory !== '/' ? $requestDirectory : '',
|
||||
'first' => $requestDirectory !== '/',
|
||||
];
|
||||
|
||||
$goBack = explode('/', trim($requestDirectory, '/'));
|
||||
if (! empty(array_filter($goBack)) && count($goBack) >= 2) {
|
||||
array_pop($goBack);
|
||||
|
||||
$directory['show'] = true;
|
||||
$directory['link'] = '/' . implode('/', $goBack);
|
||||
$directory['link_show'] = implode('/', $goBack) . '/';
|
||||
}
|
||||
|
||||
try {
|
||||
$listing = $this->fileRepository->setNode($server->node_id)
|
||||
->setAccessServer($server->uuid)
|
||||
->setAccessToken($this->session->get('server_data.token'))
|
||||
->getDirectory($requestDirectory);
|
||||
} catch (RequestException $exception) {
|
||||
$this->writer->warning($exception);
|
||||
|
||||
if (! is_null($exception->getResponse())) {
|
||||
return response()->json(
|
||||
['error' => $exception->getResponse()->getBody()], $exception->getResponse()->getStatusCode()
|
||||
);
|
||||
} else {
|
||||
return response()->json(['error' => trans('server.files.exceptions.list_directory')], 500);
|
||||
}
|
||||
}
|
||||
|
||||
return view('server.files.list', [
|
||||
'files' => $listing['files'],
|
||||
'folders' => $listing['folders'],
|
||||
'editableMime' => $this->config->get('pterodactyl.files.editable'),
|
||||
'directory' => $directory,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the contents of a file onto the daemon.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $uuid
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function store(Request $request, $uuid)
|
||||
{
|
||||
$server = $this->session->get('server_data.model');
|
||||
$this->authorize('save-files', $server);
|
||||
|
||||
try {
|
||||
$this->fileRepository->setNode($server->node_id)
|
||||
->setAccessServer($server->uuid)
|
||||
->setAccessToken($this->session->get('server_data.token'))
|
||||
->putContent($request->input('file'), $request->input('contents'));
|
||||
|
||||
return response('', 204);
|
||||
} catch (RequestException $exception) {
|
||||
$response = $exception->getResponse();
|
||||
$this->writer->warning($exception);
|
||||
|
||||
if (! is_null($response)) {
|
||||
return response()->json(['error' => $response->getBody()], $response->getStatusCode());
|
||||
} else {
|
||||
return response()->json(['error' => trans('exceptions.daemon_connection_failed', [
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
])], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue