From 46218fb3d348aaffd5b4d1b8769d8686fd5cec14 Mon Sep 17 00:00:00 2001 From: Miraty Date: Fri, 20 May 2022 00:15:13 +0200 Subject: [PATCH] Use ini file for config + remove old SFTP page --- auth.php | 3 - common/bottom.php | 4 +- common/init.php | 15 ++-- common/pages.php | 3 - common/top.php | 16 ++-- config.ini | 40 +++++++++ dns.php | 6 -- ht.php | 17 +--- ns.php | 2 - public/auth/register.php | 2 +- public/ht/http-onion.php | 22 ++--- public/ht/https-domain.php | 16 ++-- public/ht/index.php | 33 +++++++- public/ht/le.php | 8 +- public/ht/sftp.php | 169 ------------------------------------- public/ns/caa.php | 6 +- public/ns/dnssec.php | 2 +- public/ns/ip.php | 8 +- public/ns/loc.php | 6 +- public/ns/mx.php | 8 +- public/ns/ns.php | 8 +- public/ns/srv.php | 8 +- public/ns/sshfp.php | 6 +- public/ns/tlsa.php | 6 +- public/ns/txt.php | 6 +- public/ns/zone.php | 22 ++--- public/reg/ds.php | 6 +- public/reg/glue.php | 8 +- public/reg/index.php | 6 +- public/reg/ns.php | 8 +- public/reg/register.php | 30 ++----- reg.php | 8 -- 32 files changed, 178 insertions(+), 330 deletions(-) create mode 100644 config.ini delete mode 100644 public/ht/sftp.php diff --git a/auth.php b/auth.php index bae15b4..5628609 100644 --- a/auth.php +++ b/auth.php @@ -3,9 +3,6 @@ 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("ORIGIN", "https://niver.test:42443"); -define("CHGRP_PATH", "/usr/bin/chgrp"); - // Password storage security define("ALGO_PASSWORD", PASSWORD_ARGON2ID); define("OPTIONS_PASSWORD", array( diff --git a/common/bottom.php b/common/bottom.php index aae66c2..92b6d09 100644 --- a/common/bottom.php +++ b/common/bottom.php @@ -2,10 +2,10 @@ diff --git a/common/init.php b/common/init.php index ee0f861..359a9b5 100644 --- a/common/init.php +++ b/common/init.php @@ -1,19 +1,16 @@ 2. TLDs for Testing, & Documentation Examples -define("PREFIX", ""); // Prefix in URL, if any -define("ROOT_PATH", "/srv/php/niver"); // niver-php directory -define("SERVICE", substr(dirname($_SERVER['PHP_SELF']), strlen(PREFIX) + 1)); +define("CONF", parse_ini_file(__DIR__ . "/../config.ini", true, INI_SCANNER_TYPED)); + +define("SERVICE", substr(dirname($_SERVER['PHP_SELF']), strlen(CONF['common']['prefix']) + 1)); define("PAGE", basename($_SERVER['PHP_SELF'], '.php')); -define("DB_PATH", ROOT_PATH . "/db/niver.db"); // Niver's SQLite database -define("SUDO_PATH", "/usr/bin/sudo"); -define("HT_PATH", "/srv/ht"); +define("DB_PATH", CONF['common']['root_path'] . "/db/niver.db"); // Niver's SQLite database // Service-specific functions and constants if (SERVICE === "reg" OR SERVICE === "ns") - require ROOT_PATH . "/dns.php"; + require CONF['common']['root_path'] . "/dns.php"; if (SERVICE !== "") - require ROOT_PATH . "/" . SERVICE . ".php"; + require CONF['common']['root_path'] . "/" . SERVICE . ".php"; // Page titles definition require "pages.php"; diff --git a/common/pages.php b/common/pages.php index 111b836..5b23855 100644 --- a/common/pages.php +++ b/common/pages.php @@ -101,9 +101,6 @@ switch (SERVICE) { case "index": $page['title'] = $page['service']; break; - case "sftp": - $page['title'] = "Gérer l'accès SFTP"; - break; } break; } diff --git a/common/top.php b/common/top.php index d452559..90115f9 100644 --- a/common/top.php +++ b/common/top.php @@ -22,7 +22,7 @@ if ( 'cookie_secure' => true, 'cookie_httponly' => true, 'cookie_samesite' => 'Strict', - 'cookie_path' => PREFIX . '/', + 'cookie_path' => CONF['common']['prefix'] . '/', 'cookie_lifetime' => 432000, // = 60*60*24*5 = 5 days 'gc_maxlifetime' => 10800, 'use_strict_mode' => true, @@ -51,22 +51,22 @@ define("THEME", array( 'darkColor' => '#000000', )); -require_once ROOT_PATH . "/lessphp/lib/Less/Autoloader.php"; +require_once CONF['common']['root_path'] . "/lessphp/lib/Less/Autoloader.php"; Less_Autoloader::register(); // List files in less/ -$relativeLessFiles = array_diff(scandir(ROOT_PATH . "/less"), array('..', '.')); +$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[ROOT_PATH . "/less/" . $relativeLessFile] = ""; + $absoluteLessFiles[CONF['common']['root_path'] . "/less/" . $relativeLessFile] = ""; } // Generate one minified CSS file into public/css/ from sources in less/ $options = array( - 'cache_dir' => ROOT_PATH . '/public/css/', + 'cache_dir' => CONF['common']['root_path'] . '/public/css/', 'compress' => true ); $cssFileName = Less_Cache::Get($absoluteLessFiles, $options, THEME); @@ -82,7 +82,7 @@ $cssFileName = Less_Cache::Get($absoluteLessFiles, $options, THEME); if (isset($page['service'])) echo $page['service'] . " < "; ?>Niver - + @@ -90,9 +90,9 @@ $cssFileName = Less_Cache::Get($absoluteLessFiles, $options, THEME);