Skip to content

Commit 8621647

Browse files
committed
feat core filesystems: Add new ExtensionFS feature which will create filesystems for each extension automatically.
1 parent efecf45 commit 8621647

File tree

8 files changed

+187
-33
lines changed

8 files changed

+187
-33
lines changed

app/Providers/AppServiceProvider.php

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
namespace Pterodactyl\Providers;
4+
5+
use Pterodactyl\Models;
6+
use Illuminate\Support\Str;
7+
use Illuminate\Support\Facades\URL;
8+
use Illuminate\Pagination\Paginator;
9+
use Illuminate\Support\Facades\View;
10+
use Illuminate\Support\Facades\Cache;
11+
use Illuminate\Support\Facades\Schema;
12+
use Illuminate\Support\ServiceProvider;
13+
use Pterodactyl\Extensions\Themes\Theme;
14+
use Illuminate\Database\Eloquent\Relations\Relation;
15+
16+
class AppServiceProvider extends ServiceProvider
17+
{
18+
/**
19+
* Bootstrap any application services.
20+
*/
21+
public function boot(): void
22+
{
23+
Schema::defaultStringLength(191);
24+
25+
View::share('appVersion', $this->versionData()['version'] ?? 'undefined');
26+
View::share('appIsGit', $this->versionData()['is_git'] ?? false);
27+
28+
Paginator::useBootstrap();
29+
30+
// If the APP_URL value is set with https:// make sure we force it here. Theoretically
31+
// this should just work with the proxy logic, but there are a lot of cases where it
32+
// doesn't, and it triggers a lot of support requests, so lets just head it off here.
33+
//
34+
// @see https://github.com/pterodactyl/panel/issues/3623
35+
if (Str::startsWith(config('app.url') ?? '', 'https://')) {
36+
URL::forceScheme('https');
37+
}
38+
39+
Relation::enforceMorphMap([
40+
'allocation' => Models\Allocation::class,
41+
'api_key' => Models\ApiKey::class,
42+
'backup' => Models\Backup::class,
43+
'database' => Models\Database::class,
44+
'egg' => Models\Egg::class,
45+
'egg_variable' => Models\EggVariable::class,
46+
'schedule' => Models\Schedule::class,
47+
'server' => Models\Server::class,
48+
'ssh_key' => Models\UserSSHKey::class,
49+
'task' => Models\Task::class,
50+
'user' => Models\User::class,
51+
]);
52+
}
53+
54+
/**
55+
* Register application service providers.
56+
*/
57+
public function register(): void
58+
{
59+
// Merge Blueprint configurations with existing configurations.
60+
$this->mergeConfigFrom(base_path('config/ExtensionFS.php'), 'filesystems');
61+
62+
// Only load the settings service provider if the environment
63+
// is configured to allow it.
64+
if (!config('pterodactyl.load_environment_only', false) && $this->app->environment() !== 'testing') {
65+
$this->app->register(SettingsServiceProvider::class);
66+
}
67+
68+
$this->app->singleton('extensions.themes', function () {
69+
return new Theme();
70+
});
71+
}
72+
73+
/**
74+
* Return version information for the footer.
75+
*/
76+
protected function versionData(): array
77+
{
78+
return Cache::remember('git-version', 5, function () {
79+
if (file_exists(base_path('.git/HEAD'))) {
80+
$head = explode(' ', file_get_contents(base_path('.git/HEAD')));
81+
82+
if (array_key_exists(1, $head)) {
83+
$path = base_path('.git/' . trim($head[1]));
84+
}
85+
}
86+
87+
if (isset($path) && file_exists($path)) {
88+
return [
89+
'version' => substr(file_get_contents($path), 0, 8),
90+
'is_git' => true,
91+
];
92+
}
93+
94+
return [
95+
'version' => config('app.version'),
96+
'is_git' => false,
97+
];
98+
});
99+
}
100+
}

blueprint.sh

+77-31
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export BLUEPRINT__FOLDER=$FOLDER
4949
export BLUEPRINT__VERSION=$VERSION
5050
export BLUEPRINT__DEBUG="$FOLDER"/.blueprint/extensions/blueprint/private/debug/logs.txt
5151
export NODE_OPTIONS=--openssl-legacy-provider
52+
# Write internal variables.
53+
__BuildDir=".blueprint/extensions/blueprint/private/build"
5254

5355
# Automatically navigate to the Pterodactyl directory when running the core.
5456
cd $FOLDER || return
@@ -217,8 +219,8 @@ if [[ $1 != "-bash" ]]; then
217219
# Flush cache.
218220
PRINT INFO "Flushing view, config and route cache.."
219221
{
220-
php artisan view:clear
221-
php artisan config:clear
222+
php artisan view:cache
223+
php artisan config:cache
222224
php artisan route:cache
223225
php artisan cache:clear
224226
} &>> $BLUEPRINT__DEBUG
@@ -787,14 +789,14 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD="
787789
if [[ $Components_Navigation_Routes_ != "" ]]; then
788790
PRINT INFO "Linking navigation routes.."
789791

790-
ImportConstructor=".blueprint/extensions/blueprint/private/build/extensions/routes/importConstructor.bak"
791-
AccountRouteConstructor=".blueprint/extensions/blueprint/private/build/extensions/routes/accountRouteConstructor.bak"
792-
ServerRouteConstructor=".blueprint/extensions/blueprint/private/build/extensions/routes/serverRouteConstructor.bak"
792+
ImportConstructor="$__BuildDir/extensions/routes/importConstructor.bak"
793+
AccountRouteConstructor="$__BuildDir/extensions/routes/accountRouteConstructor.bak"
794+
ServerRouteConstructor="$__BuildDir/extensions/routes/serverRouteConstructor.bak"
793795

794796
{
795-
cp ".blueprint/extensions/blueprint/private/build/extensions/routes/importConstructor" "$ImportConstructor"
796-
cp ".blueprint/extensions/blueprint/private/build/extensions/routes/accountRouteConstructor" "$AccountRouteConstructor"
797-
cp ".blueprint/extensions/blueprint/private/build/extensions/routes/serverRouteConstructor" "$ServerRouteConstructor"
797+
cp "$__BuildDir/extensions/routes/importConstructor" "$ImportConstructor"
798+
cp "$__BuildDir/extensions/routes/accountRouteConstructor" "$AccountRouteConstructor"
799+
cp "$__BuildDir/extensions/routes/serverRouteConstructor" "$ServerRouteConstructor"
798800
} 2>> $BLUEPRINT__DEBUG
799801

800802
sed -i "s~\[id\^]~""${identifier^}""~g" $ImportConstructor
@@ -959,16 +961,18 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD="
959961
fi
960962

961963
# Prepare build files.
962-
AdminControllerConstructor=".blueprint/extensions/blueprint/private/build/extensions/controller.build.bak"
963-
AdminBladeConstructor=".blueprint/extensions/blueprint/private/build/extensions/admin.blade.php.bak"
964-
AdminRouteConstructor=".blueprint/extensions/blueprint/private/build/extensions/route.php.bak"
965-
AdminButtonConstructor=".blueprint/extensions/blueprint/private/build/extensions/button.blade.php.bak"
964+
AdminControllerConstructor="$__BuildDir/extensions/controller.build.bak"
965+
AdminBladeConstructor="$__BuildDir/extensions/admin.blade.php.bak"
966+
AdminRouteConstructor="$__BuildDir/extensions/route.php.bak"
967+
AdminButtonConstructor="$__BuildDir/extensions/button.blade.php.bak"
968+
ConfigExtensionFS="$__BuildDir/extensions/config/ExtensionFS.build.bak"
966969

967970
{
968-
if [[ $controller_type == "default" ]]; then cp ".blueprint/extensions/blueprint/private/build/extensions/controller.build" "$AdminControllerConstructor"; fi
969-
cp ".blueprint/extensions/blueprint/private/build/extensions/admin.blade.php" "$AdminBladeConstructor"
970-
cp ".blueprint/extensions/blueprint/private/build/extensions/route.php" "$AdminRouteConstructor"
971-
cp ".blueprint/extensions/blueprint/private/build/extensions/button.blade.php" "$AdminButtonConstructor"
971+
if [[ $controller_type == "default" ]]; then cp "$__BuildDir/extensions/controller.build" "$AdminControllerConstructor"; fi
972+
cp "$__BuildDir/extensions/admin.blade.php" "$AdminBladeConstructor"
973+
cp "$__BuildDir/extensions/route.php" "$AdminRouteConstructor"
974+
cp "$__BuildDir/extensions/button.blade.php" "$AdminButtonConstructor"
975+
cp "$__BuildDir/extensions/config/ExtensionFS.build" "$ConfigExtensionFS"
972976
} 2>> $BLUEPRINT__DEBUG;
973977

974978

@@ -1067,14 +1071,18 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD="
10671071
# Construct admin controller
10681072
if [[ $controller_type == "default" ]]; then sed -i "s~\[id\]~$identifier~g" "$AdminControllerConstructor"; fi
10691073

1074+
# Construct ExtensionFS
1075+
sed -i \
1076+
-e "s~\[id\]~$identifier~g" \
1077+
-e "s~\[id\^\]~${identifier^}~g" \
1078+
"$ConfigExtensionFS"
10701079

10711080
# Read final results.
10721081
ADMINVIEW_RESULT=$(<"$AdminBladeConstructor")
10731082
ADMINROUTE_RESULT=$(<"$AdminRouteConstructor")
10741083
ADMINBUTTON_RESULT=$(<"$AdminButtonConstructor")
1075-
if [[ $controller_type == "default" ]]; then
1076-
ADMINCONTROLLER_RESULT=$(<"$AdminControllerConstructor")
1077-
fi
1084+
if [[ $controller_type == "default" ]]; then ADMINCONTROLLER_RESULT=$(<"$AdminControllerConstructor"); fi
1085+
CONFIGEXTENSIONFS_RESULT=$(<"$ConfigExtensionFS")
10781086
ADMINCONTROLLER_NAME="${identifier}ExtensionController.php"
10791087

10801088
# Place admin extension view.
@@ -1146,18 +1154,36 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD="
11461154
sed -i "/<\!-- wrapper:insert -->/r .blueprint/tmp/$n/$admin_wrapper" "resources/views/blueprint/admin/admin.blade.php"
11471155
fi
11481156

1157+
# Create extension filesystem (ExtensionFS)
1158+
PRINT INFO "Creating and linking extension filesystem.."
1159+
mkdir -p ".blueprint/extensions/$identifier/fs"
1160+
ln -s -T $FOLDER/.blueprint/extensions/"$identifier"/fs "$FOLDER/storage/extensions/$identifier" 2>> $BLUEPRINT__DEBUG
1161+
ln -s -T $FOLDER/storage/extensions/"$identifier" "$FOLDER/public/fs/$identifier" 2>> $BLUEPRINT__DEBUG
1162+
if [[ $DUPLICATE == "y" ]]; then
1163+
sed -i \
1164+
-e "s/\/\* ${identifier^}Start \*\/.*\/\* ${identifier^}End \*\///" \
1165+
-e "s~/\* ${identifier^}Start \*/~~g" \
1166+
-e "s~/\* ${identifier^}End \*/~~g" \
1167+
"config/ExtensionFS.php"
1168+
fi
1169+
sed -i "s~\/\* blueprint/disks \*\/~/* blueprint/disks */$CONFIGEXTENSIONFS_RESULT~g" config/ExtensionFS.php
1170+
11491171
# Create backup of generated values.
1150-
mkdir -p ".blueprint/extensions/$identifier/private/.store/build"
1151-
cp ".blueprint/extensions/blueprint/private/build/extensions/button.blade.php.bak" ".blueprint/extensions/$identifier/private/.store/build/button.blade.php"
1152-
cp ".blueprint/extensions/blueprint/private/build/extensions/route.php.bak" ".blueprint/extensions/$identifier/private/.store/build/route.php"
1172+
mkdir -p \
1173+
".blueprint/extensions/$identifier/private/.store/build" \
1174+
".blueprint/extensions/$identifier/private/.store/build/config"
1175+
cp "$__BuildDir/extensions/button.blade.php.bak" ".blueprint/extensions/$identifier/private/.store/build/button.blade.php"
1176+
cp "$__BuildDir/extensions/route.php.bak" ".blueprint/extensions/$identifier/private/.store/build/route.php"
1177+
cp "$__BuildDir/extensions/config/ExtensionFS.build.bak" ".blueprint/extensions/$identifier/private/.store/build/config/ExtensionFS.build"
11531178

11541179
# Remove temporary build files.
11551180
PRINT INFO "Cleaning up build files.."
1156-
if [[ $controller_type == "default" ]]; then rm ".blueprint/extensions/blueprint/private/build/extensions/controller.build.bak"; fi
1181+
if [[ $controller_type == "default" ]]; then rm "$__BuildDir/extensions/controller.build.bak"; fi
11571182
rm \
11581183
"$AdminBladeConstructor" \
11591184
"$AdminRouteConstructor" \
1160-
"$AdminButtonConstructor"
1185+
"$AdminButtonConstructor" \
1186+
"$ConfigExtensionFS"
11611187
rm -R ".blueprint/tmp/$n"
11621188

11631189
if [[ $database_migrations != "" ]]; then
@@ -1190,12 +1216,16 @@ if [[ ( $2 == "-i" ) || ( $2 == "-install" ) || ( $2 == "-add" ) ]]; then VCMD="
11901216
$FOLDER/resources \
11911217
$FOLDER/routes \
11921218
$FOLDER/storage
1219+
1220+
# Link filesystems
1221+
PRINT INFO "Linking filesystems.."
1222+
php artisan storage:link &>> $BLUEPRINT__DEBUG
11931223

11941224
# Flush cache.
11951225
PRINT INFO "Flushing view, config and route cache.."
11961226
{
1197-
php artisan view:clear
1198-
php artisan config:clear
1227+
php artisan view:cache
1228+
php artisan config:cache
11991229
php artisan route:cache
12001230
php artisan cache:clear
12011231
} &>> $BLUEPRINT__DEBUG
@@ -1505,6 +1535,18 @@ if [[ ( $2 == "-r" ) || ( $2 == "-remove" ) ]]; then VCMD="y"
15051535
rm -R \
15061536
".blueprint/extensions/$identifier/assets" \
15071537
"public/assets/extensions/$identifier"
1538+
1539+
# Remove extension filesystem (ExtensionFS)
1540+
PRINT INFO "Removing and unlinking extension filesystem.."
1541+
rm -r \
1542+
".blueprint/extensions/$identifier/fs" \
1543+
"storage/extensions/sysautomation" \
1544+
"storage/extensions"
1545+
sed -i \
1546+
-e "s/\/\* ${identifier^}Start \*\/.*\/\* ${identifier^}End \*\///" \
1547+
-e "s~/\* ${identifier^}Start \*/~~g" \
1548+
-e "s~/\* ${identifier^}End \*/~~g" \
1549+
"config/ExtensionFS.php"
15081550

15091551
# Remove extension directory
15101552
PRINT INFO "Removing extension folder.."
@@ -1528,12 +1570,16 @@ if [[ ( $2 == "-r" ) || ( $2 == "-remove" ) ]]; then VCMD="y"
15281570
$FOLDER/resources \
15291571
$FOLDER/routes \
15301572
$FOLDER/storage
1573+
1574+
# Link filesystems
1575+
PRINT INFO "Linking filesystems.."
1576+
php artisan storage:link &>> $BLUEPRINT__DEBUG
15311577

15321578
# Flush cache.
15331579
PRINT INFO "Flushing view, config and route cache.."
15341580
{
1535-
php artisan view:clear
1536-
php artisan config:clear
1581+
php artisan view:cache
1582+
php artisan config:cache
15371583
php artisan route:cache
15381584
php artisan cache:clear
15391585
} &>> $BLUEPRINT__DEBUG
@@ -1694,11 +1740,11 @@ if [[ ( $2 == "-init" || $2 == "-I" ) ]]; then VCMD="y"
16941740
rm -R tmp/templates
16951741
cd ${FOLDER} || cdhalt
16961742

1697-
eval "$(parse_yaml .blueprint/extensions/blueprint/private/build/templates/"${tnum}"/TemplateConfiguration.yml t_)"
1743+
eval "$(parse_yaml $__BuildDir/templates/"${tnum}"/TemplateConfiguration.yml t_)"
16981744

16991745
PRINT INFO "Building template.."
17001746
mkdir -p .blueprint/tmp/init
1701-
cp -R .blueprint/extensions/blueprint/private/build/templates/"${tnum}"/contents/* .blueprint/tmp/init/
1747+
cp -R $__BuildDir/templates/"${tnum}"/contents/* .blueprint/tmp/init/
17021748

17031749
sed -i \
17041750
-e "s~␀name␀~${ASKNAME}~g" \
@@ -1722,7 +1768,7 @@ if [[ ( $2 == "-init" || $2 == "-I" ) ]]; then VCMD="y"
17221768
PRINT INFO "Cleaning up build files.."
17231769
rm -R \
17241770
".blueprint/tmp" \
1725-
".blueprint/extensions/blueprint/private/build/templates/"*
1771+
"$__BuildDir/templates/"*
17261772
mkdir -p .blueprint/tmp
17271773

17281774
sendTelemetry "INITIALIZE_DEVELOPMENT_EXTENSION" >> $BLUEPRINT__DEBUG
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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 */

blueprint/lib/logFormat.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ PRINT() {
1818
if [[ $TYPE == "FATAL" ]]; then PRIMARY=$(tput setaf 1); fi
1919
if [[ $TYPE == "SUCCESS" ]]; then PRIMARY=$(tput setaf 2); fi
2020
if [[ $TYPE == "INPUT" ]]; then PRIMARY=$(tput setaf 5); fi
21+
if [[ $TYPE == "DEBUG" ]]; then PRIMARY="$SECONDARY"; fi
2122

22-
echo -e "${BOLD}${SECONDARY}$DATE${RESET} ${PRIMARY}${TYPE}:${RESET} $MESSAGE"
23+
if [[ $TYPE != "DEBUG" ]]; then echo -e "${BOLD}${SECONDARY}$DATE${RESET} ${PRIMARY}${TYPE}:${RESET} $MESSAGE"; fi
2324
echo -e "${BOLD}${SECONDARY}$DATEDEBUG${RESET} ${PRIMARY}${TYPE}:${RESET} $MESSAGE" >> "$FOLDER"/.blueprint/extensions/blueprint/private/debug/logs.txt
2425
}

config/ExtensionFS.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
return [
4+
'disks' => [
5+
/* blueprint/disks */
6+
],
7+
];

public/fs/.gitkeep

Whitespace-only changes.

storage/app/public/hello.txt

-1
This file was deleted.

storage/extensions/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)