servnest/top.inc.php

130 lines
3.9 KiB
PHP

<?php
if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
exit("This file is meant to be included.");
session_start([
'name' => 'niver',
'sid_length' => 64,
'cookie_secure' => true,
'cookie_httponly' => true,
'cookie_samesite' => 'Strict',
'cookie_lifetime' => 604800,
'gc_maxlifetime' => 604800,
'use_strict_mode' => true,
'use_cookies' => true,
'use_only_cookies' => true,
]);
define("USERNAME_REGEX", "^[a-z]{4,32}$");
define("PASSWORD_REGEX", "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]{8,1024}|.{10,1024}$");
define("SUBDOMAIN_REGEX", "^[a-z]{4,63}$");
define("PREFIX", "/eltrode"); // Prefix in the URL, if any
define("ROOT_PATH", "/srv/http/niver" . PREFIX); // Niver directory
define("DB_PATH", ROOT_PATH . "/db/niver.db"); // Niver SQLite database
define("KNOTC_PATH", "/usr/sbin/knotc"); // Binary file
define("KEYMGR_PATH", "/usr/sbin/keymgr"); // Binary file
define("NGINX_CONFIG_PATH", "/etc/nginx/hyper"); // Config directory
define("TOR_CONFIG_PATH", "/etc/tor/torrc"); // Config file
define("TOR_KEYS_PATH", "/var/lib/tor/niver"); // Keys directory
define("SUDO_PATH", "/usr/bin/sudo"); // Binary file
define("MANIVER_PATH", "/root/maniver/target/release/maniver"); // Binary file
// The mountpoint of the hypertext storage partition (that will be accessed over SFTP)
define("HT_PATH", "/srv/hyper");
define("SERVICE", substr(dirname($_SERVER['PHP_SELF']), strlen(PREFIX) + 1));
define("PAGE", basename($_SERVER['PHP_SELF'], '.php'));
if (SERVICE != "auth" AND !isset($_SESSION['username'])) {
header('Location: ' . PREFIX . '/auth/login?redir=' . SERVICE . "/" . PAGE, true, 302);
exit;
}
if (substr($_SERVER['REQUEST_URI'], -4) == ".php") {
header("Location: " . PREFIX . "/" . SERVICE . "/" . PAGE, true, 301); // 301 Moved Permanently
exit;
}
$theme = array(
'htColor' => "#FF0000",
'regColor' => "#DA03E5",
'authColor' => "#00FF00",
'nsColor' => "#00c4c4",
'lightColor' => '#FFFFFF',
'darkColor' => '#2a2a2a',
);
switch (SERVICE) {
case "ht":
$theme = array('mainColor' => $theme['htColor']) + $theme;
break;
case "reg":
$theme = array('mainColor' => $theme['regColor']) + $theme;
break;
case "ns":
$theme = array('mainColor' => $theme['nsColor']) + $theme;
break;
default:
$theme = array('mainColor' => $theme['authColor']) + $theme;
break;
}
require "inc/all.inc.php";
require "inc/format.inc.php";
require "inc/ht.inc.php";
require "inc/ns.inc.php";
require "inc/pages.inc.php";
require "inc/reg.inc.php";
require_once 'lessphp/lib/Less/Autoloader.php';
Less_Autoloader::register();
$relativeLessFiles = array_diff(scandir(ROOT_PATH . "/less"), array('..', '.'));
$relativeLessFiles = array_flip($relativeLessFiles);
foreach ($relativeLessFiles as $relativeLessFile => $nothing) {
$absoluteLessFiles[ROOT_PATH . "/less/" . $relativeLessFile] = "";
}
$options = array('cache_dir' => ROOT_PATH . '/css/', 'compress' => true);
$cssFileName = Less_Cache::Get($absoluteLessFiles, $options, $theme);
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<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="<?= PREFIX ?>/css/<?= $cssFileName ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<header>
<nav>
<a href="<?= PREFIX ?>">Niver</a><?php
$homepage = (PAGE != "index");
if (isset($page['service'])) {
echo ' > ';
if ($homepage)
echo '<a href="./">';
echo $page['service'];
if ($homepage)
echo '</a>';
}
if ($homepage)
echo " > " . $page['title'];
?>
</nav>
<?php if (isset($page['title'])) { ?>
<h1><?= $page['title'] ?></h1>
<?php } ?>
</header>