2015-12-06 18:58:49 +00:00
|
|
|
<?php
|
2016-01-20 00:10:39 +00:00
|
|
|
/**
|
2016-01-20 21:05:16 +00:00
|
|
|
* Pterodactyl - Panel
|
2016-01-20 00:10:39 +00:00
|
|
|
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
|
|
|
|
*
|
2016-01-20 20:56:40 +00:00
|
|
|
* 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:
|
2016-01-20 00:10:39 +00:00
|
|
|
*
|
2016-01-20 20:56:40 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
2016-01-20 00:10:39 +00:00
|
|
|
*
|
2016-01-20 20:56:40 +00:00
|
|
|
* 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.
|
2016-01-20 00:10:39 +00:00
|
|
|
*/
|
2015-12-06 18:58:49 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Server;
|
|
|
|
|
|
|
|
use Auth;
|
2016-01-22 04:53:48 +00:00
|
|
|
use Debugbar;
|
|
|
|
use Uuid;
|
|
|
|
use Alert;
|
|
|
|
use Log;
|
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Pterodactyl\Models\Node;
|
|
|
|
use Pterodactyl\Models\Download;
|
2016-01-03 05:28:33 +00:00
|
|
|
use Pterodactyl\Models\Allocation;
|
2015-12-06 18:58:49 +00:00
|
|
|
|
|
|
|
use Pterodactyl\Exceptions\DisplayException;
|
2016-01-22 04:53:48 +00:00
|
|
|
use Pterodactyl\Exceptions\DisplayValidationException;
|
|
|
|
use Pterodactyl\Repositories\Daemon\FileRepository;
|
|
|
|
use Pterodactyl\Repositories\ServerRepository;
|
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class ServerController extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller Constructor
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2016-01-04 21:09:39 +00:00
|
|
|
//
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|
|
|
|
|
2016-01-09 00:54:06 +00:00
|
|
|
public function getJavascript(Request $request, $uuid, $file)
|
|
|
|
{
|
|
|
|
$server = Server::getByUUID($uuid);
|
|
|
|
return response()->view('server.js.' . $server->a_serviceFile . '.' . basename($file, '.js'), [
|
|
|
|
'server' => $server,
|
|
|
|
'node' => Node::find($server->node)
|
|
|
|
])->header('Content-Type', 'application/javascript');
|
|
|
|
}
|
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
/**
|
|
|
|
* Renders server index page for specified server.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function getIndex(Request $request)
|
|
|
|
{
|
|
|
|
$server = Server::getByUUID($request->route()->server);
|
|
|
|
return view('server.index', [
|
|
|
|
'server' => $server,
|
2016-01-03 05:28:33 +00:00
|
|
|
'allocations' => Allocation::where('assigned_to', $server->id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
|
2015-12-06 18:58:49 +00:00
|
|
|
'node' => Node::find($server->node)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders file overview page.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function getFiles(Request $request)
|
|
|
|
{
|
|
|
|
|
|
|
|
$server = Server::getByUUID($request->route()->server);
|
|
|
|
$this->authorize('list-files', $server);
|
|
|
|
|
|
|
|
return view('server.files.index', [
|
|
|
|
'server' => $server,
|
|
|
|
'node' => Node::find($server->node)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders add file page.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function getAddFile(Request $request)
|
|
|
|
{
|
|
|
|
|
|
|
|
$server = Server::getByUUID($request->route()->server);
|
|
|
|
$this->authorize('add-files', $server);
|
|
|
|
|
|
|
|
return view('server.files.add', [
|
|
|
|
'server' => $server,
|
|
|
|
'node' => Node::find($server->node),
|
|
|
|
'directory' => (in_array($request->get('dir'), [null, '/', ''])) ? '' : trim($request->get('dir'), '/') . '/'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders edit file page for a given file.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @param string $uuid
|
|
|
|
* @param string $file
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function getEditFile(Request $request, $uuid, $file)
|
|
|
|
{
|
|
|
|
|
|
|
|
$server = Server::getByUUID($uuid);
|
|
|
|
$this->authorize('edit-files', $server);
|
|
|
|
|
|
|
|
$fileInfo = (object) pathinfo($file);
|
2016-01-22 04:53:48 +00:00
|
|
|
$controller = new FileRepository($uuid);
|
2015-12-06 18:58:49 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
$fileContent = $controller->returnFileContents($file);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
|
|
Debugbar::addException($e);
|
|
|
|
$exception = 'An error occured while attempting to load the requested file for editing, please try again.';
|
|
|
|
|
|
|
|
if ($e instanceof DisplayException) {
|
|
|
|
$exception = $e->getMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
Alert::danger($exception)->flash();
|
|
|
|
return redirect()->route('files.index', $uuid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('server.files.edit', [
|
|
|
|
'server' => $server,
|
|
|
|
'node' => Node::find($server->node),
|
|
|
|
'file' => $file,
|
2016-01-01 23:08:15 +00:00
|
|
|
'contents' => $fileContent->content,
|
2015-12-06 18:58:49 +00:00
|
|
|
'directory' => (in_array($fileInfo->dirname, ['.', './', '/'])) ? '/' : trim($fileInfo->dirname, '/') . '/',
|
|
|
|
'extension' => $fileInfo->extension
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles downloading a file for the user.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @param string $uuid
|
|
|
|
* @param string $file
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function getDownloadFile(Request $request, $uuid, $file)
|
|
|
|
{
|
|
|
|
|
|
|
|
$server = Server::getByUUID($uuid);
|
|
|
|
$node = Node::find($server->node);
|
|
|
|
|
|
|
|
$this->authorize('download-files', $server);
|
|
|
|
|
|
|
|
$download = new Download;
|
|
|
|
|
|
|
|
$download->token = Uuid::generate(4);
|
2016-01-02 00:27:44 +00:00
|
|
|
$download->server = $server->uuid;
|
2015-12-06 18:58:49 +00:00
|
|
|
$download->path = str_replace('../', '', $file);
|
|
|
|
|
|
|
|
$download->save();
|
|
|
|
|
2016-01-01 23:08:15 +00:00
|
|
|
return redirect( $node->scheme . '://' . $node->fqdn . ':' . $node->daemonListen . '/server/download/' . $download->token);
|
2015-12-06 18:58:49 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-22 04:53:48 +00:00
|
|
|
/**
|
|
|
|
* Renders server settings page.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
|
|
|
public function getSettings(Request $request, $uuid)
|
|
|
|
{
|
|
|
|
$server = Server::getByUUID($uuid);
|
|
|
|
return view('server.settings', [
|
|
|
|
'server' => $server,
|
|
|
|
'node' => Node::find($server->node)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function postSettingsSFTP(Request $request, $uuid)
|
|
|
|
{
|
|
|
|
$server = Server::getByUUID($uuid);
|
|
|
|
$this->authorize('reset-sftp', $server);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$repo = new ServerRepository;
|
|
|
|
$repo->updateSFTPPassword($server->id, $request->input('sftp_pass'));
|
|
|
|
Alert::success('Successfully updated this servers SFTP password.')->flash();
|
|
|
|
} catch (DisplayValidationException $ex) {
|
|
|
|
return redirect()->route('server.settings', $uuid)->withErrors(json_decode($ex->getMessage()));
|
|
|
|
} catch (DisplayException $ex) {
|
|
|
|
Alert::danger($ex->getMessage())->flash();
|
|
|
|
} catch (\Exception $ex) {
|
|
|
|
Log::error($ex);
|
|
|
|
Alert::danger('An unknown error occured while attempting to update this server\'s SFTP settings.')->flash();
|
|
|
|
}
|
|
|
|
return redirect()->route('server.settings', $uuid);
|
|
|
|
}
|
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|