|
| 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 Illuminate\Console\Command; |
| 27 | + |
| 28 | +class UpdateEnvironment extends Command |
| 29 | +{ |
| 30 | + /** |
| 31 | + * The name and signature of the console command. |
| 32 | + * |
| 33 | + * @var string |
| 34 | + */ |
| 35 | + protected $signature = 'pterodactyl:env'; |
| 36 | + |
| 37 | + /** |
| 38 | + * The console command description. |
| 39 | + * |
| 40 | + * @var string |
| 41 | + */ |
| 42 | + protected $description = 'Update environment settings automatically.'; |
| 43 | + |
| 44 | + /** |
| 45 | + * Create a new command instance. |
| 46 | + * |
| 47 | + * @return void |
| 48 | + */ |
| 49 | + public function __construct() |
| 50 | + { |
| 51 | + parent::__construct(); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Execute the console command. |
| 56 | + * |
| 57 | + * @return mixed |
| 58 | + */ |
| 59 | + public function handle() |
| 60 | + { |
| 61 | + |
| 62 | + $variables = []; |
| 63 | + $file = base_path() . '/.env'; |
| 64 | + if (!file_exists($file)) { |
| 65 | + $this->error('Missing environment file! It appears that you have not installed this panel correctly.'); |
| 66 | + exit(); |
| 67 | + } |
| 68 | + |
| 69 | + $envContents = file_get_contents($file); |
| 70 | + |
| 71 | + // 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'); |
| 77 | + |
| 78 | + // 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)); |
| 82 | + |
| 83 | + $bar = $this->output->createProgressBar(count($variables) + 1); |
| 84 | + |
| 85 | + $this->line('Writing new environment configuration to file.'); |
| 86 | + foreach ($variables as $key => $value) { |
| 87 | + $regex = '/^' . $key . '=(.*)$/m'; |
| 88 | + $replace = $key . '=' . $value; |
| 89 | + $envContents = preg_replace($regex, $replace, $envContents); |
| 90 | + $bar->advance(); |
| 91 | + } |
| 92 | + |
| 93 | + file_put_contents($file, $envContents); |
| 94 | + $bar->finish(); |
| 95 | + echo "\n"; |
| 96 | + } |
| 97 | +} |
0 commit comments