2019-11-16 21:08:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin\Servers;
|
|
|
|
|
|
|
|
use JavaScript;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\View\View;
|
2022-11-28 16:56:03 +00:00
|
|
|
use Pterodactyl\Models\Nest;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Pterodactyl\Models\Node;
|
|
|
|
use Pterodactyl\Models\Location;
|
2019-11-16 21:08:46 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Pterodactyl\Repositories\Eloquent\NestRepository;
|
|
|
|
use Pterodactyl\Repositories\Eloquent\NodeRepository;
|
|
|
|
use Pterodactyl\Http\Requests\Admin\ServerFormRequest;
|
|
|
|
use Pterodactyl\Services\Servers\ServerCreationService;
|
|
|
|
|
|
|
|
class CreateServerController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* CreateServerController constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(
|
2022-10-14 16:59:20 +00:00
|
|
|
private AlertsMessageBag $alert,
|
|
|
|
private NestRepository $nestRepository,
|
|
|
|
private NodeRepository $nodeRepository,
|
2022-11-28 16:56:03 +00:00
|
|
|
private ServerCreationService $creationService
|
2019-11-16 21:08:46 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the create server page.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function index(): View|RedirectResponse
|
2019-11-16 21:08:46 +00:00
|
|
|
{
|
2022-10-14 16:59:20 +00:00
|
|
|
$nodes = Node::all();
|
2019-11-16 21:08:46 +00:00
|
|
|
if (count($nodes) < 1) {
|
|
|
|
$this->alert->warning(trans('admin/server.alerts.node_required'))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.nodes');
|
|
|
|
}
|
|
|
|
|
|
|
|
$nests = $this->nestRepository->getWithEggs();
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
JavaScript::put([
|
2019-11-16 21:08:46 +00:00
|
|
|
'nodeData' => $this->nodeRepository->getNodesForServerCreation(),
|
2022-11-28 16:56:03 +00:00
|
|
|
'nests' => $nests->map(function (Nest $item) {
|
2019-11-16 21:08:46 +00:00
|
|
|
return array_merge($item->toArray(), [
|
|
|
|
'eggs' => $item->eggs->keyBy('id')->toArray(),
|
|
|
|
]);
|
|
|
|
})->keyBy('id'),
|
|
|
|
]);
|
|
|
|
|
2022-11-28 16:56:03 +00:00
|
|
|
return view('admin.servers.new', [
|
2022-10-14 16:59:20 +00:00
|
|
|
'locations' => Location::all(),
|
2019-11-16 21:08:46 +00:00
|
|
|
'nests' => $nests,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new server on the remote system.
|
|
|
|
*
|
|
|
|
* @throws \Illuminate\Validation\ValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableAllocationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException
|
2019-12-17 05:02:30 +00:00
|
|
|
* @throws \Throwable
|
2019-11-16 21:08:46 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function store(ServerFormRequest $request): RedirectResponse
|
2019-11-16 21:08:46 +00:00
|
|
|
{
|
2020-12-13 17:53:17 +00:00
|
|
|
$data = $request->except(['_token']);
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!empty($data['custom_image'])) {
|
2020-12-13 17:53:17 +00:00
|
|
|
$data['image'] = $data['custom_image'];
|
|
|
|
unset($data['custom_image']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$server = $this->creationService->handle($data);
|
2019-11-16 21:08:46 +00:00
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
$this->alert->success(trans('admin/server.alerts.server_created'))->flash();
|
2019-11-16 21:08:46 +00:00
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
return new RedirectResponse('/admin/servers/view/' . $server->id);
|
2019-11-16 21:08:46 +00:00
|
|
|
}
|
|
|
|
}
|