2015-12-06 18:58:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Providers;
|
|
|
|
|
2022-05-29 23:26:28 +00:00
|
|
|
use Pterodactyl\Models;
|
2022-01-23 17:58:44 +00:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
use Illuminate\Support\Facades\URL;
|
2021-01-23 20:09:16 +00:00
|
|
|
use Illuminate\Pagination\Paginator;
|
2022-11-25 20:29:04 +00:00
|
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
2017-09-25 03:34:30 +00:00
|
|
|
use Illuminate\Support\Facades\Schema;
|
2015-12-06 18:58:49 +00:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2019-09-06 03:17:40 +00:00
|
|
|
use Pterodactyl\Extensions\Themes\Theme;
|
2022-05-29 20:19:04 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
2015-12-06 18:58:49 +00:00
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bootstrap any application services.
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2017-09-25 03:34:30 +00:00
|
|
|
Schema::defaultStringLength(191);
|
|
|
|
|
2017-04-28 02:28:01 +00:00
|
|
|
View::share('appVersion', $this->versionData()['version'] ?? 'undefined');
|
|
|
|
View::share('appIsGit', $this->versionData()['is_git'] ?? false);
|
2021-01-23 20:09:16 +00:00
|
|
|
|
|
|
|
Paginator::useBootstrap();
|
2022-01-23 17:58:44 +00:00
|
|
|
|
|
|
|
// If the APP_URL value is set with https:// make sure we force it here. Theoretically
|
|
|
|
// this should just work with the proxy logic, but there are a lot of cases where it
|
|
|
|
// doesn't, and it triggers a lot of support requests, so lets just head it off here.
|
|
|
|
//
|
|
|
|
// @see https://github.com/pterodactyl/panel/issues/3623
|
|
|
|
if (Str::startsWith(config('app.url') ?? '', 'https://')) {
|
|
|
|
URL::forceScheme('https');
|
|
|
|
}
|
2022-05-29 20:19:04 +00:00
|
|
|
|
|
|
|
Relation::enforceMorphMap([
|
2022-05-29 23:26:28 +00:00
|
|
|
'allocation' => Models\Allocation::class,
|
|
|
|
'api_key' => Models\ApiKey::class,
|
|
|
|
'backup' => Models\Backup::class,
|
|
|
|
'database' => Models\Database::class,
|
|
|
|
'egg' => Models\Egg::class,
|
|
|
|
'egg_variable' => Models\EggVariable::class,
|
|
|
|
'schedule' => Models\Schedule::class,
|
|
|
|
'server' => Models\Server::class,
|
|
|
|
'ssh_key' => Models\UserSSHKey::class,
|
|
|
|
'task' => Models\Task::class,
|
|
|
|
'user' => Models\User::class,
|
2022-05-29 20:19:04 +00:00
|
|
|
]);
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-30 22:33:00 +00:00
|
|
|
/**
|
|
|
|
* Register application service providers.
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
// Only load the settings service provider if the environment
|
|
|
|
// is configured to allow it.
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!config('pterodactyl.load_environment_only', false) && $this->app->environment() !== 'testing') {
|
2017-12-30 22:33:00 +00:00
|
|
|
$this->app->register(SettingsServiceProvider::class);
|
|
|
|
}
|
2019-09-06 03:17:40 +00:00
|
|
|
|
|
|
|
$this->app->singleton('extensions.themes', function () {
|
2021-01-23 20:33:34 +00:00
|
|
|
return new Theme();
|
2019-09-06 03:17:40 +00:00
|
|
|
});
|
2017-12-30 22:33:00 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 02:28:01 +00:00
|
|
|
/**
|
|
|
|
* Return version information for the footer.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
protected function versionData(): array
|
2017-04-28 02:28:01 +00:00
|
|
|
{
|
|
|
|
return Cache::remember('git-version', 5, function () {
|
|
|
|
if (file_exists(base_path('.git/HEAD'))) {
|
|
|
|
$head = explode(' ', file_get_contents(base_path('.git/HEAD')));
|
2017-07-23 22:55:38 +00:00
|
|
|
|
|
|
|
if (array_key_exists(1, $head)) {
|
|
|
|
$path = base_path('.git/' . trim($head[1]));
|
|
|
|
}
|
2017-04-28 02:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($path) && file_exists($path)) {
|
|
|
|
return [
|
|
|
|
'version' => substr(file_get_contents($path), 0, 8),
|
|
|
|
'is_git' => true,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'version' => config('app.version'),
|
|
|
|
'is_git' => false,
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|