2019-11-24 20:50:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin\Servers;
|
|
|
|
|
2020-04-04 03:45:37 +00:00
|
|
|
use JavaScript;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\View\View;
|
2019-11-24 20:50:16 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Pterodactyl\Models\Nest;
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Pterodactyl\Exceptions\DisplayException;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2020-08-26 02:11:25 +00:00
|
|
|
use Pterodactyl\Services\Servers\EnvironmentService;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\Contracts\View\Factory as ViewFactory;
|
2020-04-04 03:45:37 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\NodeRepository;
|
2020-05-21 19:22:32 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
2019-11-24 20:50:16 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
|
|
|
use Pterodactyl\Traits\Controllers\JavascriptInjection;
|
2020-04-04 22:24:58 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\LocationRepository;
|
2019-11-24 20:50:16 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository;
|
|
|
|
|
|
|
|
class ServerViewController extends Controller
|
|
|
|
{
|
|
|
|
use JavascriptInjection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ServerViewController constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(
|
2022-10-14 16:59:20 +00:00
|
|
|
private DatabaseHostRepository $databaseHostRepository,
|
|
|
|
private LocationRepository $locationRepository,
|
|
|
|
private MountRepository $mountRepository,
|
|
|
|
private NodeRepository $nodeRepository,
|
|
|
|
private ServerRepository $repository,
|
|
|
|
private EnvironmentService $environmentService,
|
|
|
|
private ViewFactory $view
|
2019-11-24 20:50:16 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the index view for a server.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function index(Request $request, Server $server): View
|
2019-11-24 20:50:16 +00:00
|
|
|
{
|
|
|
|
return $this->view->make('admin.servers.view.index', compact('server'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the server details page.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function details(Request $request, Server $server): View
|
2019-11-24 20:50:16 +00:00
|
|
|
{
|
|
|
|
return $this->view->make('admin.servers.view.details', compact('server'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a view of server build settings.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function build(Request $request, Server $server): View
|
2019-11-24 20:50:16 +00:00
|
|
|
{
|
|
|
|
$allocations = $server->node->allocations->toBase();
|
|
|
|
|
|
|
|
return $this->view->make('admin.servers.view.build', [
|
|
|
|
'server' => $server,
|
|
|
|
'assigned' => $allocations->where('server_id', $server->id)->sortBy('port')->sortBy('ip'),
|
|
|
|
'unassigned' => $allocations->where('server_id', null)->sortBy('port')->sortBy('ip'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the server startup management page.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function startup(Request $request, Server $server): View
|
2019-11-24 20:50:16 +00:00
|
|
|
{
|
2022-10-24 00:15:11 +00:00
|
|
|
$nests = Nest::with('eggs.variables')->get();
|
2020-08-26 02:11:25 +00:00
|
|
|
$variables = $this->environmentService->handle($server);
|
2019-11-24 20:50:16 +00:00
|
|
|
|
|
|
|
$this->plainInject([
|
|
|
|
'server' => $server,
|
2020-08-26 02:11:25 +00:00
|
|
|
'server_variables' => $variables,
|
2019-11-24 20:50:16 +00:00
|
|
|
'nests' => $nests->map(function (Nest $item) {
|
|
|
|
return array_merge($item->toArray(), [
|
|
|
|
'eggs' => $item->eggs->keyBy('id')->toArray(),
|
|
|
|
]);
|
|
|
|
})->keyBy('id'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $this->view->make('admin.servers.view.startup', compact('server', 'nests'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-14 16:59:20 +00:00
|
|
|
* Returns all the databases that exist for the server.
|
2019-11-24 20:50:16 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function database(Request $request, Server $server): View
|
2019-11-24 20:50:16 +00:00
|
|
|
{
|
|
|
|
return $this->view->make('admin.servers.view.database', [
|
|
|
|
'hosts' => $this->databaseHostRepository->all(),
|
|
|
|
'server' => $server,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-05-21 19:19:59 +00:00
|
|
|
/**
|
2022-10-14 16:59:20 +00:00
|
|
|
* Returns all the mounts that exist for the server.
|
2020-05-21 19:19:59 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function mounts(Request $request, Server $server): View
|
2020-05-21 19:19:59 +00:00
|
|
|
{
|
2020-05-21 20:23:12 +00:00
|
|
|
$server->load('mounts');
|
|
|
|
|
2020-05-21 19:19:59 +00:00
|
|
|
return $this->view->make('admin.servers.view.mounts', [
|
|
|
|
'mounts' => $this->mountRepository->getMountListForServer($server),
|
|
|
|
'server' => $server,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-11-24 20:50:16 +00:00
|
|
|
/**
|
|
|
|
* Returns the base server management page, or an exception if the server
|
|
|
|
* is in a state that cannot be recovered from.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function manage(Request $request, Server $server): View
|
2019-11-24 20:50:16 +00:00
|
|
|
{
|
2021-01-17 23:51:56 +00:00
|
|
|
if ($server->status === Server::STATUS_INSTALL_FAILED) {
|
2021-01-26 03:20:51 +00:00
|
|
|
throw new DisplayException('This server is in a failed install state and cannot be recovered. Please delete and re-create the server.');
|
2019-11-24 20:50:16 +00:00
|
|
|
}
|
|
|
|
|
2020-04-04 03:45:37 +00:00
|
|
|
// Check if the panel doesn't have at least 2 nodes configured.
|
|
|
|
$nodes = $this->nodeRepository->all();
|
|
|
|
$canTransfer = false;
|
|
|
|
if (count($nodes) >= 2) {
|
|
|
|
$canTransfer = true;
|
|
|
|
}
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
JavaScript::put([
|
2020-04-04 03:45:37 +00:00
|
|
|
'nodeData' => $this->nodeRepository->getNodesForServerCreation(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $this->view->make('admin.servers.view.manage', [
|
|
|
|
'server' => $server,
|
|
|
|
'locations' => $this->locationRepository->all(),
|
|
|
|
'canTransfer' => $canTransfer,
|
|
|
|
]);
|
2019-11-24 20:50:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the server deletion page.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function delete(Request $request, Server $server): View
|
2019-11-24 20:50:16 +00:00
|
|
|
{
|
|
|
|
return $this->view->make('admin.servers.view.delete', compact('server'));
|
|
|
|
}
|
|
|
|
}
|