diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php new file mode 100644 index 0000000..3d7177e --- /dev/null +++ b/app/Providers/AppServiceProvider.php @@ -0,0 +1,100 @@ +versionData()['version'] ?? 'undefined'); + View::share('appIsGit', $this->versionData()['is_git'] ?? false); + + Paginator::useBootstrap(); + + // 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'); + } + + Relation::enforceMorphMap([ + '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, + ]); + } + + /** + * Register application service providers. + */ + public function register(): void + { + // Merge Blueprint configurations with existing configurations. + $this->mergeConfigFrom(base_path('config/ExtensionFS.php'), 'filesystems'); + + // Only load the settings service provider if the environment + // is configured to allow it. + if (!config('pterodactyl.load_environment_only', false) && $this->app->environment() !== 'testing') { + $this->app->register(SettingsServiceProvider::class); + } + + $this->app->singleton('extensions.themes', function () { + return new Theme(); + }); + } + + /** + * Return version information for the footer. + */ + protected function versionData(): array + { + return Cache::remember('git-version', 5, function () { + if (file_exists(base_path('.git/HEAD'))) { + $head = explode(' ', file_get_contents(base_path('.git/HEAD'))); + + if (array_key_exists(1, $head)) { + $path = base_path('.git/' . trim($head[1])); + } + } + + 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, + ]; + }); + } +} diff --git a/blueprint.sh b/blueprint.sh index e7705e2..9728975 100644 --- a/blueprint.sh +++ b/blueprint.sh @@ -49,6 +49,8 @@ export BLUEPRINT__FOLDER=$FOLDER export BLUEPRINT__VERSION=$VERSION export BLUEPRINT__DEBUG="$FOLDER"/.blueprint/extensions/blueprint/private/debug/logs.txt export NODE_OPTIONS=--openssl-legacy-provider +# Write internal variables. +__BuildDir=".blueprint/extensions/blueprint/private/build" # Automatically navigate to the Pterodactyl directory when running the core. cd $FOLDER || return @@ -217,8 +219,8 @@ if [[ $1 != "-bash" ]]; then # Flush cache. PRINT INFO "Flushing view, config and route cache.." { - php artisan view:clear - php artisan config:clear + php artisan view:cache + php artisan config:cache php artisan route:cache php artisan cache:clear } &>> $BLUEPRINT__DEBUG @@ -787,14 +789,14 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD=" if [[ $Components_Navigation_Routes_ != "" ]]; then PRINT INFO "Linking navigation routes.." - ImportConstructor=".blueprint/extensions/blueprint/private/build/extensions/routes/importConstructor.bak" - AccountRouteConstructor=".blueprint/extensions/blueprint/private/build/extensions/routes/accountRouteConstructor.bak" - ServerRouteConstructor=".blueprint/extensions/blueprint/private/build/extensions/routes/serverRouteConstructor.bak" + ImportConstructor="$__BuildDir/extensions/routes/importConstructor.bak" + AccountRouteConstructor="$__BuildDir/extensions/routes/accountRouteConstructor.bak" + ServerRouteConstructor="$__BuildDir/extensions/routes/serverRouteConstructor.bak" { - cp ".blueprint/extensions/blueprint/private/build/extensions/routes/importConstructor" "$ImportConstructor" - cp ".blueprint/extensions/blueprint/private/build/extensions/routes/accountRouteConstructor" "$AccountRouteConstructor" - cp ".blueprint/extensions/blueprint/private/build/extensions/routes/serverRouteConstructor" "$ServerRouteConstructor" + cp "$__BuildDir/extensions/routes/importConstructor" "$ImportConstructor" + cp "$__BuildDir/extensions/routes/accountRouteConstructor" "$AccountRouteConstructor" + cp "$__BuildDir/extensions/routes/serverRouteConstructor" "$ServerRouteConstructor" } 2>> $BLUEPRINT__DEBUG sed -i "s~\[id\^]~""${identifier^}""~g" $ImportConstructor @@ -959,16 +961,18 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD=" fi # Prepare build files. - AdminControllerConstructor=".blueprint/extensions/blueprint/private/build/extensions/controller.build.bak" - AdminBladeConstructor=".blueprint/extensions/blueprint/private/build/extensions/admin.blade.php.bak" - AdminRouteConstructor=".blueprint/extensions/blueprint/private/build/extensions/route.php.bak" - AdminButtonConstructor=".blueprint/extensions/blueprint/private/build/extensions/button.blade.php.bak" + AdminControllerConstructor="$__BuildDir/extensions/controller.build.bak" + AdminBladeConstructor="$__BuildDir/extensions/admin.blade.php.bak" + AdminRouteConstructor="$__BuildDir/extensions/route.php.bak" + AdminButtonConstructor="$__BuildDir/extensions/button.blade.php.bak" + ConfigExtensionFS="$__BuildDir/extensions/config/ExtensionFS.build.bak" { - if [[ $controller_type == "default" ]]; then cp ".blueprint/extensions/blueprint/private/build/extensions/controller.build" "$AdminControllerConstructor"; fi - cp ".blueprint/extensions/blueprint/private/build/extensions/admin.blade.php" "$AdminBladeConstructor" - cp ".blueprint/extensions/blueprint/private/build/extensions/route.php" "$AdminRouteConstructor" - cp ".blueprint/extensions/blueprint/private/build/extensions/button.blade.php" "$AdminButtonConstructor" + if [[ $controller_type == "default" ]]; then cp "$__BuildDir/extensions/controller.build" "$AdminControllerConstructor"; fi + cp "$__BuildDir/extensions/admin.blade.php" "$AdminBladeConstructor" + cp "$__BuildDir/extensions/route.php" "$AdminRouteConstructor" + cp "$__BuildDir/extensions/button.blade.php" "$AdminButtonConstructor" + cp "$__BuildDir/extensions/config/ExtensionFS.build" "$ConfigExtensionFS" } 2>> $BLUEPRINT__DEBUG; @@ -1067,14 +1071,18 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD=" # Construct admin controller if [[ $controller_type == "default" ]]; then sed -i "s~\[id\]~$identifier~g" "$AdminControllerConstructor"; fi + # Construct ExtensionFS + sed -i \ + -e "s~\[id\]~$identifier~g" \ + -e "s~\[id\^\]~${identifier^}~g" \ + "$ConfigExtensionFS" # Read final results. ADMINVIEW_RESULT=$(<"$AdminBladeConstructor") ADMINROUTE_RESULT=$(<"$AdminRouteConstructor") ADMINBUTTON_RESULT=$(<"$AdminButtonConstructor") - if [[ $controller_type == "default" ]]; then - ADMINCONTROLLER_RESULT=$(<"$AdminControllerConstructor") - fi + if [[ $controller_type == "default" ]]; then ADMINCONTROLLER_RESULT=$(<"$AdminControllerConstructor"); fi + CONFIGEXTENSIONFS_RESULT=$(<"$ConfigExtensionFS") ADMINCONTROLLER_NAME="${identifier}ExtensionController.php" # Place admin extension view. @@ -1146,18 +1154,36 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD=" sed -i "/<\!-- wrapper:insert -->/r .blueprint/tmp/$n/$admin_wrapper" "resources/views/blueprint/admin/admin.blade.php" fi + # Create extension filesystem (ExtensionFS) + PRINT INFO "Creating and linking extension filesystem.." + mkdir -p ".blueprint/extensions/$identifier/fs" + ln -s -T $FOLDER/.blueprint/extensions/"$identifier"/fs "$FOLDER/storage/extensions/$identifier" 2>> $BLUEPRINT__DEBUG + ln -s -T $FOLDER/storage/extensions/"$identifier" "$FOLDER/public/fs/$identifier" 2>> $BLUEPRINT__DEBUG + if [[ $DUPLICATE == "y" ]]; then + sed -i \ + -e "s/\/\* ${identifier^}Start \*\/.*\/\* ${identifier^}End \*\///" \ + -e "s~/\* ${identifier^}Start \*/~~g" \ + -e "s~/\* ${identifier^}End \*/~~g" \ + "config/ExtensionFS.php" + fi + sed -i "s~\/\* blueprint/disks \*\/~/* blueprint/disks */$CONFIGEXTENSIONFS_RESULT~g" config/ExtensionFS.php + # Create backup of generated values. - mkdir -p ".blueprint/extensions/$identifier/private/.store/build" - cp ".blueprint/extensions/blueprint/private/build/extensions/button.blade.php.bak" ".blueprint/extensions/$identifier/private/.store/build/button.blade.php" - cp ".blueprint/extensions/blueprint/private/build/extensions/route.php.bak" ".blueprint/extensions/$identifier/private/.store/build/route.php" + mkdir -p \ + ".blueprint/extensions/$identifier/private/.store/build" \ + ".blueprint/extensions/$identifier/private/.store/build/config" + cp "$__BuildDir/extensions/button.blade.php.bak" ".blueprint/extensions/$identifier/private/.store/build/button.blade.php" + cp "$__BuildDir/extensions/route.php.bak" ".blueprint/extensions/$identifier/private/.store/build/route.php" + cp "$__BuildDir/extensions/config/ExtensionFS.build.bak" ".blueprint/extensions/$identifier/private/.store/build/config/ExtensionFS.build" # Remove temporary build files. PRINT INFO "Cleaning up build files.." - if [[ $controller_type == "default" ]]; then rm ".blueprint/extensions/blueprint/private/build/extensions/controller.build.bak"; fi + if [[ $controller_type == "default" ]]; then rm "$__BuildDir/extensions/controller.build.bak"; fi rm \ "$AdminBladeConstructor" \ "$AdminRouteConstructor" \ - "$AdminButtonConstructor" + "$AdminButtonConstructor" \ + "$ConfigExtensionFS" rm -R ".blueprint/tmp/$n" if [[ $database_migrations != "" ]]; then @@ -1190,12 +1216,16 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD=" $FOLDER/resources \ $FOLDER/routes \ $FOLDER/storage + + # Link filesystems + PRINT INFO "Linking filesystems.." + php artisan storage:link &>> $BLUEPRINT__DEBUG # Flush cache. PRINT INFO "Flushing view, config and route cache.." { - php artisan view:clear - php artisan config:clear + php artisan view:cache + php artisan config:cache php artisan route:cache php artisan cache:clear } &>> $BLUEPRINT__DEBUG @@ -1505,6 +1535,18 @@ if [[ ( $2 == "-r" ) || ( $2 == "-remove" ) ]]; then VCMD="y" rm -R \ ".blueprint/extensions/$identifier/assets" \ "public/assets/extensions/$identifier" + + # Remove extension filesystem (ExtensionFS) + PRINT INFO "Removing and unlinking extension filesystem.." + rm -r \ + ".blueprint/extensions/$identifier/fs" \ + "storage/extensions/sysautomation" \ + "storage/extensions" + sed -i \ + -e "s/\/\* ${identifier^}Start \*\/.*\/\* ${identifier^}End \*\///" \ + -e "s~/\* ${identifier^}Start \*/~~g" \ + -e "s~/\* ${identifier^}End \*/~~g" \ + "config/ExtensionFS.php" # Remove extension directory PRINT INFO "Removing extension folder.." @@ -1528,12 +1570,16 @@ if [[ ( $2 == "-r" ) || ( $2 == "-remove" ) ]]; then VCMD="y" $FOLDER/resources \ $FOLDER/routes \ $FOLDER/storage + + # Link filesystems + PRINT INFO "Linking filesystems.." + php artisan storage:link &>> $BLUEPRINT__DEBUG # Flush cache. PRINT INFO "Flushing view, config and route cache.." { - php artisan view:clear - php artisan config:clear + php artisan view:cache + php artisan config:cache php artisan route:cache php artisan cache:clear } &>> $BLUEPRINT__DEBUG @@ -1694,11 +1740,11 @@ if [[ ( $2 == "-init" || $2 == "-I" ) ]]; then VCMD="y" rm -R tmp/templates cd ${FOLDER} || cdhalt - eval "$(parse_yaml .blueprint/extensions/blueprint/private/build/templates/"${tnum}"/TemplateConfiguration.yml t_)" + eval "$(parse_yaml $__BuildDir/templates/"${tnum}"/TemplateConfiguration.yml t_)" PRINT INFO "Building template.." mkdir -p .blueprint/tmp/init - cp -R .blueprint/extensions/blueprint/private/build/templates/"${tnum}"/contents/* .blueprint/tmp/init/ + cp -R $__BuildDir/templates/"${tnum}"/contents/* .blueprint/tmp/init/ sed -i \ -e "s~␀name␀~${ASKNAME}~g" \ @@ -1722,7 +1768,7 @@ if [[ ( $2 == "-init" || $2 == "-I" ) ]]; then VCMD="y" PRINT INFO "Cleaning up build files.." rm -R \ ".blueprint/tmp" \ - ".blueprint/extensions/blueprint/private/build/templates/"* + "$__BuildDir/templates/"* mkdir -p .blueprint/tmp sendTelemetry "INITIALIZE_DEVELOPMENT_EXTENSION" >> $BLUEPRINT__DEBUG diff --git a/blueprint/extensions/blueprint/private/build/extensions/config/ExtensionFS.build b/blueprint/extensions/blueprint/private/build/extensions/config/ExtensionFS.build new file mode 100644 index 0000000..6e041f6 --- /dev/null +++ b/blueprint/extensions/blueprint/private/build/extensions/config/ExtensionFS.build @@ -0,0 +1 @@ +/* [id^]Start */ 'blueprint:[id]' => [ 'driver' => 'local', 'root' => storage_path('extensions/[id]'), 'url' => env('APP_URL') . '/storage/extensions/[id]', 'visibility' => 'public', 'throw' => false, ], /* [id^]End */ \ No newline at end of file diff --git a/blueprint/lib/logFormat.sh b/blueprint/lib/logFormat.sh index 0f65192..29dcdba 100644 --- a/blueprint/lib/logFormat.sh +++ b/blueprint/lib/logFormat.sh @@ -18,7 +18,8 @@ PRINT() { if [[ $TYPE == "FATAL" ]]; then PRIMARY=$(tput setaf 1); fi if [[ $TYPE == "SUCCESS" ]]; then PRIMARY=$(tput setaf 2); fi if [[ $TYPE == "INPUT" ]]; then PRIMARY=$(tput setaf 5); fi + if [[ $TYPE == "DEBUG" ]]; then PRIMARY="$SECONDARY"; fi - echo -e "${BOLD}${SECONDARY}$DATE${RESET} ${PRIMARY}${TYPE}:${RESET} $MESSAGE" + if [[ $TYPE != "DEBUG" ]]; then echo -e "${BOLD}${SECONDARY}$DATE${RESET} ${PRIMARY}${TYPE}:${RESET} $MESSAGE"; fi echo -e "${BOLD}${SECONDARY}$DATEDEBUG${RESET} ${PRIMARY}${TYPE}:${RESET} $MESSAGE" >> "$FOLDER"/.blueprint/extensions/blueprint/private/debug/logs.txt } \ No newline at end of file diff --git a/config/ExtensionFS.php b/config/ExtensionFS.php new file mode 100644 index 0000000..a3058de --- /dev/null +++ b/config/ExtensionFS.php @@ -0,0 +1,7 @@ + [ + /* blueprint/disks */ + ], +]; \ No newline at end of file diff --git a/public/fs/.gitkeep b/public/fs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/storage/app/public/hello.txt b/storage/app/public/hello.txt deleted file mode 100644 index e75cf6f..0000000 --- a/storage/app/public/hello.txt +++ /dev/null @@ -1 +0,0 @@ -Might be utilized in the future. diff --git a/storage/extensions/.gitkeep b/storage/extensions/.gitkeep new file mode 100644 index 0000000..e69de29