aboutsummaryrefslogtreecommitdiff
path: root/file/index.php
blob: d5ad3ef34e23a5374c4507fbb4f92f8423b19e9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
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'] !== "viewer.familine.minteck.org") {
    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>