Add seeders for services, cleanup environment setters

This commit is contained in:
Dane Everitt 2016-09-07 17:48:20 -04:00
parent 41a16d5fdc
commit 05f0f48caf
9 changed files with 487 additions and 10 deletions

View file

@ -0,0 +1,90 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Console\Commands;
use DB;
use Illuminate\Console\Command;
class ClearServices extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'pterodactyl:clear-services';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Removes all services from the database for installing updated ones as needed.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if (!$this->confirm('This is a destructive operation, are you sure you wish to continue?')) {
$this->error('Canceling.');
exit();
}
$bar = $this->output->createProgressBar(3);
DB::beginTransaction();
try {
DB::table('services')->truncate();
$bar->advance();
DB::table('service_options')->truncate();
$bar->advance();
DB::table('service_variables')->truncate();
$bar->advance();
DB::commit();
} catch (\Exception $ex) {
DB::rollBack();
}
$this->info("\n");
$this->info('All services have been removed. Consider running `php artisan pterodactyl:service-defaults` at this time.');
}
}

View file

@ -23,6 +23,7 @@
*/
namespace Pterodactyl\Console\Commands;
use Uuid;
use Illuminate\Console\Command;
class UpdateEnvironment extends Command
@ -68,23 +69,48 @@ class UpdateEnvironment extends Command
$envContents = file_get_contents($file);
if (!env('SERVICE_AUTHOR', false)) {
$this->info('No service author set, setting one now.');
$variables['SERVICE_AUTHOR'] = env('SERVICE_AUTHOR', (string) Uuid::generate(4));
}
// DB info
if($this->confirm('Update database host? [' . env('DB_HOST') . ']')) {
$variables['DB_HOST'] = $this->anticipate('Database Host (usually \'localhost\' or \'127.0.0.1\')', [ 'localhost', '127.0.0.1', env('DB_HOST') ]);
}
if($this->confirm('Update database port? [' . env('DB_PORT') . ']')) {
$variables['DB_PORT'] = $this->anticipate('Database Port', [ 3306, env('DB_PORT') ]);
}
if($this->confirm('Update database name? [' . env('DB_DATABASE') . ']')) {
$variables['DB_DATABASE'] = $this->anticipate('Database Name', [ 'pterodactyl', 'homestead', ENV('DB_DATABASE') ]);
}
if($this->confirm('Update database username? [' . env('DB_USERNAME') . ']')) {
$variables['DB_USERNAME'] = $this->anticipate('Database Username', [ env('DB_USERNAME') ]);
}
if($this->confirm('Update database password?')) {
$variables['DB_PASSWORD'] = $this->secret('Database User\'s Password');
}
// Other Basic Information
if($this->confirm('Update panel URL? [' . env('APP_URL') . ']')) {
$variables['APP_URL'] = $this->anticipate('Enter your current panel URL (include http or https).', [ env('APP_URL', 'http://localhost') ]);
}
if($this->confirm('Update panel timezone? [' . env('APP_TIMEZONE') . ']')) {
$this->line('The timezone should match one of the supported timezones according to http://php.net/manual/en/timezones.php');
$variables['APP_TIMEZONE'] = $this->anticipate('Enter the timezone for this panel to run with', \DateTimeZone::listIdentifiers(\DateTimeZone::ALL));
}
$bar = $this->output->createProgressBar(count($variables) + 1);
$bar = $this->output->createProgressBar(count($variables));
$this->line('Writing new environment configuration to file.');
foreach ($variables as $key => $value) {
$newValue = $key . '=' . $value;
if (preg_match_all('/^' . $key . '=(.*)$/m', $envContents) < 1) {
$envContents = $envContents . "\n" . $newValue;
} else {

View file

@ -18,6 +18,7 @@ class Kernel extends ConsoleKernel
\Pterodactyl\Console\Commands\ShowVersion::class,
\Pterodactyl\Console\Commands\UpdateEnvironment::class,
\Pterodactyl\Console\Commands\RunTasks::class,
\Pterodactyl\Console\Commands\ClearServices::class,
];
/**

View file

@ -25,6 +25,7 @@ namespace Pterodactyl\Repositories\ServiceRepository;
use DB;
use Validator;
use Uuid;
use Pterodactyl\Models;
use Pterodactyl\Services\UuidService;
@ -58,6 +59,8 @@ class Service
throw new DisplayException('A service using that configuration file already exists on the system.');
}
$data['author'] = env('SERVICE_AUTHOR', (string) Uuid::generate(4));
$service = new Models\Service;
$service->fill($data);
$service->save();

View file

@ -76,6 +76,7 @@
"php artisan key:generate",
"php artisan pterodactyl:env",
"php artisan migrate",
"php artisan db:seed"
"php artisan pterodactyl:user"
],
"setup": [
@ -84,7 +85,13 @@
"php artisan key:generate",
"php artisan pterodactyl:env",
"php artisan migrate",
"php artisan db:seed"
"php artisan pterodactyl:user"
],
"upgrade": [
"composer update --ansi --no-dev",
"php artisan pterodactyl:env",
"php artisan migrate"
]
},
"config": {

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddUniqueIdentifier extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('services', function (Blueprint $table) {
$table->char('author', 36)->after('id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('services', function (Blueprint $table) {
$table->dropColumn('author');
});
}
}

View file

@ -14,7 +14,8 @@ class DatabaseSeeder extends Seeder
{
Model::unguard();
// $this->call(UserTableSeeder::class);
$this->call(MinecraftServiceTableSeeder::class);
$this->call(SourceServiceTableSeeder::class);
Model::reguard();
}

View file

@ -0,0 +1,106 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
use Illuminate\Database\Seeder;
use Pterodactyl\Models;
class MinecraftServiceTableSeeder extends Seeder
{
/**
* The core service ID.
*
* @var Models\Service
*/
protected $service;
/**
* Stores all of the option objects
*
* @var array
*/
protected $option = [];
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->addCoreService();
$this->addCoreOptions();
$this->addVariables();
}
private function addCoreService()
{
$this->service = Models\Service::create([
'author' => 'ptrdctyl-v040-11e6-8b77-86f30ca893d3',
'name' => 'Minecraft',
'file' => 'minecraft',
'executable' => 'java',
'startup' => '-Xms128M -Xmx{{SERVER_MEMORY}}M -jar {{SERVER_JARFILE}}'
]);
}
private function addCoreOptions()
{
$this->option['vanilla'] = Models\ServiceOptions::create([
'parent_service' => $this->service->id,
'name' => 'Vanilla Minecraft',
'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.',
'tag' => 'vanilla',
'docker_image' => 'quay.io/pterodactyl/minecraft',
'executable' => null,
'startup' => null
]);
}
private function addVariables()
{
Models\ServiceVariables::create([
'option_id' => $this->option['vanilla']->id,
'name' => 'Server Jar File',
'description' => 'The name of the server jarfile to run the server with.',
'env_variable' => 'SERVER_JARFILE',
'default_value' => 'server.jar',
'user_viewable' => 1,
'user_editable' => 1,
'required' => 1,
'regex' => '/^([\w\d._-]+)(\.jar)$/'
]);
Models\ServiceVariables::create([
'option_id' => $this->option['vanilla']->id,
'name' => 'Server Jar File',
'description' => 'The version of Minecraft Vanilla to install. Use "latest" to install the latest version..',
'env_variable' => 'VANILLA_VERSION',
'default_value' => 'latest',
'user_viewable' => 1,
'user_editable' => 1,
'required' => 1,
'regex' => '/^(latest|[a-zA-Z0-9_\.-]{5,6})$/'
]);
}
}

View file

@ -0,0 +1,211 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
use Illuminate\Database\Seeder;
use Pterodactyl\Models;
class SourceServiceTableSeeder extends Seeder
{
/**
* The core service ID.
*
* @var Models\Service
*/
protected $service;
/**
* Stores all of the option objects
*
* @var array
*/
protected $option = [];
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->addCoreService();
$this->addCoreOptions();
$this->addVariables();
}
private function addCoreService()
{
$this->service = Models\Service::create([
'author' => 'ptrdctyl-v040-11e6-8b77-86f30ca893d3',
'name' => 'Source Engine',
'file' => 'srcds',
'executable' => './srcds_run',
'startup' => '-game {{SRCDS_GAME}} -console -port {{SERVER_PORT}} -strictportbind -norestart'
]);
}
private function addCoreOptions()
{
$this->option['insurgency'] = Models\ServiceOptions::create([
'parent_service' => $this->service->id,
'name' => 'Insurgency',
'description' => 'Take to the streets for intense close quarters combat, where a team\'s survival depends upon securing crucial strongholds and destroying enemy supply in this multiplayer and cooperative Source Engine based experience.',
'tag' => 'srcds',
'docker_image' => 'quay.io/pterodactyl/srcds',
'executable' => null,
'startup' => '-game {{SRCDS_GAME}} -console -port {{SERVER_PORT}} +map {{SRCDS_MAP}} -strictportbind -norestart'
]);
$this->option['tf2'] = Models\ServiceOptions::create([
'parent_service' => $this->service->id,
'name' => 'Insurgency',
'description' => 'Team Fortress 2 is a team-based first-person shooter multiplayer video game developed and published by Valve Corporation. It is the sequel to the 1996 mod Team Fortress for Quake and its 1999 remake.',
'tag' => 'srcds',
'docker_image' => 'quay.io/pterodactyl/srcds',
'executable' => null,
'startup' => '-game {{SRCDS_GAME}} -console -port {{SERVER_PORT}} +map {{SRCDS_MAP}} -strictportbind -norestart'
]);
$this->option['custom'] = Models\ServiceOptions::create([
'parent_service' => $this->service->id,
'name' => 'Custom Source Engine Game',
'description' => 'This option allows modifying the startup arguments and other details to run a custo SRCDS based game on the panel.',
'tag' => 'srcds',
'docker_image' => 'quay.io/pterodactyl/srcds',
'executable' => null,
'startup' => null
]);
}
private function addVariables()
{
$this->addInsurgencyVariables();
$this->addTF2Variables();
$this->addCustomVariables();
}
private function addInsurgencyVariables()
{
Models\ServiceVariables::create([
'option_id' => $this->option['insurgency']->id,
'name' => 'Game ID',
'description' => 'The ID corresponding to the game to download and run using SRCDS.',
'env_variable' => 'SRCDS_APPID',
'default_value' => '17705',
'user_viewable' => 1,
'user_editable' => 0,
'required' => 1,
'regex' => '/^(17705)$/'
]);
Models\ServiceVariables::create([
'option_id' => $this->option['insurgency']->id,
'name' => 'Game Name',
'description' => 'The name corresponding to the game to download and run using SRCDS.',
'env_variable' => 'SRCDS_GAME',
'default_value' => 'insurgency',
'user_viewable' => 1,
'user_editable' => 0,
'required' => 1,
'regex' => '/^(insurgency)$/'
]);
Models\ServiceVariables::create([
'option_id' => $this->option['insurgency']->id,
'name' => 'Default Map',
'description' => 'The default map to use when starting the server.',
'env_variable' => 'SRCDS_MAP',
'default_value' => 'sinjar',
'user_viewable' => 1,
'user_editable' => 1,
'required' => 1,
'regex' => '/^(\w{1,20})$/'
]);
}
private function addTF2Variables()
{
Models\ServiceVariables::create([
'option_id' => $this->option['tf2']->id,
'name' => 'Game ID',
'description' => 'The ID corresponding to the game to download and run using SRCDS.',
'env_variable' => 'SRCDS_APPID',
'default_value' => '232250',
'user_viewable' => 1,
'user_editable' => 0,
'required' => 1,
'regex' => '/^(232250)$/'
]);
Models\ServiceVariables::create([
'option_id' => $this->option['tf2']->id,
'name' => 'Game Name',
'description' => 'The name corresponding to the game to download and run using SRCDS.',
'env_variable' => 'SRCDS_GAME',
'default_value' => 'tf',
'user_viewable' => 1,
'user_editable' => 0,
'required' => 1,
'regex' => '/^(tf)$/'
]);
Models\ServiceVariables::create([
'option_id' => $this->option['tf2']->id,
'name' => 'Default Map',
'description' => 'The default map to use when starting the server.',
'env_variable' => 'SRCDS_MAP',
'default_value' => 'cp_dustbowl',
'user_viewable' => 1,
'user_editable' => 1,
'required' => 1,
'regex' => '/^(\w{1,20})$/'
]);
}
private function addCustomVariables()
{
Models\ServiceVariables::create([
'option_id' => $this->option['custom']->id,
'name' => 'Game ID',
'description' => 'The ID corresponding to the game to download and run using SRCDS.',
'env_variable' => 'SRCDS_APPID',
'default_value' => '',
'user_viewable' => 1,
'user_editable' => 0,
'required' => 1,
'regex' => '/^(\d){1,6}$/'
]);
Models\ServiceVariables::create([
'option_id' => $this->option['custom']->id,
'name' => 'Game Name',
'description' => 'The name corresponding to the game to download and run using SRCDS.',
'env_variable' => 'SRCDS_GAME',
'default_value' => '',
'user_viewable' => 1,
'user_editable' => 0,
'required' => 1,
'regex' => '/^(.*)$/'
]);
}
}