2016-01-05 04:59:45 +00:00
|
|
|
<?php
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-01-05 04:59:45 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Admin;
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\View\View;
|
2016-12-07 22:46:38 +00:00
|
|
|
use Illuminate\Http\Request;
|
2017-08-05 22:26:30 +00:00
|
|
|
use Pterodactyl\Models\Node;
|
2018-01-11 05:19:03 +00:00
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use Pterodactyl\Models\Allocation;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2017-08-05 22:26:30 +00:00
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\View\Factory as ViewFactory;
|
2016-01-05 04:59:45 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-08-27 20:10:51 +00:00
|
|
|
use Pterodactyl\Services\Nodes\NodeUpdateService;
|
2017-08-31 02:14:20 +00:00
|
|
|
use Illuminate\Cache\Repository as CacheRepository;
|
2017-08-27 20:10:51 +00:00
|
|
|
use Pterodactyl\Services\Nodes\NodeCreationService;
|
|
|
|
use Pterodactyl\Services\Nodes\NodeDeletionService;
|
2017-08-06 02:10:32 +00:00
|
|
|
use Pterodactyl\Services\Allocations\AssignmentService;
|
2017-09-11 05:27:43 +00:00
|
|
|
use Pterodactyl\Services\Helpers\SoftwareVersionService;
|
2017-08-06 02:10:32 +00:00
|
|
|
use Pterodactyl\Http\Requests\Admin\Node\NodeFormRequest;
|
2017-08-05 22:26:30 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
2019-03-02 23:58:56 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
2017-08-06 02:10:32 +00:00
|
|
|
use Pterodactyl\Http\Requests\Admin\Node\AllocationFormRequest;
|
2018-01-11 05:19:03 +00:00
|
|
|
use Pterodactyl\Services\Allocations\AllocationDeletionService;
|
2017-08-05 22:26:30 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
2017-08-06 02:10:32 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
|
|
|
use Pterodactyl\Http\Requests\Admin\Node\AllocationAliasFormRequest;
|
2016-01-05 04:59:45 +00:00
|
|
|
|
|
|
|
class NodesController extends Controller
|
|
|
|
{
|
2017-08-06 02:10:32 +00:00
|
|
|
/**
|
|
|
|
* NodesController constructor.
|
|
|
|
*/
|
2017-08-05 22:20:07 +00:00
|
|
|
public function __construct(
|
2022-10-14 16:59:20 +00:00
|
|
|
protected AlertsMessageBag $alert,
|
|
|
|
protected AllocationDeletionService $allocationDeletionService,
|
|
|
|
protected AllocationRepositoryInterface $allocationRepository,
|
|
|
|
protected AssignmentService $assignmentService,
|
|
|
|
protected CacheRepository $cache,
|
|
|
|
protected NodeCreationService $creationService,
|
|
|
|
protected NodeDeletionService $deletionService,
|
|
|
|
protected LocationRepositoryInterface $locationRepository,
|
|
|
|
protected NodeRepositoryInterface $repository,
|
|
|
|
protected ServerRepositoryInterface $serverRepository,
|
|
|
|
protected NodeUpdateService $updateService,
|
|
|
|
protected SoftwareVersionService $versionService,
|
|
|
|
protected ViewFactory $view
|
2017-08-05 22:20:07 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2017-03-04 04:37:41 +00:00
|
|
|
/**
|
|
|
|
* Displays create new node page.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function create(): View|RedirectResponse
|
2016-01-05 04:59:45 +00:00
|
|
|
{
|
2017-08-05 22:20:07 +00:00
|
|
|
$locations = $this->locationRepository->all();
|
|
|
|
if (count($locations) < 1) {
|
2017-08-09 02:21:10 +00:00
|
|
|
$this->alert->warning(trans('admin/node.notices.location_required'))->flash();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-09-30 20:05:39 +00:00
|
|
|
return redirect()->route('admin.locations');
|
|
|
|
}
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
return $this->view->make('admin.nodes.new', ['locations' => $locations]);
|
2016-01-05 04:59:45 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 04:37:41 +00:00
|
|
|
/**
|
|
|
|
* Post controller to create a new node on the system.
|
|
|
|
*
|
2017-08-05 22:20:07 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-03-04 04:37:41 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function store(NodeFormRequest $request): RedirectResponse
|
2016-01-05 04:59:45 +00:00
|
|
|
{
|
2017-08-05 22:20:07 +00:00
|
|
|
$node = $this->creationService->handle($request->normalize());
|
2017-08-09 02:21:10 +00:00
|
|
|
$this->alert->info(trans('admin/node.notices.node_created'))->flash();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-08-05 22:20:07 +00:00
|
|
|
return redirect()->route('admin.nodes.view.allocation', $node->id);
|
2016-01-05 04:59:45 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 04:14:23 +00:00
|
|
|
/**
|
|
|
|
* Updates settings for a node.
|
|
|
|
*
|
2017-08-05 22:20:07 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-09-30 17:40:07 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-04 04:14:23 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function updateSettings(NodeFormRequest $request, Node $node): RedirectResponse
|
2016-01-05 23:31:25 +00:00
|
|
|
{
|
2018-12-02 21:38:59 +00:00
|
|
|
$this->updateService->handle($node, $request->normalize(), $request->input('reset_secret') === 'on');
|
2017-08-09 02:21:10 +00:00
|
|
|
$this->alert->success(trans('admin/node.notices.node_updated'))->flash();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-08-05 22:20:07 +00:00
|
|
|
return redirect()->route('admin.nodes.view.settings', $node->id)->withInput();
|
2016-01-05 23:31:25 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 22:30:39 +00:00
|
|
|
/**
|
|
|
|
* Removes a single allocation from a node.
|
|
|
|
*
|
2018-01-11 05:19:03 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
|
2017-03-03 22:30:39 +00:00
|
|
|
*/
|
2018-02-03 18:22:10 +00:00
|
|
|
public function allocationRemoveSingle(int $node, Allocation $allocation): Response
|
2016-01-09 01:01:18 +00:00
|
|
|
{
|
2018-01-11 05:19:03 +00:00
|
|
|
$this->allocationDeletionService->handle($allocation);
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-01-09 01:01:18 +00:00
|
|
|
return response('', 204);
|
|
|
|
}
|
|
|
|
|
2018-09-19 04:43:18 +00:00
|
|
|
/**
|
|
|
|
* Removes multiple individual allocations from a node.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
|
|
|
|
*/
|
|
|
|
public function allocationRemoveMultiple(Request $request, int $node): Response
|
|
|
|
{
|
|
|
|
$allocations = $request->input('allocations');
|
|
|
|
foreach ($allocations as $rawAllocation) {
|
|
|
|
$allocation = new Allocation();
|
|
|
|
$allocation->id = $rawAllocation['id'];
|
|
|
|
$this->allocationRemoveSingle($node, $allocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response('', 204);
|
|
|
|
}
|
|
|
|
|
2017-03-03 22:30:39 +00:00
|
|
|
/**
|
|
|
|
* Remove all allocations for a specific IP at once on a node.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function allocationRemoveBlock(Request $request, int $node): RedirectResponse
|
2016-09-30 01:34:20 +00:00
|
|
|
{
|
2017-08-09 02:21:10 +00:00
|
|
|
$this->allocationRepository->deleteWhere([
|
|
|
|
['node_id', '=', $node],
|
|
|
|
['server_id', '=', null],
|
|
|
|
['ip', '=', $request->input('ip')],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->alert->success(trans('admin/node.notices.unallocated_deleted', ['ip' => $request->input('ip')]))
|
|
|
|
->flash();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-03-03 22:30:39 +00:00
|
|
|
return redirect()->route('admin.nodes.view.allocation', $node);
|
2016-09-30 01:34:20 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 22:30:39 +00:00
|
|
|
/**
|
|
|
|
* Sets an alias for a specific allocation on a node.
|
|
|
|
*
|
2017-08-06 02:10:32 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-08-21 00:23:50 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-03 22:30:39 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function allocationSetAlias(AllocationAliasFormRequest $request): \Symfony\Component\HttpFoundation\Response
|
2016-09-30 01:34:20 +00:00
|
|
|
{
|
2017-08-06 02:10:32 +00:00
|
|
|
$this->allocationRepository->update($request->input('allocation_id'), [
|
|
|
|
'ip_alias' => (empty($request->input('alias'))) ? null : $request->input('alias'),
|
|
|
|
]);
|
2016-09-30 01:34:20 +00:00
|
|
|
|
2017-08-06 02:10:32 +00:00
|
|
|
return response('', 204);
|
2016-09-30 01:34:20 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 22:30:39 +00:00
|
|
|
/**
|
|
|
|
* Creates new allocations on a node.
|
|
|
|
*
|
2018-03-10 19:10:40 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Allocation\CidrOutOfRangeException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Allocation\InvalidPortMappingException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Allocation\PortOutOfRangeException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Allocation\TooManyPortsInRangeException
|
2017-03-03 22:30:39 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function createAllocation(AllocationFormRequest $request, Node $node): RedirectResponse
|
2016-01-10 05:38:16 +00:00
|
|
|
{
|
2017-08-06 02:10:32 +00:00
|
|
|
$this->assignmentService->handle($node, $request->normalize());
|
2017-08-09 02:21:10 +00:00
|
|
|
$this->alert->success(trans('admin/node.notices.allocations_added'))->flash();
|
2016-09-30 21:12:36 +00:00
|
|
|
|
2017-08-06 02:10:32 +00:00
|
|
|
return redirect()->route('admin.nodes.view.allocation', $node->id);
|
2017-03-03 22:30:39 +00:00
|
|
|
}
|
2016-01-10 05:38:16 +00:00
|
|
|
|
2017-03-04 04:14:23 +00:00
|
|
|
/**
|
|
|
|
* Deletes a node from the system.
|
|
|
|
*
|
2017-08-05 22:20:07 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
2017-03-04 04:14:23 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function delete(int|Node $node): RedirectResponse
|
2017-03-03 22:30:39 +00:00
|
|
|
{
|
2017-08-05 22:20:07 +00:00
|
|
|
$this->deletionService->handle($node);
|
2017-08-09 02:21:10 +00:00
|
|
|
$this->alert->success(trans('admin/node.notices.node_deleted'))->flash();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-08-05 22:20:07 +00:00
|
|
|
return redirect()->route('admin.nodes');
|
2016-01-10 21:59:19 +00:00
|
|
|
}
|
2016-01-05 04:59:45 +00:00
|
|
|
}
|