|
@@ -1,54 +1,5 @@
|
|
<?php
|
|
<?php
|
|
-umask(0077);
|
|
|
|
-
|
|
|
|
-set_error_handler(function ($level, $message, $file = '', $line = 0) {
|
|
|
|
- throw new ErrorException($message, 0, $level, $file, $line);
|
|
|
|
-});
|
|
|
|
-set_exception_handler(function ($e) {
|
|
|
|
- error_log($e);
|
|
|
|
- http_response_code(500);
|
|
|
|
- echo '<h1>Error</h1>An error occured.';
|
|
|
|
-});
|
|
|
|
-register_shutdown_function(function () { // Also catch fatal errors
|
|
|
|
- if (($error = error_get_last()) !== NULL)
|
|
|
|
- throw new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']);
|
|
|
|
-});
|
|
|
|
-
|
|
|
|
-const ROOT_PATH = __DIR__;
|
|
|
|
-define('CONF', parse_ini_file(ROOT_PATH . '/config.ini', true, INI_SCANNER_TYPED));
|
|
|
|
-
|
|
|
|
-define('DB', new PDO('sqlite:' . ROOT_PATH . '/db/servnest.db'));
|
|
|
|
-DB->exec('PRAGMA foreign_keys = ON;');
|
|
|
|
-DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
-
|
|
|
|
-date_default_timezone_set('UTC');
|
|
|
|
-
|
|
|
|
-foreach (explode(',', preg_replace('/[A-Z0-9]|q=|;|-|\./', '', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '')) as $client_locale)
|
|
|
|
- if (in_array($client_locale, array_diff(scandir(ROOT_PATH . '/locales'), ['..', '.']), true)) {
|
|
|
|
- $locale = $client_locale;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-define('LOCALE', $locale ?? 'en');
|
|
|
|
-putenv('LANG=C.UTF-8');
|
|
|
|
-setlocale(LC_MESSAGES, 'C.UTF-8');
|
|
|
|
-bindtextdomain('messages', ROOT_PATH . '/locales/' . LOCALE);
|
|
|
|
-header('Content-Language: ' . LOCALE);
|
|
|
|
-
|
|
|
|
-const SERVICES_USER = ['reg', 'ns', 'ht'];
|
|
|
|
-
|
|
|
|
-const LF = "\n";
|
|
|
|
-
|
|
|
|
-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
|
|
|
|
-
|
|
|
|
-foreach (array_diff(scandir(ROOT_PATH . '/fn'), ['..', '.']) as $file)
|
|
|
|
- require ROOT_PATH . '/fn/' . $file;
|
|
|
|
-
|
|
|
|
-require ROOT_PATH . '/pages.php';
|
|
|
|
-
|
|
|
|
-if ($_SERVER['REQUEST_URI'] === '/sftpgo-auth.php')
|
|
|
|
- return;
|
|
|
|
|
|
+require 'init.php';
|
|
|
|
|
|
$pageAddress = substr($_SERVER['REQUEST_URI'], strlen(CONF['common']['prefix']) + 1);
|
|
$pageAddress = substr($_SERVER['REQUEST_URI'], strlen(CONF['common']['prefix']) + 1);
|
|
if (strpos($pageAddress, '?') !== false) {
|
|
if (strpos($pageAddress, '?') !== false) {
|
|
@@ -113,6 +64,9 @@ if (isset($_COOKIE[SESSION_COOKIE_NAME]))
|
|
startSession(); // Resume session
|
|
startSession(); // Resume session
|
|
|
|
|
|
if (isset($_SESSION['id'])) {
|
|
if (isset($_SESSION['id'])) {
|
|
|
|
+ if (!isset(query('select', 'users', ['id' => $_SESSION['id']], 'id')[0]))
|
|
|
|
+ output(403, _('This account doesn\'t exist anymore. Log out to end this ghost session.'));
|
|
|
|
+
|
|
// Decrypt display username
|
|
// Decrypt display username
|
|
if (!isset($_COOKIE['display-username-decryption-key']))
|
|
if (!isset($_COOKIE['display-username-decryption-key']))
|
|
output(403, 'The display username decryption key has not been sent.');
|
|
output(403, 'The display username decryption key has not been sent.');
|
|
@@ -157,12 +111,8 @@ if ($_POST !== []) {
|
|
if (!in_array($_SERVER['HTTP_SEC_FETCH_SITE'], ['none', 'same-origin'], true))
|
|
if (!in_array($_SERVER['HTTP_SEC_FETCH_SITE'], ['none', 'same-origin'], true))
|
|
output(403, 'The <code>Sec-Fetch-Site</code> HTTP header must be <code>same-origin</code> or <code>none</code> when submitting a POST request to prevent Cross-Site Request Forgery (<abbr>CSRF</abbr>).');
|
|
output(403, 'The <code>Sec-Fetch-Site</code> HTTP header must be <code>same-origin</code> or <code>none</code> when submitting a POST request to prevent Cross-Site Request Forgery (<abbr>CSRF</abbr>).');
|
|
|
|
|
|
- if (PAGE_METADATA['require-login'] ?? true !== false) {
|
|
|
|
- if (isset($_SESSION['id']) !== true)
|
|
|
|
- output(403, _('You need to be logged in to do this.'));
|
|
|
|
- if (isset(query('select', 'users', ['id' => $_SESSION['id']], 'id')[0]) !== true)
|
|
|
|
- output(403, _('This account doesn\'t exist anymore. Log out to end this ghost session.'));
|
|
|
|
- }
|
|
|
|
|
|
+ if (PAGE_METADATA['require-login'] ?? true AND !isset($_SESSION['id']))
|
|
|
|
+ output(403, _('You need to be logged in to do this.'));
|
|
|
|
|
|
if (file_exists(ROOT_PATH . '/pg-act/' . PAGE_ADDRESS . '.php'))
|
|
if (file_exists(ROOT_PATH . '/pg-act/' . PAGE_ADDRESS . '.php'))
|
|
require ROOT_PATH . '/pg-act/' . PAGE_ADDRESS . '.php';
|
|
require ROOT_PATH . '/pg-act/' . PAGE_ADDRESS . '.php';
|