Dateien nur mit Anmeldung, nur Microsoft-Login, mehrere Titelbilder (0.47.0)
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>
This commit is contained in:
Friederich Loheide 2026-09-28 17:26:15 +00:00
parent 47b55b4ce5
commit d91570f118
155 changed files with 1035 additions and 382 deletions

View file

@ -94,6 +94,18 @@ class Branding
return $this->url($this->get('logo_dark')) ?? $this->logoUrl();
}
/**
* Eines der Titelbilder, zufällig je Seitenaufruf.
*
* @param array<string, mixed> $theme
*/
private function randomCover(array $theme): ?string
{
$covers = array_values(array_filter((array) ($theme['profile_covers'] ?? []), 'is_string'));
return $covers !== [] ? $covers[array_rand($covers)] : ($theme['profile_cover'] ?? null);
}
public function url(?string $path): ?string
{
return $path ? Storage::disk('uploads')->url($path) : null;
@ -180,7 +192,7 @@ class Branding
],
// Titelbild in Profil und Begrüßung: eigenes Bild der Person, sonst dieses – immer mit Farbfläche darüber
'profile_cover' => [
'image_url' => $this->url($theme['profile_cover']),
'image_url' => $this->url($this->randomCover($theme)),
'overlay' => $theme['profile_cover_overlay'] / 100,
],
// Platzhalter für Personen ohne Profilbild (sonst Initialen)

View file

@ -0,0 +1,56 @@
<?php
namespace App\Support;
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\Encoders\JpegEncoder;
use Intervention\Image\Encoders\PngEncoder;
use Intervention\Image\Encoders\WebpEncoder;
use Intervention\Image\ImageManager;
use Throwable;
/**
* Bilder beim Hochladen verkleinern und komprimieren – an Ort und Stelle, im selben Format
* (Pfad und Dateiendung bleiben). Höchstens 2400 px; JPEG/WebP verlustbehaftet, PNG verlustfrei
* (Transparenz bleibt). GIF (Animationen), SVG und ICO bleiben unverändert. Wird die Datei nicht
* kleiner, bleibt das Original.
*/
class ImageCompressor
{
public const MAX_EDGE = 2400;
public static function compressFile(string $path): void
{
$info = @getimagesize($path);
if (! $info || ! in_array($info[2], [IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_WEBP], true)) {
return;
}
$size = (int) @filesize($path);
$large = max($info[0], $info[1]) > self::MAX_EDGE;
// Kleine Dateien in passender Größe: nichts zu gewinnen
if (! $large && $size < 200 * 1024) {
return;
}
try {
Images::raiseMemoryLimitFor($path);
$image = ImageManager::usingDriver(Driver::class)->decodePath($path)->scaleDown(self::MAX_EDGE, self::MAX_EDGE);
$encoded = match ($info[2]) {
IMAGETYPE_JPEG => $image->encode(new JpegEncoder(quality: 82, progressive: true)),
IMAGETYPE_PNG => $image->encode(new PngEncoder),
default => $image->encode(new WebpEncoder(quality: 80)),
};
$binary = $encoded->toString();
if ($binary !== '' && (strlen($binary) < $size || $large)) {
file_put_contents($path, $binary);
clearstatcache(true, $path);
}
} catch (Throwable $e) {
report($e);
}
}
}

View file

@ -0,0 +1,66 @@
<?php
namespace App\Support;
use App\Models\IdentityProvider;
use App\Models\User;
use Illuminate\Support\Facades\DB;
/**
* Anmeldung mit Portal-Passwort – abschaltbar, wenn ein Anmeldedienst (z. B. Microsoft) aktiv ist.
*
* Schutz gegen Aussperren: Abschalten geht nur mit einem Konto, das selbst mit einem aktiven
* Dienst verknüpft ist. Ist kein Dienst mehr nutzbar (abgeschaltet, falsch eingerichtet), gilt die
* Passwort-Anmeldung automatisch wieder. Notausgang: INHAUS_PASSWORD_LOGIN=true in der .env.
*/
class PasswordLogin
{
public const SETTING = 'auth.password_login';
public function __construct(private readonly Settings $settings) {}
public function enabled(): bool
{
if (filter_var(config('inhaus.password_login_override'), FILTER_VALIDATE_BOOLEAN)) {
return true;
}
if ($this->settings->get(self::SETTING, true) !== false) {
return true;
}
// Abgeschaltet – aber nur, solange es einen anderen Weg hinein gibt
return IdentityProvider::forLogin()->isEmpty();
}
/** Ist die Passwort-Anmeldung laut Einstellung abgeschaltet (unabhängig vom Notausgang)? */
public function switchedOff(): bool
{
return $this->settings->get(self::SETTING, true) === false;
}
/**
* Darf diese Person die Passwort-Anmeldung abschalten? null = ja, sonst der Grund.
*/
public function cannotDisableReason(User $user): ?string
{
$providers = IdentityProvider::forLogin();
if ($providers->isEmpty()) {
return 'Es ist kein Anmeldedienst (z. B. Microsoft) aktiv und nutzbar.';
}
$linked = DB::table('user_identities')->where('user_id', $user->id)->whereIn('identity_provider_id', $providers->pluck('id'))->exists();
if (! $linked) {
return 'Ihr eigenes Konto ist mit keinem aktiven Anmeldedienst verknüpft – Sie würden sich aussperren. Bitte melden Sie sich einmal über '.$providers->first()->buttonLabel().' an und schalten Sie es dann ab.';
}
return null;
}
public function set(bool $enabled): void
{
$this->settings->set(self::SETTING, $enabled);
}
}

View file

@ -204,6 +204,13 @@ class SiteHealth
'status' => $https ? self::OK : self::WARNING,
'message' => $https ? 'Das Portal läuft über HTTPS.' : 'APP_URL beginnt nicht mit https:// – Anmeldedaten würden unverschlüsselt übertragen.',
],
[
'label' => 'Hochgeladene Dateien',
'status' => UploadsGuard::installed() ? self::OK : self::ERROR,
'message' => UploadsGuard::installed()
? 'Nur mit Anmeldung abrufbar (Ausnahme: Logo und Hintergrund der Anmeldeseite). Auf nginx-Servern die Weiterleitung von /uploads an index.php einrichten (siehe Installationsanleitung).'
: 'Schutzregel public/uploads/.htaccess fehlt oder wurde geändert – Bilder und Dateien könnten ohne Anmeldung abrufbar sein. Bitte Schreibrechte prüfen und die Seite neu laden.',
],
[
'label' => 'Anwendungsschlüssel',
'status' => filled(config('app.key')) ? self::OK : self::ERROR,

View file

@ -35,6 +35,8 @@ class Theme
'login_text' => null,
'login_image' => null,
'profile_cover' => null,
// Mehrere Titelbilder – je Seitenaufruf erscheint zufällig eines (profile_cover = das erste)
'profile_covers' => [],
'avatar_placeholder' => null,
'profile_cover_overlay' => 70,
'footer_text' => null,
@ -206,6 +208,12 @@ class Theme
$theme[$file] = is_string($theme[$file]) && preg_match('#^(theme|branding)/[A-Za-z0-9/_.-]+$#', $theme[$file]) && ! str_contains($theme[$file], '..') ? $theme[$file] : null;
}
// Titelbilder: Liste gültiger Pfade; ein älteres Einzelbild wird übernommen
$validFile = fn ($path) => is_string($path) && preg_match('#^(theme|branding)/[A-Za-z0-9/_.-]+$#', $path) && ! str_contains($path, '..');
$covers = array_values(array_unique(array_filter((array) ($theme['profile_covers'] ?? []), $validFile)));
$theme['profile_covers'] = array_slice($covers !== [] ? $covers : array_filter([$theme['profile_cover']]), 0, 12);
$theme['profile_cover'] = $theme['profile_covers'][0] ?? null;
$theme['custom_css'] = filled($theme['custom_css']) ? mb_substr((string) $theme['custom_css'], 0, 50000) : null;
return $theme;

View file

@ -18,7 +18,7 @@ use Throwable;
class ThemePhotos
{
/** Bildfelder, die Fotos sind (Logos, Symbole und Platzhalter bleiben, wie sie sind) */
public const FIELDS = ['login_image', 'profile_cover'];
public const FIELDS = ['login_image', 'profile_cover', 'profile_covers'];
public const MAX_EDGE = 2400;
@ -34,9 +34,16 @@ class ThemePhotos
foreach (self::FIELDS as $field) {
if (is_string($theme[$field] ?? null) && $theme[$field] !== '') {
$theme[$field] = $this->optimize($theme[$field]);
} elseif (is_array($theme[$field] ?? null)) {
$theme[$field] = array_map(fn ($path) => is_string($path) ? $this->optimize($path) : $path, $theme[$field]);
}
}
// Das erste Titelbild ist zugleich das einzelne (ältere Stellen lesen nur dieses)
if (($theme['profile_covers'] ?? []) !== []) {
$theme['profile_cover'] = $theme['profile_covers'][0];
}
return $theme;
}

View file

@ -40,7 +40,7 @@ class ThemeTransfer
'format' => self::FORMAT,
'version' => 1,
'exported_at' => now()->toIso8601String(),
'theme' => collect($theme)->except([...self::FILES, 'icons', 'stylesheet'])->all(),
'theme' => collect($theme)->except([...self::FILES, 'profile_covers', 'icons', 'stylesheet'])->all(),
'files' => $files,
];
}
@ -56,7 +56,9 @@ class ThemeTransfer
throw new RuntimeException('Die Datei ist kein exportiertes Erscheinungsbild.');
}
$values = collect($data['theme'])->except([...self::FILES, 'icons', 'stylesheet'])->all();
$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;

View file

@ -0,0 +1,50 @@
<?php
namespace App\Support;
/**
* Schutzregel für public/uploads: Der Webserver liefert dort nichts direkt aus, sondern reicht
* jede Anfrage an das Portal weiter, das die Anmeldung prüft (UploadController).
*
* public/uploads ist vor dem Updater geschützt (Kundendaten) – deshalb schreibt eine Migration
* diese Datei bei bestehenden Installationen, neue bekommen sie mit dem Paket.
*/
class UploadsGuard
{
public const HTACCESS = <<<'HTACCESS'
# Hochgeladene Dateien nur über das Portal – es prüft die Anmeldung (UploadController).
# Direkte Links funktionieren ohne Anmeldung nicht. Diese Datei schreibt das Portal selbst.
<IfModule mod_php.c>
php_flag engine off
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^ ../index.php [L]
</IfModule>
# Ohne mod_rewrite lieber gar nichts ausliefern
<IfModule !mod_rewrite.c>
Require all denied
</IfModule>
HTACCESS;
/** Schreibt die Regel; liefert false, wenn das nicht ging */
public static function install(?string $dir = null): bool
{
$dir ??= public_path('uploads');
if (! is_dir($dir) && ! @mkdir($dir, 0775, true)) {
return false;
}
return @file_put_contents($dir.'/.htaccess', self::HTACCESS) !== false;
}
public static function installed(?string $dir = null): bool
{
return @file_get_contents(($dir ?? public_path('uploads')).'/.htaccess') === self::HTACCESS;
}
}