servnest/top.inc.php

122 lines
3.8 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
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-05-14 21:10:56 +02:00
define("PREFIX", "/pmkdel"); // Prefix in the URL, if any
define("ROOT_PATH", "/srv/http/niver" . PREFIX); // Niver directory
2021-03-04 01:02:38 +01:00
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
2021-05-14 21:10:56 +02:00
define("KNOT_ZONES_PATH", "/var/lib/knot/zones"); // Zones directory
2021-03-04 01:02:38 +01:00
define("TOR_KEYS_PATH", "/var/lib/tor/niver"); // Keys directory
define("SUDO_PATH", "/usr/bin/sudo"); // Binary file
define("LS_PATH", "/usr/bin/ls"); // Binary file
2021-05-14 21:10:56 +02:00
define("NIVER_TEMPLATE_PATH", "/usr/local/share/niver"); // Templates directory (skel, nginx, knot...)
define("MANIVER_PATH", "/usr/local/bin/maniver"); // Binary file
2021-03-04 01:02:38 +01:00
// The mountpoint of the hypertext storage partition (that will be accessed over SFTP)
define("HT_PATH", "/srv/ht");
2021-03-04 01:02:38 +01:00
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-05-14 21:10:56 +02:00
session_start([
'name' => 'niver',
'sid_length' => 64,
'cookie_secure' => true,
'cookie_httponly' => true,
'cookie_samesite' => 'Strict',
'cookie_path' => PREFIX . '/',
'cookie_lifetime' => 432000, // = 60*60*24*5 = 5 days
'gc_maxlifetime' => 10800,
'use_strict_mode' => true,
'use_cookies' => true,
'use_only_cookies' => true,
]);
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",
2021-03-20 23:48:54 +01:00
'regColor' => "#DA03E5",
2021-01-25 13:39:31 +01:00
'authColor' => "#00FF00",
2021-03-20 23:48:54 +01:00
'nsColor' => "#00c4c4",
'lightColor' => '#FFFFFF',
'darkColor' => '#2a2a2a',
2021-01-25 13:39:31 +01:00
);
2021-01-22 21:58:46 +01:00
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>
<meta charset="UTF-8">
2021-03-20 23:48:54 +01:00
<title><?php
if (isset($page['title']) AND $page['title'] != "Accueil")
echo $page['title'] . " · ";
if (isset($page['service'])) {
echo $page['service'] . " · ";
} ?>Niver</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>
2021-03-20 23:48:54 +01:00
2021-01-22 21:58:46 +01:00
<nav>
2021-03-20 23:48:54 +01:00
<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'];
?>
2021-01-22 21:58:46 +01:00
</nav>
2021-03-20 23:48:54 +01:00
<?php if (isset($page['title'])) { ?>
<h1><?= $page['title'] ?></h1>
<?php } ?>
2021-01-22 21:58:46 +01:00
</header>
2021-05-14 21:10:56 +02:00
<main>