Skip to content

Commit bab28db

Browse files
committed
Initial implementation of new task mgmt system 👮
1 parent f157c06 commit bab28db

File tree

31 files changed

+1531
-128
lines changed

31 files changed

+1531
-128
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ DB_PASSWORD=secret
1616
CACHE_DRIVER=file
1717
SESSION_DRIVER=database
1818

19+
HASHIDS_SALT=
20+
HASHIDS_LENGTH=8
21+
1922
MAIL_DRIVER=smtp
2023
MAIL_HOST=mailtrap.io
2124
MAIL_PORT=2525

.env.travis

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ CACHE_DRIVER=array
1414
SESSION_DRIVER=array
1515
MAIL_DRIVER=array
1616
QUEUE_DRIVER=sync
17+
18+
HASHIDS_SALT=test123
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Contracts\Extensions;
26+
27+
use Hashids\HashidsInterface as VendorHashidsInterface;
28+
29+
interface HashidsInterface extends VendorHashidsInterface
30+
{
31+
/**
32+
* Decode an encoded hashid and return the first result.
33+
*
34+
* @param string $encoded
35+
* @param null $default
36+
* @return mixed
37+
*
38+
* @throws \InvalidArgumentException
39+
*/
40+
public function decodeFirst($encoded, $default = null);
41+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Contracts\Repository;
26+
27+
interface TaskRepositoryInterface extends RepositoryInterface
28+
{
29+
/**
30+
* Return the parent tasks and the count of children attached to that task.
31+
*
32+
* @param int $server
33+
* @return mixed
34+
*/
35+
public function getParentTasksWithChainCount($server);
36+
37+
/**
38+
* Return a single task for a given server including all of the chained tasks.
39+
*
40+
* @param int $task
41+
* @param int $server
42+
* @return mixed
43+
*
44+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
45+
*/
46+
public function getTaskForServer($task, $server);
47+
}

app/Extensions/DynamicDatabaseConnection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public function __construct(
7373
* @param string $connection
7474
* @param \Pterodactyl\Models\DatabaseHost|int $host
7575
* @param string $database
76+
*
77+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
7678
*/
7779
public function set($connection, $host, $database = 'mysql')
7880
{

app/Extensions/Hashids.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Extensions;
26+
27+
use Hashids\Hashids as VendorHashids;
28+
use Pterodactyl\Contracts\Extensions\HashidsInterface;
29+
30+
class Hashids extends VendorHashids implements HashidsInterface
31+
{
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public function decodeFirst($encoded, $default = null)
36+
{
37+
$result = $this->decode($encoded);
38+
if (! is_array($result)) {
39+
return $default;
40+
}
41+
42+
return array_first($result, null, $default);
43+
}
44+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Http\Controllers\Server\Tasks;
26+
27+
use Illuminate\Contracts\Session\Session;
28+
use Pterodactyl\Http\Controllers\Controller;
29+
use Pterodactyl\Services\Tasks\TaskCreationService;
30+
use Pterodactyl\Contracts\Extensions\HashidsInterface;
31+
use Pterodactyl\Traits\Controllers\JavascriptInjection;
32+
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
33+
use Pterodactyl\Http\Requests\Server\TaskCreationFormRequest;
34+
35+
class TaskManagementController extends Controller
36+
{
37+
use JavascriptInjection;
38+
39+
/**
40+
* @var \Pterodactyl\Services\Tasks\TaskCreationService
41+
*/
42+
protected $creationService;
43+
44+
/**
45+
* @var \Pterodactyl\Contracts\Extensions\HashidsInterface
46+
*/
47+
protected $hashids;
48+
49+
/**
50+
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface
51+
*/
52+
protected $repository;
53+
54+
/**
55+
* @var \Illuminate\Contracts\Session\Session
56+
*/
57+
protected $session;
58+
59+
/**
60+
* TaskManagementController constructor.
61+
*
62+
* @param \Pterodactyl\Contracts\Extensions\HashidsInterface $hashids
63+
* @param \Illuminate\Contracts\Session\Session $session
64+
* @param \Pterodactyl\Services\Tasks\TaskCreationService $creationService
65+
* @param \Pterodactyl\Contracts\Repository\TaskRepositoryInterface $repository
66+
*/
67+
public function __construct(
68+
HashidsInterface $hashids,
69+
Session $session,
70+
TaskCreationService $creationService,
71+
TaskRepositoryInterface $repository
72+
) {
73+
$this->creationService = $creationService;
74+
$this->hashids = $hashids;
75+
$this->repository = $repository;
76+
$this->session = $session;
77+
}
78+
79+
/**
80+
* Display the task page listing.
81+
*
82+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
83+
*
84+
* @throws \Illuminate\Auth\Access\AuthorizationException
85+
*/
86+
public function index()
87+
{
88+
$server = $this->session->get('server_data.model');
89+
$this->authorize('list-tasks', $server);
90+
$this->injectJavascript();
91+
92+
return view('server.tasks.index', [
93+
'tasks' => $this->repository->getParentTasksWithChainCount($server->id),
94+
'actions' => [
95+
'command' => trans('server.tasks.actions.command'),
96+
'power' => trans('server.tasks.actions.power'),
97+
],
98+
]);
99+
}
100+
101+
/**
102+
* Display the task creation page.
103+
*
104+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
105+
*
106+
* @throws \Illuminate\Auth\Access\AuthorizationException
107+
*/
108+
public function create()
109+
{
110+
$server = $this->session->get('server_data.model');
111+
$this->authorize('create-task', $server);
112+
$this->injectJavascript();
113+
114+
return view('server.tasks.new');
115+
}
116+
117+
/**
118+
* @param \Pterodactyl\Http\Requests\Server\TaskCreationFormRequest $request
119+
*
120+
* @return \Illuminate\Http\RedirectResponse
121+
*
122+
* @throws \Exception
123+
* @throws \Illuminate\Auth\Access\AuthorizationException
124+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
125+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
126+
*/
127+
public function store(TaskCreationFormRequest $request)
128+
{
129+
$server = $this->session->get('server_data.model');
130+
$this->authorize('create-task', $server);
131+
132+
$task = $this->creationService->handle($server, $request->normalize(), $request->getChainedTasks());
133+
134+
return redirect()->route('server.tasks.view', [
135+
'server' => $server->uuidShort,
136+
'task' => $task->id,
137+
]);
138+
}
139+
140+
/**
141+
* Return a view to modify task settings.
142+
*
143+
* @param string $uuid
144+
* @param string $task
145+
* @return \Illuminate\View\View
146+
*
147+
* @throws \Illuminate\Auth\Access\AuthorizationException
148+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
149+
*/
150+
public function view($uuid, $task)
151+
{
152+
$server = $this->session->get('server_data.model');
153+
$this->authorize('edit-task', $server);
154+
$task = $this->repository->getTaskForServer($this->hashids->decodeFirst($task, 0), $server->id);
155+
156+
$this->injectJavascript([
157+
'chained' => $task->chained->map(function ($chain) {
158+
return collect($chain->toArray())->only('action', 'chain_delay', 'data')->all();
159+
}),
160+
]);
161+
162+
return view('server.tasks.view', ['task' => $task]);
163+
}
164+
165+
public function update(TaskCreationFormRequest $request, $uuid, $task)
166+
{
167+
$server = $this->session->get('server_data.model');
168+
$this->authorize('edit-task', $server);
169+
$task = $this->repository->getTaskForServer($this->hashids->decodeFirst($task, 0), $server->id);
170+
}
171+
}

0 commit comments

Comments
 (0)