From 556139340399eb6d4e384b1782ae69b5bb1dee0f Mon Sep 17 00:00:00 2001 From: Miraty Date: Tue, 13 Sep 2022 01:09:40 +0200 Subject: [PATCH] Use more PAGE_URL --- fn/common.php | 5 +---- router.php | 14 +++++--------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/fn/common.php b/fn/common.php index 7d94f68..f3fd671 100644 --- a/fn/common.php +++ b/fn/common.php @@ -84,10 +84,7 @@ function displayIndex() { ?> } function redirUrl($pageId) { - $currentPath = ''; - if (SERVICE !== '.') $currentPath .= SERVICE . '/'; - if (PAGE !== 'index') $currentPath .= PAGE; - return CONF['common']['prefix'] . "/$pageId?redir=$currentPath"; + return CONF['common']['prefix'] . '/' . $pageId . '?redir=' . PAGE_URL; } function redir() { diff --git a/router.php b/router.php index b44b163..4e56966 100644 --- a/router.php +++ b/router.php @@ -4,12 +4,13 @@ define("CONF", parse_ini_file(__DIR__ . "/config.ini", true, INI_SCANNER_TYPED)) foreach (array_diff(scandir(CONF['common']['root_path'] . "/fn"), array('..', '.')) as $file) require CONF['common']['root_path'] . '/fn/' . $file; +require "pages.php"; define("DB_PATH", CONF['common']['root_path'] . "/db/niver.db"); -define("PLACEHOLDER_DOMAIN", "example"); // From RFC2606: Reserved Top Level DNS Names > 2. TLDs for Testing, & Documentation Examples -define("PLACEHOLDER_IPV6", "2001:db8::3"); // From RFC3849: IPv6 Address Prefix Reserved for Documentation -define("PLACEHOLDER_IPV4", "203.0.113.42"); // From RFC5737: IPv4 Address Blocks Reserved for Documentation +const PLACEHOLDER_DOMAIN = 'example'; // From RFC2606: Reserved Top Level DNS Names > 2. TLDs for Testing, & Documentation Examples +const PLACEHOLDER_IPV6 = '2001:db8::3'; // From RFC3849: IPv6 Address Prefix Reserved for Documentation +const PLACEHOLDER_IPV4 = '203.0.113.42'; // From RFC5737: IPv4 Address Blocks Reserved for Documentation if ($_SERVER['REQUEST_URI'] === '/sftpgo-auth.php') return; @@ -19,15 +20,12 @@ if (strpos($pageAddress, "?") !== false) { parse_str(substr($pageAddress, strpos($pageAddress, "?") + 1), $_GET); $pageAddress = substr($pageAddress, 0, strpos($pageAddress, "?")); } - define("PAGE_URL", $pageAddress); define("PAGE_ADDRESS", $pageAddress . ((substr($pageAddress, -1) === '/' OR $pageAddress === '') ? 'index' : '')); define("PAGE_LINEAGE", explode('/', PAGE_ADDRESS)); define("SERVICE", dirname(PAGE_ADDRESS)); define("PAGE", basename(PAGE_ADDRESS, '.php')); -require "pages.php"; - function getTitlesLineage($titles, $pageElements) { if (!isset($titles['index']) OR $pageElements[0] === 'index') return [$titles[$pageElements[0]] ?? false]; @@ -50,9 +48,7 @@ if (!TITLES_LINEAGE[array_key_last(TITLES_LINEAGE)]) { if ( isset($_COOKIE['niver-session-key']) // Resume session OR - (SERVICE === "auth" // Create new session - AND (PAGE === "login" OR PAGE === "register") - AND isset($_POST['username'])) + (isset($_POST['username']) AND in_array(PAGE_URL, ['auth/login', 'auth/register'])) // Start new session ) { session_start([ 'name' => 'niver-session-key',