servnest/top.inc.php

116 lines
3.7 KiB
PHP
Raw Normal View History

2021-01-22 21:58:46 +01:00
<?php
2021-01-23 17:26:46 +01:00
if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
exit("This file is meant to be included.");
2021-01-22 21:58:46 +01:00
session_start([
'name' => 'niver',
2021-01-23 17:26:46 +01:00
'sid_length' => 64,
'cookie_secure' => true,
'cookie_httponly' => true,
'cookie_samesite' => 'Strict',
2021-02-16 19:20:19 +01:00
'cookie_lifetime' => 604800,
'gc_maxlifetime' => 604800,
2021-02-16 19:20:19 +01:00
'use_strict_mode' => true,
'use_cookies' => true,
'use_only_cookies' => true,
2021-01-22 21:58:46 +01:00
]);
2021-02-16 19:20:19 +01:00
define("USERNAME_REGEX", "^[a-z]{4,32}$");
define("PASSWORD_REGEX", "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]{8,1024}|.{10,1024}$");
2021-02-17 22:48:49 +01:00
define("SUBDOMAIN_REGEX", "^[a-z]{4,63}$");
2021-01-23 17:26:46 +01:00
2021-03-04 01:02:38 +01:00
define("PREFIX", "/malaxe"); // Prefix in the URL, if any
define("ROOT_PATH", "/var/www/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");
2021-02-16 19:20:19 +01:00
define("SERVICE", substr(dirname($_SERVER['PHP_SELF']), strlen(PREFIX) + 1));
define("PAGE", basename($_SERVER['PHP_SELF'], '.php'));
2021-01-23 17:26:46 +01:00
2021-02-16 19:20:19 +01:00
if (SERVICE != "auth" AND !isset($_SESSION['username'])) {
2021-02-18 22:40:16 +01:00
header('Location: ' . PREFIX . '/auth/login?redir=' . SERVICE . "/" . PAGE, true, 302);
2021-01-22 21:58:46 +01:00
exit;
}
2021-02-19 13:23:26 +01:00
if (substr($_SERVER['REQUEST_URI'], -4) == ".php") {
2021-02-18 22:40:16 +01:00
header("Location: " . PREFIX . "/" . SERVICE . "/" . PAGE, true, 301); // 301 Moved Permanently
exit;
}
2021-01-22 21:58:46 +01:00
2021-01-25 13:39:31 +01:00
$theme = array(
'htColor' => "#FF0000",
'nicColor' => "#DA03E5",
2021-01-25 13:39:31 +01:00
'authColor' => "#00FF00",
'nsColor' => "#00FFFF",
'lightColor' => '#FFFFFF',
'darkColor' => '#2a2a2a',
2021-01-25 13:39:31 +01:00
);
2021-01-22 21:58:46 +01:00
2021-02-16 19:20:19 +01:00
switch (SERVICE) {
case "ht":
2021-01-25 13:39:31 +01:00
$theme = array('mainColor' => $theme['htColor']) + $theme;
2021-01-22 21:58:46 +01:00
break;
2021-02-18 22:40:16 +01:00
case "reg":
2021-01-25 13:39:31 +01:00
$theme = array('mainColor' => $theme['nicColor']) + $theme;
2021-01-22 21:58:46 +01:00
break;
2021-02-16 19:20:19 +01:00
case "auth":
2021-01-25 13:39:31 +01:00
$theme = array('mainColor' => $theme['authColor']) + $theme;
2021-01-22 21:58:46 +01:00
break;
2021-02-16 19:20:19 +01:00
case "":
2021-01-25 13:39:31 +01:00
$theme = array('mainColor' => $theme['authColor']) + $theme;
2021-01-22 21:58:46 +01:00
break;
2021-02-16 19:20:19 +01:00
case "ns":
2021-01-25 13:39:31 +01:00
$theme = array('mainColor' => $theme['nsColor']) + $theme;
2021-01-22 21:58:46 +01:00
break;
}
2021-02-17 22:48:49 +01:00
require "inc/all.inc.php";
require "inc/format.inc.php";
require "inc/ht.inc.php";
2021-02-19 13:23:26 +01:00
require "inc/ns.inc.php";
2021-02-17 22:48:49 +01:00
require "inc/pages.inc.php";
require "inc/reg.inc.php";
2021-01-22 21:58:46 +01:00
require_once 'lessphp/lib/Less/Autoloader.php';
Less_Autoloader::register();
2021-02-16 19:20:19 +01:00
$relativeLessFiles = array_diff(scandir(ROOT_PATH . "/less"), array('..', '.'));
2021-01-23 17:26:46 +01:00
$relativeLessFiles = array_flip($relativeLessFiles);
foreach ($relativeLessFiles as $relativeLessFile => $nothing) {
2021-02-16 19:20:19 +01:00
$absoluteLessFiles[ROOT_PATH . "/less/" . $relativeLessFile] = "";
2021-01-23 17:26:46 +01:00
}
2021-02-17 22:48:49 +01:00
$options = array('cache_dir' => ROOT_PATH . '/css/', 'compress' => true);
2021-01-23 17:26:46 +01:00
$cssFileName = Less_Cache::Get($absoluteLessFiles, $options, $theme);
2021-01-22 21:58:46 +01:00
?>
<!DOCTYPE html>
2021-01-25 13:39:31 +01:00
<html lang="fr">
2021-01-22 21:58:46 +01:00
<head>
2021-01-25 13:39:31 +01:00
<title><?php if ($page['title'] != "Accueil") echo $page['title'] . " · "; ?><?php if (isset($page['service'])) { echo $page['service'] . " · "; } ?>Atope</title>
2021-02-16 19:20:19 +01:00
<link type="text/css" rel="stylesheet" href="<?= PREFIX ?>/css/<?= $cssFileName ?>">
2021-01-22 21:58:46 +01:00
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
2021-01-25 13:39:31 +01:00
2021-01-22 21:58:46 +01:00
<body>
<header>
<?php if (!isset($page['service'])) {
$page['service'] = "Atope";
} ?>
<nav>
2021-02-16 19:20:19 +01:00
<a href="<?= PREFIX ?>">Niver</a> > <a href="./"><?= $page['service'] ?></a> > <?= $page['title'] ?>
2021-01-22 21:58:46 +01:00
</nav>
2021-01-22 21:58:46 +01:00
<h1><?= $page['title'] ?></h1>
</header>