Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m25s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m52s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 8m5s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m33s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m53s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 9m1s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m49s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 54s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m4s
- /uploads nur über das Portal: UploadController prüft Sitzung bzw. App-Token; frei nur die Dateien der Anmeldeseite (Logos, Symbole, Anmeldehintergrund, Stylesheet, Schrift); public/uploads/.htaccess leitet alles an index.php (Migration schreibt sie, da der Ordner vor dem Updater geschützt ist); Systemzustand prüft die Regel; nginx-Hinweis in docs/SECURITY.md - Passwort-Anmeldung abschaltbar (PasswordLogin): Login-Formular, Passwort vergessen, App-Token und /api/v1/config; nur mit verknüpftem Konto abschaltbar, automatische Rückkehr ohne nutzbaren Dienst, Notausgang INHAUS_PASSWORD_LOGIN - Titelbilder: profile_covers (bis 12), zufällig je Seitenaufruf - ImageCompressor: Uploads im Backend (SafeUpload) und WordPress-Import auf ≤ 2400 px komprimiert, Format bleibt Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
94 lines
3.3 KiB
PHP
94 lines
3.3 KiB
PHP
<?php
|
||
|
||
namespace App\Support\Theme;
|
||
|
||
use Illuminate\Support\Facades\Storage;
|
||
use Illuminate\Support\Str;
|
||
use RuntimeException;
|
||
|
||
/**
|
||
* Erscheinungsbild als Datei – z. B. vom Test- auf das Produktivsystem.
|
||
* Bilder und Schrift reisen als Daten-URLs mit.
|
||
*/
|
||
class ThemeTransfer
|
||
{
|
||
public const FORMAT = 'inhaus-theme';
|
||
|
||
private const FILES = ['logo_light', 'logo_dark', 'logo_mark', 'app_icon', 'login_image', 'profile_cover', 'avatar_placeholder', 'custom_font'];
|
||
|
||
private const MIME = [
|
||
'image/svg+xml' => 'svg', 'image/png' => 'png', 'image/jpeg' => 'jpg', 'image/webp' => 'webp', 'font/woff2' => 'woff2',
|
||
];
|
||
|
||
/**
|
||
* @param array<string, mixed> $theme
|
||
* @return array<string, mixed>
|
||
*/
|
||
public function export(array $theme): array
|
||
{
|
||
$disk = Storage::disk('uploads');
|
||
$files = [];
|
||
|
||
foreach (self::FILES as $key) {
|
||
if ($theme[$key] && $disk->exists($theme[$key])) {
|
||
$mime = $key === 'custom_font' ? 'font/woff2' : ($disk->mimeType($theme[$key]) ?: 'application/octet-stream');
|
||
$files[$key] = 'data:'.$mime.';base64,'.base64_encode((string) $disk->get($theme[$key]));
|
||
}
|
||
}
|
||
|
||
return [
|
||
'format' => self::FORMAT,
|
||
'version' => 1,
|
||
'exported_at' => now()->toIso8601String(),
|
||
'theme' => collect($theme)->except([...self::FILES, 'profile_covers', 'icons', 'stylesheet'])->all(),
|
||
'files' => $files,
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @return array<string, mixed> Werte für den Entwurf
|
||
*/
|
||
public function import(string $json): array
|
||
{
|
||
$data = json_decode($json, true);
|
||
|
||
if (! is_array($data) || ($data['format'] ?? null) !== self::FORMAT || ! is_array($data['theme'] ?? null)) {
|
||
throw new RuntimeException('Die Datei ist kein exportiertes Erscheinungsbild.');
|
||
}
|
||
|
||
$values = collect($data['theme'])->except([...self::FILES, 'profile_covers', 'icons', 'stylesheet'])->all();
|
||
// Titelbilder: übernommen wird das eine exportierte (die Liste zeigte auf Dateien dieser Installation)
|
||
$values['profile_covers'] = [];
|
||
|
||
foreach (self::FILES as $key) {
|
||
$values[$key] = null;
|
||
$uri = $data['files'][$key] ?? null;
|
||
|
||
if (! is_string($uri) || ! preg_match('#^data:([a-z0-9.+/-]+);base64,(.+)$#i', $uri, $m)) {
|
||
continue;
|
||
}
|
||
|
||
$extension = self::MIME[strtolower($m[1])] ?? null;
|
||
$binary = base64_decode($m[2], true);
|
||
|
||
if (! $extension || $binary === false || strlen($binary) > 8 * 1024 * 1024) {
|
||
continue;
|
||
}
|
||
|
||
// Inhalt prüfen: Bilder müssen sich lesen lassen, SVG wird von allem Ausführbaren befreit.
|
||
if ($extension === 'svg' && ($binary = SvgSanitizer::sanitize($binary)) === null) {
|
||
continue;
|
||
}
|
||
|
||
if (in_array($extension, ['png', 'jpg', 'webp'], true) && @getimagesizefromstring($binary) === false) {
|
||
continue;
|
||
}
|
||
|
||
$path = ($key === 'custom_font' ? 'theme/fonts/' : 'theme/').'import-'.Str::random(20).'.'.$extension;
|
||
Storage::disk('uploads')->put($path, $binary);
|
||
$values[$key] = $path;
|
||
}
|
||
|
||
return Theme::normalize([...Theme::DEFAULTS, ...$values]);
|
||
}
|
||
}
|