Skip to content

Commit 05f0f48

Browse files
committed
Add seeders for services, cleanup environment setters
1 parent 41a16d5 commit 05f0f48

File tree

9 files changed

+487
-10
lines changed

9 files changed

+487
-10
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2016 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+
namespace Pterodactyl\Console\Commands;
25+
26+
use DB;
27+
28+
use Illuminate\Console\Command;
29+
30+
class ClearServices extends Command
31+
{
32+
/**
33+
* The name and signature of the console command.
34+
*
35+
* @var string
36+
*/
37+
protected $signature = 'pterodactyl:clear-services';
38+
39+
/**
40+
* The console command description.
41+
*
42+
* @var string
43+
*/
44+
protected $description = 'Removes all services from the database for installing updated ones as needed.';
45+
46+
/**
47+
* Create a new command instance.
48+
*
49+
* @return void
50+
*/
51+
public function __construct()
52+
{
53+
parent::__construct();
54+
}
55+
56+
/**
57+
* Execute the console command.
58+
*
59+
* @return mixed
60+
*/
61+
public function handle()
62+
{
63+
64+
if (!$this->confirm('This is a destructive operation, are you sure you wish to continue?')) {
65+
$this->error('Canceling.');
66+
exit();
67+
}
68+
69+
$bar = $this->output->createProgressBar(3);
70+
DB::beginTransaction();
71+
72+
try {
73+
DB::table('services')->truncate();
74+
$bar->advance();
75+
76+
DB::table('service_options')->truncate();
77+
$bar->advance();
78+
79+
DB::table('service_variables')->truncate();
80+
$bar->advance();
81+
82+
DB::commit();
83+
} catch (\Exception $ex) {
84+
DB::rollBack();
85+
}
86+
87+
$this->info("\n");
88+
$this->info('All services have been removed. Consider running `php artisan pterodactyl:service-defaults` at this time.');
89+
}
90+
}

app/Console/Commands/UpdateEnvironment.php

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
namespace Pterodactyl\Console\Commands;
2525

26+
use Uuid;
2627
use Illuminate\Console\Command;
2728

2829
class UpdateEnvironment extends Command
@@ -68,23 +69,48 @@ public function handle()
6869

6970
$envContents = file_get_contents($file);
7071

72+
if (!env('SERVICE_AUTHOR', false)) {
73+
$this->info('No service author set, setting one now.');
74+
$variables['SERVICE_AUTHOR'] = env('SERVICE_AUTHOR', (string) Uuid::generate(4));
75+
}
76+
7177
// DB info
72-
$variables['DB_HOST'] = $this->anticipate('Database Host (usually \'localhost\' or \'127.0.0.1\')', [ 'localhost', '127.0.0.1', env('DB_HOST') ]);
73-
$variables['DB_PORT'] = $this->anticipate('Database Port', [ 3306, env('DB_PORT') ]);
74-
$variables['DB_DATABASE'] = $this->anticipate('Database Name', [ 'pterodactyl', 'homestead', ENV('DB_DATABASE') ]);
75-
$variables['DB_USERNAME'] = $this->anticipate('Database Username', [ env('DB_USERNAME') ]);
76-
$variables['DB_PASSWORD'] = $this->secret('Database User\'s Password');
78+
if($this->confirm('Update database host? [' . env('DB_HOST') . ']')) {
79+
$variables['DB_HOST'] = $this->anticipate('Database Host (usually \'localhost\' or \'127.0.0.1\')', [ 'localhost', '127.0.0.1', env('DB_HOST') ]);
80+
}
81+
82+
if($this->confirm('Update database port? [' . env('DB_PORT') . ']')) {
83+
$variables['DB_PORT'] = $this->anticipate('Database Port', [ 3306, env('DB_PORT') ]);
84+
}
85+
86+
if($this->confirm('Update database name? [' . env('DB_DATABASE') . ']')) {
87+
$variables['DB_DATABASE'] = $this->anticipate('Database Name', [ 'pterodactyl', 'homestead', ENV('DB_DATABASE') ]);
88+
}
89+
90+
if($this->confirm('Update database username? [' . env('DB_USERNAME') . ']')) {
91+
$variables['DB_USERNAME'] = $this->anticipate('Database Username', [ env('DB_USERNAME') ]);
92+
}
93+
94+
if($this->confirm('Update database password?')) {
95+
$variables['DB_PASSWORD'] = $this->secret('Database User\'s Password');
96+
}
7797

7898
// Other Basic Information
79-
$variables['APP_URL'] = $this->anticipate('Enter your current panel URL (include http or https).', [ env('APP_URL', 'http://localhost') ]);
80-
$this->line('The timezone should match one of the supported timezones according to http://php.net/manual/en/timezones.php');
81-
$variables['APP_TIMEZONE'] = $this->anticipate('Enter the timezone for this panel to run with', \DateTimeZone::listIdentifiers(\DateTimeZone::ALL));
99+
if($this->confirm('Update panel URL? [' . env('APP_URL') . ']')) {
100+
$variables['APP_URL'] = $this->anticipate('Enter your current panel URL (include http or https).', [ env('APP_URL', 'http://localhost') ]);
101+
}
82102

83-
$bar = $this->output->createProgressBar(count($variables) + 1);
103+
if($this->confirm('Update panel timezone? [' . env('APP_TIMEZONE') . ']')) {
104+
$this->line('The timezone should match one of the supported timezones according to http://php.net/manual/en/timezones.php');
105+
$variables['APP_TIMEZONE'] = $this->anticipate('Enter the timezone for this panel to run with', \DateTimeZone::listIdentifiers(\DateTimeZone::ALL));
106+
}
107+
108+
$bar = $this->output->createProgressBar(count($variables));
84109

85110
$this->line('Writing new environment configuration to file.');
86111
foreach ($variables as $key => $value) {
87112
$newValue = $key . '=' . $value;
113+
88114
if (preg_match_all('/^' . $key . '=(.*)$/m', $envContents) < 1) {
89115
$envContents = $envContents . "\n" . $newValue;
90116
} else {

app/Console/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Kernel extends ConsoleKernel
1818
\Pterodactyl\Console\Commands\ShowVersion::class,
1919
\Pterodactyl\Console\Commands\UpdateEnvironment::class,
2020
\Pterodactyl\Console\Commands\RunTasks::class,
21+
\Pterodactyl\Console\Commands\ClearServices::class,
2122
];
2223

2324
/**

app/Repositories/ServiceRepository/Service.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
use DB;
2727
use Validator;
28+
use Uuid;
2829

2930
use Pterodactyl\Models;
3031
use Pterodactyl\Services\UuidService;
@@ -58,6 +59,8 @@ public function create(array $data)
5859
throw new DisplayException('A service using that configuration file already exists on the system.');
5960
}
6061

62+
$data['author'] = env('SERVICE_AUTHOR', (string) Uuid::generate(4));
63+
6164
$service = new Models\Service;
6265
$service->fill($data);
6366
$service->save();

composer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"php artisan key:generate",
7777
"php artisan pterodactyl:env",
7878
"php artisan migrate",
79+
"php artisan db:seed"
7980
"php artisan pterodactyl:user"
8081
],
8182
"setup": [
@@ -84,7 +85,13 @@
8485
"php artisan key:generate",
8586
"php artisan pterodactyl:env",
8687
"php artisan migrate",
88+
"php artisan db:seed"
8789
"php artisan pterodactyl:user"
90+
],
91+
"upgrade": [
92+
"composer update --ansi --no-dev",
93+
"php artisan pterodactyl:env",
94+
"php artisan migrate"
8895
]
8996
},
9097
"config": {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddUniqueIdentifier extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('services', function (Blueprint $table) {
17+
$table->char('author', 36)->after('id');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('services', function (Blueprint $table) {
29+
$table->dropColumn('author');
30+
});
31+
}
32+
}

database/seeds/DatabaseSeeder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public function run()
1414
{
1515
Model::unguard();
1616

17-
// $this->call(UserTableSeeder::class);
17+
$this->call(MinecraftServiceTableSeeder::class);
18+
$this->call(SourceServiceTableSeeder::class);
1819

1920
Model::reguard();
2021
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2016 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+
use Illuminate\Database\Seeder;
25+
26+
use Pterodactyl\Models;
27+
28+
class MinecraftServiceTableSeeder extends Seeder
29+
{
30+
/**
31+
* The core service ID.
32+
*
33+
* @var Models\Service
34+
*/
35+
protected $service;
36+
37+
/**
38+
* Stores all of the option objects
39+
*
40+
* @var array
41+
*/
42+
protected $option = [];
43+
44+
/**
45+
* Run the database seeds.
46+
*
47+
* @return void
48+
*/
49+
public function run()
50+
{
51+
$this->addCoreService();
52+
$this->addCoreOptions();
53+
$this->addVariables();
54+
}
55+
56+
private function addCoreService()
57+
{
58+
$this->service = Models\Service::create([
59+
'author' => 'ptrdctyl-v040-11e6-8b77-86f30ca893d3',
60+
'name' => 'Minecraft',
61+
'file' => 'minecraft',
62+
'executable' => 'java',
63+
'startup' => '-Xms128M -Xmx{{SERVER_MEMORY}}M -jar {{SERVER_JARFILE}}'
64+
]);
65+
}
66+
67+
private function addCoreOptions()
68+
{
69+
$this->option['vanilla'] = Models\ServiceOptions::create([
70+
'parent_service' => $this->service->id,
71+
'name' => 'Vanilla Minecraft',
72+
'description' => 'Minecraft is a game about placing blocks and going on adventures. Explore randomly generated worlds and build amazing things from the simplest of homes to the grandest of castles. Play in Creative Mode with unlimited resources or mine deep in Survival Mode, crafting weapons and armor to fend off dangerous mobs. Do all this alone or with friends.',
73+
'tag' => 'vanilla',
74+
'docker_image' => 'quay.io/pterodactyl/minecraft',
75+
'executable' => null,
76+
'startup' => null
77+
]);
78+
}
79+
80+
private function addVariables()
81+
{
82+
Models\ServiceVariables::create([
83+
'option_id' => $this->option['vanilla']->id,
84+
'name' => 'Server Jar File',
85+
'description' => 'The name of the server jarfile to run the server with.',
86+
'env_variable' => 'SERVER_JARFILE',
87+
'default_value' => 'server.jar',
88+
'user_viewable' => 1,
89+
'user_editable' => 1,
90+
'required' => 1,
91+
'regex' => '/^([\w\d._-]+)(\.jar)$/'
92+
]);
93+
94+
Models\ServiceVariables::create([
95+
'option_id' => $this->option['vanilla']->id,
96+
'name' => 'Server Jar File',
97+
'description' => 'The version of Minecraft Vanilla to install. Use "latest" to install the latest version..',
98+
'env_variable' => 'VANILLA_VERSION',
99+
'default_value' => 'latest',
100+
'user_viewable' => 1,
101+
'user_editable' => 1,
102+
'required' => 1,
103+
'regex' => '/^(latest|[a-zA-Z0-9_\.-]{5,6})$/'
104+
]);
105+
}
106+
}

0 commit comments

Comments
 (0)