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
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:
parent
47b55b4ce5
commit
d91570f118
155 changed files with 1035 additions and 382 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Filament\Components;
|
||||
|
||||
use App\Support\ImageCompressor;
|
||||
use Filament\Forms\Components\BaseFileUpload;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
|
|
@ -34,7 +36,15 @@ final class SafeUpload
|
|||
{
|
||||
return $upload
|
||||
->acceptedFileTypes($types)
|
||||
->getUploadedFileNameForStorageUsing(fn (TemporaryUploadedFile $file) => self::name($file, $forcedExtension));
|
||||
->getUploadedFileNameForStorageUsing(fn (TemporaryUploadedFile $file) => self::name($file, $forcedExtension))
|
||||
// Bilder vor dem Ablegen verkleinern und komprimieren (Kamerafotos haben oft mehrere MB)
|
||||
->saveUploadedFileUsing(function (BaseFileUpload $component, TemporaryUploadedFile $file): ?string {
|
||||
if (str_starts_with((string) $file->getMimeType(), 'image/') && is_file((string) $file->getRealPath())) {
|
||||
ImageCompressor::compressFile((string) $file->getRealPath());
|
||||
}
|
||||
|
||||
return $component->saveUploadedFile($file);
|
||||
});
|
||||
}
|
||||
|
||||
public static function name(TemporaryUploadedFile $file, ?string $forcedExtension = null): string
|
||||
|
|
|
|||
|
|
@ -24,8 +24,9 @@ class AppearanceProfile extends AppearancePage
|
|||
return [
|
||||
static::image('avatar_placeholder', 'Platzhalter für Profilbilder', 'Erscheint überall dort, wo eine Person kein eigenes Profilbild hat – z. B. ein Signet oder eine Silhouette. Quadratisch, mindestens 256 × 256 Pixel. Leer = Initialen in einer Farbe je Person.')
|
||||
->image()->acceptedFileTypes(['image/png', 'image/jpeg', 'image/webp', 'image/svg+xml'])->columnSpanFull(),
|
||||
static::image('profile_cover', 'Standard-Titelbild', 'Erscheint oben im Profil und in der Begrüßung auf der Startseite, wenn eine Person kein eigenes Titelbild hochgeladen hat. Querformat, mindestens 1600 Pixel breit. Leer = Fläche in der Markenfarbe.')
|
||||
->image()->acceptedFileTypes(['image/jpeg', 'image/png', 'image/webp'])->maxSize(8192)->columnSpanFull(),
|
||||
static::image('profile_covers', 'Titelbilder (Begrüßung und Profil)', 'Erscheinen in der Begrüßung auf der Startseite und oben im Profil, wenn eine Person kein eigenes Titelbild hat. Mehrere möglich (bis zu 12) – bei jedem Seitenaufruf erscheint zufällig eines. Querformat, mindestens 1600 Pixel breit; große Fotos werden automatisch verkleinert. Leer = Fläche in der Markenfarbe.')
|
||||
->image()->acceptedFileTypes(['image/jpeg', 'image/png', 'image/webp'])->maxSize(12288)
|
||||
->multiple()->reorderable()->appendFiles()->maxFiles(12)->panelLayout('grid')->columnSpanFull(),
|
||||
Radio::make('profile_cover_overlay')->label('Farbfläche über dem Titelbild')
|
||||
->helperText('Titelbilder liegen immer unter einer leicht durchsichtigen Fläche in der Markenfarbe – so bleiben Name und Text gut lesbar und alle Profile wirken einheitlich.')
|
||||
->options(Theme::COVER_OVERLAYS)->inline()->required()->columnSpanFull(),
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@ namespace App\Filament\Resources\IdentityProviders\Pages;
|
|||
|
||||
use App\Filament\Resources\IdentityProviders\IdentityProviderResource;
|
||||
use App\Identity\IdentityDrivers;
|
||||
use App\Support\Audit;
|
||||
use App\Support\PasswordLogin;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
|
||||
|
|
@ -13,6 +16,17 @@ class ListIdentityProviders extends ListRecords
|
|||
{
|
||||
protected static string $resource = IdentityProviderResource::class;
|
||||
|
||||
public function getSubheading(): ?string
|
||||
{
|
||||
$passwords = app(PasswordLogin::class);
|
||||
|
||||
return match (true) {
|
||||
! $passwords->switchedOff() => 'Anmeldung mit E-Mail und Passwort: eingeschaltet.',
|
||||
$passwords->enabled() => 'Anmeldung mit Passwort ist abgeschaltet, gilt aber gerade trotzdem – kein Anmeldedienst nutzbar oder Notausgang INHAUS_PASSWORD_LOGIN aktiv.',
|
||||
default => 'Anmeldung nur über den Anmeldedienst – Passwort-Anmeldung abgeschaltet.',
|
||||
};
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
$actions = collect(app(IdentityDrivers::class)->all())->map(fn ($driver, $type) => Action::make('create_'.$type)
|
||||
|
|
@ -21,7 +35,35 @@ class ListIdentityProviders extends ListRecords
|
|||
->url(IdentityProviderResource::getUrl('create', ['typ' => $type])))
|
||||
->values()->all();
|
||||
|
||||
$passwords = app(PasswordLogin::class);
|
||||
|
||||
return [
|
||||
// Nur Microsoft & Co.: Anmeldung mit Portal-Passwort abschalten (mit Schutz gegen Aussperren)
|
||||
Action::make('passwordOff')->label('Passwort-Anmeldung abschalten')->icon(Heroicon::OutlinedLockClosed)->color('gray')
|
||||
->visible(fn () => ! $passwords->switchedOff())
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Nur noch über den Anmeldedienst anmelden?')
|
||||
->modalDescription('Das Anmeldeformular mit E-Mail und Passwort, „Passwort vergessen“ und die Passwort-Anmeldung der App werden abgeschaltet – angemeldet wird nur noch z. B. über Microsoft. Fällt der Dienst aus oder wird er deaktiviert, gilt die Passwort-Anmeldung automatisch wieder. Notausgang: INHAUS_PASSWORD_LOGIN=true in der .env.')
|
||||
->modalSubmitActionLabel('Abschalten')
|
||||
->action(function () use ($passwords) {
|
||||
if ($reason = $passwords->cannotDisableReason(auth()->user())) {
|
||||
Notification::make()->danger()->title('Nicht abgeschaltet')->body($reason)->persistent()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$passwords->set(false);
|
||||
Audit::log('auth.password_login_disabled');
|
||||
Notification::make()->success()->title('Passwort-Anmeldung abgeschaltet')->body('Angemeldet wird jetzt nur noch über den Anmeldedienst.')->send();
|
||||
}),
|
||||
Action::make('passwordOn')->label('Passwort-Anmeldung wieder einschalten')->icon(Heroicon::OutlinedLockOpen)->color('gray')
|
||||
->visible(fn () => $passwords->switchedOff())
|
||||
->requiresConfirmation()
|
||||
->action(function () use ($passwords) {
|
||||
$passwords->set(true);
|
||||
Audit::log('auth.password_login_enabled');
|
||||
Notification::make()->success()->title('Passwort-Anmeldung eingeschaltet')->send();
|
||||
}),
|
||||
ActionGroup::make($actions)->label('Anmeldeverfahren hinzufügen')->icon(Heroicon::OutlinedPlus)->button()->color('primary'),
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use App\Models\User;
|
|||
use App\Push\AppDevice;
|
||||
use App\Support\AppConnect;
|
||||
use App\Support\Branding;
|
||||
use App\Support\PasswordLogin;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
|
@ -29,7 +30,7 @@ class AppController extends Controller
|
|||
'logo_dark_url' => $branding->logoDarkUrl(),
|
||||
'icon_url' => $branding->url($icons[512] ?? $icons['512'] ?? $icons[192] ?? $icons['192'] ?? null) ?? $branding->faviconUrl(),
|
||||
'login' => [
|
||||
'password' => true,
|
||||
'password' => app(PasswordLogin::class)->enabled(),
|
||||
'browser' => true,
|
||||
'providers' => IdentityProvider::forLogin()->map->toLoginButton()->pluck('label')->filter()->values(),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use App\Plugins\PluginAccess;
|
|||
use App\Plugins\PluginManager;
|
||||
use App\Providers\FortifyServiceProvider;
|
||||
use App\Support\Audit;
|
||||
use App\Support\PasswordLogin;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
|
@ -23,6 +24,10 @@ class AuthController extends Controller
|
|||
*/
|
||||
public function token(Request $request): JsonResponse
|
||||
{
|
||||
if (! app(PasswordLogin::class)->enabled()) {
|
||||
throw ValidationException::withMessages(['email' => 'Die Anmeldung mit Passwort ist abgeschaltet – bitte „Im Browser anmelden“ wählen.']);
|
||||
}
|
||||
|
||||
$data = $request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'string'],
|
||||
|
|
|
|||
81
app/Http/Controllers/UploadController.php
Normal file
81
app/Http/Controllers/UploadController.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Support\Theme\Theme;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Hochgeladene Dateien (public/uploads) nur für angemeldete Personen – Browser-Sitzung oder
|
||||
* App-Token. Der Webserver reicht jede Anfrage unter /uploads an das Portal weiter
|
||||
* (public/uploads/.htaccess), direkte Links funktionieren ohne Anmeldung also nicht.
|
||||
*
|
||||
* Ausnahme: was die Anmeldeseite braucht (Logos, App-Symbol, Favicons, Hintergrundbild,
|
||||
* Stylesheet und eigene Schrift des veröffentlichten Erscheinungsbilds).
|
||||
*/
|
||||
class UploadController extends Controller
|
||||
{
|
||||
/** Ausgelieferte Dateitypen */
|
||||
public const TYPES = [
|
||||
'webp' => 'image/webp', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif',
|
||||
'svg' => 'image/svg+xml', 'ico' => 'image/x-icon', 'avif' => 'image/avif', 'css' => 'text/css',
|
||||
'woff' => 'font/woff', 'woff2' => 'font/woff2',
|
||||
];
|
||||
|
||||
/** Theme-Felder, die zwar Bilder sind, aber nicht auf die Anmeldeseite gehören */
|
||||
private const PRIVATE_THEME_FIELDS = ['profile_cover', 'profile_covers', 'avatar_placeholder'];
|
||||
|
||||
public function __invoke(Request $request, string $path): Response
|
||||
{
|
||||
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||
|
||||
abort_if(str_contains($path, '..') || str_contains($path, "\0") || ! isset(self::TYPES[$extension]), 404);
|
||||
|
||||
$public = $this->isLoginAsset($path);
|
||||
|
||||
// Nicht angemeldet: nicht verraten, ob es die Datei gibt
|
||||
abort_unless($public || $request->user() || auth('sanctum')->user(), 404);
|
||||
|
||||
$disk = Storage::disk('uploads');
|
||||
$root = realpath($disk->path(''));
|
||||
$file = realpath($disk->path($path));
|
||||
|
||||
abort_unless($root && $file && str_starts_with($file, $root.DIRECTORY_SEPARATOR) && is_file($file), 404);
|
||||
|
||||
$response = new BinaryFileResponse($file, 200, [
|
||||
'Content-Type' => self::TYPES[$extension],
|
||||
'X-Content-Type-Options' => 'nosniff',
|
||||
// SVG-Dateien dürfen kein Skript ausführen, auch wenn man sie direkt öffnet
|
||||
'Content-Security-Policy' => "default-src 'none'; img-src 'self' data:; style-src 'unsafe-inline'; font-src 'self'; sandbox",
|
||||
// Dateinamen ändern sich mit jedem Upload; geschützte Dateien nur im eigenen Browser zwischenspeichern
|
||||
'Cache-Control' => ($public ? 'public' : 'private').', max-age=31536000, immutable',
|
||||
], $public, null, true, true);
|
||||
|
||||
$response->isNotModified($request);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function isLoginAsset(string $path): bool
|
||||
{
|
||||
if (! str_starts_with($path, 'theme/')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$theme = app(Theme::class)->published();
|
||||
|
||||
foreach (self::PRIVATE_THEME_FIELDS as $field) {
|
||||
unset($theme[$field]);
|
||||
}
|
||||
|
||||
$found = false;
|
||||
array_walk_recursive($theme, function ($value) use ($path, &$found) {
|
||||
$found = $found || $value === $path;
|
||||
});
|
||||
|
||||
return $found;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Support\PasswordLogin;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
|
|
@ -9,12 +10,18 @@ use Symfony\Component\HttpFoundation\Response;
|
|||
|
||||
/**
|
||||
* „Passwort vergessen“ und „Passwort zurücksetzen“ begrenzen (Fortify drosselt diese Wege nicht):
|
||||
* gegen Massenmails und das Durchprobieren von Adressen.
|
||||
* gegen Massenmails und das Durchprobieren von Adressen. Ist die Passwort-Anmeldung abgeschaltet,
|
||||
* sind beide gesperrt.
|
||||
*/
|
||||
class ThrottlePasswordReset
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
// Passwort-Anmeldung abgeschaltet (nur Microsoft & Co.): dann auch kein Zurücksetzen
|
||||
if ($request->routeIs('password.request', 'password.email', 'password.reset', 'password.update') && ! app(PasswordLogin::class)->enabled()) {
|
||||
return redirect()->route('login')->with('status', 'Die Anmeldung mit Passwort ist abgeschaltet – bitte über den Anmeldedienst anmelden.');
|
||||
}
|
||||
|
||||
if ($request->isMethod('POST') && $request->routeIs('password.email', 'password.update')) {
|
||||
$key = 'password-reset:'.$request->ip();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use App\Http\Responses\NeutralPasswordResetLinkResponse;
|
|||
use App\Models\IdentityProvider;
|
||||
use App\Models\User;
|
||||
use App\Support\Audit;
|
||||
use App\Support\PasswordLogin;
|
||||
use Illuminate\Auth\Events\Failed;
|
||||
use Illuminate\Auth\Events\Login;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
|
|
@ -18,6 +19,7 @@ use Illuminate\Support\Facades\Hash;
|
|||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Inertia;
|
||||
use Laravel\Fortify\Contracts\FailedPasswordResetLinkRequestResponse;
|
||||
use Laravel\Fortify\Contracts\SuccessfulPasswordResetLinkRequestResponse;
|
||||
|
|
@ -38,7 +40,8 @@ class FortifyServiceProvider extends ServiceProvider
|
|||
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
|
||||
|
||||
Fortify::loginView(fn (Request $request) => Inertia::render('Auth/Login', [
|
||||
'canResetPassword' => true,
|
||||
'canResetPassword' => app(PasswordLogin::class)->enabled(),
|
||||
'passwordLogin' => app(PasswordLogin::class)->enabled(),
|
||||
'providers' => IdentityProvider::forLogin()->map->toLoginButton()->values(),
|
||||
'identityError' => $request->session()->get('identity_error'),
|
||||
'status' => $request->boolean('eingerichtet')
|
||||
|
|
@ -58,6 +61,10 @@ class FortifyServiceProvider extends ServiceProvider
|
|||
// Deaktivierte Konten und Konten ohne lokales Passwort (später: nur IdP) können
|
||||
// sich nicht per Passwort anmelden.
|
||||
Fortify::authenticateUsing(function (Request $request): ?User {
|
||||
if (! app(PasswordLogin::class)->enabled()) {
|
||||
throw ValidationException::withMessages([Fortify::username() => 'Die Anmeldung mit Passwort ist abgeschaltet – bitte über den Anmeldedienst oben anmelden.']);
|
||||
}
|
||||
|
||||
$user = User::query()->where('email', Str::lower($request->input(Fortify::username())))->first();
|
||||
|
||||
// Immer ein Passwort prüfen – gleiche Antwortzeit, ob es das Konto gibt oder nicht
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
56
app/Support/ImageCompressor.php
Normal file
56
app/Support/ImageCompressor.php
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
66
app/Support/PasswordLogin.php
Normal file
66
app/Support/PasswordLogin.php
Normal 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
50
app/Support/UploadsGuard.php
Normal file
50
app/Support/UploadsGuard.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -9,5 +9,5 @@ namespace App;
|
|||
*/
|
||||
final class Version
|
||||
{
|
||||
public const VERSION = '0.46.0';
|
||||
public const VERSION = '0.47.0';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue