Docker-Images bauen und veröffentlichen / build (, omsorgCore/Dockerfile, omsorgcore) (push) Successful in 3s
Docker-Images bauen und veröffentlichen / build (, omsorgWeb/Dockerfile, omsorgweb) (push) Failing after 4s
Docker-Images bauen und veröffentlichen / build (VITE_OMSORG_CORE_URL=${{ vars.OMSORG_CORE_PUBLIC_URL }}, omsorgapp/Dockerfile, omsorgapp) (push) Successful in 3s
- omsorgapp: drop Electron, run as a plain Vite/React browser app; refresh token moves to an HttpOnly cookie (omsorgCore), CORS added for the new browser origin, document download/preview switched to Blob-based browser APIs. - Add Dockerfiles for omsorgCore, omsorgapp, and omsorgWeb, a docker-compose.yml wiring Postgres/MySQL/all three apps together, and a Gitea Actions workflow that builds and pushes images to the repo's container registry on push to main and on version tags. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
153 lines
5.1 KiB
PHP
153 lines
5.1 KiB
PHP
<?php
|
|
// Auth läuft vollständig über omsorgCore (siehe omsorgCoreClient.php) - kein lokaler
|
|
// Credential-Check, keine lokale users-Tabelle. Alles, was eine Seite über den eingeloggten
|
|
// Nutzer wissen muss, kommt aus $_SESSION['omsorgcore_profile'] (befüllt von /api/auth/me:
|
|
// username, firstName, lastName, email, phoneNumber, role, permissions).
|
|
require_once __DIR__ . '/omsorgCoreClient.php';
|
|
|
|
$secure = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|
|
|| (($_SERVER['SERVER_PORT'] ?? null) == 443);
|
|
session_set_cookie_params([
|
|
'lifetime' => 0,
|
|
'path' => '/',
|
|
'httponly' => true,
|
|
'secure' => $secure,
|
|
'samesite' => 'Lax',
|
|
]);
|
|
session_name('OMSORG_FELIX_APP');
|
|
session_start();
|
|
|
|
function _omsorgcore_config(): array {
|
|
static $config = null;
|
|
if ($config === null) {
|
|
$config = require __DIR__ . '/config.php';
|
|
}
|
|
return $config;
|
|
}
|
|
|
|
// Stellt sicher, dass $_SESSION['omsorgcore_access_token'] gültig ist - erneuert bei Bedarf still
|
|
// über den Refresh-Token (Server-seitig, der Browser bekommt nie einen Token zu sehen).
|
|
function _ensure_fresh_token(): bool {
|
|
if (empty($_SESSION['omsorgcore_access_token']) || empty($_SESSION['omsorgcore_refresh_token'])) {
|
|
return false;
|
|
}
|
|
|
|
$expiresAt = $_SESSION['omsorgcore_access_expires_at'] ?? null;
|
|
$stillValid = $expiresAt && strtotime($expiresAt) > time() + 30; // 30s Puffer
|
|
if ($stillValid) {
|
|
return true;
|
|
}
|
|
|
|
$result = omsorgcore_refresh(_omsorgcore_config(), $_SESSION['omsorgcore_refresh_token']);
|
|
if (!$result['ok']) {
|
|
_clear_omsorgcore_session();
|
|
return false;
|
|
}
|
|
|
|
_apply_token_pair($result['data']);
|
|
return true;
|
|
}
|
|
|
|
function _apply_token_pair(array $data): void {
|
|
$_SESSION['omsorgcore_access_token'] = $data['accessToken'];
|
|
$_SESSION['omsorgcore_refresh_token'] = $data['refreshToken'];
|
|
$_SESSION['omsorgcore_access_expires_at'] = $data['expiresAt'];
|
|
// Noch nicht verdrahtet (kein change-password.php in diesem Milestone) - Flag wird aber
|
|
// schon gesetzt, damit das Nachziehen später keine Änderung an Login/Session-Core braucht.
|
|
$_SESSION['omsorgcore_must_change_password'] = !empty($data['mustChangePassword']);
|
|
}
|
|
|
|
function _clear_omsorgcore_session(): void {
|
|
unset(
|
|
$_SESSION['omsorgcore_access_token'],
|
|
$_SESSION['omsorgcore_refresh_token'],
|
|
$_SESSION['omsorgcore_access_expires_at'],
|
|
$_SESSION['omsorgcore_must_change_password'],
|
|
$_SESSION['omsorgcore_profile']
|
|
);
|
|
}
|
|
|
|
// Lädt/cached /api/auth/me in der Session (Username/Rolle/Rechte). Wird nach Login und bei
|
|
// jedem is_logged_in()-Aufruf ohne gültigen Cache erneuert.
|
|
function _refresh_profile(): bool {
|
|
$result = omsorgcore_me(_omsorgcore_config(), $_SESSION['omsorgcore_access_token']);
|
|
if (!$result['ok']) {
|
|
return false;
|
|
}
|
|
|
|
$_SESSION['omsorgcore_profile'] = $result['data'];
|
|
return true;
|
|
}
|
|
|
|
function is_logged_in(): bool {
|
|
if (!_ensure_fresh_token()) {
|
|
return false;
|
|
}
|
|
if (empty($_SESSION['omsorgcore_profile'])) {
|
|
return _refresh_profile();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
function require_login(): void {
|
|
if (!is_logged_in()) {
|
|
header('Location: ../index.php');
|
|
exit;
|
|
}
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST)) {
|
|
verify_csrf();
|
|
}
|
|
}
|
|
|
|
function csrf_token(): string {
|
|
if (empty($_SESSION['csrf_token'])) {
|
|
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
|
}
|
|
return $_SESSION['csrf_token'];
|
|
}
|
|
|
|
function csrf_field(): string {
|
|
return '<input type="hidden" name="csrf_token" value="' . csrf_token() . '">';
|
|
}
|
|
|
|
function verify_csrf(): void {
|
|
$token = $_POST['csrf_token'] ?? '';
|
|
if (!hash_equals(csrf_token(), $token)) {
|
|
http_response_code(403);
|
|
exit('Ungültige Anfrage.');
|
|
}
|
|
}
|
|
|
|
function current_username(): string {
|
|
return $_SESSION['omsorgcore_profile']['username'] ?? '';
|
|
}
|
|
|
|
function current_name(): string {
|
|
$profile = $_SESSION['omsorgcore_profile'] ?? [];
|
|
$name = trim(($profile['firstName'] ?? '') . ' ' . ($profile['lastName'] ?? ''));
|
|
return $name !== '' ? $name : current_username();
|
|
}
|
|
|
|
function current_role(): string {
|
|
return $_SESSION['omsorgcore_profile']['role'] ?? '';
|
|
}
|
|
|
|
// Serverseitig ist jeder Endpunkt ohnehin über [RequirePermission] gegated (siehe
|
|
// omsorgCore/CLAUDE.md, "Rechtesystem") - das hier ist nur die UI-Seite davon (Tab/Formular
|
|
// ausblenden statt nur eine 403-Antwort abzuwarten), analog zu hasPermission() in
|
|
// omsorgapp/src/app/AuthContext.jsx. $_SESSION['omsorgcore_profile']['permissions'] kommt aus
|
|
// GET /api/auth/me (PermissionDto[] { module, action, scope }, siehe MeResponse in omsorgCore).
|
|
function has_permission(string $module, string $action): bool {
|
|
$permissions = $_SESSION['omsorgcore_profile']['permissions'] ?? [];
|
|
foreach ($permissions as $permission) {
|
|
if (($permission['module'] ?? null) === $module && ($permission['action'] ?? null) === $action) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function e(string $s): string {
|
|
return htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
|
}
|