2016-01-26 01:08:48 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
2017-01-24 22:57:08 +00:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
2016-01-26 01:08:48 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-01-26 01:08:48 +00:00
|
|
|
namespace Pterodactyl\Console\Commands;
|
|
|
|
|
2016-09-07 21:48:20 +00:00
|
|
|
use Uuid;
|
2016-01-26 01:08:48 +00:00
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
class UpdateEnvironment extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-10-12 23:02:15 +00:00
|
|
|
protected $signature = 'pterodactyl:env
|
|
|
|
{--dbhost=}
|
|
|
|
{--dbport=}
|
|
|
|
{--dbname=}
|
|
|
|
{--dbuser=}
|
|
|
|
{--dbpass=}
|
|
|
|
{--url=}
|
2017-04-01 20:31:18 +00:00
|
|
|
{--driver=}
|
|
|
|
{--session-driver=}
|
2017-04-10 16:49:37 +00:00
|
|
|
{--queue-driver=}
|
2016-10-12 23:02:15 +00:00
|
|
|
{--timezone=}';
|
2016-01-26 01:08:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Update environment settings automatically.';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$variables = [];
|
|
|
|
$file = base_path() . '/.env';
|
2016-12-07 22:46:38 +00:00
|
|
|
if (! file_exists($file)) {
|
2016-01-26 01:08:48 +00:00
|
|
|
$this->error('Missing environment file! It appears that you have not installed this panel correctly.');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$envContents = file_get_contents($file);
|
|
|
|
|
2016-10-12 23:02:15 +00:00
|
|
|
$this->info('Simply leave blank and press enter to fields that you do not wish to update.');
|
2017-03-18 19:56:19 +00:00
|
|
|
if (is_null(config('pterodactyl.service.author', null))) {
|
2016-09-07 21:48:20 +00:00
|
|
|
$this->info('No service author set, setting one now.');
|
2017-03-18 19:56:19 +00:00
|
|
|
$variables['SERVICE_AUTHOR'] = (string) Uuid::generate(4);
|
2016-10-30 22:34:50 +00:00
|
|
|
}
|
|
|
|
|
2016-10-12 23:02:15 +00:00
|
|
|
if (is_null($this->option('dbhost'))) {
|
2017-03-18 19:56:19 +00:00
|
|
|
$variables['DB_HOST'] = $this->anticipate('Database Host', ['localhost', '127.0.0.1', config('database.connections.mysql.host')], config('database.connections.mysql.host'));
|
2016-10-12 23:02:15 +00:00
|
|
|
} else {
|
|
|
|
$variables['DB_HOST'] = $this->option('dbhost');
|
2016-09-07 21:48:20 +00:00
|
|
|
}
|
|
|
|
|
2016-10-12 23:02:15 +00:00
|
|
|
if (is_null($this->option('dbport'))) {
|
2017-03-18 19:56:19 +00:00
|
|
|
$variables['DB_PORT'] = $this->anticipate('Database Port', [3306, config('database.connections.mysql.port')], config('database.connections.mysql.port'));
|
2016-10-12 23:02:15 +00:00
|
|
|
} else {
|
|
|
|
$variables['DB_PORT'] = $this->option('dbport');
|
2016-09-07 21:48:20 +00:00
|
|
|
}
|
|
|
|
|
2016-10-12 23:02:15 +00:00
|
|
|
if (is_null($this->option('dbname'))) {
|
2017-03-18 19:56:19 +00:00
|
|
|
$variables['DB_DATABASE'] = $this->anticipate('Database Name', ['pterodactyl', 'homestead', config('database.connections.mysql.database')], config('database.connections.mysql.database'));
|
2016-10-12 23:02:15 +00:00
|
|
|
} else {
|
|
|
|
$variables['DB_DATABASE'] = $this->option('dbname');
|
2016-09-07 21:48:20 +00:00
|
|
|
}
|
|
|
|
|
2016-10-12 23:02:15 +00:00
|
|
|
if (is_null($this->option('dbuser'))) {
|
2017-03-18 19:56:19 +00:00
|
|
|
$variables['DB_USERNAME'] = $this->anticipate('Database Username', [config('database.connections.mysql.username')], config('database.connections.mysql.username'));
|
2016-10-12 23:02:15 +00:00
|
|
|
} else {
|
|
|
|
$variables['DB_USERNAME'] = $this->option('dbuser');
|
2016-09-07 21:48:20 +00:00
|
|
|
}
|
|
|
|
|
2016-10-12 23:02:15 +00:00
|
|
|
if (is_null($this->option('dbpass'))) {
|
|
|
|
$this->line('The Database Password field is required; you cannot hit enter and use a default value.');
|
|
|
|
$variables['DB_PASSWORD'] = $this->secret('Database User Password');
|
|
|
|
} else {
|
|
|
|
$variables['DB_PASSWORD'] = $this->option('dbpass');
|
2016-09-07 21:48:20 +00:00
|
|
|
}
|
2016-01-26 01:08:48 +00:00
|
|
|
|
2016-10-12 23:02:15 +00:00
|
|
|
if (is_null($this->option('url'))) {
|
2017-03-18 19:56:19 +00:00
|
|
|
$variables['APP_URL'] = $this->ask('Panel URL (include http(s)://)', config('app.url'));
|
2016-10-12 23:02:15 +00:00
|
|
|
} else {
|
|
|
|
$variables['APP_URL'] = $this->option('url');
|
2016-09-07 21:48:20 +00:00
|
|
|
}
|
2016-01-26 01:08:48 +00:00
|
|
|
|
2016-10-12 23:02:15 +00:00
|
|
|
if (is_null($this->option('timezone'))) {
|
2016-09-07 21:48:20 +00:00
|
|
|
$this->line('The timezone should match one of the supported timezones according to http://php.net/manual/en/timezones.php');
|
2017-03-18 19:56:19 +00:00
|
|
|
$variables['APP_TIMEZONE'] = $this->anticipate('Panel Timezone', \DateTimeZone::listIdentifiers(\DateTimeZone::ALL), config('app.timezone'));
|
2016-10-12 23:02:15 +00:00
|
|
|
} else {
|
|
|
|
$variables['APP_TIMEZONE'] = $this->option('timezone');
|
2016-09-07 21:48:20 +00:00
|
|
|
}
|
|
|
|
|
2017-04-01 20:31:18 +00:00
|
|
|
if (is_null($this->option('driver'))) {
|
|
|
|
$this->line('If you chose redis as your cache driver backend, you *must* have a redis server configured already.');
|
|
|
|
$variables['CACHE_DRIVER'] = $this->choice('Which cache driver backend would you like to use?', [
|
|
|
|
'memcached' => 'Memcache',
|
|
|
|
'redis' => 'Redis (recommended)',
|
|
|
|
'apc' => 'APC',
|
|
|
|
'array' => 'PHP Array',
|
|
|
|
], config('cache.default', 'memcached'));
|
|
|
|
} else {
|
|
|
|
$variables['CACHE_DRIVER'] = $this->option('driver');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($this->option('session-driver'))) {
|
|
|
|
$this->line('If you chose redis as your cache driver backend, you *must* have a redis server configured already.');
|
|
|
|
$variables['SESSION_DRIVER'] = $this->choice('Which session driver backend would you like to use?', [
|
|
|
|
'database' => 'MySQL (recommended)',
|
|
|
|
'redis' => 'Redis',
|
|
|
|
'file' => 'File',
|
|
|
|
'cookie' => 'Cookie',
|
|
|
|
'apc' => 'APC',
|
|
|
|
'array' => 'PHP Array',
|
|
|
|
], config('session.driver', 'database'));
|
|
|
|
} else {
|
|
|
|
$variables['SESSION_DRIVER'] = $this->option('session-driver');
|
|
|
|
}
|
2017-02-17 23:19:53 +00:00
|
|
|
|
2017-04-01 21:59:43 +00:00
|
|
|
if (is_null($this->option('queue-driver'))) {
|
|
|
|
$this->line('If you chose redis as your cache driver backend, you *must* have a redis server configured already.');
|
|
|
|
$variables['QUEUE_DRIVER'] = $this->choice('Which cache driver backend would you like to use?', [
|
|
|
|
'database' => 'Database (recommended)',
|
|
|
|
'redis' => 'Redis',
|
|
|
|
'sqs' => 'Amazon SQS',
|
|
|
|
'sync' => 'Sync',
|
|
|
|
'null' => 'None',
|
|
|
|
], config('queue.driver', 'database'));
|
|
|
|
} else {
|
|
|
|
$variables['QUEUE_DRIVER'] = $this->option('queue-driver');
|
|
|
|
}
|
|
|
|
|
2016-09-07 21:48:20 +00:00
|
|
|
$bar = $this->output->createProgressBar(count($variables));
|
2016-01-26 01:08:48 +00:00
|
|
|
|
|
|
|
foreach ($variables as $key => $value) {
|
2016-01-26 01:30:50 +00:00
|
|
|
$newValue = $key . '=' . $value;
|
2016-09-07 21:48:20 +00:00
|
|
|
|
2016-01-26 01:30:50 +00:00
|
|
|
if (preg_match_all('/^' . $key . '=(.*)$/m', $envContents) < 1) {
|
|
|
|
$envContents = $envContents . "\n" . $newValue;
|
|
|
|
} else {
|
|
|
|
$envContents = preg_replace('/^' . $key . '=(.*)$/m', $newValue, $envContents);
|
|
|
|
}
|
2016-01-26 01:08:48 +00:00
|
|
|
$bar->advance();
|
|
|
|
}
|
|
|
|
|
|
|
|
file_put_contents($file, $envContents);
|
|
|
|
$bar->finish();
|
2017-02-02 20:06:35 +00:00
|
|
|
|
|
|
|
$this->call('config:cache');
|
2017-03-18 19:56:19 +00:00
|
|
|
$this->line("\n");
|
2016-01-26 01:08:48 +00:00
|
|
|
}
|
|
|
|
}
|