servnest/common/top.php

107 lines
2.8 KiB
PHP

<?php
require "init.php";
function antiCSRF() {
if (!isset($_SERVER['HTTP_SEC_FETCH_SITE']) OR $_SERVER['HTTP_SEC_FETCH_SITE'] !== "same-origin")
userError("Anti-CSRF verification failed ! (Wrong or unset Sec-Fetch-Site HTTP header)");
}
// Session initialisation (with cookies)
if (
isset($_COOKIE['niver']) // Resume session
OR
(SERVICE === "auth" // Create new session
AND (PAGE === "login" OR PAGE === "register")
AND isset($_POST['username']))
) {
session_start([
'name' => 'niver',
'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,
]);
}
// Less > CSS compilation
// Color scheme
define("THEME", array(
// Displayed on light theme
'darkRegColor' => "#D100D1",
'darkNsColor' => "#006DFF",
'darkHtColor' => "#008768",
'darkAuthColor' => "#EE0000",
// Displayed on dark theme
'lightRegColor' => "#FF50FF",
'lightNsColor' => "#00FFFF",
'lightHtColor' => "#FFFF00",
'lightAuthColor' => "#00FF00",
'lightColor' => '#FFFFFF',
'darkColor' => '#000000',
));
require_once CONF['common']['root_path'] . "/lessphp/lib/Less/Autoloader.php";
Less_Autoloader::register();
// List files in less/
$relativeLessFiles = array_diff(scandir(CONF['common']['root_path'] . "/less"), array('..', '.'));
// Replace keys by values, and values by keys
$relativeLessFiles = array_flip($relativeLessFiles);
// Change relative paths into absolute paths
foreach ($relativeLessFiles as $relativeLessFile => $nothing) {
$absoluteLessFiles[CONF['common']['root_path'] . "/less/" . $relativeLessFile] = "";
}
// Generate one minified CSS file into public/css/ from sources in less/
$options = array(
'cache_dir' => CONF['common']['root_path'] . '/public/css/',
'compress' => true
);
$cssFileName = Less_Cache::Get($absoluteLessFiles, $options, THEME);
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title><?php
if (isset($page['title']) AND $page['title'] != "Accueil")
echo $page['title'] . " < ";
if (isset($page['service']))
echo $page['service'] . " < ";
?>Niver</title>
<link type="text/css" rel="stylesheet" href="<?= CONF['common']['prefix'] ?>/css/<?= $cssFileName ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<header>
<nav>
<a href="..">Niver</a><?php
if (isset($page['service']))
echo ' > <a href=".">' . $page['service'] . '</a>';
if (PAGE != "index")
echo ' > <a href="' . PAGE . '">' . $page['title'] . "</a>";
?>
</nav>
<?php if (isset($page['title'])) { ?>
<h1><?= $page['title'] ?></h1>
<?php } ?>
</header>
<main>