Finish front-end server modification changes.
Everything is back to the point that it was before this massive code overhaul began. FInal steps before merging this into develop will be some unit tests.
This commit is contained in:
parent
5fb4b2cdcf
commit
508ff8cfb3
13 changed files with 315 additions and 198 deletions
|
@ -1,163 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Server;
|
||||
|
||||
use Log;
|
||||
use Alert;
|
||||
use Pterodactyl\Models;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
class ServerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Returns the allocation overview for a server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $uuid
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function getAllocation(Request $request, $uuid)
|
||||
{
|
||||
$server = Models\Server::byUuid($uuid);
|
||||
$this->authorize('view-allocation', $server);
|
||||
$server->js();
|
||||
|
||||
return view('server.settings.allocation', [
|
||||
'server' => $server->load(['allocations' => function ($query) {
|
||||
$query->orderBy('ip', 'asc');
|
||||
$query->orderBy('port', 'asc');
|
||||
}]),
|
||||
'node' => $server->node,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the startup overview for a server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $uuid
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function getStartup(Request $request, $uuid)
|
||||
{
|
||||
$server = Models\Server::byUuid($uuid);
|
||||
$this->authorize('view-startup', $server);
|
||||
|
||||
$server->load(['node', 'allocation', 'variables']);
|
||||
$variables = Models\EggVariable::where('option_id', $server->option_id)->get();
|
||||
|
||||
$replacements = [
|
||||
'{{SERVER_MEMORY}}' => $server->memory,
|
||||
'{{SERVER_IP}}' => $server->allocation->ip,
|
||||
'{{SERVER_PORT}}' => $server->allocation->port,
|
||||
];
|
||||
|
||||
$processed = str_replace(array_keys($replacements), array_values($replacements), $server->startup);
|
||||
|
||||
foreach ($variables as $var) {
|
||||
if ($var->user_viewable) {
|
||||
$serverVar = $server->variables->where('variable_id', $var->id)->first();
|
||||
$var->server_set_value = $serverVar->variable_value ?? $var->default_value;
|
||||
} else {
|
||||
$var->server_set_value = '[hidden]';
|
||||
}
|
||||
|
||||
$processed = str_replace('{{' . $var->env_variable . '}}', $var->server_set_value, $processed);
|
||||
}
|
||||
|
||||
$server->js();
|
||||
|
||||
return view('server.settings.startup', [
|
||||
'server' => $server,
|
||||
'node' => $server->node,
|
||||
'variables' => $variables->where('user_viewable', 1),
|
||||
'service' => $server->service,
|
||||
'processedStartup' => $processed,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SFTP overview for a server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $uuid
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function getSFTP(Request $request, $uuid)
|
||||
{
|
||||
$server = Models\Server::byUuid($uuid);
|
||||
$this->authorize('view-sftp', $server);
|
||||
$server->js();
|
||||
|
||||
return view('server.settings.sftp', [
|
||||
'server' => $server,
|
||||
'node' => $server->node,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles changing the SFTP password for a server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $uuid
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postSettingsSFTP(Request $request, $uuid)
|
||||
{
|
||||
$server = Models\Server::byUuid($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.sftp', $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.sftp', $uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles changing the startup settings for a server.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $uuid
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postSettingsStartup(Request $request, $uuid)
|
||||
{
|
||||
$server = Models\Server::byUuid($uuid);
|
||||
$this->authorize('edit-startup', $server);
|
||||
|
||||
try {
|
||||
$repo = new ServerRepository;
|
||||
$repo->updateStartup($server->id, $request->except('_token'));
|
||||
Alert::success('Server startup variables were successfully updated.')->flash();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('server.settings.startup', $uuid)->withErrors(json_decode($ex->getMessage()));
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An unhandled exception occured while attemping to update startup variables for this server. Please try again.')->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('server.settings.startup', $uuid);
|
||||
}
|
||||
}
|
92
app/Http/Controllers/Server/Settings/StartupController.php
Normal file
92
app/Http/Controllers/Server/Settings/StartupController.php
Normal file
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Server\Settings;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Prologue\Alerts\AlertsMessageBag;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Traits\Controllers\JavascriptInjection;
|
||||
use Pterodactyl\Services\Servers\StartupCommandViewService;
|
||||
use Pterodactyl\Services\Servers\StartupModificationService;
|
||||
use Pterodactyl\Http\Requests\Server\UpdateStartupParametersFormRequest;
|
||||
|
||||
class StartupController extends Controller
|
||||
{
|
||||
use JavascriptInjection;
|
||||
|
||||
/**
|
||||
* @var \Prologue\Alerts\AlertsMessageBag
|
||||
*/
|
||||
private $alert;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\StartupCommandViewService
|
||||
*/
|
||||
private $commandViewService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\StartupModificationService
|
||||
*/
|
||||
private $modificationService;
|
||||
|
||||
/**
|
||||
* StartupController constructor.
|
||||
*
|
||||
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
||||
* @param \Pterodactyl\Services\Servers\StartupCommandViewService $commandViewService
|
||||
* @param \Pterodactyl\Services\Servers\StartupModificationService $modificationService
|
||||
*/
|
||||
public function __construct(
|
||||
AlertsMessageBag $alert,
|
||||
StartupCommandViewService $commandViewService,
|
||||
StartupModificationService $modificationService
|
||||
) {
|
||||
$this->alert = $alert;
|
||||
$this->commandViewService = $commandViewService;
|
||||
$this->modificationService = $modificationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the server startup page.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\View\View
|
||||
*
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$server = $request->attributes->get('server');
|
||||
$this->authorize('view-startup', $server);
|
||||
$this->injectJavascript();
|
||||
|
||||
$data = $this->commandViewService->handle($server->id);
|
||||
|
||||
return view('server.settings.startup', [
|
||||
'variables' => $data->get('variables'),
|
||||
'server_values' => $data->get('server_values'),
|
||||
'startup' => $data->get('startup'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle request to update the startup variables for a server. Authorization
|
||||
* is handled in the form request.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Server\UpdateStartupParametersFormRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function update(UpdateStartupParametersFormRequest $request): RedirectResponse
|
||||
{
|
||||
$this->modificationService->handle($request->attributes->get('server'), $request->normalize());
|
||||
$this->alert->success(trans('server.config.startup.edited'))->flash();
|
||||
|
||||
return redirect()->route('server.settings.startup', ['server' => $request->attributes->get('server')->uuidShort]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Server;
|
||||
|
||||
use Pterodactyl\Http\Requests\FrontendUserFormRequest;
|
||||
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
|
||||
|
||||
class UpdateStartupParametersFormRequest extends FrontendUserFormRequest
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $validationAttributes = [];
|
||||
|
||||
/**
|
||||
* Determine if the user has permission to update the startup parameters
|
||||
* for this server.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if (! parent::authorize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->user()->can('edit-startup', $this->attributes->get('server'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that all of the required fields were passed and that the environment
|
||||
* variable values meet the defined criteria for those fields.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$repository = $this->container->make(EggVariableRepositoryInterface::class);
|
||||
|
||||
$variables = $repository->getEditableVariables($this->attributes->get('server')->egg_id);
|
||||
$rules = $variables->mapWithKeys(function ($variable) {
|
||||
$this->validationAttributes['environment.' . $variable->env_variable] = $variable->name;
|
||||
|
||||
return ['environment.' . $variable->env_variable => $variable->rules];
|
||||
})->toArray();
|
||||
|
||||
return array_merge($rules, [
|
||||
'environment' => 'required|array',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return attributes to provide better naming conventions for error messages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes()
|
||||
{
|
||||
return $this->validationAttributes;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue