Compare commits
15
Commits
No files matched your search
@@ -0,0 +1,63 @@
|
||||
# Production settings – copy to <DEPLOY_PATH>/shared/.env on the server and fill in.
|
||||
# Generate APP_KEY locally once: php artisan key:generate --show
|
||||
|
||||
APP_NAME="Ferienwohnung Stommer"
|
||||
APP_ENV=production
|
||||
APP_KEY=
|
||||
APP_DEBUG=false
|
||||
APP_URL=https://www.fewo-stommer.de
|
||||
APP_TIMEZONE=Europe/Berlin
|
||||
APP_LOCALE=de
|
||||
APP_FALLBACK_LOCALE=de
|
||||
APP_FAKER_LOCALE=de_DE
|
||||
APP_MAINTENANCE_DRIVER=file
|
||||
|
||||
LOG_CHANNEL=daily
|
||||
LOG_LEVEL=warning
|
||||
|
||||
# Strato MariaDB 11.8 (Kundenlogin › Datenbanken und Webspace › Datenbanken verwalten)
|
||||
DB_CONNECTION=mariadb
|
||||
DB_HOST=
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=
|
||||
DB_USERNAME=
|
||||
DB_PASSWORD=
|
||||
|
||||
SESSION_DRIVER=database
|
||||
SESSION_LIFETIME=120
|
||||
SESSION_SECURE_COOKIE=true
|
||||
CACHE_STORE=database
|
||||
QUEUE_CONNECTION=sync
|
||||
FILESYSTEM_DISK=local
|
||||
|
||||
# Strato mailbox fewo@stommer.de
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=smtp.strato.de
|
||||
MAIL_PORT=465
|
||||
MAIL_SCHEME=smtps
|
||||
MAIL_USERNAME=fewo@stommer.de
|
||||
MAIL_PASSWORD=
|
||||
MAIL_FROM_ADDRESS="fewo@stommer.de"
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
FEWO_OWNER_NAME="Brigitte Stommer"
|
||||
FEWO_OWNER_EMAIL=fewo@stommer.de
|
||||
FEWO_NOTIFICATION_EMAIL=fewo@stommer.de
|
||||
FEWO_BANK_ACCOUNT_HOLDER=
|
||||
FEWO_BANK_IBAN=
|
||||
FEWO_BANK_BIC=
|
||||
FEWO_BANK_NAME=
|
||||
|
||||
# Portal booking e-mails (fast path)
|
||||
FEWO_MAILBOX_HOST=imap.strato.de
|
||||
FEWO_MAILBOX_PORT=993
|
||||
FEWO_MAILBOX_ENCRYPTION=ssl
|
||||
FEWO_MAILBOX_USERNAME=fewo@stommer.de
|
||||
FEWO_MAILBOX_PASSWORD=
|
||||
FEWO_MAILBOX_FOLDER=INBOX
|
||||
|
||||
# Monitoring / automation (long random values, e.g. php -r "echo bin2hex(random_bytes(24));")
|
||||
FEWO_HEALTH_TOKEN=
|
||||
FEWO_SCHEDULER_TOKEN=
|
||||
FEWO_AUTOMATION_SECRET=
|
||||
FEWO_AUTOMATION_WEBHOOK_URL=
|
||||
@@ -0,0 +1,105 @@
|
||||
# Tests on every push; deployment to Strato for tags "v*" or by hand (Gitea › Actions › Deploy › Run workflow).
|
||||
# Needs a Gitea act_runner (e.g. on the private server) and these repository secrets:
|
||||
# DEPLOY_SSH_KEY private key whose public key is stored at Strato (SFTP & SSH)
|
||||
# DEPLOY_HOST package-specific SSH server, e.g. 51539426.ssh.w1.strato.hosting (not ssh.strato.de)
|
||||
# DEPLOY_USER SSH user from the Strato customer login
|
||||
# DEPLOY_PATH e.g. fewo-production
|
||||
# DEPLOY_PHP e.g. /opt/RZphp84/bin/php-cli
|
||||
# DEPLOY_URL e.g. https://www.fewo-stommer.de
|
||||
name: Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags: ['v*']
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
environment:
|
||||
description: Ziel
|
||||
type: choice
|
||||
options: [production, staging]
|
||||
default: production
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
mariadb:
|
||||
image: mariadb:11.8
|
||||
env:
|
||||
MARIADB_DATABASE: fewo_test
|
||||
MARIADB_ROOT_PASSWORD: test
|
||||
ports: ['3306:3306']
|
||||
options: >-
|
||||
--health-cmd="healthcheck.sh --connect --innodb_initialized"
|
||||
--health-interval=5s --health-timeout=5s --health-retries=20
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.4'
|
||||
extensions: mbstring, intl, gd, exif, zip, pdo_sqlite, sqlite3, pdo_mysql, fileinfo, openssl
|
||||
tools: composer:v2
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
cache: npm
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
composer install --no-interaction --no-progress --prefer-dist
|
||||
npm ci --no-audit --no-fund
|
||||
npm run build
|
||||
cp .env.example .env
|
||||
php artisan key:generate
|
||||
|
||||
- name: Tests (SQLite)
|
||||
run: php artisan test --compact
|
||||
|
||||
- name: Tests (MariaDB 11.8, wie auf Strato)
|
||||
env:
|
||||
DB_CONNECTION: mariadb
|
||||
DB_HOST: 127.0.0.1
|
||||
DB_PORT: '3306'
|
||||
DB_DATABASE: fewo_test
|
||||
DB_USERNAME: root
|
||||
DB_PASSWORD: test
|
||||
run: php artisan test --compact
|
||||
|
||||
deploy:
|
||||
needs: test
|
||||
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.4'
|
||||
extensions: mbstring, intl, gd, exif, zip, fileinfo, openssl
|
||||
tools: composer:v2
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
cache: npm
|
||||
|
||||
- name: SSH key
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
printf '%s\n' "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key
|
||||
chmod 600 ~/.ssh/deploy_key
|
||||
ssh-keyscan -H "${{ secrets.DEPLOY_HOST }}" >> ~/.ssh/known_hosts
|
||||
|
||||
- name: Deploy
|
||||
env:
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
|
||||
DEPLOY_PHP: ${{ secrets.DEPLOY_PHP }}
|
||||
DEPLOY_URL: ${{ secrets.DEPLOY_URL }}
|
||||
run: |
|
||||
export DEPLOY_SSH_KEY="$HOME/.ssh/deploy_key"
|
||||
bash scripts/deploy.sh "${{ inputs.environment || 'production' }}" deploy
|
||||
@@ -28,3 +28,7 @@ _ide_helper.php
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
Thumbs.db
|
||||
|
||||
# Deployment settings with access data
|
||||
/scripts/deploy.*.env
|
||||
!/scripts/deploy.example.env
|
||||
@@ -13,6 +13,8 @@ # Ferienwohnung Stommer
|
||||
- Special offers are evaluated automatically by `PriceCalculator`; discounts are `QuoteLineType::Discount` lines with negative amounts.
|
||||
- Portal sync lives in `app/Channels` (connector interface + registry in `config/channels.php`, iCal connector/parser/feed). Our system leads; `SyncChannel` imports portal occupations as `BlockedPeriod` rows with `channel_id`; each channel's export feed excludes its own blocks. Observers on Booking/BlockedPeriod create `ChannelTask`s for portals with `requires_manual_blocking`. Portal booking e-mails are a fast path (`app/Channels/Mail`, `ProcessPortalMail`): they create blocks with source `email`, which `SyncChannel` later confirms/replaces and never removes as stale. Portal analysis: `docs/PORTALE.md`.
|
||||
- Website = theme system (`docs/THEMES.md`): themes live in `resources/themes/<key>` (theme.json, theme.css, theme.js, views); views resolve via the `theme::` namespace (theme → parent → base `ostsee-licht`). Pages are lists of sections (`app/Themes/Sections`, catalogue in `config/themes.php`); seasonal `Appearance`s override tokens/texts/hero photo. Theme views use only token colour classes (`bg-accent`, `text-muted`, …). Resolve `Theme` lazily (`app(Theme::class)`), never in constructors – middleware `ResolveTheme` replaces it per request.
|
||||
- Operations (environments, Strato access, server .env, admin accounts, 2FA, known pitfalls): `docs/BETRIEB.md` – read it before touching a server. Admin accounts: `php artisan users:create`; 2FA (Filament app authentication) is mandatory for admins via `RequireTwoFactorForAdmins`.
|
||||
- Deployment: `scripts/deploy.sh <env> setup|deploy [ref]|rollback|releases|artisan` (atomic releases on Strato, docs/DEPLOYMENT.md; the server keeps only the active release because of Strato's file quota – history = Git tags `deploy/<env>/<timestamp>`); CI `.gitea/workflows/deploy.yml`. Production has no dev packages (no factories/Faker) – production seeding via `ProductionSeeder`.
|
||||
- Vite fonts plugin is removed on purpose (corporate proxy breaks remote font downloads, and fonts must be self-hosted for GDPR).
|
||||
- PHP/Composer on this machine: winget package dir `%LOCALAPPDATA%\Microsoft\WinGet\Packages\PHP.PHP.8.4_*` (Composer as `composer\composer.phar` there).
|
||||
- Git remote: Gitea `https://gitea.stommer.de/Lars/fewo-stommer.git`, branch `main`.
|
||||
|
||||
@@ -13,6 +13,8 @@ # Ferienwohnung Stommer
|
||||
- Special offers are evaluated automatically by `PriceCalculator`; discounts are `QuoteLineType::Discount` lines with negative amounts.
|
||||
- Portal sync lives in `app/Channels` (connector interface + registry in `config/channels.php`, iCal connector/parser/feed). Our system leads; `SyncChannel` imports portal occupations as `BlockedPeriod` rows with `channel_id`; each channel's export feed excludes its own blocks. Observers on Booking/BlockedPeriod create `ChannelTask`s for portals with `requires_manual_blocking`. Portal booking e-mails are a fast path (`app/Channels/Mail`, `ProcessPortalMail`): they create blocks with source `email`, which `SyncChannel` later confirms/replaces and never removes as stale. Portal analysis: `docs/PORTALE.md`.
|
||||
- Website = theme system (`docs/THEMES.md`): themes live in `resources/themes/<key>` (theme.json, theme.css, theme.js, views); views resolve via the `theme::` namespace (theme → parent → base `ostsee-licht`). Pages are lists of sections (`app/Themes/Sections`, catalogue in `config/themes.php`); seasonal `Appearance`s override tokens/texts/hero photo. Theme views use only token colour classes (`bg-accent`, `text-muted`, …). Resolve `Theme` lazily (`app(Theme::class)`), never in constructors – middleware `ResolveTheme` replaces it per request.
|
||||
- Operations (environments, Strato access, server .env, admin accounts, 2FA, known pitfalls): `docs/BETRIEB.md` – read it before touching a server. Admin accounts: `php artisan users:create`; 2FA (Filament app authentication) is mandatory for admins via `RequireTwoFactorForAdmins`.
|
||||
- Deployment: `scripts/deploy.sh <env> setup|deploy [ref]|rollback|releases|artisan` (atomic releases on Strato, docs/DEPLOYMENT.md; the server keeps only the active release because of Strato's file quota – history = Git tags `deploy/<env>/<timestamp>`); CI `.gitea/workflows/deploy.yml`. Production has no dev packages (no factories/Faker) – production seeding via `ProductionSeeder`.
|
||||
- Vite fonts plugin is removed on purpose (corporate proxy breaks remote font downloads, and fonts must be self-hosted for GDPR).
|
||||
- PHP/Composer on this machine: winget package dir `%LOCALAPPDATA%\Microsoft\WinGet\Packages\PHP.PHP.8.4_*` (Composer as `composer\composer.phar` there).
|
||||
- Git remote: Gitea `https://gitea.stommer.de/Lars/fewo-stommer.git`, branch `main`.
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
use function Laravel\Prompts\password;
|
||||
use function Laravel\Prompts\select;
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
#[Signature('users:create {email? : E-Mail-Adresse} {--name= : Name} {--role= : admin, rentals oder content}')]
|
||||
#[Description('Create an admin panel account (the password is entered interactively and never passed as an argument)')]
|
||||
class CreateUser extends Command
|
||||
{
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$email = $this->argument('email') ?? text('E-Mail-Adresse', required: true, validate: ['email' => 'email']);
|
||||
$email = mb_strtolower(trim($email));
|
||||
|
||||
if (User::where('email', $email)->exists()) {
|
||||
$this->error("Es gibt bereits einen Benutzer mit {$email}.");
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$name = $this->option('name') ?? text('Name', required: true);
|
||||
|
||||
$role = $this->option('role') !== null
|
||||
? UserRole::tryFrom($this->option('role'))
|
||||
: UserRole::from(select('Rolle', collect(UserRole::cases())->mapWithKeys(fn (UserRole $role): array => [$role->value => "{$role->getLabel()} – {$role->getDescription()}"])->all(), default: UserRole::Admin->value));
|
||||
|
||||
if ($role === null) {
|
||||
$this->error('Unbekannte Rolle. Erlaubt: '.implode(', ', array_column(UserRole::cases(), 'value')));
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$password = password('Passwort (mind. 12 Zeichen)', required: true, validate: ['password' => Password::min(12)]);
|
||||
|
||||
if (password('Passwort wiederholen', required: true) !== $password) {
|
||||
$this->error('Die Passwörter stimmen nicht überein.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
User::create(['name' => $name, 'email' => $email, 'role' => $role, 'password' => $password]);
|
||||
|
||||
$this->info("Benutzer {$email} ({$role->getLabel()}) angelegt.");
|
||||
|
||||
if ($role === UserRole::Admin) {
|
||||
$this->line('Bei der ersten Anmeldung wird die Zwei-Faktor-Anmeldung mit einer Authenticator-App eingerichtet.');
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
@@ -63,6 +64,19 @@ public function health(Request $request): JsonResponse
|
||||
], $ok ? 200 : 503);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the task scheduler once (fallback for hosting without suitable cron jobs).
|
||||
*/
|
||||
public function scheduler(Request $request): JsonResponse
|
||||
{
|
||||
$token = config('fewo.scheduler_token');
|
||||
abort_if(blank($token) || ! hash_equals($token, (string) $request->query('token')), 404);
|
||||
|
||||
Artisan::call('schedule:run');
|
||||
|
||||
return response()->json(['ran_at' => now()->toIso8601String(), 'output' => trim(Artisan::output())]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push variant of the e-mail fast path, e.g. from an n8n IMAP trigger:
|
||||
* JSON {message_id, from, subject, text, received_at}, signed like the automation webhook.
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use App\Models\User;
|
||||
use Closure;
|
||||
use Filament\Auth\MultiFactor\Http\Middleware\EnsureMultiFactorAuthenticationIsEnabled;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Filament evaluates "two-factor required" once per panel; this narrows it to administrators.
|
||||
* Other roles may set it up voluntarily in their profile.
|
||||
*/
|
||||
class RequireTwoFactorForAdmins extends EnsureMultiFactorAuthenticationIsEnabled
|
||||
{
|
||||
public function handle(Request $request, Closure $next): mixed
|
||||
{
|
||||
$user = Filament::auth()->user();
|
||||
|
||||
if (! $user instanceof User || ! $user->hasRole(UserRole::Admin)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
return parent::handle($request, $next);
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -5,6 +5,10 @@
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use App\Enums\UserRole;
|
||||
use Database\Factories\UserFactory;
|
||||
use Filament\Auth\MultiFactor\App\Concerns\InteractsWithAppAuthentication;
|
||||
use Filament\Auth\MultiFactor\App\Concerns\InteractsWithAppAuthenticationRecovery;
|
||||
use Filament\Auth\MultiFactor\App\Contracts\HasAppAuthentication;
|
||||
use Filament\Auth\MultiFactor\App\Contracts\HasAppAuthenticationRecovery;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
@@ -15,10 +19,10 @@
|
||||
|
||||
#[Fillable(['name', 'email', 'role', 'password'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable implements FilamentUser
|
||||
class User extends Authenticatable implements FilamentUser, HasAppAuthentication, HasAppAuthenticationRecovery
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
use HasFactory, InteractsWithAppAuthentication, InteractsWithAppAuthenticationRecovery, Notifiable;
|
||||
|
||||
/**
|
||||
* Accounts are created by administrators only; an account without a role has no access.
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
@@ -19,6 +20,11 @@ public function register(): void
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
// On Strato the domain points at the deployment folder and .htaccess forwards to current/public;
|
||||
// without a fixed root, some URLs (e.g. /sitemap.xml) would be generated with /current/public.
|
||||
if (! $this->app->environment('local', 'testing')) {
|
||||
URL::forceRootUrl(config('app.url'));
|
||||
URL::forceScheme(parse_url((string) config('app.url'), PHP_URL_SCHEME) ?: 'https');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Providers\Filament;
|
||||
|
||||
use App\Http\Middleware\RequireTwoFactorForAdmins;
|
||||
use Filament\Auth\MultiFactor\App\AppAuthentication;
|
||||
use Filament\Http\Middleware\Authenticate;
|
||||
use Filament\Http\Middleware\AuthenticateSession;
|
||||
use Filament\Http\Middleware\DisableBladeIconComponents;
|
||||
@@ -27,6 +29,13 @@ public function panel(Panel $panel): Panel
|
||||
->id('admin')
|
||||
->path('admin')
|
||||
->login()
|
||||
->profile(isSimple: false)
|
||||
// Two-factor login with an authenticator app (TOTP) and recovery codes; mandatory for administrators.
|
||||
->multiFactorAuthentication(
|
||||
[AppAuthentication::make()->brandName('FeWo Stommer')->recoverable()],
|
||||
isRequired: true,
|
||||
)
|
||||
->multiFactorAuthenticationRequiredMiddlewareName(RequireTwoFactorForAdmins::class)
|
||||
->brandName('FeWo Stommer · Verwaltung')
|
||||
->navigationGroups(['Vermietung', 'Webseite', 'System'])
|
||||
->colors([
|
||||
|
||||
@@ -76,6 +76,12 @@
|
||||
'stale_after_minutes' => (int) env('FEWO_MAILBOX_STALE_AFTER_MINUTES', 15),
|
||||
],
|
||||
|
||||
/*
|
||||
| Fallback trigger for the task scheduler (e.g. from n8n every minute) if the hosting's cron jobs
|
||||
| are not available or not frequent enough: GET /automation/scheduler?token=… . Empty = disabled.
|
||||
*/
|
||||
'scheduler_token' => env('FEWO_SCHEDULER_TOKEN'),
|
||||
|
||||
/*
|
||||
| Optional external automation (e.g. a browser bot on a private server) that carries out
|
||||
| manual blocking tasks. Tasks are POSTed signed with HMAC-SHA256 of the body.
|
||||
|
||||
@@ -32,9 +32,18 @@ public function definition(): array
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
'role' => UserRole::Admin,
|
||||
'app_authentication_secret' => 'JBSWY3DPEHPK3PXP',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the user has not set up two-factor authentication yet.
|
||||
*/
|
||||
public function withoutTwoFactor(): static
|
||||
{
|
||||
return $this->state(fn (): array => ['app_authentication_secret' => null]);
|
||||
}
|
||||
|
||||
public function role(?UserRole $role): static
|
||||
{
|
||||
return $this->state(fn (): array => ['role' => $role]);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->text('app_authentication_secret')->nullable()->after('password');
|
||||
$table->text('app_authentication_recovery_codes')->nullable()->after('app_authentication_secret');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn(['app_authentication_secret', 'app_authentication_recovery_codes']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -16,7 +16,7 @@ class DatabaseSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
User::factory()->create([
|
||||
User::factory()->withoutTwoFactor()->create([
|
||||
'name' => 'Admin',
|
||||
'email' => 'admin@example.com',
|
||||
'role' => UserRole::Admin,
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Site;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
/**
|
||||
* Initial data for a fresh production installation (no test data, no factories – they are not deployed).
|
||||
* Run once: scripts/deploy.sh production artisan db:seed --class=ProductionSeeder --force
|
||||
* Create the first administrator afterwards: scripts/deploy.sh production artisan make:filament-user
|
||||
*/
|
||||
class ProductionSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
if (Site::query()->exists()) {
|
||||
$this->command?->warn('Es gibt bereits eine Website – Ersteinrichtung übersprungen.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->call([PropertySeeder::class, WebsiteContentSeeder::class, SiteSeeder::class]);
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
# Betrieb: Umgebungen, Zugänge, Einrichtung
|
||||
|
||||
Stand: 22.10.2026. Dieses Dokument beschreibt den **tatsächlichen Stand** der Installationen, damit jede neue Arbeitssitzung (Mensch oder KI) ohne Vorwissen weitermachen kann. Allgemeine Abläufe des Deployments stehen in [DEPLOYMENT.md](DEPLOYMENT.md), das fachliche Konzept in [KONZEPT.md](KONZEPT.md).
|
||||
|
||||
> **Geheimnisse stehen nie im Repository und nie im Chat.** Passwörter (Datenbank, E-Mail), `APP_KEY`, Tokens und private SSH-Schlüssel liegen nur in `shared/.env` auf dem Server bzw. im Vaultwarden von Lars. Hier ist nur dokumentiert, *wo* sie liegen.
|
||||
|
||||
## 1. Überblick
|
||||
|
||||
| | Testbetrieb (staging) | Produktion |
|
||||
|---|---|---|
|
||||
| Adresse | **https://stommer.info** | später https://www.fewo-stommer.de (heute noch WordPress) |
|
||||
| Ordner auf dem Webspace | `test.fewo-stommer.de/` | noch nicht angelegt (Vorschlag: `fewo-production/`) |
|
||||
| Deploy-Konfiguration (lokal, nicht committet) | `scripts/deploy.staging.env` | `scripts/deploy.production.env` (anlegen aus `deploy.example.env`) |
|
||||
| Datenbank | MariaDB 11.8, siehe §3 | eigene Datenbank anlegen |
|
||||
| E-Mail | `MAIL_MAILER=log` – **verschickt nichts** | Strato-SMTP |
|
||||
| Postfach-Abruf (Portal-Mails) | aus (`FEWO_MAILBOX_HOST` leer) | `imap.strato.de` |
|
||||
| Suchmaschinen | `noindex` (alles außer `APP_ENV=production`) | indexiert |
|
||||
| Cronjob | **noch offen** (§6) | einrichten |
|
||||
|
||||
Git: `https://gitea.stommer.de/Lars/fewo-stommer.git`, Branch `main`. Gebaut und ausgeliefert wird immer der **letzte Commit**.
|
||||
|
||||
## 2. Strato-Paket (Hosting Pro)
|
||||
|
||||
- **SSH/SFTP-Server:** `51539426.ssh.w1.strato.hosting` (paketspezifisch, *nicht* `ssh.strato.de` – der lehnt ab). Port 22.
|
||||
- **SSH-Benutzer:** `stu100093250` (Kundenlogin › Datenbanken und Webspace › SFTP & SSH › Details). Startverzeichnis `/` = Webspace-Wurzel.
|
||||
- **Absoluter Pfad des Webspace:** `/mnt/web508/e3/26/51539426/htdocs/` (für Cronjobs).
|
||||
- **PHP-CLI:** `/opt/RZphp84/bin/php-cli` (8.4). Die Web-PHP-Version des Pakets ist eine andere (8.3); die `.htaccess` im Deploy-Ordner setzt per `AddType application/x-httpd-php84 .php` 8.4 **nur für diesen Ordner**.
|
||||
- **Andere Inhalte im Webspace nicht anfassen:** u. a. `www.fewo-stommer.de/` (bestehendes WordPress), `fewo`, Karate-Wiki, Moodle. Das Deploy-Skript arbeitet ausschließlich unterhalb von `DEPLOY_PATH`.
|
||||
- **Domains:** SSL-Zertifikate gibt es im Paket nur für Hauptdomains, nicht für Subdomains. Deshalb läuft der Test unter `stommer.info` (Ziel: Ordner `test.fewo-stommer.de`, SSL aktiv, `www.stommer.info` ebenso). Die Subdomain `test.fewo-stommer.de` wird nicht mehr gebraucht.
|
||||
- **Domain-Ziel = Deploy-Ordner selbst** (Strato kann kein Symlink-Ziel wählen). Die dort vom Skript geschriebene `.htaccess` leitet auf `releases/<aktive Version>/public` und sperrt alles Interne mit 403.
|
||||
|
||||
## 3. Datenbank (staging)
|
||||
|
||||
- Host `database-5021719836.webspace-host.com`, Port 3306, Datenbank `dbs16257975`, Benutzer `dbu2231025`, `DB_CONNECTION=mariadb`.
|
||||
- Passwort: nur in `test.fewo-stommer.de/shared/.env` (und Vaultwarden).
|
||||
|
||||
## 4. SSH-Zugang einrichten (neuer Rechner, z. B. privater PC)
|
||||
|
||||
1. Schlüssel erzeugen: `ssh-keygen -t ed25519 -f ~/.ssh/strato_fewo -C "fewo-deploy <rechner>"`.
|
||||
2. Öffentlichen Schlüssel beim Server eintragen (fragt einmal das SSH-Passwort des Strato-Benutzers ab):
|
||||
`ssh-copy-id -i ~/.ssh/strato_fewo.pub stu100093250@51539426.ssh.w1.strato.hosting`
|
||||
(Windows ohne `ssh-copy-id`: Inhalt von `strato_fewo.pub` per SSH an `~/.ssh/authorized_keys` anhängen.)
|
||||
3. Test: `ssh -i ~/.ssh/strato_fewo stu100093250@51539426.ssh.w1.strato.hosting "ls"`.
|
||||
4. Den privaten Schlüssel nur im Vaultwarden sichern, nie committen oder weitergeben.
|
||||
5. **Aufräumen:** Der Schlüssel des Firmen-Laptops (Kommentar in `~/.ssh/authorized_keys` auf dem Server) wird entfernt, sobald der private PC eingerichtet ist.
|
||||
|
||||
Lokale Werkzeuge: PHP 8.4 CLI, Composer, Node/npm, Git, Bash (Windows: Git Bash). Danach `scripts/deploy.example.env` nach `scripts/deploy.staging.env` kopieren und mit den Werten aus §2 füllen (`DEPLOY_PATH=test.fewo-stommer.de`, `DEPLOY_URL=https://stommer.info`, `DEPLOY_SSH_KEY=~/.ssh/strato_fewo`; unter Windows ggf. `COMPOSER_BIN="php /c/…/composer.phar"`).
|
||||
|
||||
## 5. Konfiguration auf dem Server (`shared/.env`)
|
||||
|
||||
Vorlage: [.env.production.example](../.env.production.example). Bearbeiten nur direkt auf dem Server, damit Passwörter nicht durch Chat oder Repository laufen:
|
||||
|
||||
```bash
|
||||
ssh -t -i ~/.ssh/strato_fewo stu100093250@51539426.ssh.w1.strato.hosting "nano test.fewo-stommer.de/shared/.env"
|
||||
bash scripts/deploy.sh staging artisan optimize # danach Konfiguration neu einlesen
|
||||
```
|
||||
|
||||
Gesetzte Werte im Testbetrieb (Geheimnisse ausgelassen):
|
||||
|
||||
| Schlüssel | Wert | Bemerkung |
|
||||
|---|---|---|
|
||||
| `APP_ENV` | `staging` | nicht `production` → `noindex` |
|
||||
| `APP_DEBUG` | `false` | |
|
||||
| `APP_URL` | `https://stommer.info` | alle erzeugten Links bauen darauf auf (`URL::forceRootUrl`) |
|
||||
| `APP_KEY` | gesetzt | **nie ändern** – sonst sind 2FA-Schlüssel und Sitzungen unlesbar |
|
||||
| `DB_*` | siehe §3 | |
|
||||
| `SESSION_DRIVER` / `CACHE_STORE` | `database` | |
|
||||
| `SESSION_SECURE_COOKIE` | `true` | Anmeldung nur über HTTPS |
|
||||
| `QUEUE_CONNECTION` | `sync` | keine Worker auf Shared Hosting |
|
||||
| `MAIL_MAILER` | `log` | Testbetrieb verschickt **keine** E-Mails (landen in `shared/storage/logs`) |
|
||||
| `FEWO_MAILBOX_HOST` | leer | Testbetrieb liest **kein** echtes Postfach |
|
||||
| `FEWO_BANK_*` | leer | für Verträge/Angebote noch einzutragen |
|
||||
| `FEWO_HEALTH_TOKEN`, `FEWO_SCHEDULER_TOKEN`, `FEWO_AUTOMATION_SECRET` | gesetzt | für n8n (Überwachung, Scheduler-Ersatz, Webhooks) |
|
||||
|
||||
## 6. Erledigt / offen im Testbetrieb
|
||||
|
||||
Erledigt (22.10.2026): Ordnerstruktur, `shared/.env`, Migrationen, Grunddaten (`ProductionSeeder`: Wohnung, Saisons 2026, Inhalte, Seiten, Erscheinungsbilder), HTTPS unter stommer.info, Gesundheitscheck mit automatischem Rollback.
|
||||
|
||||
Offen:
|
||||
- **Admin-Benutzer anlegen** (§7) und 2FA einrichten.
|
||||
- **Cronjob** (Kundenlogin › Cronjobs), jede Minute:
|
||||
`/opt/RZphp84/bin/php-cli /mnt/web508/e3/26/51539426/htdocs/test.fewo-stommer.de/current/artisan schedule:run`
|
||||
Falls Strato nicht minütlich erlaubt: n8n ruft jede Minute `https://stommer.info/automation/scheduler?token=<FEWO_SCHEDULER_TOKEN>` auf.
|
||||
- Fotos importieren, Bankdaten, Vertrags- und AGB-Texte, Rechtstexte prüfen.
|
||||
- Gitea-Runner für automatisches Deployment (DEPLOYMENT.md §5).
|
||||
|
||||
## 7. Zugang zur Verwaltung (`/admin`)
|
||||
|
||||
**Benutzer anlegen** – der erste Administrator per Befehl (das Passwort wird verdeckt im eigenen Terminal eingegeben, nie als Argument):
|
||||
|
||||
```bash
|
||||
ssh -t -i ~/.ssh/strato_fewo stu100093250@51539426.ssh.w1.strato.hosting \
|
||||
"cd test.fewo-stommer.de/current && /opt/RZphp84/bin/php-cli artisan users:create lars@stommer.com --name='Lars Stommer' --role=admin"
|
||||
```
|
||||
|
||||
Weitere Benutzer legt ein Administrator in der Verwaltung an (System › Benutzer). Rollen: `admin` (alles inkl. Benutzer), `rentals` (Vermietung), `content` (Inhalte); ohne Rolle kein Zugang.
|
||||
|
||||
**Zwei-Faktor-Anmeldung (2FA):** Filament-eigene Lösung mit Authenticator-App (TOTP, z. B. Bitwarden/Vaultwarden, Google oder Microsoft Authenticator) und Wiederherstellungscodes.
|
||||
- **Pflicht für Administratoren:** Nach der ersten Anmeldung wird man auf die Einrichtungsseite geleitet (QR-Code scannen, Code bestätigen, Wiederherstellungscodes sichern). Umgesetzt mit `App\Http\Middleware\RequireTwoFactorForAdmins`.
|
||||
- **Freiwillig für andere Rollen:** im Profil (Avatar oben rechts › Profil).
|
||||
- Schlüssel und Codes liegen verschlüsselt (mit `APP_KEY`) in `users.app_authentication_secret` / `app_authentication_recovery_codes`.
|
||||
- **Handy verloren:** Anmeldung mit einem Wiederherstellungscode. Sind auch die weg, setzt ein Administrator mit Serverzugang die 2FA zurück:
|
||||
```bash
|
||||
bash scripts/deploy.sh staging artisan tinker --execute='App\Models\User::where("email", "lars@stommer.com")->update(["app_authentication_secret" => null, "app_authentication_recovery_codes" => null]);'
|
||||
```
|
||||
Danach bei der nächsten Anmeldung neu einrichten.
|
||||
|
||||
Lokal (nur Entwicklung, `php artisan migrate:fresh --seed`): `admin@example.com` / `password`, 2FA wird bei der ersten Anmeldung eingerichtet.
|
||||
|
||||
## 8. Bekannte Eigenheiten und Lösungen
|
||||
|
||||
| Problem | Ursache | Lösung (umgesetzt) |
|
||||
|---|---|---|
|
||||
| Nach dem Umschalten lief die alte Version weiter | Strato-OPcache speichert Skripte unter dem Symlink-Pfad `current/…` | `.htaccess` zeigt auf den konkreten Ordner `releases/<version>/public` und wird bei jedem Umschalten neu geschrieben |
|
||||
| Links mit `/current/public` (z. B. Sitemap) | Laravel leitet den Basis-Pfad aus dem Skript-Pfad ab | `URL::forceRootUrl(APP_URL)` außerhalb von local/testing (`AppServiceProvider`) |
|
||||
| HTTP 500 „Composer platform“ | Web-PHP des Pakets ist 8.3 | `AddType application/x-httpd-php84 .php` in der Ordner-`.htaccess` |
|
||||
| SSH „connection closed“ | falscher Server `ssh.strato.de` | paketspezifischer Server (§2) |
|
||||
| Domain-Ziel `current/public` nicht wählbar | Strato erlaubt kein Symlink-Ziel | Domain auf den Deploy-Ordner, `.htaccess` leitet weiter |
|
||||
| Ersteinrichtung mit Factories schlägt fehl | Produktion ohne Dev-Pakete | `ProductionSeeder` |
|
||||
| Kein SSL für Subdomain | Paket erlaubt SSL nur für Hauptdomains | Testbetrieb auf `stommer.info` |
|
||||
| `Disk quota exceeded` beim Hochladen / Hinweis „zu viele Dateien“ | Webspace-Kontingent voll (geteilt mit allen anderen Seiten/Backups im Paket); jede Version belegt ~136 MB | Es ist die **Anzahl der Dateien** (Inode-Limit), nicht der Platz. Der Server behält nur die aktive Version (Geschichte als Git-Tags in Gitea), `vendor` wird beim Build ausgedünnt (~15.000 statt ~19.500 Dateien je Version); Reste abgebrochener Läufe räumt das nächste Deployment selbst weg. **Ordner außerhalb des Deploy-Ordners entscheidet nur Lars** (teils produktiv). |
|
||||
| Windows: Symlinks, `php` nicht im PATH | Git Bash | Deploy nur gegen Strato testen; `export PATH="<php-ordner>:$PATH"` |
|
||||
|
||||
## 9. Nützliche Befehle
|
||||
|
||||
```bash
|
||||
bash scripts/deploy.sh staging deploy # ausliefern (letzter Commit)
|
||||
bash scripts/deploy.sh staging releases # aktive Version + Deploy-Tags in Git
|
||||
bash scripts/deploy.sh staging deploy deploy/staging/<zeitstempel> # frühere Version erneut ausliefern
|
||||
bash scripts/deploy.sh staging artisan about # Zustand der Installation
|
||||
bash scripts/deploy.sh staging artisan migrate:status
|
||||
ssh -i ~/.ssh/strato_fewo stu100093250@51539426.ssh.w1.strato.hosting \
|
||||
"tail -n 50 test.fewo-stommer.de/shared/storage/logs/laravel-$(date +%F).log" # Fehlerprotokoll
|
||||
```
|
||||
@@ -0,0 +1,92 @@
|
||||
# Deployment auf Strato
|
||||
|
||||
Stand: 22.10.2026 · Skript: `scripts/deploy.sh` · CI: `.gitea/workflows/deploy.yml`
|
||||
|
||||
## 1. Prinzip
|
||||
|
||||
```
|
||||
Gitea (main/Tag) ──► Build (CI oder lokal): git-Stand · composer --no-dev · npm run build
|
||||
│ tar.gz
|
||||
▼ SSH
|
||||
Strato <DEPLOY_PATH>/
|
||||
releases/20261022…/ ◄─ entpackt
|
||||
shared/.env ◄─ einmalig von Hand
|
||||
shared/storage/ ◄─ Uploads, Logs, Sessions (bleiben)
|
||||
current ──► releases/… ◄─ atomar umgeschaltet nach migrate + optimize
|
||||
.htaccess ──► releases/<aktiv>/public (Domain-Zielverzeichnis = <DEPLOY_PATH>)
|
||||
│
|
||||
▼ https://…/up – Gesundheitscheck, bei Fehler automatischer Rollback
|
||||
```
|
||||
|
||||
Auf dem Server werden nur **bash, tar und PHP-CLI** gebraucht – kein Composer, kein Node, kein Git, kein rsync.
|
||||
|
||||
## 2. SSH oder SFTP?
|
||||
|
||||
**Empfehlung: SSH.** Das Skript führt nach dem Hochladen Befehle auf dem Server aus (Archiv entpacken, Datenbank migrieren, Caches erzeugen, Version umschalten, ggf. zurückschalten). Das geht nur mit SSH.
|
||||
|
||||
Nur mit SFTP wäre ein Deployment möglich, aber deutlich schwächer:
|
||||
- Kein Entpacken auf dem Server → jede Datei einzeln übertragen (über 10.000 Dateien, mehrere Minuten pro Update, unterbrechungsanfällig).
|
||||
- Migrationen und Caches müssten über einen gesicherten Web-Aufruf angestoßen werden; kein `artisan` für Wartung und Fehlersuche.
|
||||
- Umschalten wäre per SFTP-Symlink möglich, aber ohne sauberen Rückfall bei Fehlern.
|
||||
|
||||
Strato richtet beide Zugänge im selben Menü ein (Kundenlogin › Datenbanken und Webspace › **SFTP & SSH**). Bei Hosting Pro sollte SSH enthalten sein – bitte dort prüfen. Falls nicht: Bescheid geben, dann ergänze ich einen SFTP-Modus.
|
||||
|
||||
## 3. Einmalige Einrichtung bei Strato
|
||||
|
||||
1. **PHP-Version** auf 8.4 stellen (Datenbanken und Webspace › PHP-Version).
|
||||
2. **SSH-Zugang** anlegen (SFTP & SSH, Protokoll „SFTP + SSH“); **Benutzername und Server** aus „Details“ notieren – der Server ist paketspezifisch (z. B. `12345678.ssh.w1.strato.hosting`), nicht `ssh.strato.de`. Eigenen SSH-Schlüssel hinterlegen oder einmalig `ssh-copy-id -i ~/.ssh/strato_fewo.pub <benutzer>@<server>`.
|
||||
3. Per SSH prüfen:
|
||||
```bash
|
||||
ssh <benutzer>@<server>
|
||||
ls /opt | grep RZphp # PHP-CLI-Pfad, z. B. /opt/RZphp84/bin/php-cli
|
||||
/opt/RZphp84/bin/php-cli -v
|
||||
```
|
||||
4. **Datenbank MariaDB 11.8** anlegen (Datenbanken verwalten; nicht MySQL 8.0 – Support endete im April 2026); Host, Name, Benutzer, Passwort notieren. In `shared/.env`: `DB_CONNECTION=mariadb`.
|
||||
5. Lokal `scripts/deploy.example.env` nach `scripts/deploy.production.env` kopieren und ausfüllen (wird nicht committet).
|
||||
6. `bash scripts/deploy.sh production setup` – legt die Ordner an und zeigt die PHP-Version.
|
||||
7. `.env.production.example` ausfüllen (u. a. `APP_KEY` via `php artisan key:generate --show`, Datenbank, SMTP/IMAP-Passwort, Tokens) und auf den Server nach `<DEPLOY_PATH>/shared/.env` kopieren (z. B. per SFTP).
|
||||
8. Erstes Deployment: `bash scripts/deploy.sh production deploy`
|
||||
9. Ersteinrichtung der Daten und erster Admin:
|
||||
```bash
|
||||
bash scripts/deploy.sh production artisan db:seed --class=ProductionSeeder --force
|
||||
bash scripts/deploy.sh production artisan make:filament-user
|
||||
```
|
||||
10. **Domain-Zielverzeichnis** auf den Ordner `<DEPLOY_PATH>` selbst setzen (Strato kann kein Symlink-Ziel wählen). Die `.htaccess` dort (von `setup` und bei jedem Umschalten neu geschrieben) leitet alles intern nach `releases/<aktive Version>/public` – bewusst **nicht** über den Symlink `current`, weil der OPcache von Strato Skripte unter dem Symlink-Pfad zwischenspeichert und sonst nach dem Umschalten die alte Version ausliefert. Sie sperrt interne Dateien (403) und setzt per `AddType application/x-httpd-php84 .php` die Web-PHP-Version **nur für diesen Ordner** auf die CLI-Version – andere Anwendungen im Paket bleiben unberührt. SSL-Zertifikat für die Domain aktivieren.
|
||||
11. **Cronjob** (Kundenlogin › Cronjobs), jede Minute:
|
||||
```
|
||||
/opt/RZphp84/bin/php-cli <home>/<DEPLOY_PATH>/current/artisan schedule:run
|
||||
```
|
||||
Falls Cronjobs nicht minütlich möglich sind: `FEWO_SCHEDULER_TOKEN` setzen und n8n jede Minute `GET https://…/automation/scheduler?token=…` aufrufen lassen.
|
||||
12. Überwachung: n8n alle 5 Min. `GET https://…/health/sync?token=<FEWO_HEALTH_TOKEN>` (200 = ok, 503 = Störung).
|
||||
|
||||
**Testbetrieb zuerst:** Für eine Subdomain (z. B. `test.fewo-stommer.de`) eine zweite Konfiguration `scripts/deploy.staging.env` mit eigenem `DEPLOY_PATH`, eigener Datenbank und eigenem `shared/.env` anlegen; `bash scripts/deploy.sh staging deploy`.
|
||||
|
||||
## 4. Tägliche Nutzung
|
||||
|
||||
| Aufgabe | Befehl |
|
||||
|---|---|
|
||||
| Neue Version ausliefern | `bash scripts/deploy.sh production deploy` (baut den **letzten Commit**) |
|
||||
| Bestimmten Stand ausliefern | `bash scripts/deploy.sh production deploy <commit oder tag>` |
|
||||
| Zurück zu einer früheren Version | `bash scripts/deploy.sh production releases` zeigt die Deploy-Tags; dann `bash scripts/deploy.sh production deploy deploy/production/<zeitstempel>` (Migrationen werden nicht zurückgenommen) |
|
||||
| Sofort zurück, solange die alte Version noch auf dem Server liegt (nur während eines laufenden Deployments) | `bash scripts/deploy.sh production rollback` |
|
||||
|
||||
**Versionsgeschichte in Gitea statt auf Strato:** Strato begrenzt die Anzahl der Dateien im Paket (eine Version ≈ 15.000 Dateien). Auf dem Server liegt deshalb nur die **aktive** Version, während eines Deployments kurz zusätzlich die neue. Die alte wird erst gelöscht, wenn die neue den Gesundheitscheck bestanden hat – schlägt er fehl, wird automatisch zurückgeschaltet. Jede erfolgreiche Auslieferung wird als Tag `deploy/<umgebung>/<zeitstempel>` in Gitea festgehalten; ein Build ist durch `composer.lock`/`package-lock.json` reproduzierbar. Außerdem entfernt der Build Sprachdateien außer de/en sowie Tests/Doku aus `vendor` (~4.800 Dateien weniger).
|
||||
| Artisan auf dem Server | `bash scripts/deploy.sh production artisan about` |
|
||||
|
||||
Windows: in Git Bash ausführen; `COMPOSER_BIN="php /c/…/composer.phar"` in der `.env`-Datei des Deployments setzen, falls `composer` nicht im PATH ist.
|
||||
|
||||
## 5. Automatisch über Gitea Actions
|
||||
|
||||
- Workflow `.gitea/workflows/deploy.yml`: **Tests bei jedem Push**; **Deployment** bei Tags `v*` (z. B. `git tag v1.0.0 && git push --tags`) oder per Knopfdruck (Actions › Deploy › Run workflow, Ziel production/staging).
|
||||
- Voraussetzung: Gitea Actions aktiviert und ein **act_runner** registriert – passt gut auf den privaten Server (Docker). Anleitung: Gitea-Doku „Act Runner“.
|
||||
- Repository-Secrets: `DEPLOY_SSH_KEY` (privater Schlüssel, dessen öffentlicher Teil bei Strato hinterlegt ist), `DEPLOY_HOST`, `DEPLOY_USER`, `DEPLOY_PATH`, `DEPLOY_PHP`, `DEPLOY_URL`.
|
||||
|
||||
## 6. Getestet / offen
|
||||
|
||||
- Lokal im Testmodus (`DEPLOY_HOST=local`) erfolgreich: Build (~19 MB), Upload, Entpacken, alle Migrationen auf frischer Datenbank, `optimize`, Ersteinrichtung per `ProductionSeeder`, alle Seiten und Admin-Login liefern 200.
|
||||
- **Nicht** unter Windows prüfbar: der Symlink-Wechsel von `current` (Git Bash legt Kopien statt Symlinks an). Unter Linux (Strato) ist das Standardverhalten; der erste Lauf auf dem Testbetrieb bestätigt es – bei Fehler greift der automatische Rollback.
|
||||
- **Auf Strato erfolgreich (22.10.2026, test.fewo-stommer.de):** SSH mit Schlüssel (paketspezifischer Server), PHP-CLI `/opt/RZphp84/bin/php-cli`, Migrationen auf MariaDB, Symlink-Umschaltung, `.htaccess`-Weiterleitung, Web-PHP 8.4 per `AddType`, `ProductionSeeder`; alle Seiten 200.
|
||||
- Testbetrieb läuft unter **https://stommer.info** (Domain-Ziel: Ordner `test.fewo-stommer.de`; SSL für Subdomains ist im Paket nicht verfügbar). Gesundheitscheck über HTTPS mit automatischem Rollback funktioniert.
|
||||
- Behoben: OPcache lieferte nach dem Umschalten die alte Version (→ `.htaccess` zeigt auf den konkreten Release-Ordner); URLs mit `/current/public` (→ `URL::forceRootUrl(APP_URL)` außerhalb von local/testing).
|
||||
- Noch offen: Cronjob.
|
||||
- Erstes Deployment auf ein neues Ziel: `SKIP_HEALTH_CHECK=1 bash scripts/deploy.sh <env> deploy` (die Domain zeigt da noch nicht auf die neue Installation).
|
||||
@@ -20,7 +20,7 @@
|
||||
<meta property="og:image" content="{{ $ogImage }}">
|
||||
@endisset
|
||||
<link rel="canonical" href="{{ url()->current() }}">
|
||||
@if ($theme->isPreview)
|
||||
@if ($theme->isPreview || ! app()->isProduction())
|
||||
<meta name="robots" content="noindex">
|
||||
@endif
|
||||
@vite($theme->assets())
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
Route::get('/kalender/{token}.ics', [ChannelController::class, 'feed'])->name('channels.feed')->middleware('throttle:60,1');
|
||||
Route::get('/health/sync', [ChannelController::class, 'health'])->name('health.sync');
|
||||
Route::get('/automation/scheduler', [ChannelController::class, 'scheduler'])->name('automation.scheduler')->middleware('throttle:10,1');
|
||||
Route::post('/automation/portal-mail', [ChannelController::class, 'portalMail'])
|
||||
->name('channels.portal-mail')
|
||||
->withoutMiddleware(PreventRequestForgery::class)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# Copy to scripts/deploy.production.env (or deploy.staging.env) and fill in. These files are not committed.
|
||||
|
||||
# SSH access (Strato: Kundenlogin › Datenbanken und Webspace › SFTP & SSH › Details › "Server", e.g. 12345678.ssh.w1.strato.hosting)
|
||||
DEPLOY_HOST=12345678.ssh.w1.strato.hosting
|
||||
DEPLOY_USER=stu123456789
|
||||
DEPLOY_PORT=22
|
||||
# Optional: private key file (otherwise the SSH agent / default key is used)
|
||||
# DEPLOY_SSH_KEY=~/.ssh/strato_fewo
|
||||
|
||||
# Folder below the SSH start directory. The domain's target directory must be <DEPLOY_PATH>/current/public.
|
||||
DEPLOY_PATH=fewo-production
|
||||
|
||||
# PHP CLI on Strato shared hosting: /opt/RZphp<major><minor>/bin/php-cli (check with: ls /opt)
|
||||
DEPLOY_PHP=/opt/RZphp84/bin/php-cli
|
||||
|
||||
# Public address for the health check after switching (empty = no check, no automatic rollback)
|
||||
DEPLOY_URL=https://www.fewo-stommer.de
|
||||
|
||||
# After a successful deployment, tag the commit as deploy/<environment>/<timestamp> and push the tag to Gitea
|
||||
# (the server keeps only the active release; going back = deploy an older tag). 0 = no tags.
|
||||
DEPLOY_TAG=1
|
||||
|
||||
# Local build: how Composer is called (Windows example: "php /c/path/to/composer.phar")
|
||||
# COMPOSER_BIN=composer
|
||||
@@ -0,0 +1,286 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Deployment to Strato (or any SSH host offering bash, tar and a PHP CLI) with atomic releases.
|
||||
#
|
||||
# scripts/deploy.sh <environment> setup create the folder structure on the server (once)
|
||||
# scripts/deploy.sh <environment> deploy [ref] build a Git commit/tag (default HEAD), upload, migrate, switch,
|
||||
# health check (switch back on failure), tag it in Gitea
|
||||
# scripts/deploy.sh <environment> rollback switch back while the previous release is still on the server
|
||||
# scripts/deploy.sh <environment> releases active release on the server and deployment tags in Git
|
||||
# scripts/deploy.sh <environment> artisan <args> run an artisan command in the active release
|
||||
#
|
||||
# Settings come from scripts/deploy.<environment>.env (not committed, see scripts/deploy.example.env)
|
||||
# or from environment variables (CI). Server layout below DEPLOY_PATH:
|
||||
#
|
||||
# releases/<timestamp>/ the active release (code, vendor, built assets); during a deployment also the new one.
|
||||
# Older releases are not kept (Strato file quota) – history lives in Git as tags
|
||||
# deploy/<environment>/<timestamp>; going back = deploy that tag again.
|
||||
# shared/.env production settings – created by hand once
|
||||
# shared/storage/ uploads, logs, sessions, cache – survive every release
|
||||
# current -> releases/… active release (CLI, cron); the domain points at DEPLOY_PATH, whose .htaccess
|
||||
# forwards to the active release's public folder
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
ENVIRONMENT="${1:?Bitte Umgebung angeben, z. B.: scripts/deploy.sh production deploy}"
|
||||
COMMAND="${2:-deploy}"
|
||||
shift $(($# >= 2 ? 2 : 1))
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
CONFIG="$ROOT/scripts/deploy.$ENVIRONMENT.env"
|
||||
if [[ -f "$CONFIG" ]]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "$CONFIG"
|
||||
fi
|
||||
|
||||
: "${DEPLOY_HOST:?DEPLOY_HOST fehlt (z. B. ssh.strato.de oder local)}"
|
||||
: "${DEPLOY_PATH:?DEPLOY_PATH fehlt (Ordner auf dem Server, z. B. fewo-production)}"
|
||||
DEPLOY_USER="${DEPLOY_USER:-}"
|
||||
DEPLOY_PORT="${DEPLOY_PORT:-22}"
|
||||
DEPLOY_PHP="${DEPLOY_PHP:-/opt/RZphp84/bin/php-cli}"
|
||||
DEPLOY_TAG="${DEPLOY_TAG:-1}"
|
||||
DEPLOY_URL="${DEPLOY_URL:-}"
|
||||
DEPLOY_SSH_KEY="${DEPLOY_SSH_KEY:-}"
|
||||
DEPLOY_SSH_KEY="${DEPLOY_SSH_KEY/#\~/$HOME}"
|
||||
COMPOSER_BIN="${COMPOSER_BIN:-composer}"
|
||||
|
||||
say() { printf '\n\033[1;34m▶ %s\033[0m\n' "$*"; }
|
||||
fail() { printf '\n\033[1;31m✗ %s\033[0m\n' "$*" >&2; exit 1; }
|
||||
|
||||
# The script executed on the server. Arguments: <base path> <php binary> <command> [args…]
|
||||
remote_script() {
|
||||
cat <<'REMOTE'
|
||||
set -euo pipefail
|
||||
base="$1"; php="$2"; cmd="$3"; shift 3
|
||||
mkdir -p "$base"
|
||||
cd "$base"
|
||||
|
||||
# The web is served from the concrete release folder, not through the "current" symlink: Strato's
|
||||
# OPcache keys scripts by the symlinked path and would keep serving the previous release.
|
||||
# Strato: the web server's PHP version can be chosen per folder; use the same version as the CLI.
|
||||
write_htaccess() {
|
||||
local target="$1"
|
||||
local web_php
|
||||
web_php="$(printf '%s' "$php" | grep -oE 'RZphp[0-9]+' | grep -oE '[0-9]+' || true)"
|
||||
{ [[ -n "$web_php" ]] && echo "AddType application/x-httpd-php$web_php .php"; cat <<HTACCESS
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteRule ^(releases/(?!$target/public/)|shared(/|$)|current(/|$)|\.|upload-) - [F,L]
|
||||
RewriteCond %{REQUEST_URI} !^/releases/$target/public/
|
||||
RewriteRule ^(.*)\$ releases/$target/public/\$1 [L]
|
||||
</IfModule>
|
||||
<IfModule !mod_rewrite.c>
|
||||
Require all denied
|
||||
</IfModule>
|
||||
HTACCESS
|
||||
} > .htaccess.new
|
||||
mv -f .htaccess.new .htaccess
|
||||
}
|
||||
|
||||
switch_to() {
|
||||
ln -sfn "$1" current.new
|
||||
mv -Tf current.new current
|
||||
write_htaccess "$(basename "$1")"
|
||||
}
|
||||
|
||||
case "$cmd" in
|
||||
setup)
|
||||
mkdir -p releases shared/storage/app/public shared/storage/framework/cache/data shared/storage/framework/sessions shared/storage/framework/views shared/storage/logs
|
||||
# For hosting panels that cannot point a domain at a symlink: the domain points at this folder,
|
||||
# .htaccess forwards to the active release's public folder and blocks all internal files.
|
||||
active="$(readlink current 2>/dev/null || true)"
|
||||
if [[ -n "$active" ]]; then write_htaccess "$(basename "$active")"; else printf 'Require all denied
|
||||
' > .htaccess; fi
|
||||
echo ".htaccess angelegt (Domain-Ziel: $base)."
|
||||
if [[ -f shared/.env ]]; then echo "shared/.env vorhanden."; else echo "HINWEIS: Bitte $base/shared/.env anlegen (Vorlage: .env.production.example)."; fi
|
||||
echo "PHP: $("$php" -v | head -n 1)"
|
||||
;;
|
||||
receive)
|
||||
release="$1"
|
||||
mkdir -p "releases/$release"
|
||||
tar -xzf "upload-$release.tgz" -C "releases/$release" || { rm -rf "releases/$release" "upload-$release.tgz"; exit 1; }
|
||||
rm -f "upload-$release.tgz"
|
||||
;;
|
||||
cleanup)
|
||||
# Everything except the active release: older releases, leftovers of aborted uploads.
|
||||
active="$(basename "$(readlink current 2>/dev/null || echo none)")"
|
||||
for dir in releases/*; do
|
||||
[[ -d "$dir" && "$(basename "$dir")" != "$active" ]] && rm -rf "$dir" && echo "Entfernt: $dir"
|
||||
done
|
||||
rm -f upload-*.tgz
|
||||
;;
|
||||
activate)
|
||||
release="$1"; dir="releases/$release"
|
||||
[[ -f shared/.env ]] || { echo "shared/.env fehlt – erst anlegen (siehe docs/DEPLOYMENT.md)." >&2; exit 1; }
|
||||
rm -rf "$dir/storage"
|
||||
ln -s ../../shared/storage "$dir/storage"
|
||||
ln -sfn ../../shared/.env "$dir/.env"
|
||||
mkdir -p "$dir/bootstrap/cache"
|
||||
ln -sfn ../storage/app/public "$dir/public/storage"
|
||||
(
|
||||
cd "$dir"
|
||||
"$php" artisan migrate --force --no-interaction
|
||||
"$php" artisan optimize --no-interaction
|
||||
"$php" artisan filament:optimize --no-interaction >/dev/null 2>&1 || true
|
||||
)
|
||||
readlink current > .previous_release 2>/dev/null || true
|
||||
switch_to "$dir"
|
||||
echo "Aktiv: $release"
|
||||
;;
|
||||
rollback)
|
||||
active="$(readlink current 2>/dev/null || true)"
|
||||
target="$(cat .previous_release 2>/dev/null || true)"
|
||||
if [[ -z "$target" || "$target" == "$active" || ! -d "$target" ]]; then
|
||||
target="$(ls -1d releases/* | sort | grep -vx "$active" | tail -n 1 || true)"
|
||||
fi
|
||||
[[ -n "$target" && -d "$target" ]] || { echo "Keine frühere Version mehr auf dem Server – stattdessen einen Deploy-Tag erneut ausliefern (siehe: releases)." >&2; exit 1; }
|
||||
switch_to "$target"
|
||||
echo "$active" > .previous_release
|
||||
echo "Zurückgeschaltet auf: $target (Datenbank-Migrationen werden dabei nicht zurückgenommen)"
|
||||
;;
|
||||
releases)
|
||||
echo "Auf dem Server: $(ls -1 releases | tr '\n' ' ')"
|
||||
echo "Aktiv: $(readlink current 2>/dev/null || echo '–')"
|
||||
;;
|
||||
artisan)
|
||||
cd current
|
||||
"$php" artisan "$@"
|
||||
;;
|
||||
*)
|
||||
echo "Unbekannter Befehl: $cmd" >&2; exit 1
|
||||
;;
|
||||
esac
|
||||
REMOTE
|
||||
}
|
||||
|
||||
run_remote() {
|
||||
if [[ "$DEPLOY_HOST" == "local" ]]; then
|
||||
bash -s -- "$DEPLOY_PATH" "$DEPLOY_PHP" "$@"
|
||||
else
|
||||
local ssh_args=(-p "$DEPLOY_PORT" -o BatchMode=yes -o ServerAliveInterval=30)
|
||||
[[ -n "$DEPLOY_SSH_KEY" ]] && ssh_args+=(-i "$DEPLOY_SSH_KEY")
|
||||
ssh "${ssh_args[@]}" "${DEPLOY_USER:+$DEPLOY_USER@}$DEPLOY_HOST" bash -s -- "$DEPLOY_PATH" "$DEPLOY_PHP" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Runs the remote script (sent via stdin) with the given command.
|
||||
remote() {
|
||||
run_remote "$@" < <(remote_script)
|
||||
}
|
||||
|
||||
# Copies the release archive to <DEPLOY_PATH>/upload-<release>.tgz on the server.
|
||||
upload() {
|
||||
local archive="$1" release="$2"
|
||||
if [[ "$DEPLOY_HOST" == "local" ]]; then
|
||||
mkdir -p "$DEPLOY_PATH"
|
||||
cp "$archive" "$DEPLOY_PATH/upload-$release.tgz"
|
||||
else
|
||||
local ssh_args=(-p "$DEPLOY_PORT" -o BatchMode=yes)
|
||||
[[ -n "$DEPLOY_SSH_KEY" ]] && ssh_args+=(-i "$DEPLOY_SSH_KEY")
|
||||
ssh "${ssh_args[@]}" "${DEPLOY_USER:+$DEPLOY_USER@}$DEPLOY_HOST" "mkdir -p '$DEPLOY_PATH' && cat > '$DEPLOY_PATH/upload-$release.tgz'" < "$archive"
|
||||
fi
|
||||
}
|
||||
|
||||
# Strato limits the number of files per package (inode quota), and every release carries ~19,000 files.
|
||||
# Removes what the application never loads at runtime: translations other than de/en, tests and docs.
|
||||
prune_vendor() {
|
||||
local before
|
||||
before="$(find vendor -type f | wc -l)"
|
||||
find vendor -mindepth 5 -maxdepth 5 -type d -path '*/resources/lang/*' ! -name de ! -name en -exec rm -rf {} +
|
||||
find vendor/nesbot/carbon/src/Carbon/Lang -type f ! -name 'de*' ! -name 'en*' -delete 2>/dev/null || true
|
||||
find vendor -mindepth 3 -maxdepth 3 -type d \( -name tests -o -name docs -o -name .github \) -exec rm -rf {} +
|
||||
find vendor -type f \( -iname '*.md' -o -name 'phpunit.xml*' -o -name '.gitattributes' -o -name '.editorconfig' \) -delete
|
||||
echo "vendor: $before → $(find vendor -type f | wc -l) Dateien"
|
||||
}
|
||||
|
||||
build() {
|
||||
REVISION="$(git -C "$ROOT" rev-parse --verify "$REF^{commit}")" || fail "Unbekannter Git-Stand: $REF"
|
||||
say "Baue Version aus Git-Stand $REF (${REVISION:0:7})"
|
||||
if [[ "$REF" == "HEAD" && -n "$(git -C "$ROOT" status --porcelain)" ]]; then
|
||||
echo "Hinweis: Nicht committete Änderungen werden NICHT ausgeliefert (gebaut wird der letzte Commit)."
|
||||
fi
|
||||
|
||||
BUILD_DIR="$(mktemp -d)"
|
||||
git -C "$ROOT" archive --format=tar "$REVISION" | tar -x -C "$BUILD_DIR"
|
||||
(
|
||||
cd "$BUILD_DIR"
|
||||
$COMPOSER_BIN install --no-dev --prefer-dist --optimize-autoloader --no-interaction --no-progress
|
||||
npm ci --no-audit --no-fund
|
||||
npm run build
|
||||
rm -rf node_modules tests docs .gitea .github scripts storage .env.example .env.production.example .ai .claude .cursor AGENTS.md CLAUDE.md boost.json phpunit.xml
|
||||
prune_vendor
|
||||
echo "$REVISION" > REVISION
|
||||
)
|
||||
ARCHIVE="$BUILD_DIR.tgz"
|
||||
tar -czf "$ARCHIVE" -C "$BUILD_DIR" .
|
||||
echo "Paket: $(du -h "$ARCHIVE" | cut -f1)"
|
||||
}
|
||||
|
||||
# Records the live version in Git (and Gitea) – the release history, since the server keeps no old releases.
|
||||
tag_release() {
|
||||
[[ "$DEPLOY_TAG" == "1" ]] || return 0
|
||||
local tag="deploy/$ENVIRONMENT/$1"
|
||||
git -C "$ROOT" -c user.name="${GIT_AUTHOR_NAME:-deploy}" -c user.email="${GIT_AUTHOR_EMAIL:-deploy@localhost}" tag -a "$tag" -m "Deployed to $ENVIRONMENT" "$REVISION" || { echo "Hinweis: Git-Tag $tag konnte nicht angelegt werden."; return 0; }
|
||||
git -C "$ROOT" push -q origin "$tag" 2>/dev/null || git -C "$ROOT" push -q origin "$tag" || echo "Hinweis: Tag $tag nur lokal angelegt – bitte später 'git push origin $tag'."
|
||||
echo "Git-Tag: $tag"
|
||||
}
|
||||
|
||||
health_check() {
|
||||
[[ -n "$DEPLOY_URL" ]] || { echo "Kein DEPLOY_URL gesetzt – Gesundheitscheck übersprungen."; return 0; }
|
||||
# First deployment: the domain does not point to current/public yet.
|
||||
[[ "${SKIP_HEALTH_CHECK:-}" == "1" ]] && { echo "SKIP_HEALTH_CHECK=1 – Gesundheitscheck übersprungen."; return 0; }
|
||||
say "Prüfe $DEPLOY_URL/up"
|
||||
for attempt in 1 2 3 4 5; do
|
||||
if curl -fsS --max-time 15 "$DEPLOY_URL/up" > /dev/null; then
|
||||
echo "Webseite antwortet."
|
||||
return 0
|
||||
fi
|
||||
sleep 3
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
case "$COMMAND" in
|
||||
setup)
|
||||
say "Lege Ordnerstruktur in $DEPLOY_PATH an"
|
||||
remote setup
|
||||
;;
|
||||
deploy)
|
||||
REF="${1:-HEAD}"
|
||||
build
|
||||
RELEASE="$(date -u +%Y%m%d%H%M%S)"
|
||||
say "Räume Server auf (nur die aktive Version bleibt)"
|
||||
remote cleanup
|
||||
say "Übertrage Version $RELEASE"
|
||||
upload "$ARCHIVE" "$RELEASE"
|
||||
remote receive "$RELEASE"
|
||||
say "Migrieren, Caches aufwärmen, umschalten"
|
||||
remote activate "$RELEASE"
|
||||
if ! health_check; then
|
||||
say "Gesundheitscheck fehlgeschlagen – schalte zurück"
|
||||
remote rollback
|
||||
remote cleanup
|
||||
fail "Deployment zurückgerollt. Logs: scripts/deploy.sh $ENVIRONMENT artisan about / shared/storage/logs"
|
||||
fi
|
||||
remote cleanup
|
||||
tag_release "$RELEASE"
|
||||
rm -rf "$BUILD_DIR" "$ARCHIVE"
|
||||
say "Fertig: Version $RELEASE ist live."
|
||||
;;
|
||||
rollback)
|
||||
remote rollback
|
||||
health_check || fail "Auch die vorige Version antwortet nicht – bitte Logs prüfen."
|
||||
;;
|
||||
releases)
|
||||
remote releases
|
||||
echo "Deploy-Tags in Git (neueste zuerst; zurück mit: scripts/deploy.sh $ENVIRONMENT deploy <tag>):"
|
||||
git -C "$ROOT" fetch -q --tags origin 2>/dev/null || true
|
||||
git -C "$ROOT" tag -l "deploy/$ENVIRONMENT/*" --sort=-refname | head -n 10
|
||||
;;
|
||||
artisan)
|
||||
remote artisan "$@"
|
||||
;;
|
||||
*)
|
||||
fail "Unbekannter Befehl: $COMMAND (setup | deploy | rollback | releases | artisan …)"
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SchedulerEndpointTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_scheduler_endpoint_is_disabled_without_token(): void
|
||||
{
|
||||
$this->get('/automation/scheduler')->assertNotFound();
|
||||
$this->get('/automation/scheduler?token=irgendwas')->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_scheduler_runs_with_the_configured_token(): void
|
||||
{
|
||||
config(['fewo.scheduler_token' => 'geheim']);
|
||||
|
||||
$this->get('/automation/scheduler?token=falsch')->assertNotFound();
|
||||
$this->getJson('/automation/scheduler?token=geheim')->assertOk()->assertJsonStructure(['ran_at', 'output']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use App\Filament\Resources\Bookings\BookingResource;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TwoFactorAuthenticationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_admin_without_two_factor_must_set_it_up_first(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->withoutTwoFactor()->create());
|
||||
|
||||
$setUpUrl = Filament::getPanel('admin')->getSetUpRequiredMultiFactorAuthenticationUrl();
|
||||
|
||||
$this->get(BookingResource::getUrl('index'))->assertRedirect($setUpUrl);
|
||||
$this->get($setUpUrl)->assertOk()->assertSee('Authenticator', false);
|
||||
}
|
||||
|
||||
public function test_admin_with_two_factor_enters_the_admin(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->create());
|
||||
|
||||
$this->get(BookingResource::getUrl('index'))->assertOk();
|
||||
}
|
||||
|
||||
public function test_other_roles_may_work_without_two_factor(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->role(UserRole::Rentals)->withoutTwoFactor()->create());
|
||||
|
||||
$this->get(BookingResource::getUrl('index'))->assertOk();
|
||||
}
|
||||
|
||||
public function test_two_factor_secret_is_stored_encrypted(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->assertNotSame('JBSWY3DPEHPK3PXP', $user->getRawOriginal('app_authentication_secret'));
|
||||
$this->assertSame('JBSWY3DPEHPK3PXP', $user->fresh()->getAppAuthenticationSecret());
|
||||
}
|
||||
|
||||
public function test_command_creates_an_admin_with_interactively_entered_password(): void
|
||||
{
|
||||
$this->artisan('users:create', ['email' => 'Lars@Example.com', '--name' => 'Lars', '--role' => 'admin'])
|
||||
->expectsQuestion('Passwort (mind. 12 Zeichen)', 'ein-sicheres-passwort')
|
||||
->expectsQuestion('Passwort wiederholen', 'ein-sicheres-passwort')
|
||||
->assertSuccessful();
|
||||
|
||||
$user = User::firstWhere('email', 'lars@example.com');
|
||||
|
||||
$this->assertSame(UserRole::Admin, $user->role);
|
||||
$this->assertTrue(Hash::check('ein-sicheres-passwort', $user->password));
|
||||
$this->assertNull($user->getAppAuthenticationSecret());
|
||||
}
|
||||
|
||||
public function test_command_rejects_mismatching_passwords(): void
|
||||
{
|
||||
$this->artisan('users:create', ['email' => 'lars@example.com', '--name' => 'Lars', '--role' => 'admin'])
|
||||
->expectsQuestion('Passwort (mind. 12 Zeichen)', 'ein-sicheres-passwort')
|
||||
->expectsQuestion('Passwort wiederholen', 'etwas-anderes-passwort')
|
||||
->assertFailed();
|
||||
|
||||
$this->assertDatabaseCount('users', 0);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user