From d1df6e65e2d00c0e8512dc40e064794cfad3e505 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 7 Nov 2023 12:33:42 +0100 Subject: [PATCH] wait #6446 @0.5 --- app/Models/FluidbookExternalInstallServer.php | 37 +++++++++++++++++++ composer.lock | 36 +++++++++--------- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/app/Models/FluidbookExternalInstallServer.php b/app/Models/FluidbookExternalInstallServer.php index 55d8e0176..689556394 100644 --- a/app/Models/FluidbookExternalInstallServer.php +++ b/app/Models/FluidbookExternalInstallServer.php @@ -3,9 +3,13 @@ namespace App\Models; use Cubist\Backpack\Magic\Fields\Checkbox; +use Cubist\Backpack\Magic\Fields\Table; use Cubist\Backpack\Magic\Fields\Text; use Cubist\Backpack\Magic\Models\ExternalServer; use Cubist\Net\Transfer\Local; +use Cubist\Util\Files\Files; +use Cubist\Util\Json; + // __('!! Serveurs externes') class FluidbookExternalInstallServer extends ExternalServer { @@ -25,9 +29,42 @@ class FluidbookExternalInstallServer extends ExternalServer public function setFields() { parent::setFields(); + $this->addField('redirections', Table::class, __('Redirections'), ['entity_singular' => __('redirection'), 'columns' => ['from' => __('De'), 'to' => __('Vers')], 'when' => ['protocol' => 'hosting']]); $this->addField('allows_root', Checkbox::class, __('Autoriser le chargement à la racine (sur le chemin de base)'), ['default' => false]); } + public function onSaved(): bool + { + $this->updateHtaccess(); + return parent::onSaved(); + } + + protected function updateHtaccess() + { + if ($this->getProtocol() === 'hosting') { + + $redirections = Json::isJson($this->redirections) ? json_decode($this->redirections, true) : $this->redirections; + + $content = ' + + Options -MultiViews -Indexes + + RewriteEngine On + # Handle Authorization Header + RewriteCond %{HTTP:Authorization} . + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] +'; + foreach ($redirections as $redirection) { + $content .= ' RewriteRule ' . $redirection['from'] . ' /' . ltrim($redirection['to'], '/') . " [R=308,L]\n"; + } + $content .= '' . "\n"; + $tmp = Files::tempnam(); + file_put_contents($tmp, $content); + $this->getTransferDriver()->copyFile($tmp, '.htaccess'); + unlink($tmp); + } + } + public function getProtocols() { return parent::getProtocols() + ['hosting' => 'Hosting']; diff --git a/composer.lock b/composer.lock index 6ddcf3326..7739e0aeb 100644 --- a/composer.lock +++ b/composer.lock @@ -2050,13 +2050,13 @@ "source": { "type": "git", "url": "git://git.cubedesigners.com/cubist_net.git", - "reference": "f0203ae9addff45df5811cd5d68d64b77de829da" + "reference": "a67603800a93bde7294c450a99a862d2f51b219a" }, "dist": { "type": "tar", - "url": "https://composer.cubedesigners.com/dist/cubist/net/cubist-net-dev-master-52aa4b.tar", - "reference": "f0203ae9addff45df5811cd5d68d64b77de829da", - "shasum": "1fc86d55ae26e48ea286a4fa0ac6e82cd1a09e0a" + "url": "https://composer.cubedesigners.com/dist/cubist/net/cubist-net-dev-master-b429cc.tar", + "reference": "a67603800a93bde7294c450a99a862d2f51b219a", + "shasum": "f2a91449c8b133fc14b1130d4b7c1c55482c6bf0" }, "require": { "cubist/util": "dev-master", @@ -2080,7 +2080,7 @@ } ], "description": "net cubist composer package", - "time": "2023-04-19T09:17:27+00:00" + "time": "2023-11-07T11:19:05+00:00" }, { "name": "cubist/pdf", @@ -5760,16 +5760,16 @@ }, { "name": "league/flysystem", - "version": "3.18.0", + "version": "3.19.0", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "015633a05aee22490495159237a5944091d8281e" + "reference": "1b2aa10f2326e0351399b8ce68e287d8e9209a83" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/015633a05aee22490495159237a5944091d8281e", - "reference": "015633a05aee22490495159237a5944091d8281e", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/1b2aa10f2326e0351399b8ce68e287d8e9209a83", + "reference": "1b2aa10f2326e0351399b8ce68e287d8e9209a83", "shasum": "" }, "require": { @@ -5834,7 +5834,7 @@ ], "support": { "issues": "https://github.com/thephpleague/flysystem/issues", - "source": "https://github.com/thephpleague/flysystem/tree/3.18.0" + "source": "https://github.com/thephpleague/flysystem/tree/3.19.0" }, "funding": [ { @@ -5846,20 +5846,20 @@ "type": "github" } ], - "time": "2023-10-20T17:59:40+00:00" + "time": "2023-11-07T09:04:28+00:00" }, { "name": "league/flysystem-local", - "version": "3.18.0", + "version": "3.19.0", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem-local.git", - "reference": "e7381ef7643f658b87efb7dbe98fe538fb1bbf32" + "reference": "8d868217f9eeb4e9a7320db5ccad825e9a7a4076" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem-local/zipball/e7381ef7643f658b87efb7dbe98fe538fb1bbf32", - "reference": "e7381ef7643f658b87efb7dbe98fe538fb1bbf32", + "url": "https://api.github.com/repos/thephpleague/flysystem-local/zipball/8d868217f9eeb4e9a7320db5ccad825e9a7a4076", + "reference": "8d868217f9eeb4e9a7320db5ccad825e9a7a4076", "shasum": "" }, "require": { @@ -5894,7 +5894,7 @@ ], "support": { "issues": "https://github.com/thephpleague/flysystem-local/issues", - "source": "https://github.com/thephpleague/flysystem-local/tree/3.18.0" + "source": "https://github.com/thephpleague/flysystem-local/tree/3.19.0" }, "funding": [ { @@ -5906,7 +5906,7 @@ "type": "github" } ], - "time": "2023-10-19T20:07:13+00:00" + "time": "2023-11-06T20:35:28+00:00" }, { "name": "league/glide", @@ -17302,5 +17302,5 @@ "ext-zlib": "*" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.1.0" } -- 2.39.5