Skip to content

Commit f4985d4

Browse files
authored
Merge pull request pterodactyl#678 from Pterodactyl/feature/service-export-import
Overhaul service system and add ability to export/import them.
2 parents b3fdf64 + 5e712f0 commit f4985d4

File tree

177 files changed

+4883
-5735
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+4883
-5735
lines changed

.env.example

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,4 @@ QUEUE_HIGH=high
3232
QUEUE_STANDARD=standard
3333
QUEUE_LOW=low
3434

35-
SQS_KEY=aws-public
36-
SQS_SECRET=aws-secret
37-
SQS_QUEUE_PREFIX=aws-queue-prefix
35+
SERVICE_AUTHOR=undefined@unknown-author.com

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ before_install:
1515
before_script:
1616
- cp .env.travis .env
1717
- composer install --no-interaction --prefer-dist --no-suggest --verbose
18-
- php artisan migrate --seed -v
18+
- php artisan migrate -v
1919
script:
2020
- vendor/bin/phpunit --coverage-clover coverage.xml
2121
notifications:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1212
* New CLI command to disabled 2-Factor Authentication on an account if necessary.
1313
* Ability to delete users and locations via the CLI.
1414
* You can now require 2FA for all users, admins only, or at will using a simple configuration in the Admin CP.
15+
* Added ability to export and import service options and their associated settings and environment variables via the Admin CP.
1516

1617
### Changed
1718
* Theme colors and login pages updated to give a more unique feel to the project.

app/Console/Commands/Environment/AppSettingsCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace Pterodactyl\Console\Commands\Environment;
1111

12-
use Ramsey\Uuid\Uuid;
1312
use Illuminate\Console\Command;
1413
use Illuminate\Contracts\Console\Kernel;
1514
use Pterodactyl\Traits\Commands\EnvironmentWriterTrait;
@@ -38,6 +37,7 @@ class AppSettingsCommand extends Command
3837
* @var string
3938
*/
4039
protected $signature = 'p:environment:setup
40+
{--author= : The email that services created on this instance should be linked to.}
4141
{--url= : The URL that this Panel is running on.}
4242
{--timezone= : The timezone to use for Panel times.}
4343
{--cache= : The cache driver backend to use.}
@@ -72,9 +72,10 @@ public function __construct(ConfigRepository $config, Kernel $command)
7272
*/
7373
public function handle()
7474
{
75-
if (is_null($this->config->get('pterodactyl.service.author'))) {
76-
$this->variables['SERVICE_AUTHOR'] = Uuid::uuid4()->toString();
77-
}
75+
$this->output->comment(trans('command/messages.environment.app.author_help'));
76+
$this->variables['SERVICE_AUTHOR'] = $this->option('author') ?? $this->ask(
77+
trans('command/messages.environment.app.author'), $this->config->get('pterodactyl.service.author', 'undefined@unknown-author.com')
78+
);
7879

7980
$this->output->comment(trans('command/messages.environment.app.app_url_help'));
8081
$this->variables['APP_URL'] = $this->option('url') ?? $this->ask(

app/Console/Commands/Server/RebuildServerCommand.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212
use Webmozart\Assert\Assert;
1313
use Illuminate\Console\Command;
1414
use GuzzleHttp\Exception\RequestException;
15-
use Pterodactyl\Services\Servers\EnvironmentService;
1615
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
16+
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
1717
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
1818

1919
class RebuildServerCommand extends Command
2020
{
21+
/**
22+
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
23+
*/
24+
protected $configurationStructureService;
25+
2126
/**
2227
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
2328
*/
@@ -28,11 +33,6 @@ class RebuildServerCommand extends Command
2833
*/
2934
protected $description = 'Rebuild a single server, all servers on a node, or all servers on the panel.';
3035

31-
/**
32-
* @var \Pterodactyl\Services\Servers\EnvironmentService
33-
*/
34-
protected $environmentService;
35-
3636
/**
3737
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
3838
*/
@@ -49,18 +49,18 @@ class RebuildServerCommand extends Command
4949
* RebuildServerCommand constructor.
5050
*
5151
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonRepository
52-
* @param \Pterodactyl\Services\Servers\EnvironmentService $environmentService
52+
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
5353
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
5454
*/
5555
public function __construct(
5656
DaemonServerRepositoryInterface $daemonRepository,
57-
EnvironmentService $environmentService,
57+
ServerConfigurationStructureService $configurationStructureService,
5858
ServerRepositoryInterface $repository
5959
) {
6060
parent::__construct();
6161

62+
$this->configurationStructureService = $configurationStructureService;
6263
$this->daemonRepository = $daemonRepository;
63-
$this->environmentService = $environmentService;
6464
$this->repository = $repository;
6565
}
6666

@@ -74,19 +74,7 @@ public function handle()
7474

7575
$servers->each(function ($server) use ($bar) {
7676
$bar->clear();
77-
$json = [
78-
'build' => [
79-
'image' => $server->image,
80-
'env|overwrite' => $this->environmentService->process($server),
81-
],
82-
'service' => [
83-
'type' => $server->option->service->folder,
84-
'option' => $server->option->tag,
85-
'pack' => object_get($server, 'pack.uuid'),
86-
'skip_scripts' => $server->skip_scripts,
87-
],
88-
'rebuild' => true,
89-
];
77+
$json = array_merge($this->configurationStructureService->handle($server), ['rebuild' => true]);
9078

9179
try {
9280
$this->daemonRepository->setNode($server->node_id)->setAccessServer($server->uuid)->update($json);

app/Contracts/Repository/Daemon/ServerRepositoryInterface.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@
99

1010
namespace Pterodactyl\Contracts\Repository\Daemon;
1111

12+
use Psr\Http\Message\ResponseInterface;
13+
1214
interface ServerRepositoryInterface extends BaseRepositoryInterface
1315
{
1416
/**
1517
* Create a new server on the daemon for the panel.
1618
*
17-
* @param int $id
19+
* @param array $structure
1820
* @param array $overrides
19-
* @param bool $start
2021
* @return \Psr\Http\Message\ResponseInterface
22+
*
23+
* @throws \GuzzleHttp\Exception\RequestException
2124
*/
22-
public function create($id, array $overrides = [], $start = false);
25+
public function create(array $structure, array $overrides = []): ResponseInterface;
2326

2427
/**
2528
* Update server details on the daemon.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* This software is licensed under the terms of the MIT license.
7+
* https://opensource.org/licenses/MIT
8+
*/
9+
10+
namespace Pterodactyl\Contracts\Repository;
11+
12+
use Pterodactyl\Models\Egg;
13+
use Illuminate\Database\Eloquent\Collection;
14+
15+
interface EggRepositoryInterface extends RepositoryInterface
16+
{
17+
/**
18+
* Return an egg with the variables relation attached.
19+
*
20+
* @param int $id
21+
* @return \Pterodactyl\Models\Egg
22+
*
23+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
24+
*/
25+
public function getWithVariables(int $id): Egg;
26+
27+
/**
28+
* Return all eggs and their relations to be used in the daemon API.
29+
*
30+
* @return \Illuminate\Database\Eloquent\Collection
31+
*/
32+
public function getAllWithCopyAttributes(): Collection;
33+
34+
/**
35+
* Return an egg with the scriptFrom and configFrom relations loaded onto the model.
36+
*
37+
* @param int|string $value
38+
* @param string $column
39+
* @return \Pterodactyl\Models\Egg
40+
*/
41+
public function getWithCopyAttributes($value, string $column = 'id'): Egg;
42+
43+
/**
44+
* Return all of the data needed to export a service.
45+
*
46+
* @param int $id
47+
* @return \Pterodactyl\Models\Egg
48+
*
49+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
50+
*/
51+
public function getWithExportAttributes(int $id): Egg;
52+
53+
/**
54+
* Confirm a copy script belongs to the same nest as the item trying to use it.
55+
*
56+
* @param int $copyFromId
57+
* @param int $service
58+
* @return bool
59+
*/
60+
public function isCopiableScript(int $copyFromId, int $service): bool;
61+
}

app/Contracts/Repository/OptionVariableRepositoryInterface.php renamed to app/Contracts/Repository/EggVariableRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
namespace Pterodactyl\Contracts\Repository;
1111

12-
interface OptionVariableRepositoryInterface extends RepositoryInterface
12+
interface EggVariableRepositoryInterface extends RepositoryInterface
1313
{
1414
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* This software is licensed under the terms of the MIT license.
7+
* https://opensource.org/licenses/MIT
8+
*/
9+
10+
namespace Pterodactyl\Contracts\Repository;
11+
12+
use Pterodactyl\Models\Nest;
13+
14+
interface NestRepositoryInterface extends RepositoryInterface
15+
{
16+
/**
17+
* Return a nest or all nests with their associated eggs, variables, and packs.
18+
*
19+
* @param int $id
20+
* @return \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Nest
21+
*
22+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
23+
*/
24+
public function getWithEggs(int $id = null);
25+
26+
/**
27+
* Return a nest or all nests and the count of eggs, packs, and servers for that nest.
28+
*
29+
* @param int|null $id
30+
* @return \Pterodactyl\Models\Nest|\Illuminate\Database\Eloquent\Collection
31+
*
32+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
33+
*/
34+
public function getWithCounts(int $id = null);
35+
36+
/**
37+
* Return a nest along with its associated eggs and the servers relation on those eggs.
38+
*
39+
* @param int $id
40+
* @return \Pterodactyl\Models\Nest
41+
*
42+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
43+
*/
44+
public function getWithEggServers(int $id): Nest;
45+
}

app/Contracts/Repository/PackRepositoryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
interface PackRepositoryInterface extends RepositoryInterface, SearchableInterface
1515
{
1616
/**
17-
* Return a paginated listing of packs with their associated option and server count.
17+
* Return a paginated listing of packs with their associated egg and server count.
1818
*
1919
* @param int $paginate
2020
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
2121
*/
22-
public function paginateWithOptionAndServerCount($paginate = 50);
22+
public function paginateWithEggAndServerCount($paginate = 50);
2323

2424
/**
2525
* Return a pack with the associated server models attached to it.

0 commit comments

Comments
 (0)