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-03-16 23:35:29 +00:00
|
|
|
use Pterodactyl\Models\DatabaseHost;
|
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-07-15 16:52:34 +00:00
|
|
|
use Pterodactyl\Services\Database\DatabaseHostService;
|
2017-06-18 00:48:31 +00:00
|
|
|
use Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest;
|
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
|
|
|
|
*/
|
|
|
|
protected $alert;
|
|
|
|
|
|
|
|
/**
|
2017-08-09 04:24:55 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
|
2017-06-18 00:48:31 +00:00
|
|
|
*/
|
2017-08-09 04:24:55 +00:00
|
|
|
protected $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-08-09 04:24:55 +00:00
|
|
|
protected $repository;
|
2017-06-18 00:48:31 +00:00
|
|
|
|
|
|
|
/**
|
2017-07-15 16:52:34 +00:00
|
|
|
* @var \Pterodactyl\Services\Database\DatabaseHostService
|
2017-06-18 00:48:31 +00:00
|
|
|
*/
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DatabaseController constructor.
|
|
|
|
*
|
2017-08-09 04:24:55 +00:00
|
|
|
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface $repository
|
|
|
|
* @param \Pterodactyl\Services\Database\DatabaseHostService $service
|
|
|
|
* @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,
|
|
|
|
DatabaseHostService $service,
|
|
|
|
LocationRepositoryInterface $locationRepository
|
2017-06-18 00:48:31 +00:00
|
|
|
) {
|
|
|
|
$this->alert = $alert;
|
2017-08-09 04:24:55 +00:00
|
|
|
$this->repository = $repository;
|
2017-06-18 00:48:31 +00:00
|
|
|
$this->service = $service;
|
2017-08-09 04:24:55 +00:00
|
|
|
$this->locationRepository = $locationRepository;
|
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-06-18 00:48:31 +00:00
|
|
|
public function index()
|
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-08-16 04:16:00 +00:00
|
|
|
public function view($host)
|
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
|
|
|
*
|
|
|
|
* @throws \Throwable
|
2017-03-16 23:35:29 +00:00
|
|
|
*/
|
2017-06-18 00:48:31 +00:00
|
|
|
public function create(DatabaseHostFormRequest $request)
|
2016-02-15 02:43:20 +00:00
|
|
|
{
|
|
|
|
try {
|
2017-06-18 00:48:31 +00:00
|
|
|
$host = $this->service->create($request->normalize());
|
|
|
|
$this->alert->success('Successfully created a new database host on the system.')->flash();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-03-16 23:35:29 +00:00
|
|
|
return redirect()->route('admin.databases.view', $host->id);
|
|
|
|
} 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
|
|
|
|
|
|
|
return redirect()->route('admin.databases');
|
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
|
|
|
|
* @param \Pterodactyl\Models\DatabaseHost $host
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-06-18 00:48:31 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
2017-08-05 22:20:07 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-03-16 23:35:29 +00:00
|
|
|
*/
|
2017-06-18 00:48:31 +00:00
|
|
|
public function update(DatabaseHostFormRequest $request, DatabaseHost $host)
|
2016-02-15 02:43:20 +00:00
|
|
|
{
|
2017-06-18 00:48:31 +00:00
|
|
|
if ($request->input('action') === 'delete') {
|
|
|
|
return $this->delete($host);
|
|
|
|
}
|
2017-03-16 23:35:29 +00:00
|
|
|
|
2016-02-15 02:43:20 +00:00
|
|
|
try {
|
2017-06-18 00:48:31 +00:00
|
|
|
$host = $this->service->update($host->id, $request->normalize());
|
|
|
|
$this->alert->success('Database host was updated successfully.')->flash();
|
2017-03-16 23:35:29 +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-08-22 03:10:48 +00:00
|
|
|
* @param \Pterodactyl\Models\DatabaseHost $host
|
2017-06-18 00:48:31 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
*/
|
|
|
|
public function delete(DatabaseHost $host)
|
|
|
|
{
|
|
|
|
$this->service->delete($host->id);
|
|
|
|
$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
|
|
|
}
|