Use env() properly throughout panel to avoid cache issues.

This commit is contained in:
Dane Everitt 2017-03-18 15:56:19 -04:00
parent 9a581ef536
commit 4f16509447
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
14 changed files with 68 additions and 100 deletions

View file

@ -83,7 +83,7 @@ class AddNode extends Command
$selectedLocation = $this->option('location');
}
$this->data['location'] = $locations->where('short', $selectedLocation)->first()->id;
$this->data['location_id'] = $locations->where('short', $selectedLocation)->first()->id;
if (is_null($this->option('fqdn'))) {
$this->line('Please enter domain name (e.g node.example.com) to be used for connecting to the daemon. An IP address may only be used if you are not using SSL for this node.');

View file

@ -64,7 +64,7 @@ class ClearTasks extends Command
*/
public function handle()
{
$entries = Models\TaskLog::where('run_time', '<=', Carbon::now()->subHours(env('APP_CLEAR_TASKLOG', 720))->toAtomString())->get();
$entries = Models\TaskLog::where('run_time', '<=', Carbon::now()->subHours(config('pterodactyl.tasks.clear_log'))->toAtomString())->get();
$this->info(sprintf('Preparing to delete %d old task log entries.', count($entries)));
$bar = $this->output->createProgressBar(count($entries));

View file

@ -72,7 +72,7 @@ class RunTasks extends Command
foreach ($tasks as &$task) {
$bar->advance();
$this->dispatch((new SendScheduledTask(Models\Server::findOrFail($task->server), $task))->onQueue(env('QUEUE_LOW', 'low')));
$this->dispatch((new SendScheduledTask(Models\Server::findOrFail($task->server), $task))->onQueue(config('pterodactyl.queues.low')));
}
$bar->finish();

View file

@ -100,6 +100,7 @@ class UpdateEmailSettings extends Command
'Postmark Transactional Email Service',
],
]);
$variables['MAIL_DRIVER'] = is_null($this->option('driver')) ? $this->choice('Which email driver would you like to use?', [
'smtp',
'mail',
@ -110,9 +111,9 @@ class UpdateEmailSettings extends Command
switch ($variables['MAIL_DRIVER']) {
case 'smtp':
$variables['MAIL_HOST'] = is_null($this->option('host')) ? $this->ask('SMTP Host (e.g smtp.google.com)') : $this->option('host');
$variables['MAIL_PORT'] = is_null($this->option('port')) ? $this->anticipate('SMTP Host Port (e.g 587)', ['587']) : $this->option('port');
$variables['MAIL_USERNAME'] = is_null($this->option('username')) ? $this->ask('SMTP Username') : $this->option('password');
$variables['MAIL_HOST'] = is_null($this->option('host')) ? $this->ask('SMTP Host (e.g smtp.google.com)', config('mail.host')) : $this->option('host');
$variables['MAIL_PORT'] = is_null($this->option('port')) ? $this->anticipate('SMTP Host Port (e.g 587)', ['587', config('mail.port')], config('mail.port')) : $this->option('port');
$variables['MAIL_USERNAME'] = is_null($this->option('username')) ? $this->ask('SMTP Username', config('mail.username')) : $this->option('password');
$variables['MAIL_PASSWORD'] = is_null($this->option('password')) ? $this->secret('SMTP Password') : $this->option('password');
break;
case 'mail':
@ -128,7 +129,7 @@ class UpdateEmailSettings extends Command
$variables['MAIL_DRIVER'] = 'smtp';
$variables['MAIL_HOST'] = 'smtp.postmarkapp.com';
$variables['MAIL_PORT'] = 587;
$variables['MAIL_USERNAME'] = is_null($this->option('username')) ? $this->ask('Postmark API Token') : $this->option('username');
$variables['MAIL_USERNAME'] = is_null($this->option('username')) ? $this->ask('Postmark API Token', config('mail.username')) : $this->option('username');
$variables['MAIL_PASSWORD'] = $variables['MAIL_USERNAME'];
break;
default:
@ -137,8 +138,9 @@ class UpdateEmailSettings extends Command
break;
}
$variables['MAIL_FROM'] = is_null($this->option('email')) ? $this->ask('Email address emails should originate from') : $this->option('email');
$variables['MAIL_FROM_NAME'] = is_null($this->option('from-name')) ? $this->ask('Name emails should appear to be from') : $this->option('from-name');
$variables['MAIL_FROM'] = is_null($this->option('email')) ? $this->ask('Email address emails should originate from', config('mail.from.address')) : $this->option('email');
$variables['MAIL_FROM_NAME'] = is_null($this->option('from-name')) ? $this->ask('Name emails should appear to be from', config('mail.from.name')) : $this->option('from-name');
$variables['MAIL_FROM_NAME'] = '"' . $variables['MAIL_FROM_NAME'] . '"';
$variables['MAIL_ENCRYPTION'] = 'tls';
$bar = $this->output->createProgressBar(count($variables));

View file

@ -77,39 +77,31 @@ class UpdateEnvironment extends Command
$envContents = file_get_contents($file);
$this->info('Simply leave blank and press enter to fields that you do not wish to update.');
if (! env('SERVICE_AUTHOR', false)) {
if (is_null(config('pterodactyl.service.author', null))) {
$this->info('No service author set, setting one now.');
$variables['SERVICE_AUTHOR'] = env('SERVICE_AUTHOR', (string) Uuid::generate(4));
}
if (! env('QUEUE_STANDARD', false) || ! env('QUEUE_DRIVER', false)) {
$this->info('Setting default queue settings.');
$variables['QUEUE_DRIVER'] = env('QUEUE_DRIVER', 'database');
$variables['QUEUE_HIGH'] = env('QUEUE_HIGH', 'high');
$variables['QUEUE_STANDARD'] = env('QUEUE_STANDARD', 'standard');
$variables['QUEUE_LOW'] = env('QUEUE_LOW', 'low');
$variables['SERVICE_AUTHOR'] = (string) Uuid::generate(4);
}
if (is_null($this->option('dbhost'))) {
$variables['DB_HOST'] = $this->anticipate('Database Host', ['localhost', '127.0.0.1', env('DB_HOST')], env('DB_HOST'));
$variables['DB_HOST'] = $this->anticipate('Database Host', ['localhost', '127.0.0.1', config('database.connections.mysql.host')], config('database.connections.mysql.host'));
} else {
$variables['DB_HOST'] = $this->option('dbhost');
}
if (is_null($this->option('dbport'))) {
$variables['DB_PORT'] = $this->anticipate('Database Port', [3306, env('DB_PORT')], env('DB_PORT'));
$variables['DB_PORT'] = $this->anticipate('Database Port', [3306, config('database.connections.mysql.port')], config('database.connections.mysql.port'));
} else {
$variables['DB_PORT'] = $this->option('dbport');
}
if (is_null($this->option('dbname'))) {
$variables['DB_DATABASE'] = $this->anticipate('Database Name', ['pterodactyl', 'homestead', ENV('DB_DATABASE')], env('DB_DATABASE'));
$variables['DB_DATABASE'] = $this->anticipate('Database Name', ['pterodactyl', 'homestead', config('database.connections.mysql.database')], config('database.connections.mysql.database'));
} else {
$variables['DB_DATABASE'] = $this->option('dbname');
}
if (is_null($this->option('dbuser'))) {
$variables['DB_USERNAME'] = $this->anticipate('Database Username', [ENV('DB_DATABASE')], env('DB_USERNAME'));
$variables['DB_USERNAME'] = $this->anticipate('Database Username', [config('database.connections.mysql.username')], config('database.connections.mysql.username'));
} else {
$variables['DB_USERNAME'] = $this->option('dbuser');
}
@ -122,25 +114,23 @@ class UpdateEnvironment extends Command
}
if (is_null($this->option('url'))) {
$variables['APP_URL'] = $this->ask('Panel URL (include http(s)://)', env('APP_URL'));
$variables['APP_URL'] = $this->ask('Panel URL (include http(s)://)', config('app.url'));
} else {
$variables['APP_URL'] = $this->option('url');
}
if (is_null($this->option('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('Panel Timezone', \DateTimeZone::listIdentifiers(\DateTimeZone::ALL), env('APP_TIMEZONE'));
$variables['APP_TIMEZONE'] = $this->anticipate('Panel Timezone', \DateTimeZone::listIdentifiers(\DateTimeZone::ALL), config('app.timezone'));
} else {
$variables['APP_TIMEZONE'] = $this->option('timezone');
}
$variables['APP_THEME'] = 'pterodactyl';
$variables['CACHE_DRIVER'] = 'memcached';
$variables['SESSION_DRIVER'] = 'database';
$bar = $this->output->createProgressBar(count($variables));
$this->line('Writing new environment configuration to file.');
foreach ($variables as $key => $value) {
$newValue = $key . '=' . $value;
@ -155,8 +145,7 @@ class UpdateEnvironment extends Command
file_put_contents($file, $envContents);
$bar->finish();
$this->line('Updating evironment configuration cache file.');
$this->call('config:cache');
echo "\n";
$this->line("\n");
}
}

View file

@ -32,14 +32,6 @@ use Pterodactyl\Http\Controllers\Controller;
class BaseController extends Controller
{
/**
* Controller Constructor.
*/
public function __construct()
{
//
}
public function getIndex(Request $request)
{
return view('admin.index');
@ -55,8 +47,6 @@ class BaseController extends Controller
$validator = Validator::make($request->all(), [
'company' => 'required|between:1,256',
'default_language' => 'required|alpha_dash|min:2|max:5',
'email_from' => 'required|email',
'email_sender_name' => 'required|between:1,256',
]);
if ($validator->fails()) {
@ -65,8 +55,6 @@ class BaseController extends Controller
Settings::set('company', $request->input('company'));
Settings::set('default_language', $request->input('default_language'));
Settings::set('email_from', $request->input('email_from'));
Settings::set('email_sender_name', $request->input('email_sender_name'));
Alert::success('Settings have been successfully updated.')->flash();

View file

@ -79,7 +79,7 @@ class ServerObserver
{
event(new Events\Server\Deleting($server));
$this->dispatch((new SuspendServer($server->id))->onQueue(env('QUEUE_HIGH', 'high')));
$this->dispatch((new SuspendServer($server->id))->onQueue(config('pterodactyl.queues.high')));
}
/**
@ -94,8 +94,8 @@ class ServerObserver
$this->dispatch(
(new DeleteServer($server->id))
->delay(Carbon::now()->addMinutes(env('APP_DELETE_MINUTES', 10)))
->onQueue(env('QUEUE_STANDARD', 'standard'))
->delay(Carbon::now()->addMinutes(config('pterodactyl.tasks.delete_server')))
->onQueue(config('pterodactyl.queues.standard'))
);
}

View file

@ -36,11 +36,11 @@ class VersionService
*/
public function __construct()
{
self::$versions = Cache::remember('versions', env('VERSION_CACHE_TIME', 60), function () {
self::$versions = Cache::remember('versions', config('pterodactyl.cdn.cache'), function () {
$client = new Client();
try {
$response = $client->request('GET', env('VERSION_CHECK_URL', 'https://cdn.pterodactyl.io/releases/latest.json'));
$response = $client->request('GET', config('pterodactyl.cdn.url'));
if ($response->getStatusCode() === 200) {
return json_decode($response->getBody());
@ -52,7 +52,7 @@ class VersionService
return (object) [
'panel' => 'error',
'daemon' => 'error',
'discord' => 'https://pterodactyl.io',
'discord' => 'https://pterodactyl.io/discord',
];
}
});