瀏覽代碼

Merge html.php into router.php

Miraty 2 年之前
父節點
當前提交
9775de3a40
共有 2 個文件被更改,包括 76 次插入85 次删除
  1. 0 83
      html.php
  2. 76 2
      router.php

+ 0 - 83
html.php

@@ -1,83 +0,0 @@
-<?php
-
-// Session initialisation (with cookies)
-if (
-		isset($_COOKIE['niver-session-key']) // Resume session
-	OR
-		(SERVICE === "auth" // Create new session
-		AND (PAGE === "login" OR PAGE === "register")
-		AND isset($_POST['username']))
-	) {
-	session_start([
-		'name' => 'niver-session-key',
-		'sid_length' => 64,
-		'sid_bits_per_character' => 6,
-		'cookie_secure' => true,
-		'cookie_httponly' => true,
-		'cookie_samesite' => 'Strict',
-		'cookie_path' => CONF['common']['prefix'] . '/',
-		'cookie_lifetime' => 432000, // = 60*60*24*5 = 5 days
-		'gc_maxlifetime' => 10800,
-		'use_strict_mode' => true,
-		'use_cookies' => true,
-		'use_only_cookies' => true,
-	]);
-}
-
-?>
-<!DOCTYPE html>
-<html lang="fr"<?php if (!empty(SERVICE)) echo ' class="' . SERVICE . '"'; ?>>
-	<head>
-		<meta charset="utf-8">
-		<title><?php
-foreach(array_reverse(TITLES_LINEAGE) as $id => $title)
-	echo strip_tags($title) . (array_key_last(TITLES_LINEAGE) === $id ? '' : ' < ');
-?></title>
-<?php
-foreach (array_diff(scandir(CONF['common']['root_path'] . "/css"), array('..', '.')) as $cssPath)
-	echo '		<link type="text/css" rel="stylesheet" media="screen" href="' . CONF['common']['prefix'] . '/css/' . $cssPath . '">' . "\n";
-?>
-		<meta name="viewport" content="width=device-width, initial-scale=1">
-	</head>
-	<body>
-		<header>
-			<p>
-<?php if (isset($_SESSION['username'])) { ?>
-				🆔 <strong><?= $_SESSION['username'] ?></strong> <a class='auth' href='<?= CONF['common']['prefix'] ?>/auth/logout'>Se déconnecter</a>
-<?php } else { ?>
-				<span aria-hidden="true">👻 </span><em>Anonyme</em> <a class="auth" href="<?= redirUrl('auth/login') ?>">Se connecter</a>
-<?php } ?>
-			</p>
-			<nav>
-<?php
-foreach (TITLES_LINEAGE as $id => $title) {
-	$lastTitle = (TITLES_LINEAGE[array_key_last(TITLES_LINEAGE)] === $title);
-	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";
-}
-echo str_repeat('</li></ul>', count(TITLES_LINEAGE));
-?>
-
-			</nav>
-		</header>
-		<main>
-<?php
-
-if (in_array(SERVICE, ['reg', 'ns', 'ht']) AND CONF[SERVICE]['enabled'] !== true)
-	userError("Ce service est désactivé.");
-
-// Protect against cross-site request forgery if a POST request is received
-if (empty($_POST) === false AND (isset($_SERVER['HTTP_SEC_FETCH_SITE']) !== true OR $_SERVER['HTTP_SEC_FETCH_SITE'] !== "same-origin"))
-	userError("Anti-<abbr title='Cross-Site Request Forgery'>CSRF</abbr> verification failed ! (Wrong or unset <code>Sec-Fetch-Site</code> HTTP header)");
-
-function closeHTML() {
-	global $final_message;
-	if (isset($final_message))
-		echo $final_message;
-?>
-		</main>
-	</body>
-</html>
-<?php
-
-	exit();
-}

+ 76 - 2
router.php

@@ -55,10 +55,84 @@ function getTitlesLineage($titles, $pageElements) {
 }
 define('TITLES_LINEAGE', array_reverse(getTitlesLineage(TITLES, PAGE_LINEAGE)));
 
-require "html.php";
+if (
+		isset($_COOKIE['niver-session-key']) // Resume session
+	OR
+		(SERVICE === "auth" // Create new session
+		AND (PAGE === "login" OR PAGE === "register")
+		AND isset($_POST['username']))
+	) {
+	session_start([
+		'name' => 'niver-session-key',
+		'sid_length' => 64,
+		'sid_bits_per_character' => 6,
+		'cookie_secure' => true,
+		'cookie_httponly' => true,
+		'cookie_samesite' => 'Strict',
+		'cookie_path' => CONF['common']['prefix'] . '/',
+		'cookie_lifetime' => 432000, // = 60*60*24*5 = 5 days
+		'gc_maxlifetime' => 10800,
+		'use_strict_mode' => true,
+		'use_cookies' => true,
+		'use_only_cookies' => true,
+	]);
+}
+
+?>
+<!DOCTYPE html>
+<html lang="fr"<?php if (!empty(SERVICE)) echo ' class="' . SERVICE . '"'; ?>>
+	<head>
+		<meta charset="utf-8">
+		<title><?php
+foreach(array_reverse(TITLES_LINEAGE) as $id => $title)
+	echo strip_tags($title) . (array_key_last(TITLES_LINEAGE) === $id ? '' : ' < ');
+?></title>
+<?php
+foreach (array_diff(scandir(CONF['common']['root_path'] . "/css"), array('..', '.')) as $cssPath)
+	echo '		<link type="text/css" rel="stylesheet" media="screen" href="' . CONF['common']['prefix'] . '/css/' . $cssPath . '">' . "\n";
+?>
+		<meta name="viewport" content="width=device-width, initial-scale=1">
+	</head>
+	<body>
+		<header>
+			<p>
+<?php if (isset($_SESSION['username'])) { ?>
+				🆔 <strong><?= $_SESSION['username'] ?></strong> <a class='auth' href='<?= CONF['common']['prefix'] ?>/auth/logout'>Se déconnecter</a>
+<?php } else { ?>
+				<span aria-hidden="true">👻 </span><em>Anonyme</em> <a class="auth" href="<?= redirUrl('auth/login') ?>">Se connecter</a>
+<?php } ?>
+			</p>
+			<nav>
+<?php
+foreach (TITLES_LINEAGE as $id => $title) {
+	$lastTitle = (TITLES_LINEAGE[array_key_last(TITLES_LINEAGE)] === $title);
+	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";
+}
+echo str_repeat('</li></ul>', count(TITLES_LINEAGE));
+?>
+
+			</nav>
+		</header>
+		<main>
+<?php
+
+if (in_array(SERVICE, ['reg', 'ns', 'ht']) AND CONF[SERVICE]['enabled'] !== true)
+	userError("Ce service est désactivé.");
+
+// Protect against cross-site request forgery if a POST request is received
+if (empty($_POST) === false AND (isset($_SERVER['HTTP_SEC_FETCH_SITE']) !== true OR $_SERVER['HTTP_SEC_FETCH_SITE'] !== "same-origin"))
+	userError("Anti-<abbr title='Cross-Site Request Forgery'>CSRF</abbr> verification failed ! (Wrong or unset <code>Sec-Fetch-Site</code> HTTP header)");
 
 function executePage() {
 	require "pages/" . PAGE_ADDRESS . ".php";
-	closeHtml();
+
+	global $final_message;
+	echo $final_message ?? '';
+?>
+		</main>
+	</body>
+</html>
+<?php
+	exit();
 }
 executePage();