2016-02-13 05:18:32 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
2017-01-24 22:57:08 +00:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
2016-02-13 05:18:32 +00:00
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2016-02-13 05:18:32 +00:00
|
|
|
*/
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-02-13 05:18:32 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Admin;
|
|
|
|
|
2017-10-19 03:32:19 +00:00
|
|
|
use PDOException;
|
|
|
|
use Illuminate\View\View;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
2017-06-18 00:48:31 +00:00
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2016-02-13 05:18:32 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-10-19 03:32:19 +00:00
|
|
|
use Pterodactyl\Services\Databases\Hosts\HostUpdateService;
|
2017-06-18 00:48:31 +00:00
|
|
|
use Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest;
|
2017-10-19 03:32:19 +00:00
|
|
|
use Pterodactyl\Services\Databases\Hosts\HostCreationService;
|
|
|
|
use Pterodactyl\Services\Databases\Hosts\HostDeletionService;
|
2017-08-09 04:24:55 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
|
|
|
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
|
2016-02-13 05:18:32 +00:00
|
|
|
|
|
|
|
class DatabaseController extends Controller
|
|
|
|
{
|
2017-06-18 00:48:31 +00:00
|
|
|
/**
|
|
|
|
* @var \Prologue\Alerts\AlertsMessageBag
|
|
|
|
*/
|
2017-10-19 03:32:19 +00:00
|
|
|
private $alert;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Databases\Hosts\HostCreationService
|
|
|
|
*/
|
|
|
|
private $creationService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Databases\Hosts\HostDeletionService
|
|
|
|
*/
|
|
|
|
private $deletionService;
|
2017-06-18 00:48:31 +00:00
|
|
|
|
|
|
|
/**
|
2017-08-09 04:24:55 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
|
2017-06-18 00:48:31 +00:00
|
|
|
*/
|
2017-10-19 03:32:19 +00:00
|
|
|
private $locationRepository;
|
2017-06-18 00:48:31 +00:00
|
|
|
|
|
|
|
/**
|
2017-08-09 04:24:55 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface
|
2017-06-18 00:48:31 +00:00
|
|
|
*/
|
2017-10-19 03:32:19 +00:00
|
|
|
private $repository;
|
2017-06-18 00:48:31 +00:00
|
|
|
|
|
|
|
/**
|
2017-10-19 03:32:19 +00:00
|
|
|
* @var \Pterodactyl\Services\Databases\Hosts\HostUpdateService
|
2017-06-18 00:48:31 +00:00
|
|
|
*/
|
2017-10-19 03:32:19 +00:00
|
|
|
private $updateService;
|
2017-06-18 00:48:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DatabaseController constructor.
|
|
|
|
*
|
2017-08-09 04:24:55 +00:00
|
|
|
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface $repository
|
2017-10-19 03:32:19 +00:00
|
|
|
* @param \Pterodactyl\Services\Databases\Hosts\HostCreationService $creationService
|
|
|
|
* @param \Pterodactyl\Services\Databases\Hosts\HostDeletionService $deletionService
|
|
|
|
* @param \Pterodactyl\Services\Databases\Hosts\HostUpdateService $updateService
|
2017-08-09 04:24:55 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $locationRepository
|
2017-06-18 00:48:31 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
AlertsMessageBag $alert,
|
2017-08-09 04:24:55 +00:00
|
|
|
DatabaseHostRepositoryInterface $repository,
|
2017-10-19 03:32:19 +00:00
|
|
|
HostCreationService $creationService,
|
|
|
|
HostDeletionService $deletionService,
|
|
|
|
HostUpdateService $updateService,
|
2017-08-09 04:24:55 +00:00
|
|
|
LocationRepositoryInterface $locationRepository
|
2017-06-18 00:48:31 +00:00
|
|
|
) {
|
|
|
|
$this->alert = $alert;
|
2017-10-19 03:32:19 +00:00
|
|
|
$this->creationService = $creationService;
|
|
|
|
$this->deletionService = $deletionService;
|
2017-08-09 04:24:55 +00:00
|
|
|
$this->repository = $repository;
|
|
|
|
$this->locationRepository = $locationRepository;
|
2017-10-19 03:32:19 +00:00
|
|
|
$this->updateService = $updateService;
|
2017-06-18 00:48:31 +00:00
|
|
|
}
|
|
|
|
|
2016-02-13 05:18:32 +00:00
|
|
|
/**
|
2017-03-16 23:35:29 +00:00
|
|
|
* Display database host index.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
2016-02-13 05:18:32 +00:00
|
|
|
*/
|
2017-10-19 03:32:19 +00:00
|
|
|
public function index(): View
|
2016-02-13 05:18:32 +00:00
|
|
|
{
|
|
|
|
return view('admin.databases.index', [
|
2017-08-09 04:24:55 +00:00
|
|
|
'locations' => $this->locationRepository->getAllWithNodes(),
|
|
|
|
'hosts' => $this->repository->getWithViewDetails(),
|
2016-02-13 05:18:32 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-03-16 23:35:29 +00:00
|
|
|
/**
|
|
|
|
* Display database host to user.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param int $host
|
2017-03-16 23:35:29 +00:00
|
|
|
* @return \Illuminate\View\View
|
2017-08-16 04:16:00 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-16 23:35:29 +00:00
|
|
|
*/
|
2017-10-19 03:32:19 +00:00
|
|
|
public function view($host): View
|
2016-02-15 02:43:20 +00:00
|
|
|
{
|
2017-03-16 23:35:29 +00:00
|
|
|
return view('admin.databases.view', [
|
2017-08-09 04:24:55 +00:00
|
|
|
'locations' => $this->locationRepository->getAllWithNodes(),
|
2017-08-16 04:16:00 +00:00
|
|
|
'host' => $this->repository->getWithServers($host),
|
2016-02-15 02:43:20 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-03-16 23:35:29 +00:00
|
|
|
/**
|
2017-06-18 00:48:31 +00:00
|
|
|
* Handle request to create a new database host.
|
2017-03-16 23:35:29 +00:00
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest $request
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-06-18 00:48:31 +00:00
|
|
|
*
|
2017-10-19 03:32:19 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-16 23:35:29 +00:00
|
|
|
*/
|
2017-10-19 03:32:19 +00:00
|
|
|
public function create(DatabaseHostFormRequest $request): RedirectResponse
|
2016-02-15 02:43:20 +00:00
|
|
|
{
|
|
|
|
try {
|
2017-10-19 03:32:19 +00:00
|
|
|
$host = $this->creationService->handle($request->normalize());
|
|
|
|
} catch (PDOException $ex) {
|
2017-06-18 00:48:31 +00:00
|
|
|
$this->alert->danger($ex->getMessage())->flash();
|
2017-10-19 03:32:19 +00:00
|
|
|
|
|
|
|
return redirect()->route('admin.databases');
|
2016-02-15 02:43:20 +00:00
|
|
|
}
|
2017-03-16 23:35:29 +00:00
|
|
|
|
2017-10-19 03:32:19 +00:00
|
|
|
$this->alert->success('Successfully created a new database host on the system.')->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.databases.view', $host->id);
|
2016-02-15 02:43:20 +00:00
|
|
|
}
|
|
|
|
|
2017-03-16 23:35:29 +00:00
|
|
|
/**
|
2017-06-18 00:48:31 +00:00
|
|
|
* Handle updating database host.
|
2017-03-16 23:35:29 +00:00
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest $request
|
2017-10-19 03:32:19 +00:00
|
|
|
* @param int $host
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-06-18 00:48:31 +00:00
|
|
|
*
|
2017-08-05 22:20:07 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-10-19 03:32:19 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-16 23:35:29 +00:00
|
|
|
*/
|
2017-10-19 03:32:19 +00:00
|
|
|
public function update(DatabaseHostFormRequest $request, int $host): RedirectResponse
|
2016-02-15 02:43:20 +00:00
|
|
|
{
|
|
|
|
try {
|
2017-10-19 03:32:19 +00:00
|
|
|
$host = $this->updateService->handle($host, $request->normalize());
|
2017-06-18 00:48:31 +00:00
|
|
|
$this->alert->success('Database host was updated successfully.')->flash();
|
2017-10-19 03:32:19 +00:00
|
|
|
} catch (PDOException $ex) {
|
2017-06-18 00:48:31 +00:00
|
|
|
$this->alert->danger($ex->getMessage())->flash();
|
2016-02-15 02:43:20 +00:00
|
|
|
}
|
2017-03-16 23:35:29 +00:00
|
|
|
|
2017-06-18 00:48:31 +00:00
|
|
|
return redirect()->route('admin.databases.view', $host->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request to delete a database host.
|
|
|
|
*
|
2017-10-19 03:32:19 +00:00
|
|
|
* @param int $host
|
2017-06-18 00:48:31 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*
|
2017-10-19 03:32:19 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
2017-06-18 00:48:31 +00:00
|
|
|
*/
|
2017-10-19 03:32:19 +00:00
|
|
|
public function delete(int $host): RedirectResponse
|
2017-06-18 00:48:31 +00:00
|
|
|
{
|
2017-10-19 03:32:19 +00:00
|
|
|
$this->deletionService->handle($host);
|
2017-06-18 00:48:31 +00:00
|
|
|
$this->alert->success('The requested database host has been deleted from the system.')->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.databases');
|
2016-02-15 02:43:20 +00:00
|
|
|
}
|
2016-02-13 05:18:32 +00:00
|
|
|
}
|