2015-12-06 13:58:49 -05:00
|
|
|
<?php
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2015-12-06 13:58:49 -05:00
|
|
|
namespace Pterodactyl\Http\Controllers\Admin;
|
|
|
|
|
2020-05-21 15:16:16 -06:00
|
|
|
use Illuminate\Http\Request;
|
2017-10-26 23:49:54 -05:00
|
|
|
use Pterodactyl\Models\User;
|
2022-10-14 10:59:20 -06:00
|
|
|
use Illuminate\Http\Response;
|
2020-10-03 12:42:27 -07:00
|
|
|
use Pterodactyl\Models\Mount;
|
2017-08-05 17:26:30 -05:00
|
|
|
use Pterodactyl\Models\Server;
|
2022-06-05 13:28:46 -04:00
|
|
|
use Pterodactyl\Models\Database;
|
2020-10-12 11:11:40 -06:00
|
|
|
use Pterodactyl\Models\MountServer;
|
2022-10-14 10:59:20 -06:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2017-08-05 17:26:30 -05:00
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2016-12-07 22:46:38 +00:00
|
|
|
use Pterodactyl\Exceptions\DisplayException;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2020-06-23 20:24:09 -07:00
|
|
|
use Illuminate\Validation\ValidationException;
|
2017-08-30 21:14:20 -05:00
|
|
|
use Pterodactyl\Services\Servers\SuspensionService;
|
2020-05-21 13:19:59 -06:00
|
|
|
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
2017-08-27 15:10:51 -05:00
|
|
|
use Pterodactyl\Services\Servers\ServerDeletionService;
|
|
|
|
use Pterodactyl\Services\Servers\ReinstallServerService;
|
2020-06-23 20:24:09 -07:00
|
|
|
use Pterodactyl\Exceptions\Model\DataValidationException;
|
2020-05-21 15:16:16 -06:00
|
|
|
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
2017-08-05 17:26:30 -05:00
|
|
|
use Pterodactyl\Services\Servers\BuildModificationService;
|
2017-10-18 22:32:19 -05:00
|
|
|
use Pterodactyl\Services\Databases\DatabasePasswordService;
|
2017-08-05 17:26:30 -05:00
|
|
|
use Pterodactyl\Services\Servers\DetailsModificationService;
|
|
|
|
use Pterodactyl\Services\Servers\StartupModificationService;
|
2017-10-06 23:57:53 -05:00
|
|
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
2017-08-05 17:26:30 -05:00
|
|
|
use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository;
|
2017-10-18 22:32:19 -05:00
|
|
|
use Pterodactyl\Services\Databases\DatabaseManagementService;
|
2017-08-05 17:26:30 -05:00
|
|
|
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|
|
|
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
|
|
|
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
2020-05-21 15:16:16 -06:00
|
|
|
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
2018-05-20 17:11:52 -07:00
|
|
|
use Pterodactyl\Http\Requests\Admin\Servers\Databases\StoreServerDatabaseRequest;
|
2015-12-06 13:58:49 -05:00
|
|
|
|
|
|
|
class ServersController extends Controller
|
|
|
|
{
|
2017-07-23 14:51:18 -05:00
|
|
|
/**
|
|
|
|
* ServersController constructor.
|
|
|
|
*/
|
2017-07-15 11:52:34 -05:00
|
|
|
public function __construct(
|
2022-10-14 10:59:20 -06:00
|
|
|
protected AlertsMessageBag $alert,
|
|
|
|
protected AllocationRepositoryInterface $allocationRepository,
|
|
|
|
protected BuildModificationService $buildModificationService,
|
|
|
|
protected ConfigRepository $config,
|
|
|
|
protected DaemonServerRepository $daemonServerRepository,
|
|
|
|
protected DatabaseManagementService $databaseManagementService,
|
|
|
|
protected DatabasePasswordService $databasePasswordService,
|
|
|
|
protected DatabaseRepositoryInterface $databaseRepository,
|
|
|
|
protected DatabaseHostRepository $databaseHostRepository,
|
|
|
|
protected ServerDeletionService $deletionService,
|
|
|
|
protected DetailsModificationService $detailsModificationService,
|
|
|
|
protected ReinstallServerService $reinstallService,
|
|
|
|
protected ServerRepositoryInterface $repository,
|
|
|
|
protected MountRepository $mountRepository,
|
|
|
|
protected NestRepositoryInterface $nestRepository,
|
|
|
|
protected ServerConfigurationStructureService $serverConfigurationStructureService,
|
|
|
|
protected StartupModificationService $startupModificationService,
|
|
|
|
protected SuspensionService $suspensionService
|
2017-07-15 11:52:34 -05:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2017-03-04 19:03:49 -05:00
|
|
|
/**
|
|
|
|
* Update the details for a server.
|
|
|
|
*
|
2017-07-22 20:15:01 -05:00
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-09-30 12:06:16 -05:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-04 19:03:49 -05:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function setDetails(Request $request, Server $server): RedirectResponse
|
2017-03-04 19:03:49 -05:00
|
|
|
{
|
2018-01-20 16:03:23 -06:00
|
|
|
$this->detailsModificationService->handle($server, $request->only([
|
2018-02-24 11:57:12 -06:00
|
|
|
'owner_id', 'external_id', 'name', 'description',
|
2017-07-22 20:15:01 -05:00
|
|
|
]));
|
2016-09-17 20:14:36 -04:00
|
|
|
|
2017-07-22 20:15:01 -05:00
|
|
|
$this->alert->success(trans('admin/server.alerts.details_updated'))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.servers.view.details', $server->id);
|
2016-09-17 20:14:36 -04:00
|
|
|
}
|
|
|
|
|
2017-03-04 19:03:49 -05:00
|
|
|
/**
|
2022-10-14 10:59:20 -06:00
|
|
|
* Toggles the installation status for a server.
|
2017-07-23 14:51:18 -05:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-08-26 19:58:24 -05:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-04 19:03:49 -05:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function toggleInstall(Server $server): RedirectResponse
|
2017-03-04 19:03:49 -05:00
|
|
|
{
|
2021-01-17 15:51:56 -08:00
|
|
|
if ($server->status === Server::STATUS_INSTALL_FAILED) {
|
2017-07-23 14:51:18 -05:00
|
|
|
throw new DisplayException(trans('admin/server.exceptions.marked_as_failed'));
|
2017-03-04 19:03:49 -05:00
|
|
|
}
|
|
|
|
|
2017-07-23 14:51:18 -05:00
|
|
|
$this->repository->update($server->id, [
|
2021-01-17 15:51:56 -08:00
|
|
|
'status' => $server->isInstalled() ? Server::STATUS_INSTALLING : null,
|
2018-01-30 22:40:21 -06:00
|
|
|
], true, true);
|
2017-07-23 14:51:18 -05:00
|
|
|
|
|
|
|
$this->alert->success(trans('admin/server.alerts.install_toggled'))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.servers.view.manage', $server->id);
|
2016-01-02 18:04:18 -05:00
|
|
|
}
|
|
|
|
|
2017-04-20 18:52:43 -04:00
|
|
|
/**
|
2020-09-13 11:13:37 -07:00
|
|
|
* Reinstalls the server with the currently assigned service.
|
2017-04-20 18:52:43 -04:00
|
|
|
*
|
2017-07-23 14:51:18 -05:00
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-04-20 18:52:43 -04:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function reinstallServer(Server $server): RedirectResponse
|
2017-04-20 18:52:43 -04:00
|
|
|
{
|
2020-10-05 21:54:29 -07:00
|
|
|
$this->reinstallService->handle($server);
|
2017-07-23 14:51:18 -05:00
|
|
|
$this->alert->success(trans('admin/server.alerts.server_reinstalled'))->flash();
|
2017-04-20 18:52:43 -04:00
|
|
|
|
2017-07-23 15:09:25 -05:00
|
|
|
return redirect()->route('admin.servers.view.manage', $server->id);
|
2017-04-20 18:52:43 -04:00
|
|
|
}
|
|
|
|
|
2017-03-04 19:03:49 -05:00
|
|
|
/**
|
|
|
|
* Manage the suspension status for a server.
|
|
|
|
*
|
2017-07-23 14:51:18 -05:00
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-08-26 19:58:24 -05:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-04 19:03:49 -05:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function manageSuspension(Request $request, Server $server): RedirectResponse
|
2016-01-02 23:21:22 -05:00
|
|
|
{
|
2017-07-23 14:51:18 -05:00
|
|
|
$this->suspensionService->toggle($server, $request->input('action'));
|
|
|
|
$this->alert->success(trans('admin/server.alerts.suspension_toggled', [
|
|
|
|
'status' => $request->input('action') . 'ed',
|
|
|
|
]))->flash();
|
2017-03-04 19:03:49 -05:00
|
|
|
|
2017-07-23 14:51:18 -05:00
|
|
|
return redirect()->route('admin.servers.view.manage', $server->id);
|
2016-01-02 23:21:22 -05:00
|
|
|
}
|
|
|
|
|
2017-03-04 19:03:49 -05:00
|
|
|
/**
|
|
|
|
* Update the build configuration for a server.
|
|
|
|
*
|
2017-07-23 19:57:43 -05:00
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
2018-03-02 19:49:09 -06:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2020-06-23 20:24:09 -07:00
|
|
|
* @throws \Illuminate\Validation\ValidationException
|
2017-03-04 19:03:49 -05:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function updateBuild(Request $request, Server $server): RedirectResponse
|
2016-01-03 23:16:03 -05:00
|
|
|
{
|
2020-06-23 20:24:09 -07:00
|
|
|
try {
|
|
|
|
$this->buildModificationService->handle($server, $request->only([
|
|
|
|
'allocation_id', 'add_allocations', 'remove_allocations',
|
|
|
|
'memory', 'swap', 'io', 'cpu', 'threads', 'disk',
|
|
|
|
'database_limit', 'allocation_limit', 'backup_limit', 'oom_disabled',
|
|
|
|
]));
|
|
|
|
} catch (DataValidationException $exception) {
|
2022-06-26 16:31:48 -04:00
|
|
|
throw new ValidationException($exception->getValidator());
|
2020-06-23 20:24:09 -07:00
|
|
|
}
|
|
|
|
|
2017-07-23 19:57:43 -05:00
|
|
|
$this->alert->success(trans('admin/server.alerts.build_updated'))->flash();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-07-23 19:57:43 -05:00
|
|
|
return redirect()->route('admin.servers.view.build', $server->id);
|
2016-01-03 23:16:03 -05:00
|
|
|
}
|
|
|
|
|
2017-03-04 19:03:49 -05:00
|
|
|
/**
|
|
|
|
* Start the server deletion process.
|
|
|
|
*
|
2017-07-24 21:34:10 -05:00
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
2019-12-22 13:45:40 -08:00
|
|
|
* @throws \Throwable
|
2017-03-04 19:03:49 -05:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function delete(Request $request, Server $server): RedirectResponse
|
2016-01-04 16:09:22 -05:00
|
|
|
{
|
2017-12-17 13:07:38 -06:00
|
|
|
$this->deletionService->withForce($request->filled('force_delete'))->handle($server);
|
2017-07-24 21:34:10 -05:00
|
|
|
$this->alert->success(trans('admin/server.alerts.server_deleted'))->flash();
|
2017-03-04 19:03:49 -05:00
|
|
|
|
2017-07-24 21:34:10 -05:00
|
|
|
return redirect()->route('admin.servers');
|
2016-10-27 20:05:29 -04:00
|
|
|
}
|
2017-03-04 19:03:49 -05:00
|
|
|
|
2017-03-04 23:45:22 -05:00
|
|
|
/**
|
|
|
|
* Update the startup command as well as variables.
|
|
|
|
*
|
2018-05-13 12:19:35 -04:00
|
|
|
* @throws \Illuminate\Validation\ValidationException
|
2017-03-04 23:45:22 -05:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function saveStartup(Request $request, Server $server): RedirectResponse
|
2017-03-04 23:45:22 -05:00
|
|
|
{
|
2020-12-13 09:53:17 -08:00
|
|
|
$data = $request->except('_token');
|
|
|
|
if (!empty($data['custom_docker_image'])) {
|
|
|
|
$data['docker_image'] = $data['custom_docker_image'];
|
|
|
|
unset($data['custom_docker_image']);
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:05:04 -07:00
|
|
|
try {
|
|
|
|
$this->startupModificationService
|
|
|
|
->setUserLevel(User::USER_LEVEL_ADMIN)
|
2020-12-13 09:53:17 -08:00
|
|
|
->handle($server, $data);
|
2020-10-03 19:05:04 -07:00
|
|
|
} catch (DataValidationException $exception) {
|
2022-06-26 16:31:48 -04:00
|
|
|
throw new ValidationException($exception->getValidator());
|
2020-10-03 19:05:04 -07:00
|
|
|
}
|
|
|
|
|
2017-07-24 21:34:10 -05:00
|
|
|
$this->alert->success(trans('admin/server.alerts.startup_changed'))->flash();
|
2017-03-04 23:45:22 -05:00
|
|
|
|
2017-07-24 21:34:10 -05:00
|
|
|
return redirect()->route('admin.servers.view.startup', $server->id);
|
2017-03-04 23:45:22 -05:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:37:38 -05:00
|
|
|
/**
|
|
|
|
* Creates a new database assigned to a specific server.
|
2017-03-19 19:36:50 -04:00
|
|
|
*
|
2020-06-23 20:07:37 -07:00
|
|
|
* @throws \Throwable
|
2017-03-05 16:37:38 -05:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function newDatabase(StoreServerDatabaseRequest $request, Server $server): RedirectResponse
|
2017-03-05 16:37:38 -05:00
|
|
|
{
|
2017-07-24 21:34:10 -05:00
|
|
|
$this->databaseManagementService->create($server, [
|
2020-10-11 11:59:46 -07:00
|
|
|
'database' => DatabaseManagementService::generateUniqueDatabaseName($request->input('database'), $server->id),
|
2017-07-22 13:55:30 -05:00
|
|
|
'remote' => $request->input('remote'),
|
|
|
|
'database_host_id' => $request->input('database_host_id'),
|
2020-05-19 04:14:36 -04:00
|
|
|
'max_connections' => $request->input('max_connections'),
|
2017-07-22 13:55:30 -05:00
|
|
|
]);
|
2017-03-05 16:37:38 -05:00
|
|
|
|
2020-06-23 20:07:37 -07:00
|
|
|
return redirect()->route('admin.servers.view.database', $server->id)->withInput();
|
2017-03-05 16:37:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the database password for a specific database on this server.
|
2017-03-19 19:36:50 -04:00
|
|
|
*
|
2019-08-03 14:42:32 -07:00
|
|
|
* @throws \Throwable
|
2017-03-05 16:37:38 -05:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function resetDatabasePassword(Request $request, Server $server): Response
|
2017-03-05 16:37:38 -05:00
|
|
|
{
|
2022-10-14 10:59:20 -06:00
|
|
|
/** @var \Pterodactyl\Models\Database $database */
|
|
|
|
$database = $server->databases()->findOrFail($request->input('database'));
|
2017-03-05 16:37:38 -05:00
|
|
|
|
2019-08-03 14:42:32 -07:00
|
|
|
$this->databasePasswordService->handle($database);
|
2017-03-05 16:37:38 -05:00
|
|
|
|
2017-07-22 14:07:51 -05:00
|
|
|
return response('', 204);
|
2017-03-05 16:37:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a database from a server.
|
2017-03-19 19:36:50 -04:00
|
|
|
*
|
2017-07-22 14:07:51 -05:00
|
|
|
* @throws \Exception
|
2017-03-05 16:37:38 -05:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function deleteDatabase(Server $server, Database $database): Response
|
2017-03-05 16:37:38 -05:00
|
|
|
{
|
2020-10-08 21:08:55 -07:00
|
|
|
$this->databaseManagementService->delete($database);
|
2017-03-05 16:37:38 -05:00
|
|
|
|
2017-07-22 14:07:51 -05:00
|
|
|
return response('', 204);
|
2017-03-05 16:37:38 -05:00
|
|
|
}
|
2020-05-21 14:23:12 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a mount to a server.
|
|
|
|
*
|
2020-11-02 19:58:14 -08:00
|
|
|
* @throws \Throwable
|
2020-05-21 14:23:12 -06:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function addMount(Request $request, Server $server): RedirectResponse
|
2020-05-21 14:23:12 -06:00
|
|
|
{
|
2021-01-23 12:33:34 -08:00
|
|
|
$mountServer = (new MountServer())->forceFill([
|
2022-05-30 11:33:42 -04:00
|
|
|
'mount_id' => $request->input('mount_id'),
|
2020-11-02 19:58:14 -08:00
|
|
|
'server_id' => $server->id,
|
|
|
|
]);
|
2020-05-21 15:14:09 -06:00
|
|
|
|
2020-11-02 19:58:14 -08:00
|
|
|
$mountServer->saveOrFail();
|
2020-05-21 15:14:09 -06:00
|
|
|
|
2020-05-21 14:23:12 -06:00
|
|
|
$this->alert->success('Mount was added successfully.')->flash();
|
2020-05-21 14:27:23 -06:00
|
|
|
|
2020-05-21 14:23:12 -06:00
|
|
|
return redirect()->route('admin.servers.view.mounts', $server->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a mount from a server.
|
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function deleteMount(Server $server, Mount $mount): RedirectResponse
|
2020-05-21 14:23:12 -06:00
|
|
|
{
|
2020-10-12 11:11:40 -06:00
|
|
|
MountServer::where('mount_id', $mount->id)->where('server_id', $server->id)->delete();
|
2020-05-21 14:23:12 -06:00
|
|
|
|
|
|
|
$this->alert->success('Mount was removed successfully.')->flash();
|
2020-05-21 14:27:23 -06:00
|
|
|
|
2020-05-21 14:23:12 -06:00
|
|
|
return redirect()->route('admin.servers.view.mounts', $server->id);
|
|
|
|
}
|
2015-12-06 13:58:49 -05:00
|
|
|
}
|