aboutsummaryrefslogtreecommitdiff
path: root/file/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'file/index.php')
-rw-r--r--file/index.php481
1 files changed, 481 insertions, 0 deletions
diff --git a/file/index.php b/file/index.php
new file mode 100644
index 0000000..d0cc0f9
--- /dev/null
+++ b/file/index.php
@@ -0,0 +1,481 @@
+<?php
+
+session_start();
+
+function l($fr, $en = null) {
+ if (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) === "fr") {
+ return $fr;
+ } else return $en ?? $fr;
+}
+
+function fallback() {if (true): ?>
+
+<!DOCTYPE html>
+<html>
+
+<head>
+ <title><?= l("Erreur", "Error") ?> | Familine Share</title>
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
+ <link rel="icon" href="/icns/22/application-x-core.svg">
+ <link rel="stylesheet" href="/dark.css">
+</head>
+
+<body>
+ <div style="margin-top:50px;text-align:center;padding-bottom:50px;" class="container">
+ <img src="/icns/64/application-x-core.svg" width="64px">
+ <h1><?= l("Fichier inconnu", "Unknown file") ?></h1>
+ <p><?= l("Nous ne parvenons pas à trouver le fichier, il a peut-être été supprimé ou a expiré. Si vous avez entré le lien par vous même, vérifiez l'ortographe.", "We couldn't find this file, it may have expired or has been deleted. If you entered the link by yourself, please check for spelling mistakes.") ?></p>
+ </div>
+</body>
+
+</html>
+
+<?php die();endif;
+}
+
+if ($_SERVER['SERVER_NAME'] !== "flsh.sytes.net") {
+ header("Location: /");
+ die();
+}
+
+if (isset($_GET['i'])) {
+ $id = $_GET['i'];
+} else {
+ fallback();
+}
+
+$selected = null;
+$profiles = scandir($_SERVER['DOCUMENT_ROOT'] . "/private/profiles");
+foreach ($profiles as $profile) {
+ if ($profile !== "." && $profile !== ".." && $profile !== "_base.json") {
+ $staging = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/private/profiles/" . $profile), true);
+ foreach ($staging['files'] as $file) {
+ if ($file['id'] === $id) {
+ $selected = $file;
+ $puser = $staging;
+ }
+ }
+ }
+}
+
+if ($selected === null) {
+ fallback();
+} else {
+ if ($selected['mime'] === "image/svg") {
+ $selected['mime'] = "image/svg+xml";
+ }
+ if ($selected['mime'] === "application/x-dosexec") {
+ $selected['mime'] = "application/x-ms-dos-executable";
+ }
+ if ($selected['mime'] === "application/x-mach-binary") {
+ $selected['mime'] = "application/x-macbinary";
+ }
+ $file = $selected;
+}
+
+$_SESSION["dlid"] = bin2hex(random_bytes(16)) . bin2hex(random_bytes(16)) . bin2hex(random_bytes(16)) . bin2hex(random_bytes(16));
+$_SESSION["pvid"] = bin2hex(random_bytes(16)) . bin2hex(random_bytes(16)) . bin2hex(random_bytes(16)) . bin2hex(random_bytes(16));
+$_SESSION['filename'] = $selected['file'];
+$_SESSION['name'] = $selected['name'];
+
+?>
+<!DOCTYPE html>
+<html>
+
+<head>
+ <title><?= $selected['name'] ?> | Familine Share</title>
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
+ <link rel="stylesheet" href="/dark.css">
+ <link rel="icon" href="<?php
+
+ $pmime = str_replace("/", "-", $selected['mime']);
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/icns/22/" . $pmime . ".svg")) {
+ echo("/icns/22/" . $pmime . ".svg");
+ } else {
+ echo("/icns/22/unknown.svg");
+ }
+
+ ?>">
+</head>
+
+<style>
+ @media (max-width: 700px) {
+ #desktopinfo {
+ display: none;
+ }
+ #header {
+ text-align: center;
+ display: block !important;
+ grid-template-columns: unset !important;
+ font-size: 1.5rem !important;
+ }
+ #header * {
+ font-size: 1.5rem !important;
+ }
+ #header img {
+ width: 64px !important;
+ }
+ .container > div {
+ width: 100% !important;
+ }
+ }
+</style>
+
+<body>
+ <div style="color:white;background:#111;padding-bottom:50px;padding-top:50px;">
+ <div class="container" id="header" style="display:grid;grid-template-columns: 1fr 1fr;">
+ <div>
+ <img src="<?php
+
+ $pmime = str_replace("/", "-", $selected['mime']);
+ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/icns/22/" . $pmime . ".svg")) {
+ echo("/icns/64/" . $pmime . ".svg");
+ } else {
+ echo("/icns/64/unknown.svg");
+ }
+
+ ?>" width="96px">
+ <h1><?= $selected['name'] ?></h1>
+ </div>
+ <div id="desktopinfo" style="text-align:right;">
+ <?php
+
+ $mime = $file['mime'];
+ if (strpos($mime, "audio/") !== false || strpos($mime, "video/") !== false || strpos($mime, "image/") !== false || strpos($mime, "application/pdf") !== false || strpos($mime, "text/html") !== false || strpos($mime, "text/xml") !== false || strpos($mime, "application/x-executable") !== false || strpos($mime, "application/x-sharedlib") !== false || strpos($mime, "application/x-pie-executable") !== false || strpos($mime, "application/x-dosexec") !== false || strpos($mime, "application/x-ms-dos-executable") !== false || strpos($mime, "application/x-mach-binary") !== false || strpos($mime, "application/x-macbinary") !== false): ?>
+ <h5><?= l("compatible avec", "works with") ?></h5>
+ <h3><b>Familine Share</b> Instant</h3>
+ <p style="max-width:75%;margin-left:auto;"><?= l("Ayez un aperçu du fichier avant même de le télécharger grâce à Familine Share Instant.", "Get a preview of this file before even downloading it with Familine Share Instant.") ?> <a href="#" data-toggle="modal" data-target="#aboutinstant" style="color:white;text-decoration:underline;"><?= l("En savoir plus", "Learn more") ?></a></p>
+ <a href="#instant" class="btn btn-light"><?= l("Voir l'Instant", "View the Instant") ?></a>
+ <?php endif;
+
+ ?>
+ </div>
+ </div>
+ </div>
+ <div style="margin-top:50px;text-align:center;margin-bottom: 50px;" class="container">
+ <p><?= !$selected['anonymous'] ? "<b>" . $selected['author'] . "</b>" : l("Quelqu'un", "Someone") ?> <?php
+
+ if (!$selected['anonymous'] && isset($puser['staff'])) {
+ echo('<span title="'.l("Équipe d'administration système de Familine", "Familine system administrators team").'" style="cursor:help;background: none;color: purple;border: 1px solid purple;" class="badge badge-pill badge-primary">STAFF</span> ');
+ }
+
+ ?><?= l("vous partage un fichier de type :", "shares with you a file of the following type:") ?> <b><?php
+
+ $done = true;
+ switch ($selected['mime']) {
+ case 'directory':
+ $icon = "folder";
+ $pretty = l("Dossier", "Directory");
+ break;
+ case 'text/plain':
+ $icon = "text_snippet";
+ $pretty = l("Fichier texte", "Text file");
+ break;
+ case 'application/octet-stream':
+ $icon = "help_center";
+ $pretty = l("Fichier binaire", "Binary file");
+ break;
+ case 'application/pdf':
+ case 'application/vnd.oasis.opendocument.text':
+ case 'application/rtf':
+ case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
+ case 'application/msword':
+ case 'application/x-abiword':
+ $icon = "description";
+ $pretty = l("Document texte", "Text document");
+ break;
+ case 'application/vnd.visio':
+ case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
+ case 'application/vnd.ms-powerpoint':
+ case 'application/vnd.oasis.opendocument.presentation':
+ $icon = "analytics";
+ $pretty = l("Présentation", "Presentation");
+ break;
+ case 'application/epub+zip':
+ case 'application/vnd.amazon.ebook':
+ $icon = "book";
+ $pretty = l("Livre électronique", "Electronical book");
+ break;
+ case 'text/x-mup':
+ case 'application/zip':
+ case 'application/gzip':
+ case 'application/x-7z-compressed':
+ case 'application/x-tar':
+ case 'application/x-bzip':
+ case 'application/x-bzip2':
+ case 'application/vnd.rar':
+ case 'application/x-freearc':
+ $icon = "archive";
+ $pretty = l("Archive compressée", "Compressed archive");
+ break;
+ case 'application/x-cd-image':
+ $icon = "album";
+ $pretty = l("Image de disque", "Disk image");
+ break;
+ case 'application/x-sh':
+ case 'application/x-cshell':
+ $icon = "request_quote";
+ $pretty = l("Programme d'interpréteur", "Interpreted script");
+ break;
+ case 'font/woff2':
+ case 'font/woff':
+ case 'font/ttf':
+ case 'font/otf':
+ case 'application/vnd.ms-fontobject':
+ $icon = "font_download";
+ $pretty = l("Typographie", "Font");
+ break;
+ case 'application/xhtml+xml':
+ case 'application/xml':
+ case 'text/xml':
+ case 'text/html':
+ case 'application/json':
+ case 'application/ld+json':
+ case 'text/javascript':
+ case 'text/css':
+ $icon = "code";
+ $pretty = l("Code source", "Source code");
+ break;
+ case 'text/calendar':
+ $icon = "event";
+ $pretty = l("Calendrier", "Calendar");
+ break;
+ case 'application/vnd.mozilla.xul+xml':
+ case 'application/x-shockwave-flash':
+ case 'application/x-sharedlib':
+ case 'application/vnd.android.package-archive':
+ case 'application/x-msi':
+ case 'application/x-ms-dos-executable':
+ case 'application/vnd.apple.installer+xml':
+ case 'application/java-archive':
+ case 'application/x-macbinary':
+ case 'application/x-mach-binary':
+ $icon = "open_in_browser";
+ $pretty = l("Exécutable", "Application");
+ break;
+ case 'application/vnd.oasis.opendocument.spreadsheet':
+ case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
+ case 'application/vnd.ms-excel':
+ case 'text/csv':
+ $icon = "table_view";
+ $pretty = l("Feuille de calcul", "Spreadsheet");
+ break;
+ case 'application/vnd.oasis.opendocument.graphics':
+ $pretty = l("Composition graphique", "Graphical composition");
+ break;
+ case 'application/ogg':
+ $icon = "headset";
+ $pretty = l("Fichier audio", "Audio file");
+ break;
+ default:
+ $done = false;
+ break;
+ }
+
+ if (substr($selected['mime'], 0, 6) == "audio/") {
+ $icon = "headset";
+ $pretty = l("Fichier audio", "Audio file");
+ $done = true;
+ }
+
+ if (substr($selected['mime'], 0, 6) == "video/") {
+ $icon = "videocam";
+ $pretty = l("Fichier vidéo", "Video file");
+ $done = true;
+ }
+
+ if (substr($selected['mime'], 0, 6) == "image/") {
+ $icon = "insert_photo";
+ $pretty = l("Image", "Picture");
+ $done = true;
+ }
+
+ if ($done) {
+ echo($pretty);
+ } else {
+ echo(ucwords(implode(" ► ", explode("/", $selected['mime']))));
+ }
+
+ ?></b></p>
+
+ <p>
+ <a class="btn btn-primary" href="/d/<?= $_SESSION['dlid'] ?>" style="font-size:32px;"><?= l("Télécharger", "Download") ?></a>
+ </p>
+
+ <p><?= l("Taille du fichier :", "File size:") ?> <?php
+
+ $size = $selected['size'];
+
+ if ($size > 1000) {
+ if ($size > (1000 * 1000)) {
+ echo(round(($size / (1000 * 1000))) . " ". l("Mo", "MB"));
+ } else {
+ echo(round(($size / 1000)) . " ". l("Ko", "KB"));
+ }
+ } else {
+ echo($size . " ". l("octets", "bytes"));
+ }
+
+ ?><br><?= l("Somme de contrôle MD5 :", "MD5 checksum:") ?> <code><?= md5_file($_SERVER['DOCUMENT_ROOT'] . "/private/shares/" . $selected['file']) ?></code><br><?= l("Expire dans", "Expires in") ?> <?php
+
+ $old = new DateTime($selected['expiration']);
+ $new = new DateTime();
+ $diff = $new->diff($old, true);
+
+ if ($diff->m > 0) {
+ if ($diff->m > 1) {
+ echo($diff->m . " " . l("mois", "months"));
+ } else {
+ echo($diff->m . " " . l("mois", "month"));
+ }
+ } else if ($diff->d > 0) {
+ if ($diff->d > 1) {
+ echo($diff->d . " " . l("jours", "days"));
+ } else {
+ echo($diff->d . " " . l("jour", "day"));
+ }
+ } else if ($diff->h > 0) {
+ if ($diff->h > 1) {
+ echo($diff->h . " " . l("heures", "hours"));
+ } else {
+ echo($diff->h . " " . l("heure", "hour"));
+ }
+ } else if ($diff->i > 0) {
+ if ($diff->i > 1) {
+ echo($diff->i . " " . l("minutes", "minutes"));
+ } else {
+ echo($diff->i . " " . l("minute", "minute"));
+ }
+ } else {
+ echo(l("moins d'une minute", "less than a minute"));
+ }
+
+ ?></p>
+
+ <hr>
+ <?php if (trim($selected['message']) !== ""): ?>
+ <b>Description<?= l(" ", "") ?>:</b><br>
+ <?= str_replace("\n", "<br>", str_replace(">", "&gt;", str_replace("<", "&lt;", $selected['message']))) ?>
+ <hr>
+ <?php endif; ?>
+ <h3><b>Familine Share</b> Instant</h3>
+ <p><?= l("Ayez un aperçu du fichier avant même de le télécharger grâce à Familine Share Instant.", "Get a preview of this file before even downloading it with Familine Share Instant.") ?> <a href="#" data-toggle="modal" data-target="#aboutinstant"><?= l("En savoir plus", "Learn more") ?></a></p>
+ <?php
+
+ $mime = $selected['mime'];
+ $nothing = true;
+ if (strpos($mime, "audio/") !== false): ?>
+ <audio id="instant" controls style="border:2px solid blue;max-width:100%;max-height:100vh;border-radius:10px;">
+ <source src="/p/<?= $_SESSION["pvid"] ?>">
+ </audio>
+ <?php $nothing = false; endif; if (strpos($mime, "video/") !== false): ?>
+ <video id="instant" controls style="border:2px solid blue;max-width:100%;max-height:100vh;border-radius:10px;">
+ <source src="/p/<?= $_SESSION["pvid"] ?>">
+ </video>
+ <?php $nothing = false; endif; if (strpos($mime, "image/svg") !== false): ?>
+ <img id="instant" src="data:image/svg+xml;base64,<?= base64_encode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/private/shares/" . $selected['file'])) ?>" style="border:2px solid blue;max-width:100%;max-height:100vh;border-radius:10px;">
+ <?php $nothing = false; endif; if (strpos($mime, "image/") !== false && $nothing): ?>
+ <img id="instant" src="/p/<?= $_SESSION["pvid"] ?>" style="border:2px solid blue;max-width:100%;max-height:100vh;border-radius:10px;">
+ <?php $nothing = false; endif; if (strpos($mime, "application/pdf") !== false): ?>
+ <iframe id="instant" src="/p/<?= $_SESSION["pvid"] ?>" style="border:2px solid blue;width:100%;height:100vh;border-radius:10px;"></iframe>
+ <?php $nothing = false; endif; if (strpos($mime, "text/html") !== false): ?>
+ <iframe id="instant" src="/p/<?= $_SESSION["pvid"] ?>" style="border:2px solid blue;width:100%;height:100vh;border-radius:10px;"></iframe>
+ <?php $nothing = false; endif; if (strpos($mime, "text/xml") !== false): ?>
+ <iframe id="instant" src="/p/<?= $_SESSION["pvid"] ?>" style="border:2px solid blue;width:100%;height:100vh;border-radius:10px;"></iframe>
+ <?php $nothing = false; endif; if (strpos($mime, "application/x-executable") !== false || strpos($mime, "application/x-sharedlib") !== false || strpos($mime, "application/x-pie-executable") !== false): ?>
+ <div id="instant" style="border:2px solid blue;max-width:100%;max-height:100vh;border-radius:10px;"><p>
+ <b><?= l("Programme Linux", "Linux executable") ?></b>
+ <p><?php
+
+ $parts = explode(", ", exec("file -b \"" . $_SERVER['DOCUMENT_ROOT'] . "/private/shares/" . $selected['file'] . "\""));
+ foreach ($parts as $part) {
+ echo("<li>{$part}</li>");
+ }
+
+ ?></p>
+ </p></div>
+ <?php $nothing = false; endif; if (strpos($mime, "application/x-dosexec") !== false || strpos($mime, "application/x-ms-dos-executable") !== false): ?>
+ <div id="instant" style="border:2px solid blue;max-width:100%;max-height:100vh;border-radius:10px;"><p>
+ <b><?= l("Programme DOS/Windows", "DOS/Windows executable") ?></b>
+ <p><?php
+
+ $parts = explode(", ", exec("file -b \"" . $_SERVER['DOCUMENT_ROOT'] . "/private/shares/" . $selected['file'] . "\""));
+ foreach ($parts as $part) {
+ echo("<li>{$part}</li>");
+ }
+
+ ?></p>
+ </p></div>
+ <?php $nothing = false; endif; if (strpos($mime, "application/x-mach-binary") !== false || strpos($mime, "application/x-macbinary") !== false): ?>
+ <div id="instant" style="border:2px solid blue;max-width:100%;max-height:100vh;border-radius:10px;"><p>
+ <b><?= l("Programme macOS/OpenDarwin", "macOS/OpenDarwin executable") ?></b>
+ <p><?php
+
+ $parts = explode(", ", exec("file -b \"" . $_SERVER['DOCUMENT_ROOT'] . "/private/shares/" . $selected['file'] . "\""));
+ foreach ($parts as $part) {
+ echo("<li>{$part}</li>");
+ }
+
+ ?></p>
+ </p></div>
+ <?php $nothing = false; endif; if (strpos($mime, "text/") !== false && $nothing): ?>
+ <textarea id="instant" disabled style="background:white; color: black;font-family: var(--font-family-monospace);cursor:text;border:2px solid blue;width:100%;height:100vh;border-radius:10px;"><?php
+ $file = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/private/shares/" . $selected['file']);
+ echo(substr($file, 0, 50000));
+ if (strlen($file) > 50000) {
+ echo("\n\n**********\n" . l("Fichier tronqué, téléchargez pour récupérer le fichier complet.", "File is truncated, download it to get the whole file."));
+ }
+ ?></textarea>
+ <?php $nothing = false; endif; if ($nothing): ?>
+ <i id="instant">Familine Share Instant <?= l("n'est pas disponible pour ce type de fichier", "isn't available for this type of file") ?></i>
+ <?php endif;
+
+ ?>
+ </div>
+
+ <div class="modal fade" id="aboutinstant">
+ <div class="modal-dialog">
+ <div class="modal-content">
+
+ <div class="modal-header">
+ <h4 class="modal-title"><?= l("À propos de", "About") ?> Familine Share Instant</h4>
+ <button type="button" class="close" data-dismiss="modal">&times;</button>
+ </div>
+
+ <div class="modal-body">
+ <p>
+ <?= l("Familine Share Instant est une technologie qui vous permet de visualiser les fichiers sans que vous ayez besoin de les télécharger. Cela vous permet entre autres de vous assurer que le fichier que vous vous apprêtez à télécharger et bien ce à quoi vous vous attendez.", "Familine Share Instant is a technology that helps you preview files without having to download them. This, in fact, helps you make sure the file you download is what you expect.") ?>
+ </p>
+ <p>
+ <?= l("Familine Share Instant détecte automatiquement le type de fichier et détermine si il est possible d'afficher un aperçu du fichier. Dans le cas où c'est possible, il doit par la suite déterminer quel type d'aperçu il doit charger (lecteur vidéo, lecteur audio, image, ...)", "Familine Share Instant automatically detects the file type and checks whether or not it's possible to show a preview of the file. If it is possible, it then needs to find which type of preview it needs to load (video player, audio player, picture, ...)") ?>
+ </p>
+ <?= l("Familine Share Instant est actuellement compatible avec les fichiers suivants :", "Familine Share Instant is currently compatible with these files:") ?>
+ <ul>
+ <li><?= l("fichiers audio", "audio files") ?></li>
+ <li><?= l("fichiers vidéo", "video files") ?></li>
+ <li><?= l("images matricielles et vectorielles", "raster and vector graphics (pictures)") ?></li>
+ <li><?= l("documents PDF", "PDF documents") ?></li>
+ <li><?= l("documents HTML et XHTML", "XHTML and HTML documents") ?></li>
+ <li><?= l("code et texte brut", "source code and plain text") ?></li>
+ <li><?= l("programmes et autres exécutables", "programs and other executables") ?></li>
+ </ul>
+ <?= l("Le support ne peut toutefois pas être garanti car il dépend de votre système d'exploitation et/ou de votre navigateur Web.", "Support cannot however be guaranteed since it depends on your operating system and/or Web browser.") ?>
+ </div>
+
+ <div class="modal-footer">
+ <span style="margin-right: auto;"><b>Instant</b> version <?= date('Y-m-d') ?></span>
+ <button type="button" class="btn btn-danger" data-dismiss="modal"><?= l("Fermer", "Close") ?></button>
+ </div>
+
+ </div>
+ </div>
+ </div>
+</body>
+
+</html> \ No newline at end of file