Push updated server views

This commit is contained in:
Dane Everitt 2017-03-04 19:03:49 -05:00
parent 9a14cb5687
commit e688468920
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
17 changed files with 1245 additions and 776 deletions

View file

@ -29,6 +29,7 @@ use Alert;
use Javascript;
use Pterodactyl\Models;
use Illuminate\Http\Request;
use GuzzleHttp\Exception\TransferException;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Repositories\ServerRepository;
@ -38,14 +39,12 @@ use Pterodactyl\Exceptions\DisplayValidationException;
class ServersController extends Controller
{
/**
* Controller Constructor.
* Display the index page with all servers currently on the system.
*
* @param Request $request
* @return \Illuminate\View\View
*/
public function __construct()
{
//
}
public function getIndex(Request $request)
public function index(Request $request)
{
$servers = Models\Server::withTrashed()->with(
'node', 'user', 'allocation'
@ -60,7 +59,13 @@ class ServersController extends Controller
]);
}
public function getNew(Request $request)
/**
* Display create new server page.
*
* @param Request $request
* @return \Illuminate\View\View
*/
public function new(Request $request)
{
$services = Models\Service::with('options.packs', 'options.variables')->get();
Javascript::put([
@ -77,55 +82,38 @@ class ServersController extends Controller
]);
}
public function getView(Request $request, $id)
{
$server = Models\Server::withTrashed()->with(
'user', 'option.variables', 'variables',
'node.allocations', 'databases.host'
)->findOrFail($id);
$server->option->variables->transform(function ($item, $key) use ($server) {
$item->server_value = $server->variables->where('variable_id', $item->id)->pluck('variable_value')->first();
return $item;
});
return view('admin.servers.view', [
'server' => $server,
'assigned' => $server->node->allocations->where('server_id', $server->id)->sortBy('port')->sortBy('ip'),
'unassigned' => $server->node->allocations->where('server_id', null)->sortBy('port')->sortBy('ip'),
'db_servers' => Models\DatabaseServer::all(),
]);
}
public function postNewServer(Request $request)
/**
* Create server controller method.
*
* @param Request $request
* @return \Illuminate\Response\RedirectResponse
*/
public function create(Request $request)
{
try {
$server = new ServerRepository;
$response = $server->create($request->except('_token'));
$repo = new ServerRepository;
$server = $repo->create($request->except('_token'));
return redirect()->route('admin.servers.view', ['id' => $response->id]);
return redirect()->route('admin.servers.view', $server->id);
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.servers.new')->withErrors(json_decode($ex->getMessage()))->withInput();
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
return redirect()->route('admin.servers.new')->withInput();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled exception occured while attemping to add this server. Please try again.')->flash();
return redirect()->route('admin.servers.new')->withInput();
}
return redirect()->route('admin.servers.new')->withInput();
}
/**
* Returns a JSON tree of all avaliable nodes in a given location.
* Returns a tree of all avaliable nodes in a given location.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\View\View
* @param Request $request
* @return array
*/
public function postNewServerGetNodes(Request $request)
public function newServerNodes(Request $request)
{
$nodes = Models\Node::with('allocations')->where('location_id', $request->input('location'))->get();
@ -149,263 +137,388 @@ class ServersController extends Controller
})->values();
}
public function postUpdateServerDetails(Request $request, $id)
/**
* Display the index when viewing a specific server.
*
* @param Request $request
* @param int $id
* @return \Illuminate\View\View
*/
public function viewIndex(Request $request, $id)
{
return view('admin.servers.view.index', ['server' => Models\Server::withTrashed()->findOrFail($id)]);
}
/**
* Display the details page when viewing a specific server.
*
* @param Request $request
* @param int $id
* @return \Illuminate\View\View
*/
public function viewDetails(Request $request, $id)
{
$server = Models\Server::where('installed', 1)->findOrFail($id);
return view('admin.servers.view.details', ['server' => $server]);
}
/**
* Display the build details page when viewing a specific server.
*
* @param Request $request
* @param int $id
* @return \Illuminate\View\View
*/
public function viewBuild(Request $request, $id)
{
$server = Models\Server::where('installed', 1)->with('node.allocations')->findOrFail($id);
return view('admin.servers.view.build', [
'server' => $server,
'assigned' => $server->node->allocations->where('server_id', $server->id)->sortBy('port')->sortBy('ip'),
'unassigned' => $server->node->allocations->where('server_id', null)->sortBy('port')->sortBy('ip'),
]);
}
/**
* Display startup configuration page for a server.
*
* @param Request $request
* @param int $id
* @return \Illuminate\View\View
*/
public function viewStartup(Request $request, $id)
{
$server = Models\Server::where('installed', 1)->with('option.variables', 'variables')->findOrFail($id);
$server->option->variables->transform(function ($item, $key) use ($server) {
$item->server_value = $server->variables->where('variable_id', $item->id)->pluck('variable_value')->first();
return $item;
});
return view('admin.servers.view.startup', ['server' => $server]);
}
/**
* Display the database management page for a specific server.
*
* @param Request $request
* @param int $id
* @return \Illuminate\View\View
*/
public function viewDatabase(Request $request, $id)
{
$server = Models\Server::where('installed', 1)->with('databases.host')->findOrFail($id);
return view('admin.servers.view.build', ['server' => $server]);
}
/**
* Display the management page when viewing a specific server.
*
* @param Request $request
* @param int $id
* @return \Illuminate\View\View
*/
public function viewManage(Request $request, $id)
{
return view('admin.servers.view.manage', ['server' => Models\Server::findOrFail($id)]);
}
/**
* Display the deletion page for a server.
*
* @param Request $request
* @param int $id
* @return \Illuminate\View\View
*/
public function viewDelete(Request $request, $id)
{
return view('admin.servers.view.delete', ['server' => Models\Server::withTrashed()->findOrFail($id)]);
}
/**
* Update the details for a server.
*
* @param Request $request
* @param int $id
* @return \Illuminate\Response\RedirectResponse
*/
public function setDetails(Request $request, $id)
{
$repo = new ServerRepository;;
try {
$server = new ServerRepository;
$server->updateDetails($id, $request->intersect([
$repo->updateDetails($id, $request->intersect([
'owner_id', 'name', 'reset_token',
]));
Alert::success('Server details were successfully updated.')->flash();
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_details',
])->withErrors(json_decode($ex->getMessage()))->withInput();
return redirect()->route('admin.servers.view.details', $id)->withErrors(json_decode($ex->getMessage()))->withInput();
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled exception occured while attemping to update this server. Please try again.')->flash();
Alert::danger('An unhandled exception occured while attemping to update this server. This error has been logged.')->flash();
}
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_details',
])->withInput();
return redirect()->route('admin.servers.view.details', $id)->withInput();
}
public function postUpdateContainerDetails(Request $request, $id)
/**
* Set the new docker container for a server.
*
* @param Request $request
* @param int $id
* @return \Illuminate\Response\RedirectResponse
*/
public function setContainer(Request $request, $id)
{
$repo = new ServerRepository;
try {
$server = new ServerRepository;
$server->updateContainer($id, $request->intersect('docker_image'));
$repo->updateContainer($id, $request->intersect('docker_image'));
Alert::success('Successfully updated this server\'s docker image.')->flash();
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_details',
])->withErrors(json_decode($ex->getMessage()))->withInput();
return redirect()->route('admin.servers.view.details', $id)->withErrors(json_decode($ex->getMessage()))->withInput();
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled exception occured while attemping to update this server\'s docker image. Please try again.')->flash();
Alert::danger('An unhandled exception occured while attemping to update this server\'s docker image. This error has been logged.')->flash();
}
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_details',
]);
return redirect()->route('admin.servers.view.details', $id);
}
public function postUpdateServerToggleBuild(Request $request, $id)
/**
* Toggles the install status for a server.
*
* @param Request $request
* @param int $id
* @return \Illuminate\Response\RedirectResponse
*/
public function toggleInstall(Request $request, $id)
{
$repo = new ServerRepository;
try {
$repo->toggleInstall($id);
Alert::success('Server install status was successfully toggled.')->flash();
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled exception occured while attemping to toggle this servers status. This error has been logged.')->flash();
}
return redirect()->route('admin.servers.view.manage', $id);
}
/**
* Setup a server to have a container rebuild.
*
* @param Request $request
* @param int $id
* @return \Illuminate\Response\RedirectResponse
*/
public function rebuildContainer(Request $request, $id)
{
$server = Models\Server::with('node')->findOrFail($id);
try {
$res = $server->node->guzzleClient([
$server->node->guzzleClient([
'X-Access-Server' => $server->uuid,
'X-Access-Token' => $server->node->daemonSecret,
])->request('POST', '/server/rebuild');
Alert::success('A rebuild has been queued successfully. It will run the next time this server is booted.')->flash();
} catch (\GuzzleHttp\Exception\TransferException $ex) {
} catch (TransferException $ex) {
Log::warning($ex);
Alert::danger('An error occured while attempting to toggle a rebuild.')->flash();
Alert::danger('A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.')->flash();
}
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_manage',
]);
return redirect()->route('admin.servers.view.manage', $id);
}
public function postUpdateServerUpdateBuild(Request $request, $id)
/**
* Manage the suspension status for a server.
*
* @param Request $request
* @param int $id
* @return \Illuminate\Response\RedirectResponse
*/
public function manageSuspension(Request $request, $id)
{
$repo = new ServerRepository;
$action = $request->input('action');
if (! in_array($action, ['suspend', 'unsuspend'])) {
Alert::danger('Invalid action was passed to function.')->flash();
return redirect()->route('admin.servers.view.manage', $id);
}
try {
$server = new ServerRepository;
$server->changeBuild($id, $request->intersect([
'allocation_id', 'add_allocations',
'remove_allocations', 'memory',
'swap', 'io', 'cpu',
]));
Alert::success('Server details were successfully updated.')->flash();
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_build',
])->withErrors(json_decode($ex->getMessage()))->withInput();
$repo->$action($id);
Alert::success('Server has been ' . $action . 'ed.');
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_build',
]);
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled exception occured while attemping to add this server. Please try again.')->flash();
Alert::danger('An unhandled exception occured while attemping to ' . $action . ' this server. This error has been logged.')->flash();
}
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_build',
]);
return redirect()->route('admin.servers.view.manage', $id);
}
public function deleteServer(Request $request, $id, $force = null)
/**
* Update the build configuration for a server.
*
* @param Request $request
* @param int $id
* @return \Illuminate\Response\RedirectResponse
*/
public function updateBuild(Request $request, $id)
{
$repo = new ServerRepository;
try {
$server = new ServerRepository;
$server->deleteServer($id, $force);
$repo->changeBuild($id, $request->intersect([
'allocation_id', 'add_allocations', 'remove_allocations',
'memory', 'swap', 'io', 'cpu',
]));
Alert::success('Server details were successfully updated.')->flash();
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.servers.view.build', $id)->withErrors(json_decode($ex->getMessage()))->withInput();
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled exception occured while attemping to add this server. This error has been logged.')->flash();
}
return redirect()->route('admin.servers.view.build', $id);
}
/**
* Start the server deletion process.
*
* @param Request $request
* @param int $id
* @return \Illuminate\Response\RedirectResponse
*/
public function delete(Request $request, $id)
{
$repo = new ServerRepository;
try {
$repo->queueDeletion($id, ($request->input('is_force') > 0));
Alert::success('Server has been marked for deletion on the system.')->flash();
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled exception occured while attemping to delete this server. This error has been logged.')->flash();
}
return redirect()->route('admin.servers.view.delete', $id);
}
/**
* Cancels a pending server deletion request.
*
* @param Request $request
* @param int $id
* @return \Illuminate\Response\RedirectResponse
*/
public function cancelDeletion(Request $request, $id)
{
$repo = new ServerRepository;
$repo->cancelDeletion($id);
Alert::success('Server deletion has been cancelled. This server will remain suspended until you unsuspend it.')->flash();
return redirect()->route('admin.servers.view.delete', $id);
}
/**
* Skips the queue and continues the server deletion process.
*
* @param Request $request
* @param int $id
* @return \Illuminate\Response\RedirectResponse
*/
public function continueDeletion(Request $request, $id, $method)
{
$repo = new ServerRepository;
try {
$repo->delete($id, (isset($method) && $method === 'force'));
Alert::success('Server was successfully deleted from the system.')->flash();
return redirect()->route('admin.servers');
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
} catch (TransferException $ex) {
Log::warning($ex);
Alert::danger('A TransferException occurred while attempting to delete this server from the daemon, please ensure it is running. This error has been logged.')->flash();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled exception occured while attemping to delete this server. Please try again.')->flash();
Alert::danger('An unhandled exception occured while attemping to delete this server. This error has been logged.')->flash();
}
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_delete',
]);
return redirect()->route('admin.servers.view.delete', $id);
}
public function postToggleInstall(Request $request, $id)
{
try {
$server = new ServerRepository;
$server->toggleInstall($id);
Alert::success('Server status was successfully toggled.')->flash();
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled exception occured while attemping to toggle this servers status.')->flash();
} finally {
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_manage',
]);
}
}
public function postUpdateServerStartup(Request $request, $id)
{
try {
$server = new ServerRepository;
$server->updateStartup($id, $request->except([
'_token',
]), true);
Alert::success('Server startup variables were successfully updated.')->flash();
} catch (\Pterodactyl\Exceptions\DisplayException $e) {
Alert::danger($e->getMessage())->flash();
} catch (\Exception $e) {
Log::error($e);
Alert::danger('An unhandled exception occured while attemping to update startup variables for this server. Please try again.')->flash();
} finally {
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_startup',
])->withInput();
}
}
public function postDatabase(Request $request, $id)
{
try {
$repo = new DatabaseRepository;
$repo->create($id, $request->only([
'db_server', 'database', 'remote',
]));
Alert::success('Added new database to this server.')->flash();
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_database',
])->withInput()->withErrors(json_decode($ex->getMessage()))->withInput();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An exception occured while attempting to add a new database for this server.')->flash();
}
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_database',
])->withInput();
}
public function postSuspendServer(Request $request, $id)
{
try {
$repo = new ServerRepository;
$repo->suspend($id);
Alert::success('Server has been suspended on the system. All running processes have been stopped and will not be startable until it is un-suspended.');
} catch (DisplayException $e) {
Alert::danger($e->getMessage())->flash();
} catch (\Exception $e) {
Log::error($e);
Alert::danger('An unhandled exception occured while attemping to suspend this server. Please try again.')->flash();
} finally {
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_manage',
]);
}
}
public function postUnsuspendServer(Request $request, $id)
{
try {
$repo = new ServerRepository;
$repo->unsuspend($id);
Alert::success('Server has been unsuspended on the system. Access has been re-enabled.');
} catch (DisplayException $e) {
Alert::danger($e->getMessage())->flash();
} catch (\Exception $e) {
Log::error($e);
Alert::danger('An unhandled exception occured while attemping to unsuspend this server. Please try again.')->flash();
} finally {
return redirect()->route('admin.servers.view', [
'id' => $id,
'tab' => 'tab_manage',
]);
}
}
public function postQueuedDeletionHandler(Request $request, $id)
{
try {
$repo = new ServerRepository;
if (! is_null($request->input('cancel'))) {
$repo->cancelDeletion($id);
Alert::success('Server deletion has been cancelled. This server will remain suspended until you unsuspend it.')->flash();
return redirect()->route('admin.servers.view', $id);
} elseif (! is_null($request->input('delete'))) {
$repo->deleteNow($id);
Alert::success('Server was successfully deleted from the system.')->flash();
return redirect()->route('admin.servers');
} elseif (! is_null($request->input('force_delete'))) {
$repo->deleteNow($id, true);
Alert::success('Server was successfully force deleted from the system.')->flash();
return redirect()->route('admin.servers');
}
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
return redirect()->route('admin.servers.view', $id);
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled error occured while attempting to perform this action.')->flash();
return redirect()->route('admin.servers.view', $id);
}
}
// //
// public function postUpdateServerStartup(Request $request, $id)
// {
// try {
// $server = new ServerRepository;
// $server->updateStartup($id, $request->except([
// '_token',
// ]), true);
// Alert::success('Server startup variables were successfully updated.')->flash();
// } catch (\Pterodactyl\Exceptions\DisplayException $e) {
// Alert::danger($e->getMessage())->flash();
// } catch (\Exception $e) {
// Log::error($e);
// Alert::danger('An unhandled exception occured while attemping to update startup variables for this server. Please try again.')->flash();
// } finally {
// return redirect()->route('admin.servers.view', [
// 'id' => $id,
// 'tab' => 'tab_startup',
// ])->withInput();
// }
// }
//
// public function postDatabase(Request $request, $id)
// {
// try {
// $repo = new DatabaseRepository;
// $repo->create($id, $request->only([
// 'db_server', 'database', 'remote',
// ]));
// Alert::success('Added new database to this server.')->flash();
// } catch (DisplayValidationException $ex) {
// return redirect()->route('admin.servers.view', [
// 'id' => $id,
// 'tab' => 'tab_database',
// ])->withInput()->withErrors(json_decode($ex->getMessage()))->withInput();
// } catch (\Exception $ex) {
// Log::error($ex);
// Alert::danger('An exception occured while attempting to add a new database for this server.')->flash();
// }
//
// return redirect()->route('admin.servers.view', [
// 'id' => $id,
// 'tab' => 'tab_database',
// ])->withInput();
// }
// //
}