|
@@ -15,13 +15,15 @@ setlocale(LC_MESSAGES, 'C.UTF-8');
|
|
bindtextdomain('messages', 'locales/' . LOCALE);
|
|
bindtextdomain('messages', 'locales/' . LOCALE);
|
|
header('Content-Language: ' . LOCALE);
|
|
header('Content-Language: ' . LOCALE);
|
|
|
|
|
|
|
|
+const SERVICES_USER = ['reg', 'ns', 'ht'];
|
|
|
|
+
|
|
const LF = "\n";
|
|
const LF = "\n";
|
|
|
|
|
|
const PLACEHOLDER_DOMAIN = 'example'; // From RFC2606: Reserved Top Level DNS Names > 2. TLDs for Testing, & Documentation Examples
|
|
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_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
|
|
const PLACEHOLDER_IPV4 = '203.0.113.42'; // From RFC5737: IPv4 Address Blocks Reserved for Documentation
|
|
|
|
|
|
-foreach (array_diff(scandir(CONF['common']['root_path'] . '/fn'), array('..', '.')) as $file)
|
|
|
|
|
|
+foreach (array_diff(scandir(CONF['common']['root_path'] . '/fn'), ['..', '.']) as $file)
|
|
require CONF['common']['root_path'] . '/fn/' . $file;
|
|
require CONF['common']['root_path'] . '/fn/' . $file;
|
|
|
|
|
|
require 'pages.php';
|
|
require 'pages.php';
|
|
@@ -38,7 +40,6 @@ define('PAGE_URL', $pageAddress);
|
|
define('PAGE_ADDRESS', $pageAddress . ((substr($pageAddress, -1) === '/' OR $pageAddress === '') ? 'index' : ''));
|
|
define('PAGE_ADDRESS', $pageAddress . ((substr($pageAddress, -1) === '/' OR $pageAddress === '') ? 'index' : ''));
|
|
define('PAGE_LINEAGE', explode('/', PAGE_ADDRESS));
|
|
define('PAGE_LINEAGE', explode('/', PAGE_ADDRESS));
|
|
define('SERVICE', dirname(PAGE_ADDRESS));
|
|
define('SERVICE', dirname(PAGE_ADDRESS));
|
|
-define('PAGE', basename(PAGE_ADDRESS, '.php'));
|
|
|
|
|
|
|
|
function getPageInformations($pages, $pageElements) {
|
|
function getPageInformations($pages, $pageElements) {
|
|
if (!isset($pages['index']) OR $pageElements[0] === 'index')
|
|
if (!isset($pages['index']) OR $pageElements[0] === 'index')
|
|
@@ -87,6 +88,7 @@ if (isset($_COOKIE[SESSION_COOKIE_NAME]))
|
|
startSession(); // Resume session
|
|
startSession(); // Resume session
|
|
|
|
|
|
if (isset($_SESSION['id'])) {
|
|
if (isset($_SESSION['id'])) {
|
|
|
|
+ // 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.');
|
|
$decryption_result = htmlspecialchars(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt(
|
|
$decryption_result = htmlspecialchars(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt(
|
|
@@ -98,17 +100,18 @@ if (isset($_SESSION['id'])) {
|
|
if ($decryption_result === false)
|
|
if ($decryption_result === false)
|
|
output(403, 'Unable to decrypt display username.');
|
|
output(403, 'Unable to decrypt display username.');
|
|
define('DISPLAY_USERNAME', $decryption_result);
|
|
define('DISPLAY_USERNAME', $decryption_result);
|
|
-}
|
|
|
|
|
|
|
|
-if (in_array(SERVICE, ['reg', 'ns', 'ht']) AND CONF[SERVICE]['enabled'] !== true)
|
|
|
|
- output(403, 'Ce service est désactivé.');
|
|
|
|
|
|
+ // Enable not already enabled services for this user
|
|
|
|
+ $user_services = array_filter(explode(',', query('select', 'users', ['id' => $_SESSION['id']], 'services')[0]));
|
|
|
|
+ if (in_array(SERVICE, SERVICES_USER, true) AND !in_array(SERVICE, $user_services, true) AND CONF['common']['services'][SERVICE] === 'enabled') {
|
|
|
|
+ $user_services[] = SERVICE;
|
|
|
|
|
|
-// Protect against cross-site request forgery if a POST request is received
|
|
|
|
-if ($_POST !== []) {
|
|
|
|
- if (isset($_SERVER['HTTP_SEC_FETCH_SITE']) !== true)
|
|
|
|
- output(403, 'The <code>Sec-Fetch-Site</code> HTTP header is required when submitting a POST request to prevent Cross-Site Request Forgery (<abbr>CSRF</abbr>).');
|
|
|
|
- if ($_SERVER['HTTP_SEC_FETCH_SITE'] !== 'same-origin')
|
|
|
|
- output(403, 'The <code>Sec-Fetch-Site</code> HTTP header must be <code>same-origin</code> when submitting a POST request to prevent Cross-Site Request Forgery (<abbr>CSRF</abbr>).');
|
|
|
|
|
|
+ DB->prepare('UPDATE users SET services = :services WHERE id = :id')
|
|
|
|
+ ->execute([':services' => implode(',', $user_services), ':id' => $_SESSION['id']]);
|
|
|
|
+
|
|
|
|
+ if (SERVICE === 'ht')
|
|
|
|
+ htSetupUserFs($_SESSION['id']);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
if (isset($_SERVER['SERVER_NAME']) !== true)
|
|
if (isset($_SERVER['SERVER_NAME']) !== true)
|
|
@@ -125,18 +128,27 @@ function displayFinalMessage($data) {
|
|
}
|
|
}
|
|
|
|
|
|
if ($_POST !== []) {
|
|
if ($_POST !== []) {
|
|
|
|
+ if (in_array(SERVICE, SERVICES_USER, true) AND CONF['common']['services'][SERVICE] !== 'enabled')
|
|
|
|
+ output(503, _('This service is currently under maintenance. No action can be taken on it until an administrator finishes repairing it.'));
|
|
|
|
+
|
|
|
|
+ // Protect against cross-site request forgery if a POST request is received
|
|
|
|
+ if (isset($_SERVER['HTTP_SEC_FETCH_SITE']) !== true)
|
|
|
|
+ output(403, 'The <code>Sec-Fetch-Site</code> HTTP header is required when submitting a POST request to prevent Cross-Site Request Forgery (<abbr>CSRF</abbr>).');
|
|
|
|
+ if ($_SERVER['HTTP_SEC_FETCH_SITE'] !== 'same-origin')
|
|
|
|
+ output(403, 'The <code>Sec-Fetch-Site</code> HTTP header must be <code>same-origin</code> when submitting a POST request to prevent Cross-Site Request Forgery (<abbr>CSRF</abbr>).');
|
|
|
|
+
|
|
if (PAGE_METADATA['require-login'] ?? true !== false) {
|
|
if (PAGE_METADATA['require-login'] ?? true !== false) {
|
|
if (isset($_SESSION['id']) !== true)
|
|
if (isset($_SESSION['id']) !== true)
|
|
output(403, _('You need to be logged in to do this.'));
|
|
output(403, _('You need to be logged in to do this.'));
|
|
if (isset(query('select', 'users', ['id' => $_SESSION['id']], 'id')[0]) !== true)
|
|
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.'));
|
|
output(403, _('This account doesn\'t exist anymore. Log out to end this ghost session.'));
|
|
}
|
|
}
|
|
|
|
+
|
|
if (file_exists('pg-act/' . PAGE_ADDRESS . '.php'))
|
|
if (file_exists('pg-act/' . PAGE_ADDRESS . '.php'))
|
|
require 'pg-act/' . PAGE_ADDRESS . '.php';
|
|
require 'pg-act/' . PAGE_ADDRESS . '.php';
|
|
}
|
|
}
|
|
|
|
|
|
function displayPage($data) {
|
|
function displayPage($data) {
|
|
-
|
|
|
|
require 'view.php';
|
|
require 'view.php';
|
|
exit();
|
|
exit();
|
|
}
|
|
}
|