isEmailSharingEnabled()) { echo json_encode(['success' => false, 'error' => 'E-Mail-Sharing ist deaktiviert']); exit; } // Config laden $configFile = dirname(__DIR__) . '/config.php'; $config = file_exists($configFile) ? require $configFile : []; $mailConfig = $config['mail'] ?? []; if (empty($mailConfig['host']) || empty($mailConfig['username'])) { echo json_encode(['success' => false, 'error' => 'E-Mail-Server nicht konfiguriert']); exit; } // === GET: Share-Link generieren === if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['generate'])) { $path = $_GET['path'] ?? ''; $type = $_GET['type'] ?? 'video'; if (empty($path)) { echo json_encode(['success' => false, 'error' => 'Kein Pfad angegeben']); exit; } // Token generieren $expiryHours = $settingsManager->getShareLinkExpiryHours(); $expiry = time() + ($expiryHours * 3600); $token = hash_hmac('sha256', $path . $expiry, session_id() . 'share_secret'); // Share-Link speichern $shareDir = dirname(__DIR__) . '/data/shares/'; if (!is_dir($shareDir)) { mkdir($shareDir, 0755, true); } $shareId = bin2hex(random_bytes(16)); $shareData = [ 'id' => $shareId, 'path' => $path, 'type' => $type, 'token' => $token, 'expiry' => $expiry, 'created_at' => date('Y-m-d H:i:s') ]; file_put_contents($shareDir . $shareId . '.json', json_encode($shareData)); // URL generieren $baseUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; $shareUrl = $baseUrl . '/api/share.php?view=' . $shareId; echo json_encode([ 'success' => true, 'share_url' => $shareUrl, 'share_id' => $shareId, 'expires_at' => date('Y-m-d H:i:s', $expiry) ]); exit; } // === GET: Share-Link anzeigen === if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['view'])) { $shareId = preg_replace('/[^a-f0-9]/', '', $_GET['view']); $shareFile = dirname(__DIR__) . '/data/shares/' . $shareId . '.json'; if (!file_exists($shareFile)) { header('Content-Type: text/html; charset=utf-8'); echo '
Dieser Share-Link existiert nicht oder wurde bereits gelöscht.
'; exit; } $shareData = json_decode(file_get_contents($shareFile), true); // Ablauf prüfen if (time() > $shareData['expiry']) { @unlink($shareFile); header('Content-Type: text/html; charset=utf-8'); echo 'Dieser Share-Link ist abgelaufen. Bitte fordere einen neuen Link an.
'; exit; } // Datei existiert? $filePath = dirname(__DIR__) . $shareData['path']; if (!file_exists($filePath)) { header('Content-Type: text/html; charset=utf-8'); echo 'Die geteilte Datei existiert nicht mehr.
'; exit; } // Redirect zur Datei oder HTML-Seite mit eingebettetem Player $isVideo = in_array(pathinfo($filePath, PATHINFO_EXTENSION), ['mp4', 'webm', 'mov']); $isImage = in_array(pathinfo($filePath, PATHINFO_EXTENSION), ['jpg', 'jpeg', 'png', 'gif', 'webp']); $siteName = $config['app']['name'] ?? 'Aurora Livecam'; $baseUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; header('Content-Type: text/html; charset=utf-8'); echo '' . htmlspecialchars($senderName) . ' hat ' . ($type === 'video' ? 'ein Video' : 'ein Bild') . ' mit dir geteilt!
' . (!empty($message) ? 'Dieser Link ist ' . $expiryHours . ' Stunden gültig.