diff --git a/index2.php b/index2.php new file mode 100644 index 0000000..5a3daf1 --- /dev/null +++ b/index2.php @@ -0,0 +1,1780 @@ +uploadDir, $this->imageDir, $this->galleryDir] + as $dir + ) { + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } + } + if (!file_exists($this->commentsFile)) { + file_put_contents($this->commentsFile, "[]"); + } + $this->lang = $_SESSION["lang"] ?? "de"; + } + public function getVideoPlayer() + { + return ' +'; + } + public function getImageFiles() + { + $files = glob($this->imageDir . "/screenshot_*.jpg"); + + rsort($files); + return json_encode($files); + } + public function getGalleryImages() + { + $images = []; + foreach ( + glob($this->galleryDir . "/*.{jpg,jpeg,png,gif}", GLOB_BRACE) + as $img + ) { + $images[] = [ + "src" => $img, + "thumb" => $img, + "date" => filemtime($img), + ]; + } + usort($images, function ($a, $b) { + return $b["date"] - $a["date"]; + }); + return $images; + } + public function getLatestVideo() + { + $videos = glob($this->imageDir . "/daily_video_*.mp4"); + if (empty($videos)) { + return null; + } + usort($videos, function ($a, $b) { + return filemtime($b) - filemtime($a); + }); + return $videos[0]; + } + public function addComment($name, $comment, $rating = 5) + { + $comments = + json_decode(file_get_contents($this->commentsFile), true) ?: []; + $comments[] = [ + "name" => htmlspecialchars($name), + "comment" => htmlspecialchars($comment), + "rating" => intval($rating), + "time" => time(), + "id" => uniqid(), + ]; + file_put_contents($this->commentsFile, json_encode($comments)); + return true; + } + public function getComments() + { + $comments = + json_decode(file_get_contents($this->commentsFile), true) ?: []; + usort($comments, function ($a, $b) { + return $b["time"] - $a["time"]; + }); + return array_slice($comments, 0, 50); + } +} +class TranslationManager +{ + private $translations = [ + "de" => [ + "live" => "Live", + "timelapse" => "Zeitraffer", + "archive" => "Archiv", + "gallery" => "Galerie", + "comments" => "Kommentare", + "info" => "Info", + "chat" => "Chat", + "send" => "Senden", + "download" => "Herunterladen", + "screenshot" => "Bildschirmfoto", + "fullscreen" => "Vollbild", + "welcome" => 'Willkommen +bei Aurora Webcam', + "rules" => "Nutzungsbedingungen", + "accept" => "Akzeptieren", + "decline" => "Ablehnen", + "contact" => "Kontakt", + "abuse" => 'Missbrauch +melden', + "rating" => "Bewertung", + "name" => "Name", + "comment" => "Kommentar", + "submit" => "Absenden", + "loading" => "Lädt...", + "error" => "Fehler", + "success" => "Erfolgreich", + "darkmode" => "Dunkler Modus", + "lightmode" => "Heller Modus", + ], + "fr" => [ + "live" => 'En +direct', + "timelapse" => "Accéléré", + "archive" => "Archive", + "gallery" => "Galerie", + "comments" => "Commentaires", + "info" => "Info", + "chat" => "Chat", + "send" => "Envoyer", + "download" => "Télécharger", + "screenshot" => 'Capture d\'écran', + "fullscreen" => 'Plein +écran', + "welcome" => "Bienvenue à Aurora Webcam", + "rules" => 'Conditions d\'utilisation', + "accept" => "Accepter", + "decline" => "Refuser", + "contact" => "Contact", + "abuse" => 'Signaler un +abus', + "rating" => "Évaluation", + "name" => "Nom", + "comment" => "Commentaire", + "submit" => "Envoyer", + "darkmode" => "Mode sombre", + "lightmode" => "Mode clair", + ], + "it" => [ + "live" => 'Dal +vivo', + "timelapse" => "Time-lapse", + "archive" => "Archivio", + "gallery" => "Galleria", + "comments" => "Commenti", + "info" => "Info", + "chat" => "Chat", + "send" => "Invia", + "download" => "Scarica", + "screenshot" => "Screenshot", + "fullscreen" => 'Schermo +intero', + "welcome" => "Benvenuti a Aurora Webcam", + "rules" => "Termini di utilizzo", + "accept" => "Accetta", + "decline" => "Rifiuta", + "contact" => "Contatto", + "abuse" => 'Segnala +abuso', + "rating" => "Valutazione", + "name" => "Nome", + "comment" => "Commento", + "submit" => "Invia", + "darkmode" => "Modalità scura", + "lightmode" => 'Modalità +chiara', + ], + "en" => [ + "live" => "Live", + "timelapse" => "Timelapse", + "archive" => "Archive", + "gallery" => "Gallery", + "comments" => "Comments", + "info" => "Info", + "chat" => "Chat", + "send" => "Send", + "download" => "Download", + "screenshot" => "Screenshot", + "fullscreen" => "Fullscreen", + "welcome" => 'Welcome +to Aurora Webcam', + "rules" => "Terms of Use", + "accept" => "Accept", + "decline" => "Decline", + "contact" => "Contact", + "abuse" => "Report Abuse", + "rating" => "Rating", + "name" => "Name", + "comment" => "Comment", + "submit" => "Submit", + "darkmode" => 'Dark +Mode', + "lightmode" => 'Light +Mode', + ], + "zh" => [ + "live" => "直播", + "timelapse" => "延时摄影", + "archive" => "档案", + "gallery" => "图库", + "comments" => "评论", + "info" => "信息", + "chat" => "聊天", + "send" => "发送", + "download" => "下载", + "screenshot" => "截图", + "fullscreen" => "全屏", + "welcome" => "欢迎来到Aurora网络摄像头", + "rules" => "使用条款", + "accept" => "接受", + "decline" => "拒绝", + "contact" => "联系", + "abuse" => "举报滥用", + "rating" => "评分", + "name" => "姓名", + "comment" => "评论", + "submit" => "提交", + "darkmode" => "深色模式", + "lightmode" => "浅色模式", + ], + ]; + private $currentLang = "de"; + public function __construct($lang = "de") + { + $this->currentLang = $lang; + } + public function t($key) + { + return $this->translations[$this->currentLang][$key] ?? + ($this->translations["de"][$key] ?? $key); + } + public function getLang() + { + return $this->currentLang; + } + public function setLang($lang) + { + if (isset($this->translations[$lang])) { + $this->currentLang = $lang; + $_SESSION["lang"] = $lang; + } + } +} +class ChatManager +{ + private $chatFile = "chat.json"; + private $maxMessages = 100; + public function __construct() + { + if (!file_exists($this->chatFile)) { + file_put_contents($this->chatFile, json_encode([])); + } + } + public function addMessage($user, $message) + { + $messages = $this->getMessages(); + $messages[] = [ + "user" => htmlspecialchars($user), + "message" => htmlspecialchars($message), + "time" => time(), + "id" => uniqid(), + ]; + if (count($messages) > $this->maxMessages) { + array_shift($messages); + } + file_put_contents($this->chatFile, json_encode($messages)); + return true; + } + public function getMessages() + { + $messages = json_decode(file_get_contents($this->chatFile), true) ?: []; + return array_filter($messages, function ($msg) { + return time() - $msg["time"] < 86400; + }); + } +} +class CalendarManager +{ + private $videoDir = "./image"; + public function getVideosForMonth($year, $month) + { + $videos = []; + $startDate = sprintf("%04d%02d01", $year, $month); + $endDate = sprintf("%04d%02d31", $year, $month); + foreach (glob($this->videoDir . "/daily_video_*.mp4") as $video) { + $filename = basename($video); + if (preg_match("/daily_video_(\d{8})/", $filename, $matches)) { + $videoDate = $matches[1]; + if ($videoDate >= $startDate && $videoDate <= $endDate) { + $day = intval(substr($videoDate, 6, 2)); + if (!isset($videos[$day])) { + $videos[$day] = []; + } + $videos[$day][] = $video; + } + } + } + return $videos; + } +} +$lang = $_GET["lang"] ?? ($_SESSION["lang"] ?? "de"); +$_SESSION["lang"] = $lang; +$t = new TranslationManager($lang); +$webcam = new WebcamManager(); +$chat = new ChatManager(); +$calendar = new CalendarManager(); +if (isset($_POST["chat_message"])) { + $chat->addMessage($_POST["chat_user"] ?? "Anonym", $_POST["chat_message"]); + header("Content-Type:application/json"); + echo json_encode(["success" => true]); + exit(); +} + +// Nach den anderen POST-Handlern +if (isset($_POST['action']) && $_POST['action'] === 'upload_screenshot') { + if (isset($_FILES['screenshot'])) { + // In BEIDE Ordner speichern + $galleries = ['./gallery/', './image/']; + $success = false; + + foreach ($galleries as $uploadDir) { + if (!file_exists($uploadDir)) mkdir($uploadDir, 0777, true); + + $filename = 'screenshot_' . date('Ymd_His') . '.jpg'; + $uploadFile = $uploadDir . $filename; + + if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $uploadFile)) { + $success = true; + break; + } + } + + header('Content-Type: application/json'); + echo json_encode(['success' => $success, 'file' => $filename]); + exit; + } +} + + +if (isset($_GET["get_messages"])) { + header("Content-Type:application/json"); + echo json_encode($chat->getMessages()); + exit(); +} +if (isset($_POST["add_comment"])) { + $webcam->addComment( + $_POST["comment_name"] ?? "Anonym", + $_POST["comment_text"], + $_POST["rating"] ?? 5, + ); + header("Content-Type:application/json"); + echo json_encode(["success" => true]); + exit(); +} +if (isset($_GET["get_comments"])) { + header("Content-Type:application/json"); + echo json_encode($webcam->getComments()); + exit(); +} +if (isset($_GET["get_gallery"])) { + header("Content-Type:application/json"); + echo json_encode($webcam->getGalleryImages()); + exit(); +} +if (isset($_GET["get_calendar_videos"])) { + $month = $_GET["month"] ?? date("n"); + $year = $_GET["year"] ?? date("Y"); + header("Content-Type:application/json"); + echo json_encode($calendar->getVideosForMonth($year, $month)); + exit(); +} +if (isset($_GET["download_video"])) { + $video = $webcam->getLatestVideo(); + if ($video && file_exists($video)) { + header("Content-Type:video/mp4"); + header( + 'Content-Disposition:attachment;filename="' . + basename($video) . + '"', + ); + readfile($video); + exit(); + } +} ?> + + + +
+ + +Die Webcam zeigt öffentlichen Raum. Die Nutzung erfolgt auf eigene Verantwortung.
+Mit der Nutzung akzeptieren Sie diese Regeln. Verstöße führen zur Sperrung.
+
t('comments');?>
+ +