1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-10-26 12:52:28 +02:00

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'); $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'))) { 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.'); $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() 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))); $this->info(sprintf('Preparing to delete %d old task log entries.', count($entries)));
$bar = $this->output->createProgressBar(count($entries)); $bar = $this->output->createProgressBar(count($entries));

View File

@ -72,7 +72,7 @@ class RunTasks extends Command
foreach ($tasks as &$task) { foreach ($tasks as &$task) {
$bar->advance(); $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(); $bar->finish();

View File

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

View File

@ -77,39 +77,31 @@ class UpdateEnvironment extends Command
$envContents = file_get_contents($file); $envContents = file_get_contents($file);
$this->info('Simply leave blank and press enter to fields that you do not wish to update.'); $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.'); $this->info('No service author set, setting one now.');
$variables['SERVICE_AUTHOR'] = env('SERVICE_AUTHOR', (string) Uuid::generate(4)); $variables['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');
} }
if (is_null($this->option('dbhost'))) { 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 { } else {
$variables['DB_HOST'] = $this->option('dbhost'); $variables['DB_HOST'] = $this->option('dbhost');
} }
if (is_null($this->option('dbport'))) { 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 { } else {
$variables['DB_PORT'] = $this->option('dbport'); $variables['DB_PORT'] = $this->option('dbport');
} }
if (is_null($this->option('dbname'))) { 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 { } else {
$variables['DB_DATABASE'] = $this->option('dbname'); $variables['DB_DATABASE'] = $this->option('dbname');
} }
if (is_null($this->option('dbuser'))) { 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 { } else {
$variables['DB_USERNAME'] = $this->option('dbuser'); $variables['DB_USERNAME'] = $this->option('dbuser');
} }
@ -122,25 +114,23 @@ class UpdateEnvironment extends Command
} }
if (is_null($this->option('url'))) { 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 { } else {
$variables['APP_URL'] = $this->option('url'); $variables['APP_URL'] = $this->option('url');
} }
if (is_null($this->option('timezone'))) { 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'); $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 { } else {
$variables['APP_TIMEZONE'] = $this->option('timezone'); $variables['APP_TIMEZONE'] = $this->option('timezone');
} }
$variables['APP_THEME'] = 'pterodactyl';
$variables['CACHE_DRIVER'] = 'memcached'; $variables['CACHE_DRIVER'] = 'memcached';
$variables['SESSION_DRIVER'] = 'database'; $variables['SESSION_DRIVER'] = 'database';
$bar = $this->output->createProgressBar(count($variables)); $bar = $this->output->createProgressBar(count($variables));
$this->line('Writing new environment configuration to file.');
foreach ($variables as $key => $value) { foreach ($variables as $key => $value) {
$newValue = $key . '=' . $value; $newValue = $key . '=' . $value;
@ -155,8 +145,7 @@ class UpdateEnvironment extends Command
file_put_contents($file, $envContents); file_put_contents($file, $envContents);
$bar->finish(); $bar->finish();
$this->line('Updating evironment configuration cache file.');
$this->call('config:cache'); $this->call('config:cache');
echo "\n"; $this->line("\n");
} }
} }

View File

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

View File

@ -79,7 +79,7 @@ class ServerObserver
{ {
event(new Events\Server\Deleting($server)); 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( $this->dispatch(
(new DeleteServer($server->id)) (new DeleteServer($server->id))
->delay(Carbon::now()->addMinutes(env('APP_DELETE_MINUTES', 10))) ->delay(Carbon::now()->addMinutes(config('pterodactyl.tasks.delete_server')))
->onQueue(env('QUEUE_STANDARD', 'standard')) ->onQueue(config('pterodactyl.queues.standard'))
); );
} }

View File

@ -36,11 +36,11 @@ class VersionService
*/ */
public function __construct() 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(); $client = new Client();
try { 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) { if ($response->getStatusCode() === 200) {
return json_decode($response->getBody()); return json_decode($response->getBody());
@ -52,7 +52,7 @@ class VersionService
return (object) [ return (object) [
'panel' => 'error', 'panel' => 'error',
'daemon' => 'error', 'daemon' => 'error',
'discord' => 'https://pterodactyl.io', 'discord' => 'https://pterodactyl.io/discord',
]; ];
} }
}); });

View File

@ -46,12 +46,6 @@ return [
'connections' => [ 'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path('database.sqlite'),
'prefix' => '',
],
'mysql' => [ 'mysql' => [
'driver' => 'mysql', 'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'), 'host' => env('DB_HOST', 'localhost'),
@ -65,27 +59,6 @@ return [
'strict' => false, 'strict' => false,
], ],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
], ],
/* /*

View File

@ -42,4 +42,41 @@ return [
'connect_timeout' => env('GUZZLE_CONNECT_TIMEOUT', 3), 'connect_timeout' => env('GUZZLE_CONNECT_TIMEOUT', 3),
], ],
/*
|--------------------------------------------------------------------------
| Queue Names
|--------------------------------------------------------------------------
|
| Configure the names of queues to be used in the database.
*/
'queues' => [
'low' => env('QUEUE_LOW', 'low'),
'standard' => env('QUEUE_STANDARD', 'standard'),
'high' => env('QUEUE_HIGH', 'high'),
],
/*
|--------------------------------------------------------------------------
| Task Timers
|--------------------------------------------------------------------------
|
| The amount of time in minutes before performing certain actions on the system.
*/
'tasks' => [
'clear_log' => env('PTERODACTYL_CLEAR_TASKLOG', 720),
'delete_server' => env('PTERODACTYL_DELETE_MINUTES', 10),
],
/*
|--------------------------------------------------------------------------
| CDN
|--------------------------------------------------------------------------
|
| Information for the panel to use when contacting the CDN to confirm
| if panel is up to date.
*/
'cdn' => [
'cache' => 60,
'url' => 'https://cdn.pterodactyl.io/releases/latest.json',
],
]; ];

View File

@ -4,14 +4,9 @@ return [
'enabled' => true, 'enabled' => true,
'themes_path' => realpath(base_path('resources/themes')), 'themes_path' => realpath(base_path('resources/themes')),
'asset_not_found' => 'LOG_ERROR', 'asset_not_found' => 'LOG_ERROR',
'active' => ENV('APP_THEME', 'default'), 'active' => env('APP_THEME', 'pterodactyl'),
'themes' => [ 'themes' => [
'default' => [
'extends' => null,
'views-path' => 'default',
'asset-path' => 'themes/default',
],
'pterodactyl' => [ 'pterodactyl' => [
'extends' => null, 'extends' => null,
'views-path' => 'pterodactyl', 'views-path' => 'pterodactyl',

View File

@ -61,7 +61,7 @@
<h3 class="box-title">Marked for Deletion</h3> <h3 class="box-title">Marked for Deletion</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
<p>This server is currently marked for deletion by the system <strong>{{ Carbon::parse($server->deleted_at)->addMinutes(env('APP_DELETE_MINUTES', 10))->diffForHumans() }}</strong>.</p> <p>This server is currently marked for deletion by the system <strong>{{ Carbon::parse($server->deleted_at)->addMinutes(config('pterodactyl.tasks.delete_server'))->diffForHumans() }}</strong>.</p>
<p class="text-danger small">Deleting a server is an irreversible action. <strong>All server data</strong> (including files and users) will be removed from the system.</p> <p class="text-danger small">Deleting a server is an irreversible action. <strong>All server data</strong> (including files and users) will be removed from the system.</p>
</div> </div>
<div class="box-footer"> <div class="box-footer">

View File

@ -69,23 +69,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<div class="alert alert-info">In order to modify your SMTP settings for sending mail you will need to edit the <code>.env</code> file in this project's root folder.</div> <div class="alert alert-info">In order to modify your SMTP settings for sending mail you will need to run <code>php artisan pterodactyl:mail</code> in this project's root folder.</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Send Emails From:</label>
<div>
<input type="text" class="form-control" name="email_from" value="{{ old('email_from', Settings::get('email_from', env('MAIL_FROM', 'you@example.com'))) }}" />
<p class="text-muted"><small>The email address that panel emails will be sent from. Note that some SMTP services require this to match for a given API key.</small></p>
</div>
</div>
<div class="form-group col-md-6">
<label class="control-label">Email Sender Name:</label>
<div>
<input type="text" class="form-control" name="email_sender_name" value="{{ old('email_sender_name', Settings::get('email_sender_name', env('MAIL_FROM_NAME', 'Pterodactyl Panel'))) }}" />
<p class="text-muted"><small>The name that emails will appear to come from.</small></p>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -76,7 +76,7 @@
</td> </td>
<td data-identifier="size" class="hidden-xs">{{ $folder['size'] }}</td> <td data-identifier="size" class="hidden-xs">{{ $folder['size'] }}</td>
<td data-identifier="modified" class="hidden-xs"> <td data-identifier="modified" class="hidden-xs">
<?php $carbon = Carbon::createFromTimestamp($folder['date'])->timezone(env('APP_TIMEZONE', 'America/New_York')); ?> <?php $carbon = Carbon::createFromTimestamp($folder['date'])->timezone(config('app.timezone')); ?>
@if($carbon->diffInMinutes(Carbon::now()) > 60) @if($carbon->diffInMinutes(Carbon::now()) > 60)
{{ $carbon->format('m/d/y H:i:s') }} {{ $carbon->format('m/d/y H:i:s') }}
@elseif($carbon->diffInSeconds(Carbon::now()) < 5 || $carbon->isFuture()) @elseif($carbon->diffInSeconds(Carbon::now()) < 5 || $carbon->isFuture())
@ -153,7 +153,7 @@
</td> </td>
<td data-identifier="size" class="hidden-xs">{{ $file['size'] }}</td> <td data-identifier="size" class="hidden-xs">{{ $file['size'] }}</td>
<td data-identifier="modified" class="hidden-xs"> <td data-identifier="modified" class="hidden-xs">
<?php $carbon = Carbon::createFromTimestamp($file['date'])->timezone(env('APP_TIMEZONE', 'America/New_York')); ?> <?php $carbon = Carbon::createFromTimestamp($file['date'])->timezone(config('app.timezone')); ?>
@if($carbon->diffInMinutes(Carbon::now()) > 60) @if($carbon->diffInMinutes(Carbon::now()) > 60)
{{ $carbon->format('m/d/y H:i:s') }} {{ $carbon->format('m/d/y H:i:s') }}
@elseif($carbon->diffInSeconds(Carbon::now()) < 5 || $carbon->isFuture()) @elseif($carbon->diffInSeconds(Carbon::now()) < 5 || $carbon->isFuture())