2016-01-18 06:24:33 +00:00
|
|
|
<?php
|
2016-01-20 00:10:39 +00:00
|
|
|
/**
|
2016-01-20 21:05:16 +00:00
|
|
|
* Pterodactyl - Panel
|
2017-01-24 22:57:08 +00:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
2016-01-20 00:10:39 +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-01-20 00:10:39 +00:00
|
|
|
*/
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-01-18 06:24:33 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Server;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2017-09-04 23:12:13 +00:00
|
|
|
use Pterodactyl\Models\Permission;
|
2017-09-05 00:07:00 +00:00
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
|
|
|
use Illuminate\Contracts\Session\Session;
|
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-09-04 23:12:13 +00:00
|
|
|
use Pterodactyl\Services\Subusers\SubuserUpdateService;
|
|
|
|
use Pterodactyl\Traits\Controllers\JavascriptInjection;
|
2017-09-05 00:07:00 +00:00
|
|
|
use Pterodactyl\Services\Subusers\SubuserCreationService;
|
|
|
|
use Pterodactyl\Services\Subusers\SubuserDeletionService;
|
|
|
|
use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;
|
2016-01-18 06:24:33 +00:00
|
|
|
|
|
|
|
class SubuserController extends Controller
|
|
|
|
{
|
2017-09-04 23:12:13 +00:00
|
|
|
use JavascriptInjection;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Prologue\Alerts\AlertsMessageBag
|
|
|
|
*/
|
|
|
|
protected $alert;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\SubuserRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Session\Session
|
|
|
|
*/
|
|
|
|
protected $session;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Subusers\SubuserCreationService
|
|
|
|
*/
|
|
|
|
protected $subuserCreationService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Subusers\SubuserDeletionService
|
|
|
|
*/
|
|
|
|
protected $subuserDeletionService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Subusers\SubuserUpdateService
|
|
|
|
*/
|
|
|
|
protected $subuserUpdateService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SubuserController constructor.
|
|
|
|
*
|
|
|
|
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
|
|
|
* @param \Illuminate\Contracts\Session\Session $session
|
|
|
|
* @param \Pterodactyl\Services\Subusers\SubuserCreationService $subuserCreationService
|
|
|
|
* @param \Pterodactyl\Services\Subusers\SubuserDeletionService $subuserDeletionService
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\SubuserRepositoryInterface $repository
|
|
|
|
* @param \Pterodactyl\Services\Subusers\SubuserUpdateService $subuserUpdateService
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
AlertsMessageBag $alert,
|
|
|
|
Session $session,
|
|
|
|
SubuserCreationService $subuserCreationService,
|
|
|
|
SubuserDeletionService $subuserDeletionService,
|
|
|
|
SubuserRepositoryInterface $repository,
|
|
|
|
SubuserUpdateService $subuserUpdateService
|
|
|
|
) {
|
|
|
|
$this->alert = $alert;
|
|
|
|
$this->repository = $repository;
|
|
|
|
$this->session = $session;
|
|
|
|
$this->subuserCreationService = $subuserCreationService;
|
|
|
|
$this->subuserDeletionService = $subuserDeletionService;
|
|
|
|
$this->subuserUpdateService = $subuserUpdateService;
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:24:33 +00:00
|
|
|
/**
|
2017-03-19 23:36:50 +00:00
|
|
|
* Displays the subuser overview index.
|
2016-01-18 06:24:33 +00:00
|
|
|
*
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\View\View
|
2017-09-04 23:12:13 +00:00
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2016-01-18 06:24:33 +00:00
|
|
|
*/
|
2017-09-04 23:12:13 +00:00
|
|
|
public function index()
|
2016-01-18 06:24:33 +00:00
|
|
|
{
|
2017-09-04 23:12:13 +00:00
|
|
|
$server = $this->session->get('server_data.model');
|
2016-01-18 06:24:33 +00:00
|
|
|
$this->authorize('list-subusers', $server);
|
2017-01-21 18:49:14 +00:00
|
|
|
|
2017-09-04 23:12:13 +00:00
|
|
|
$this->injectJavascript();
|
2016-01-18 06:24:33 +00:00
|
|
|
|
|
|
|
return view('server.users.index', [
|
2017-09-04 23:12:13 +00:00
|
|
|
'subusers' => $this->repository->findWhere([['server_id', '=', $server->id]]),
|
2016-01-18 06:24:33 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Displays the a single subuser overview.
|
|
|
|
*
|
2017-09-04 23:12:13 +00:00
|
|
|
* @param string $uuid
|
|
|
|
* @param int $id
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\View\View
|
2017-09-04 23:12:13 +00:00
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2017-09-04 23:12:13 +00:00
|
|
|
public function view($uuid, $id)
|
2016-01-18 06:24:33 +00:00
|
|
|
{
|
2017-09-04 23:12:13 +00:00
|
|
|
$server = $this->session->get('server_data.model');
|
2016-01-18 06:24:33 +00:00
|
|
|
$this->authorize('view-subuser', $server);
|
|
|
|
|
2017-09-04 23:12:13 +00:00
|
|
|
$subuser = $this->repository->getWithPermissions($id);
|
|
|
|
$this->injectJavascript();
|
2017-02-03 00:41:38 +00:00
|
|
|
|
2016-01-18 06:24:33 +00:00
|
|
|
return view('server.users.view', [
|
|
|
|
'subuser' => $subuser,
|
2017-09-04 23:12:13 +00:00
|
|
|
'permlist' => Permission::getPermissions(),
|
2017-02-10 00:38:54 +00:00
|
|
|
'permissions' => $subuser->permissions->mapWithKeys(function ($item, $key) {
|
|
|
|
return [$item->permission => true];
|
|
|
|
}),
|
2016-01-18 06:24:33 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Handles editing a subuser.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param string $uuid
|
|
|
|
* @param int $id
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-09-04 23:12:13 +00:00
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2017-04-09 23:13:22 +00:00
|
|
|
public function update(Request $request, $uuid, $id)
|
2016-01-18 06:24:33 +00:00
|
|
|
{
|
2017-09-04 23:12:13 +00:00
|
|
|
$server = $this->session->get('server_data.model');
|
2016-01-19 00:57:10 +00:00
|
|
|
$this->authorize('edit-subuser', $server);
|
|
|
|
|
2017-09-04 23:12:13 +00:00
|
|
|
$this->subuserUpdateService->handle($id, $request->input('permissions', []));
|
|
|
|
$this->alert->success(trans('server.users.user_updated'))->flash();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-09-04 23:12:13 +00:00
|
|
|
return redirect()->route('server.subusers.view', ['uuid' => $uuid, 'id' => $id]);
|
2016-01-19 00:57:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Display new subuser creation page.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
2017-09-04 23:12:13 +00:00
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2017-09-04 23:12:13 +00:00
|
|
|
public function create()
|
2016-01-19 00:57:10 +00:00
|
|
|
{
|
2017-09-04 23:12:13 +00:00
|
|
|
$server = $this->session->get('server_data.model');
|
2016-01-19 00:57:10 +00:00
|
|
|
$this->authorize('create-subuser', $server);
|
|
|
|
|
2017-09-04 23:12:13 +00:00
|
|
|
$this->injectJavascript();
|
|
|
|
|
|
|
|
return view('server.users.new', ['permissions' => Permission::getPermissions()]);
|
2016-01-19 00:57:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Handles creating a new subuser.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param string $uuid
|
2017-03-19 23:36:50 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2017-09-04 23:12:13 +00:00
|
|
|
*
|
|
|
|
* @throws \Exception
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Subuser\ServerSubuserExistsException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Subuser\UserIsServerOwnerException
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2017-04-09 23:13:22 +00:00
|
|
|
public function store(Request $request, $uuid)
|
2016-01-19 00:57:10 +00:00
|
|
|
{
|
2017-09-04 23:12:13 +00:00
|
|
|
$server = $this->session->get('server_data.model');
|
2016-01-19 00:57:10 +00:00
|
|
|
$this->authorize('create-subuser', $server);
|
|
|
|
|
2017-09-04 23:12:13 +00:00
|
|
|
$subuser = $this->subuserCreationService->handle($server, $request->input('email'), $request->input('permissions', []));
|
|
|
|
$this->alert->success(trans('server.users.user_assigned'))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('server.subusers.view', [
|
|
|
|
'uuid' => $uuid,
|
|
|
|
'id' => $subuser->id,
|
|
|
|
]);
|
2016-01-19 00:57:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Handles deleting a subuser.
|
|
|
|
*
|
2017-09-04 23:12:13 +00:00
|
|
|
* @param string $uuid
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-03-19 23:36:50 +00:00
|
|
|
*/
|
2017-09-04 23:12:13 +00:00
|
|
|
public function delete($uuid, $id)
|
2016-01-19 00:57:10 +00:00
|
|
|
{
|
2017-09-04 23:12:13 +00:00
|
|
|
$server = $this->session->get('server_data.model');
|
2016-01-19 00:57:10 +00:00
|
|
|
$this->authorize('delete-subuser', $server);
|
|
|
|
|
2017-09-04 23:12:13 +00:00
|
|
|
$this->subuserDeletionService->handle($id);
|
|
|
|
|
|
|
|
return response('', 204);
|
2016-01-18 06:24:33 +00:00
|
|
|
}
|
|
|
|
}
|