28 lines
1.0 KiB
PHP
28 lines
1.0 KiB
PHP
<?php
|
|
// /var/www/html/db_download.php
|
|
require_once __DIR__ . '/common.php';
|
|
|
|
// Token prüfen
|
|
$auth = $_SERVER['HTTP_AUTHORIZATION'] ?? ($_SERVER['Authorization'] ?? '');
|
|
if (stripos($auth, 'Bearer ') !== 0) { http_response_code(401); echo "Fehlender Bearer-Token"; exit; }
|
|
$token = substr($auth, 7);
|
|
if (!token_is_valid($token)) { http_response_code(403); echo "Ungültiger oder abgelaufener Token"; exit; }
|
|
|
|
// DB entschlüsseln
|
|
$path = __DIR__ . '/uploads/questionnaire_database';
|
|
if (!file_exists($path)) { http_response_code(404); echo "Datenbank nicht gefunden"; exit; }
|
|
$enc = file_get_contents($path);
|
|
if ($enc === false) { http_response_code(500); echo "Lesefehler"; exit; }
|
|
|
|
try {
|
|
$plain = aes256_cbc_decrypt_bytes($enc, get_master_key_bytes());
|
|
} catch (Throwable $e) {
|
|
http_response_code(500); echo "Entschlüsselung fehlgeschlagen"; exit;
|
|
}
|
|
|
|
// Ausliefern
|
|
header('Content-Type: application/octet-stream');
|
|
header('Content-Disposition: attachment; filename="questionnaire.sqlite"');
|
|
header('Content-Length: ' . strlen($plain));
|
|
echo $plain;
|