html.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // Session initialisation (with cookies)
  3. if (
  4. isset($_COOKIE['niver-session-key']) // Resume session
  5. OR
  6. (SERVICE === "auth" // Create new session
  7. AND (PAGE === "login" OR PAGE === "register")
  8. AND isset($_POST['username']))
  9. ) {
  10. session_start([
  11. 'name' => 'niver-session-key',
  12. 'sid_length' => 64,
  13. 'sid_bits_per_character' => 6,
  14. 'cookie_secure' => true,
  15. 'cookie_httponly' => true,
  16. 'cookie_samesite' => 'Strict',
  17. 'cookie_path' => CONF['common']['prefix'] . '/',
  18. 'cookie_lifetime' => 432000, // = 60*60*24*5 = 5 days
  19. 'gc_maxlifetime' => 10800,
  20. 'use_strict_mode' => true,
  21. 'use_cookies' => true,
  22. 'use_only_cookies' => true,
  23. ]);
  24. }
  25. ?>
  26. <!DOCTYPE html>
  27. <html lang="fr"<?php if (!empty(SERVICE)) echo ' class="' . SERVICE . '"'; ?>>
  28. <head>
  29. <meta charset="utf-8">
  30. <title><?php
  31. foreach(array_reverse(TITLES_LINEAGE) as $id => $title)
  32. echo strip_tags($title) . (array_key_last(TITLES_LINEAGE) === $id ? '' : ' < ');
  33. ?></title>
  34. <?php
  35. foreach (array_diff(scandir(CONF['common']['root_path'] . "/css"), array('..', '.')) as $cssPath)
  36. echo ' <link type="text/css" rel="stylesheet" media="screen" href="' . CONF['common']['prefix'] . '/css/' . $cssPath . '">' . "\n";
  37. ?>
  38. <meta name="viewport" content="width=device-width, initial-scale=1">
  39. </head>
  40. <body>
  41. <header>
  42. <p>
  43. <?php if (isset($_SESSION['username'])) { ?>
  44. 🆔 <strong><?= $_SESSION['username'] ?></strong> <a class='auth' href='<?= CONF['common']['prefix'] ?>/auth/logout'>Se déconnecter</a>
  45. <?php } else { ?>
  46. <span aria-hidden="true">👻 </span><em>Anonyme</em> <a class="auth" href="<?= redirUrl('auth/login') ?>">Se connecter</a>
  47. <?php } ?>
  48. </p>
  49. <nav>
  50. <?php
  51. foreach (TITLES_LINEAGE as $id => $title) {
  52. $lastTitle = (TITLES_LINEAGE[array_key_last(TITLES_LINEAGE)] === $title);
  53. echo '<ul><li>' . ($lastTitle ? '<h1>' : '') . '<a' . (($id === 0) ? ' class="niver"' : '') . ' href="' . CONF['common']['prefix'] . ($lastTitle ? '/' . PAGE_URL : '/' . implode('/', array_slice(PAGE_LINEAGE, 0, $id)) . (($lastTitle OR $id === 0) ? '' : '/')) . '">' . $title . '</a>' . ($lastTitle ? '</h1>' : '') . "\n";
  54. }
  55. echo str_repeat('</li></ul>', count(TITLES_LINEAGE));
  56. ?>
  57. </nav>
  58. </header>
  59. <main>
  60. <?php
  61. if (in_array(SERVICE, ['reg', 'ns', 'ht']) AND CONF[SERVICE]['enabled'] !== true)
  62. userError("Ce service est désactivé.");
  63. // Protect against cross-site request forgery if a POST request is received
  64. if (empty($_POST) === false AND (isset($_SERVER['HTTP_SEC_FETCH_SITE']) !== true OR $_SERVER['HTTP_SEC_FETCH_SITE'] !== "same-origin"))
  65. userError("Anti-<abbr title='Cross-Site Request Forgery'>CSRF</abbr> verification failed ! (Wrong or unset <code>Sec-Fetch-Site</code> HTTP header)");
  66. function closeHTML() {
  67. global $final_message;
  68. if (isset($final_message))
  69. echo $final_message;
  70. ?>
  71. </main>
  72. </body>
  73. </html>
  74. <?php
  75. exit();
  76. }