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
|
@ -31,6 +31,8 @@ interface FileRepositoryInterface extends BaseRepositoryInterface
|
|||
*
|
||||
* @param string $path
|
||||
* @return object
|
||||
*
|
||||
* @throws \GuzzleHttp\Exception\RequestException
|
||||
*/
|
||||
public function getFileStat($path);
|
||||
|
||||
|
@ -39,6 +41,8 @@ interface FileRepositoryInterface extends BaseRepositoryInterface
|
|||
*
|
||||
* @param string $path
|
||||
* @return object
|
||||
*
|
||||
* @throws \GuzzleHttp\Exception\RequestException
|
||||
*/
|
||||
public function getContent($path);
|
||||
|
||||
|
@ -48,6 +52,8 @@ interface FileRepositoryInterface extends BaseRepositoryInterface
|
|||
* @param string $path
|
||||
* @param string $content
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*
|
||||
* @throws \GuzzleHttp\Exception\RequestException
|
||||
*/
|
||||
public function putContent($path, $content);
|
||||
|
||||
|
@ -56,6 +62,8 @@ interface FileRepositoryInterface extends BaseRepositoryInterface
|
|||
*
|
||||
* @param string $path
|
||||
* @return array
|
||||
*
|
||||
* @throws \GuzzleHttp\Exception\RequestException
|
||||
*/
|
||||
public function getDirectory($path);
|
||||
}
|
||||
|
|
31
app/Exceptions/Http/Server/FileSizeTooLargeException.php
Normal file
31
app/Exceptions/Http/Server/FileSizeTooLargeException.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?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\Exceptions\Http\Server;
|
||||
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
class FileSizeTooLargeException extends DisplayException
|
||||
{
|
||||
}
|
31
app/Exceptions/Http/Server/FileTypeNotEditableException.php
Normal file
31
app/Exceptions/Http/Server/FileTypeNotEditableException.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?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\Exceptions\Http\Server;
|
||||
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
class FileTypeNotEditableException extends DisplayException
|
||||
{
|
||||
}
|
|
@ -30,7 +30,6 @@ use Illuminate\Http\Request;
|
|||
use Pterodactyl\Repositories;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class AjaxController extends Controller
|
||||
{
|
||||
|
@ -49,134 +48,6 @@ class AjaxController extends Controller
|
|||
*/
|
||||
protected $directory;
|
||||
|
||||
/**
|
||||
* Returns a listing of files in a given directory for a server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $uuid
|
||||
* @return \Illuminate\View\View|\Illuminate\Http\Response
|
||||
*/
|
||||
public function postDirectoryList(Request $request, $uuid)
|
||||
{
|
||||
$server = Models\Server::byUuid($uuid);
|
||||
$this->authorize('list-files', $server);
|
||||
|
||||
$this->directory = '/' . trim(urldecode($request->input('directory', '/')), '/');
|
||||
$prevDir = [
|
||||
'header' => ($this->directory !== '/') ? $this->directory : '',
|
||||
];
|
||||
if ($this->directory !== '/') {
|
||||
$prevDir['first'] = true;
|
||||
}
|
||||
|
||||
// Determine if we should show back links in the file browser.
|
||||
// This code is strange, and could probably be rewritten much better.
|
||||
$goBack = explode('/', trim($this->directory, '/'));
|
||||
if (! empty(array_filter($goBack)) && count($goBack) >= 2) {
|
||||
$prevDir['show'] = true;
|
||||
array_pop($goBack);
|
||||
$prevDir['link'] = '/' . implode('/', $goBack);
|
||||
$prevDir['link_show'] = implode('/', $goBack) . '/';
|
||||
}
|
||||
|
||||
$controller = new Repositories\old_Daemon\FileRepository($uuid);
|
||||
|
||||
try {
|
||||
$directoryContents = $controller->returnDirectoryListing($this->directory);
|
||||
} catch (DisplayException $ex) {
|
||||
return response($ex->getMessage(), 500);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
|
||||
return response('An error occured while attempting to load the requested directory, please try again.', 500);
|
||||
}
|
||||
|
||||
return view('server.files.list', [
|
||||
'server' => $server,
|
||||
'files' => $directoryContents->files,
|
||||
'folders' => $directoryContents->folders,
|
||||
'editableMime' => Repositories\HelperRepository::editableFiles(),
|
||||
'directory' => $prevDir,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a POST request to save a file.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $uuid
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function postSaveFile(Request $request, $uuid)
|
||||
{
|
||||
$server = Models\Server::byUuid($uuid);
|
||||
$this->authorize('save-files', $server);
|
||||
|
||||
$controller = new Repositories\old_Daemon\FileRepository($uuid);
|
||||
|
||||
try {
|
||||
$controller->saveFileContents($request->input('file'), $request->input('contents'));
|
||||
|
||||
return response(null, 204);
|
||||
} catch (DisplayException $ex) {
|
||||
return response($ex->getMessage(), 500);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
|
||||
return response('An error occured while attempting to save this file, please try again.', 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the primary allocation for a server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $uuid
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @deprecated
|
||||
*/
|
||||
public function postSetPrimary(Request $request, $uuid)
|
||||
{
|
||||
$server = Models\Server::byUuid($uuid)->load('allocations');
|
||||
$this->authorize('set-connection', $server);
|
||||
|
||||
if ((int) $request->input('allocation') === $server->allocation_id) {
|
||||
return response()->json([
|
||||
'error' => 'You are already using this as your default connection.',
|
||||
], 409);
|
||||
}
|
||||
|
||||
try {
|
||||
$allocation = $server->allocations->where('id', $request->input('allocation'))->where('server_id', $server->id)->first();
|
||||
if (! $allocation) {
|
||||
return response()->json([
|
||||
'error' => 'No allocation matching your request was found in the system.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$repo = new Repositories\ServerRepository;
|
||||
$repo->changeBuild($server->id, [
|
||||
'default' => $allocation->ip . ':' . $allocation->port,
|
||||
]);
|
||||
|
||||
return response('The default connection for this server has been updated. Please be aware that you will need to restart your server for this change to go into effect.');
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return response()->json([
|
||||
'error' => json_decode($ex->getMessage(), true),
|
||||
], 422);
|
||||
} catch (DisplayException $ex) {
|
||||
return response()->json([
|
||||
'error' => $ex->getMessage(),
|
||||
], 503);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
|
||||
return response()->json([
|
||||
'error' => 'An unhandled exception occured while attemping to modify the default connection for this server.',
|
||||
], 503);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets a database password for a server.
|
||||
*
|
||||
|
|
|
@ -26,12 +26,12 @@ namespace Pterodactyl\Http\Controllers\Server;
|
|||
|
||||
use Illuminate\Contracts\Session\Session;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Traits\Controllers\ServerToJavascript;
|
||||
use Pterodactyl\Traits\Controllers\JavascriptInjection;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
|
||||
class ConsoleController extends Controller
|
||||
{
|
||||
use ServerToJavascript;
|
||||
use JavascriptInjection;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository
|
||||
|
@ -77,7 +77,7 @@ class ConsoleController extends Controller
|
|||
],
|
||||
]);
|
||||
|
||||
return view('server.index', ['server' => $server, 'node' => $server->node]);
|
||||
return view('server.index');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,13 +87,11 @@ class ConsoleController extends Controller
|
|||
*/
|
||||
public function console()
|
||||
{
|
||||
$server = $this->session->get('server_data.model');
|
||||
|
||||
$this->injectJavascript(['config' => [
|
||||
'console_count' => $this->config->get('pterodactyl.console.count'),
|
||||
'console_freq' => $this->config->get('pterodactyl.console.frequency'),
|
||||
]]);
|
||||
|
||||
return view('server.console', ['server' => $server, 'node' => $server->node]);
|
||||
return view('server.console');
|
||||
}
|
||||
}
|
||||
|
|
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,7 +26,6 @@ namespace Pterodactyl\Http\Controllers\Server;
|
|||
|
||||
use Log;
|
||||
use Alert;
|
||||
use Cache;
|
||||
use Pterodactyl\Models;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
@ -35,126 +34,6 @@ use Pterodactyl\Exceptions\DisplayValidationException;
|
|||
|
||||
class ServerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Renders file overview page.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $uuid
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function getFiles(Request $request, $uuid)
|
||||
{
|
||||
$server = Models\Server::byUuid($uuid);
|
||||
$this->authorize('list-files', $server);
|
||||
|
||||
$server->js([
|
||||
'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', [
|
||||
'server' => $server,
|
||||
'node' => $server->node,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders add file page.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $uuid
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function getAddFile(Request $request, $uuid)
|
||||
{
|
||||
$server = Models\Server::byUuid($uuid);
|
||||
$this->authorize('create-files', $server);
|
||||
|
||||
$server->js();
|
||||
|
||||
return view('server.files.add', [
|
||||
'server' => $server,
|
||||
'node' => $server->node,
|
||||
'directory' => (in_array($request->get('dir'), [null, '/', ''])) ? '' : trim($request->get('dir'), '/') . '/',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders edit file page for a given file.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $uuid
|
||||
* @param string $file
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function getEditFile(Request $request, $uuid, $file)
|
||||
{
|
||||
$server = Models\Server::byUuid($uuid);
|
||||
$this->authorize('edit-files', $server);
|
||||
|
||||
$fileInfo = (object) pathinfo($file);
|
||||
$controller = new FileRepository($uuid);
|
||||
|
||||
try {
|
||||
$fileContent = $controller->returnFileContents($file);
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
|
||||
return redirect()->route('server.files.index', $uuid);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error occured while attempting to load the requested file for editing, please try again.')->flash();
|
||||
|
||||
return redirect()->route('server.files.index', $uuid);
|
||||
}
|
||||
|
||||
$server->js([
|
||||
'stat' => $fileContent['stat'],
|
||||
]);
|
||||
|
||||
return view('server.files.edit', [
|
||||
'server' => $server,
|
||||
'node' => $server->node,
|
||||
'file' => $file,
|
||||
'stat' => $fileContent['stat'],
|
||||
'contents' => $fileContent['file']->content,
|
||||
'directory' => (in_array($fileInfo->dirname, ['.', './', '/'])) ? '/' : trim($fileInfo->dirname, '/') . '/',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles downloading a file for the user.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $uuid
|
||||
* @param string $file
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function getDownloadFile(Request $request, $uuid, $file)
|
||||
{
|
||||
$server = Models\Server::byUuid($uuid);
|
||||
$this->authorize('download-files', $server);
|
||||
|
||||
$token = str_random(40);
|
||||
Cache::tags(['Server:Downloads'])->put($token, [
|
||||
'server' => $server->uuid,
|
||||
'path' => $file,
|
||||
], 5);
|
||||
|
||||
return redirect($server->node->scheme . '://' . $server->node->fqdn . ':' . $server->node->daemonListen . '/server/file/download/' . $token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the allocation overview for a server.
|
||||
*
|
||||
|
|
127
app/Http/Requests/Server/UpdateFileContentsFormRequest.php
Normal file
127
app/Http/Requests/Server/UpdateFileContentsFormRequest.php
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?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\Requests\Server;
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
use Illuminate\Contracts\Session\Session;
|
||||
use Illuminate\Log\Writer;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\Http\Server\FileSizeTooLargeException;
|
||||
use Pterodactyl\Exceptions\Http\Server\FileTypeNotEditableException;
|
||||
use Pterodactyl\Http\Requests\FrontendUserFormRequest;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
|
||||
|
||||
class UpdateFileContentsFormRequest extends FrontendUserFormRequest
|
||||
{
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
protected $stats;
|
||||
|
||||
/**
|
||||
* Authorize a request to edit a file.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Http\Server\FileSizeTooLargeException
|
||||
* @throws \Pterodactyl\Exceptions\Http\Server\FileTypeNotEditableException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
parent::authorize();
|
||||
|
||||
$session = app()->make(Session::class);
|
||||
$server = $session->get('server_data.model');
|
||||
$token = $session->get('server_data.token');
|
||||
|
||||
$permission = $this->user()->can('edit-files', $server);
|
||||
if (! $permission) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->checkFileCanBeEdited($server, $token);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file stats from the Daemon.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getStats()
|
||||
{
|
||||
return $this->stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param string $token
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Http\Server\FileSizeTooLargeException
|
||||
* @throws \Pterodactyl\Exceptions\Http\Server\FileTypeNotEditableException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
protected function checkFileCanBeEdited($server, $token)
|
||||
{
|
||||
$config = app()->make(Repository::class);
|
||||
$repository = app()->make(FileRepositoryInterface::class);
|
||||
|
||||
try {
|
||||
$this->stats = $repository->setNode($server->node_id)
|
||||
->setAccessServer($server->uuid)
|
||||
->setAccessToken($token)
|
||||
->getFileStat($this->route()->parameter('file'));
|
||||
} catch (RequestException $exception) {
|
||||
$response = $exception->getResponse();
|
||||
app()->make(Writer::class)->warning($exception);
|
||||
|
||||
throw new DisplayException(trans('exceptions.daemon_connection_failed', [
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]));
|
||||
}
|
||||
|
||||
if (! $this->stats->file || ! in_array($this->stats->mime, $config->get('pterodactyl.files.editable'))) {
|
||||
throw new FileTypeNotEditableException(trans('server.files.exceptions.invalid_mime'));
|
||||
}
|
||||
|
||||
if ($this->stats->size > $config->get('pterodactyl.files.max_edit_size')) {
|
||||
throw new FileSizeTooLargeException(trans('server.files.exceptions.max_size'));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
60
app/Http/ViewComposers/Server/ServerDataComposer.php
Normal file
60
app/Http/ViewComposers/Server/ServerDataComposer.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?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\ViewComposers\Server;
|
||||
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Contracts\Session\Session;
|
||||
|
||||
class ServerDataComposer
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Session\Session
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* ServerDataComposer constructor.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Session\Session $session
|
||||
*/
|
||||
public function __construct(Session $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach server data to a view automatically.
|
||||
*
|
||||
* @param \Illuminate\View\View $view
|
||||
*/
|
||||
public function compose(View $view)
|
||||
{
|
||||
$data = $this->session->get('server_data');
|
||||
|
||||
$view->with('server', array_get($data, 'model'));
|
||||
$view->with('node', object_get($data['model'], 'node'));
|
||||
$view->with('daemon_token', array_get($data, 'token'));
|
||||
}
|
||||
}
|
39
app/Providers/ViewComposerServiceProvider.php
Normal file
39
app/Providers/ViewComposerServiceProvider.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?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\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Pterodactyl\Http\ViewComposers\Server\ServerDataComposer;
|
||||
|
||||
class ViewComposerServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register bindings in the container.
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->app->make('view')->composer('server.*', ServerDataComposer::class);
|
||||
}
|
||||
}
|
|
@ -59,7 +59,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
|
|||
rawurlencode($file['dirname'] . $file['basename'])
|
||||
));
|
||||
|
||||
return json_decode($response->getBody());
|
||||
return object_get(json_decode($response->getBody()), 'content');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -78,7 +78,7 @@ class AssignmentService
|
|||
$explode = explode('/', $data['allocation_ip']);
|
||||
if (count($explode) !== 1) {
|
||||
if (! ctype_digit($explode[1]) || ($explode[1] > self::CIDR_MIN_BITS || $explode[1] < self::CIDR_MAX_BITS)) {
|
||||
throw new DisplayException(trans('admin/exceptions.allocations.cidr_out_of_range'));
|
||||
throw new DisplayException(trans('exceptions.allocations.cidr_out_of_range'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ class AssignmentService
|
|||
foreach (Network::parse(gethostbyname($data['allocation_ip'])) as $ip) {
|
||||
foreach ($data['allocation_ports'] as $port) {
|
||||
if (! ctype_digit($port) && ! preg_match(self::PORT_RANGE_REGEX, $port)) {
|
||||
throw new DisplayException(trans('admin/exceptions.allocations.invalid_mapping', ['port' => $port]));
|
||||
throw new DisplayException(trans('exceptions.allocations.invalid_mapping', ['port' => $port]));
|
||||
}
|
||||
|
||||
$insertData = [];
|
||||
|
@ -94,7 +94,7 @@ class AssignmentService
|
|||
$block = range($matches[1], $matches[2]);
|
||||
|
||||
if (count($block) > self::PORT_RANGE_LIMIT) {
|
||||
throw new DisplayException(trans('admin/exceptions.allocations.too_many_ports'));
|
||||
throw new DisplayException(trans('exceptions.allocations.too_many_ports'));
|
||||
}
|
||||
|
||||
foreach ($block as $unit) {
|
||||
|
|
|
@ -155,7 +155,7 @@ class DatabaseHostService
|
|||
{
|
||||
$count = $this->databaseRepository->findCountWhere([['database_host_id', '=', $id]]);
|
||||
if ($count > 0) {
|
||||
throw new DisplayException(trans('admin/exceptions.databases.delete_has_databases'));
|
||||
throw new DisplayException(trans('exceptions.databases.delete_has_databases'));
|
||||
}
|
||||
|
||||
return $this->repository->delete($id);
|
||||
|
|
|
@ -80,7 +80,7 @@ class NodeDeletionService
|
|||
|
||||
$servers = $this->serverRepository->withColumns('id')->findCountWhere([['node_id', '=', $node]]);
|
||||
if ($servers > 0) {
|
||||
throw new HasActiveServersException($this->translator->trans('admin/exceptions.node.servers_attached'));
|
||||
throw new HasActiveServersException($this->translator->trans('exceptions.node.servers_attached'));
|
||||
}
|
||||
|
||||
return $this->repository->delete($node);
|
||||
|
|
|
@ -95,7 +95,7 @@ class NodeUpdateService
|
|||
$response = $exception->getResponse();
|
||||
$this->writer->warning($exception);
|
||||
|
||||
throw new DisplayException(trans('admin/exceptions.node.daemon_off_config_updated', [
|
||||
throw new DisplayException(trans('exceptions.node.daemon_off_config_updated', [
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]));
|
||||
}
|
||||
|
|
|
@ -86,11 +86,11 @@ class PackCreationService
|
|||
{
|
||||
if (! is_null($file)) {
|
||||
if (! $file->isValid()) {
|
||||
throw new InvalidFileUploadException(trans('admin/exceptions.packs.invalid_upload'));
|
||||
throw new InvalidFileUploadException(trans('exceptions.packs.invalid_upload'));
|
||||
}
|
||||
|
||||
if (! in_array($file->getMimeType(), self::VALID_UPLOAD_TYPES)) {
|
||||
throw new InvalidFileMimeTypeException(trans('admin/exceptions.packs.invalid_mime', [
|
||||
throw new InvalidFileMimeTypeException(trans('exceptions.packs.invalid_mime', [
|
||||
'type' => implode(', ', self::VALID_UPLOAD_TYPES),
|
||||
]));
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ class PackDeletionService
|
|||
|
||||
$count = $this->serverRepository->findCountWhere([['pack_id', '=', $pack->id]]);
|
||||
if ($count !== 0) {
|
||||
throw new HasActiveServersException(trans('admin/exceptions.packs.delete_has_servers'));
|
||||
throw new HasActiveServersException(trans('exceptions.packs.delete_has_servers'));
|
||||
}
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
|
|
|
@ -76,7 +76,7 @@ class PackUpdateService
|
|||
$count = $this->serverRepository->findCountWhere([['pack_id', '=', $pack->id]]);
|
||||
|
||||
if ($count !== 0) {
|
||||
throw new HasActiveServersException(trans('admin/exceptions.packs.update_has_servers'));
|
||||
throw new HasActiveServersException(trans('exceptions.packs.update_has_servers'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,11 +81,11 @@ class TemplateUploadService
|
|||
public function handle($option, UploadedFile $file)
|
||||
{
|
||||
if (! $file->isValid()) {
|
||||
throw new InvalidFileUploadException(trans('admin/exceptions.packs.invalid_upload'));
|
||||
throw new InvalidFileUploadException(trans('exceptions.packs.invalid_upload'));
|
||||
}
|
||||
|
||||
if (! in_array($file->getMimeType(), self::VALID_UPLOAD_TYPES)) {
|
||||
throw new InvalidFileMimeTypeException(trans('admin/exceptions.packs.invalid_mime', [
|
||||
throw new InvalidFileMimeTypeException(trans('exceptions.packs.invalid_mime', [
|
||||
'type' => implode(', ', self::VALID_UPLOAD_TYPES),
|
||||
]));
|
||||
}
|
||||
|
@ -117,11 +117,11 @@ class TemplateUploadService
|
|||
protected function handleArchive($option, $file)
|
||||
{
|
||||
if (! $this->archive->open($file->getRealPath())) {
|
||||
throw new UnreadableZipArchiveException(trans('admin/exceptions.packs.unreadable'));
|
||||
throw new UnreadableZipArchiveException(trans('exceptions.packs.unreadable'));
|
||||
}
|
||||
|
||||
if (! $this->archive->locateName('import.json') || ! $this->archive->locateName('archive.tar.gz')) {
|
||||
throw new InvalidPackArchiveFormatException(trans('admin/exceptions.packs.invalid_archive_exception'));
|
||||
throw new InvalidPackArchiveFormatException(trans('exceptions.packs.invalid_archive_exception'));
|
||||
}
|
||||
|
||||
$json = json_decode($this->archive->getFromName('import.json'), true);
|
||||
|
@ -130,7 +130,7 @@ class TemplateUploadService
|
|||
$pack = $this->creationService->handle($json);
|
||||
if (! $this->archive->extractTo(storage_path('app/packs/' . $pack->uuid), 'archive.tar.gz')) {
|
||||
// @todo delete the pack that was created.
|
||||
throw new ZipExtractionException(trans('admin/exceptions.packs.zip_extraction'));
|
||||
throw new ZipExtractionException(trans('exceptions.packs.zip_extraction'));
|
||||
}
|
||||
|
||||
$this->archive->close();
|
||||
|
|
|
@ -63,7 +63,7 @@ class InstallScriptUpdateService
|
|||
|
||||
if (! is_null(array_get($data, 'copy_script_from'))) {
|
||||
if (! $this->repository->isCopiableScript(array_get($data, 'copy_script_from'), $option->service_id)) {
|
||||
throw new InvalidCopyFromException(trans('admin/exceptions.service.options.invalid_copy_id'));
|
||||
throw new InvalidCopyFromException(trans('exceptions.service.options.invalid_copy_id'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ class OptionCreationService
|
|||
]);
|
||||
|
||||
if ($results !== 1) {
|
||||
throw new NoParentConfigurationFoundException(trans('admin/exceptions.service.options.must_be_child'));
|
||||
throw new NoParentConfigurationFoundException(trans('exceptions.service.options.must_be_child'));
|
||||
}
|
||||
} else {
|
||||
$data['config_from'] = null;
|
||||
|
|
|
@ -69,7 +69,7 @@ class OptionDeletionService
|
|||
]);
|
||||
|
||||
if ($servers > 0) {
|
||||
throw new HasActiveServersException(trans('admin/exceptions.service.options.delete_has_servers'));
|
||||
throw new HasActiveServersException(trans('exceptions.service.options.delete_has_servers'));
|
||||
}
|
||||
|
||||
return $this->repository->delete($option);
|
||||
|
|
|
@ -68,7 +68,7 @@ class OptionUpdateService
|
|||
]);
|
||||
|
||||
if ($results !== 1) {
|
||||
throw new NoParentConfigurationFoundException(trans('admin/exceptions.service.options.must_be_child'));
|
||||
throw new NoParentConfigurationFoundException(trans('exceptions.service.options.must_be_child'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ class ServiceDeletionService
|
|||
{
|
||||
$count = $this->serverRepository->findCountWhere([['service_id', '=', $service]]);
|
||||
if ($count > 0) {
|
||||
throw new HasActiveServersException(trans('admin/exceptions.service.delete_has_servers'));
|
||||
throw new HasActiveServersException(trans('exceptions.service.delete_has_servers'));
|
||||
}
|
||||
|
||||
return $this->repository->delete($service);
|
||||
|
|
|
@ -66,7 +66,7 @@ class VariableUpdateService
|
|||
|
||||
if (! is_null(array_get($data, 'env_variable'))) {
|
||||
if (in_array(strtoupper(array_get($data, 'env_variable')), explode(',', ServiceVariable::RESERVED_ENV_NAMES))) {
|
||||
throw new ReservedVariableNameException(trans('admin/exceptions.service.variables.reserved_name', [
|
||||
throw new ReservedVariableNameException(trans('exceptions.service.variables.reserved_name', [
|
||||
'name' => array_get($data, 'env_variable'),
|
||||
]));
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class VariableUpdateService
|
|||
]);
|
||||
|
||||
if ($search > 0) {
|
||||
throw new DisplayException(trans('admin/exceptions.service.variables.env_not_unique', [
|
||||
throw new DisplayException(trans('exceptions.service.variables.env_not_unique', [
|
||||
'name' => array_get($data, 'env_variable'),
|
||||
]));
|
||||
}
|
||||
|
|
|
@ -131,12 +131,12 @@ class SubuserCreationService
|
|||
]);
|
||||
} else {
|
||||
if ($server->owner_id === $user->id) {
|
||||
throw new UserIsServerOwnerException(trans('admin/exceptions.subusers.user_is_owner'));
|
||||
throw new UserIsServerOwnerException(trans('exceptions.subusers.user_is_owner'));
|
||||
}
|
||||
|
||||
$subuserCount = $this->subuserRepository->findCountWhere([['user_id', '=', $user->id], ['server_id', '=', $server->id]]);
|
||||
if ($subuserCount !== 0) {
|
||||
throw new ServerSubuserExistsException(trans('admin/exceptions.subusers.subuser_exists'));
|
||||
throw new ServerSubuserExistsException(trans('exceptions.subusers.subuser_exists'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ class SubuserCreationService
|
|||
$this->writer->warning($exception);
|
||||
|
||||
$response = $exception->getResponse();
|
||||
throw new DisplayException(trans('admin/exceptions.daemon_connection_failed', [
|
||||
throw new DisplayException(trans('exceptions.daemon_connection_failed', [
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]));
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ class SubuserDeletionService
|
|||
$this->writer->warning($exception);
|
||||
|
||||
$response = $exception->getResponse();
|
||||
throw new DisplayException(trans('admin/exceptions.daemon_connection_failed', [
|
||||
throw new DisplayException(trans('exceptions.daemon_connection_failed', [
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]));
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ class SubuserUpdateService
|
|||
$this->writer->warning($exception);
|
||||
|
||||
$response = $exception->getResponse();
|
||||
throw new DisplayException(trans('admin/exceptions.daemon_connection_failed', [
|
||||
throw new DisplayException(trans('exceptions.daemon_connection_failed', [
|
||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||
]));
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace Pterodactyl\Traits\Controllers;
|
|||
|
||||
use Javascript;
|
||||
|
||||
trait ServerToJavascript
|
||||
trait JavascriptInjection
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Session\Session
|
Reference in a new issue