diff --git a/README.md b/README.md index fc962cc..9c62eca 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Niver is a set of 3 network services: ## Status -I plan to create and maintain a public stable instance of Niver, but I haven't done so yet. Thus Niver is not yet tested with real world and long-term usages, and **should be considered alpha software**. +I plan to create and maintain a public stable instance of Niver, but I haven't done so yet. Thus Niver is not yet tested with real world and long-term usages, and is **alpha software**. ## Detailed features diff --git a/fn/auth.php b/fn/auth.php index a414eb0..f4c5c4c 100644 --- a/fn/auth.php +++ b/fn/auth.php @@ -9,18 +9,18 @@ const PLACEHOLDER_PASSWORD = '•••••••••••••••• // Password storage security const ALGO_PASSWORD = PASSWORD_ARGON2ID; const OPTIONS_PASSWORD = [ - "memory_cost" => 65536, - "time_cost" => 4, - "threads" => 64, + 'memory_cost' => 65536, + 'time_cost' => 4, + 'threads' => 64, ]; function checkPasswordFormat($password) { - if (preg_match("/" . PASSWORD_REGEX . "/u", $password) !== 1) + if (preg_match('/' . PASSWORD_REGEX . '/u', $password) !== 1) output(403, 'Password malformed.'); } function checkUsernameFormat($username) { - if (preg_match("/" . USERNAME_REGEX . "/u", $username) !== 1) + if (preg_match('/' . USERNAME_REGEX . '/u', $username) !== 1) output(403, 'Username malformed.'); } @@ -43,7 +43,7 @@ function outdatedPasswordHash($username) { function changePassword($username, $password) { $db = new PDO('sqlite:' . DB_PATH); - $stmt = $db->prepare("UPDATE users SET password = :password WHERE username = :username"); + $stmt = $db->prepare('UPDATE users SET password = :password WHERE username = :username'); $stmt->bindValue(':username', $username); $stmt->bindValue(':password', hashPassword($password)); @@ -75,7 +75,7 @@ function rateLimitAccount($requestedTokens) { // Update $db = new PDO('sqlite:' . DB_PATH); - $stmt = $db->prepare("UPDATE users SET bucket_tokens = :bucket_tokens, bucket_last_update = :bucket_last_update WHERE username = :username"); + $stmt = $db->prepare('UPDATE users SET bucket_tokens = :bucket_tokens, bucket_last_update = :bucket_last_update WHERE username = :username'); $stmt->bindValue(':username', $_SESSION['username']); $stmt->bindValue(':bucket_tokens', $tokens); $stmt->bindValue(':bucket_last_update', time()); diff --git a/fn/common.php b/fn/common.php index c97808e..300dffb 100644 --- a/fn/common.php +++ b/fn/common.php @@ -6,13 +6,13 @@ function output($code, $msg = '', $logs = ['']) { global $final_message; $shortCode = $code / 100 % 10; $final_message = match ($shortCode) { - 2 => ($msg === '') ? '' : "

Succès : " . $msg . "

\n", - 4 => "

Erreur utilisataire : " . $msg . "

\n", - 5 => "

Server error: The server encountered an error: " . $msg . "

\n", + 2 => ($msg === '') ? '' : '

Succès : ' . $msg . '

' . LF, + 4 => '

Erreur utilisataire : ' . $msg . '

' . LF, + 5 => '

Server error: The server encountered an error: ' . $msg . '

' . LF, }; http_response_code($code); if ($shortCode === 5) - error_log("Niver internal error: " . strip_tags($msg) . implode("\n", $logs)); + error_log('Niver internal error: ' . strip_tags($msg) . implode(LF, $logs)); if ($code !== 200) executePage(); } @@ -39,14 +39,14 @@ function insert($table, $values) { $query .= "$key, "; } - $query .= ") VALUES("; + $query .= ') VALUES('; foreach ($values as $key => $val) { if ($key === array_key_last($values)) $query .= ":$key"; else $query .= ":$key, "; } - $query .= ")"; + $query .= ')'; $db = new PDO('sqlite:' . DB_PATH); @@ -65,7 +65,7 @@ function query($action, $table, $conditions = [], $column = NULL) { 'delete' => 'DELETE', }; - $query .= " FROM $table"; + $query .= ' FROM ' . $table; foreach ($conditions as $key => $val) { if ($key === array_key_first($conditions)) diff --git a/fn/dns.php b/fn/dns.php index 1d58f3d..d32cca4 100644 --- a/fn/dns.php +++ b/fn/dns.php @@ -1,21 +1,21 @@ knotc failed with exit code ' . $code['begin'] . ': ' . $output['begin'][0] . '.'); foreach ($cmds as $cmd) { - exec(CONF['dns']['knotc_path'] . " conf-" . $cmd, $output['op'], $code['op']); + exec(CONF['dns']['knotc_path'] . ' conf-' . $cmd, $output['op'], $code['op']); if ($code['op'] !== 0) { - exec(CONF['dns']['knotc_path'] . " conf-abort"); + exec(CONF['dns']['knotc_path'] . ' conf-abort'); output(500, 'knotcConfExec: knotc failed with exit code ' . $code['op'] . ': ' . $output['op'][0] . '.'); } } - exec(CONF['dns']['knotc_path'] . " conf-commit", $output['commit'], $code['commit']); + exec(CONF['dns']['knotc_path'] . ' conf-commit', $output['commit'], $code['commit']); if ($code['commit'] !== 0) { - exec(CONF['dns']['knotc_path'] . " conf-abort"); + exec(CONF['dns']['knotc_path'] . ' conf-abort'); output(500, 'knotcConfExec: knotc failed with exit code ' . $code['commit'] . ': ' . $output['commit'][0] . '.'); } } @@ -23,34 +23,34 @@ function knotcConfExec($cmds) { function knotcZoneExec($zone, $cmd) { $action = checkAction($_POST['action']); - exec(CONF['dns']['knotc_path'] . " zone-begin " . $zone, $output['begin'], $code['begin']); + exec(CONF['dns']['knotc_path'] . ' zone-begin ' . $zone, $output['begin'], $code['begin']); if ($code['begin'] !== 0) output(500, 'knotcZoneExec: knotc failed with exit code ' . $code['begin'] . ': ' . $output['begin'][0] . '.'); - exec(CONF['dns']['knotc_path'] . " zone-" . $action . "set " . $zone . " " . implode(" ", $cmd), $output['op'], $code['op']); + exec(CONF['dns']['knotc_path'] . ' zone-' . $action . 'set ' . $zone . ' ' . implode(' ', $cmd), $output['op'], $code['op']); if ($code['op'] !== 0) { - exec(CONF['dns']['knotc_path'] . " zone-abort " . $zone); + exec(CONF['dns']['knotc_path'] . ' zone-abort ' . $zone); output(500, 'knotcZoneExec: knotc failed with exit code ' . $code['op'] . ': ' . $output['op'][0] . '.'); } - exec(CONF['dns']['knotc_path'] . " zone-commit " . $zone, $output['commit'], $code['commit']); + exec(CONF['dns']['knotc_path'] . ' zone-commit ' . $zone, $output['commit'], $code['commit']); if ($code['commit'] !== 0) { - exec(CONF['dns']['knotc_path'] . " zone-abort " . $zone); + exec(CONF['dns']['knotc_path'] . ' zone-abort ' . $zone); output(500, 'knotcZoneExec: knotc failed with exit code ' . $code['commit'] . ': ' . $output['commit'][0] . '.'); } } function checkIpFormat($ip) { if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) - return "A"; + return 'A'; if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) - return "AAAA"; + return 'AAAA'; output(403, 'IP address malformed.'); } function checkAbsoluteDomainFormat($domain) { // If the domain must end with a dot - if (!filter_var($domain, FILTER_VALIDATE_DOMAIN) OR !preg_match("/^([a-z0-9_-]{1,63}\.){2,127}$/", $domain)) + if (!filter_var($domain, FILTER_VALIDATE_DOMAIN) OR !preg_match('/^([a-z0-9_-]{1,63}\.){2,127}$/', $domain)) output(403, 'Domain malformed.'); } diff --git a/fn/ht.php b/fn/ht.php index 42b99d1..56d8767 100644 --- a/fn/ht.php +++ b/fn/ht.php @@ -2,7 +2,7 @@ function checkDomainFormat($domain) { // If the domain must end without a dot - if (!filter_var($domain, FILTER_VALIDATE_DOMAIN) OR !preg_match("/^([a-z0-9_-]{1,63}\.){1,126}[a-z0-9]{1,63}$/", $domain)) + if (!filter_var($domain, FILTER_VALIDATE_DOMAIN) OR !preg_match('/^([a-z0-9_-]{1,63}\.){1,126}[a-z0-9]{1,63}$/', $domain)) output(403, 'Domain malformed.'); } @@ -13,7 +13,7 @@ function formatDomain($domain) { } function listFsDirs($username) { - $absoluteDirs = glob(CONF['ht']['ht_path'] . "/" . $username . "/*/", GLOB_ONLYDIR); + $absoluteDirs = glob(CONF['ht']['ht_path'] . '/' . $username . '/*/', GLOB_ONLYDIR); $dirs = []; foreach ($absoluteDirs as $absoluteDir) if (preg_match('/^[\p{L}\p{N}_-]{1,64}$/u', basename($absoluteDir))) @@ -28,7 +28,7 @@ function addSite($username, $siteDir, $domain, $domainType, $protocol) { 'domain' => $domain, 'domain_type' => $domainType, 'protocol' => $protocol, - 'creation_date' => date("Y-m-d H:i:s"), + 'creation_date' => date('Y-m-d H:i:s'), ]); } @@ -52,7 +52,7 @@ function htDeleteSite($dir, $domainType, $protocol) { output(500, 'Failed to delete Tor configuration.'); // Reload Tor - exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload " . CONF['ht']['tor_service'], $output, $code); + exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['systemctl_path'] . ' reload ' . CONF['ht']['tor_service'], $output, $code); if ($code !== 0) output(500, 'Failed to reload Tor.'); @@ -79,7 +79,7 @@ function htDeleteSite($dir, $domainType, $protocol) { if ($domainType === 'dns') { // Delete Let's Encrypt certificate - exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['certbot_path'] . " delete --quiet --cert-name " . $domain, $output, $code); + exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['certbot_path'] . ' delete --quiet --cert-name ' . $domain, $output, $code); if ($code !== 0) output(500, 'Certbot failed to delete the Let\'s Encrypt certificate.'); } diff --git a/fn/ns.php b/fn/ns.php index 2463bdd..af8a667 100644 --- a/fn/ns.php +++ b/fn/ns.php @@ -64,7 +64,7 @@ function nsDeleteZone($zone) { output(500, 'Failed to remove Knot zone file.'); // Remove Knot related data - exec(CONF['dns']['knotc_path'] . " zone-purge " . $zone); + exec(CONF['dns']['knotc_path'] . ' zone-purge ' . $zone); // Remove from database query('delete', 'zones', [ diff --git a/fn/reg.php b/fn/reg.php index 53359a3..4c9f05d 100644 --- a/fn/reg.php +++ b/fn/reg.php @@ -14,7 +14,7 @@ function regDeleteDomain($domain) { $regFile = file_get_contents(CONF['reg']['registry_file']); if ($regFile === false) output(500, 'Failed to read current registry File.'); - $regFile = preg_replace("#[^\n]{0,1024}" . $domain . " {0,1024}[^\n]{0,1024}\n#", "", $regFile); + $regFile = preg_replace('/[^\n]{0,1024}' . $domain . ' {0,1024}[^\n]{0,1024}\n/', '', $regFile); if (file_put_contents(CONF['reg']['registry_file'], $regFile) === false) output(500, 'Failed to write new registry file.'); diff --git a/pages/auth/register.php b/pages/auth/register.php index 751842b..69cbba3 100644 --- a/pages/auth/register.php +++ b/pages/auth/register.php @@ -13,7 +13,7 @@ if (processForm(false)) { insert('users', [ 'username' => $_POST['username'], 'password' => hashPassword($_POST['password']), - 'registration_date' => date("Y-m-d H:i:s"), + 'registration_date' => date('Y-m-d H:i:s'), 'bucket_tokens' => 0, 'bucket_last_update' => 0, 'type' => 'testing', @@ -21,18 +21,18 @@ if (processForm(false)) { // Setup SFTP directory umask(0002); - if (mkdir(CONF['ht']['ht_path'] . "/" . $_POST['username'], 0775) !== true) + if (mkdir(CONF['ht']['ht_path'] . '/' . $_POST['username'], 0775) !== true) output(500, 'Can\'t create user directory.'); - exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['chgrp_path'] . " " . CONF['ht']['sftpgo_group'] . " " . CONF['ht']['ht_path'] . "/" . $_POST['username'] . " --no-dereference", result_code: $code); + exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['chgrp_path'] . ' ' . CONF['ht']['sftpgo_group'] . ' ' . CONF['ht']['ht_path'] . '/' . $_POST['username'] . ' --no-dereference', result_code: $code); if ($code !== 0) output(500, 'Can\'t change user directory group.'); // Setup Tor config directory - if (mkdir(CONF['ht']['tor_config_path'] . "/" . $_POST['username'], 0755) !== true) + if (mkdir(CONF['ht']['tor_config_path'] . '/' . $_POST['username'], 0755) !== true) output(500, 'Can\'t create Tor config directory.'); // Setup Tor keys directory - exec(CONF['ht']['sudo_path'] . " -u " . CONF['ht']['tor_user'] . " " . CONF['ht']['mkdir_path'] . " --mode=0700 " . CONF['ht']['tor_keys_path'] . "/" . $_POST['username'], result_code: $code); + exec(CONF['ht']['sudo_path'] . ' -u ' . CONF['ht']['tor_user'] . ' ' . CONF['ht']['mkdir_path'] . ' --mode=0700 ' . CONF['ht']['tor_keys_path'] . '/' . $_POST['username'], result_code: $code); if ($code !== 0) output(500, 'Can\'t create Tor keys directory.'); diff --git a/pages/auth/unregister.php b/pages/auth/unregister.php index bcf9e3b..3122319 100644 --- a/pages/auth/unregister.php +++ b/pages/auth/unregister.php @@ -24,7 +24,7 @@ if (processForm()) { ], 'site_dir') as $dir) htDeleteSite($dir, domainType: 'dns', protocol: 'http'); - exec(CONF['ht']['sudo_path'] . " -u " . CONF['ht']['tor_user'] . " " . CONF['ht']['rm_path'] . " --recursive " . CONF['ht']['tor_keys_path'] . "/" . $_SESSION['username'], result_code: $code); + exec(CONF['ht']['sudo_path'] . ' -u ' . CONF['ht']['tor_user'] . ' ' . CONF['ht']['rm_path'] . ' --recursive ' . CONF['ht']['tor_keys_path'] . '/' . $_SESSION['username'], result_code: $code); if ($code !== 0) output(500, 'Can\'t remove Tor keys directory.'); @@ -36,7 +36,7 @@ if (processForm()) { query('delete', 'users', ['username' => $_SESSION['username']]); - require "logout.php"; + require 'logout.php'; output(200, 'Compte supprimé.'); } diff --git a/pages/ht/add-http-dns.php b/pages/ht/add-http-dns.php index 3a20fe6..f39fc42 100644 --- a/pages/ht/add-http-dns.php +++ b/pages/ht/add-http-dns.php @@ -1,7 +1,7 @@ &1 ' . CONF['ht']['sudo_path'] . ' ' . CONF['ht']['certbot_path'] . ' certonly' . (($_SESSION['type'] === 'trusted') ? '' : ' --test-cert') . ' --key-type rsa --rsa-key-size 3072 --webroot --webroot-path /srv/niver/acme --domain ' . $_POST['domain'], $output, $returnCode); if ($returnCode !== 0) @@ -54,11 +54,11 @@ if (processForm()) { include inc/ht-tls.conf; } '; - if (file_put_contents(CONF['ht']['nginx_config_path'] . "/" . $_POST['domain'] . ".conf", $nginxConf) === false) + if (file_put_contents(CONF['ht']['nginx_config_path'] . '/' . $_POST['domain'] . '.conf', $nginxConf) === false) output(500, 'Failed to write Nginx configuration.'); // Reload Nginx - exec(CONF['ht']['sudo_path'] . " " . CONF['ht']['systemctl_path'] . " reload nginx", result_code: $code); + exec(CONF['ht']['sudo_path'] . ' ' . CONF['ht']['systemctl_path'] . ' reload nginx', result_code: $code); if ($code !== 0) output(500, 'Failed to reload Nginx.'); @@ -99,10 +99,8 @@ $proof = getAuthToken();
diff --git a/pages/ht/add-http-onion.php b/pages/ht/add-http-onion.php index 242dac6..0611038 100644 --- a/pages/ht/add-http-onion.php +++ b/pages/ht/add-http-onion.php @@ -1,7 +1,7 @@ Dossier ciblé

diff --git a/pages/ht/del-http-dns.php b/pages/ht/del-http-dns.php index 24944e3..d2c831c 100644 --- a/pages/ht/del-http-dns.php +++ b/pages/ht/del-http-dns.php @@ -1,7 +1,7 @@ Dossier ciblé

diff --git a/pages/ht/del-http-onion.php b/pages/ht/del-http-onion.php index d67082a..d4aff78 100644 --- a/pages/ht/del-http-onion.php +++ b/pages/ht/del-http-onion.php @@ -1,7 +1,7 @@ Dossier ciblé

diff --git a/pages/ht/index.php b/pages/ht/index.php index 720d24b..50b1c79 100644 --- a/pages/ht/index.php +++ b/pages/ht/index.php @@ -11,9 +11,9 @@ $sites = query('select', 'sites', ['username' => $_SESSION['username'] ?? '']); if ($sites === []) - echo '

Ce compte n\'héberge aucun site sur cette instance.

' . "\n"; + echo '

Ce compte n\'héberge aucun site sur cette instance.

' . LF; else { - echo '

' . "\n"; + echo '
' . LF; foreach ($sites as $site) { $url = 'http' . (($site['domain_type'] === 'onion') ? '' : 's') . '://' . $site['domain'] . '/'; ?> @@ -23,7 +23,7 @@ else { ' . "\n"; + echo '
' . LF; } ?> diff --git a/pages/ns/caa.php b/pages/ns/caa.php index 8072008..6cc43da 100644 --- a/pages/ns/caa.php +++ b/pages/ns/caa.php @@ -6,16 +6,16 @@ if (processForm()) { if (!($_POST['flag'] >= 0 AND $_POST['flag'] <= 255)) output(403, 'Wrong value for flag.'); - if (!(preg_match("/^[a-z]{1,127}$/", $_POST['tag']))) + if (!(preg_match('/^[a-z]{1,127}$/', $_POST['tag']))) output(403, 'Wrong value for tag.'); - if (!(preg_match("/^[a-z0-9.-]{1,255}$/", $_POST['value']))) + if (!(preg_match('/^[a-z0-9.-]{1,255}$/', $_POST['value']))) output(403, 'Wrong value for value.'); knotcZoneExec($_POST['zone'], array( $values['domain'], $values['ttl'], - "CAA", + 'CAA', $_POST['flag'], $_POST['tag'], $_POST['value'] @@ -32,7 +32,7 @@ if (processForm()) {
- +
diff --git a/pages/ns/cname.php b/pages/ns/cname.php index af5a093..8a7963b 100644 --- a/pages/ns/cname.php +++ b/pages/ns/cname.php @@ -8,7 +8,7 @@ if (processForm()) { knotcZoneExec($_POST['zone'], array( $values['domain'], $values['ttl'], - "CNAME", + 'CNAME', $_POST['cname'] )); @@ -22,7 +22,7 @@ if (processForm()) {

- +

diff --git a/pages/ns/dname.php b/pages/ns/dname.php index 937b883..680224e 100644 --- a/pages/ns/dname.php +++ b/pages/ns/dname.php @@ -8,7 +8,7 @@ if (processForm()) { knotcZoneExec($_POST['zone'], array( $values['domain'], $values['ttl'], - "DNAME", + 'DNAME', $_POST['dname'] )); @@ -22,7 +22,7 @@ if (processForm()) {

- +

diff --git a/pages/ns/edit.php b/pages/ns/edit.php index 1dabaec..4012f45 100644 --- a/pages/ns/edit.php +++ b/pages/ns/edit.php @@ -11,7 +11,7 @@ if (processForm() AND isset($_POST['zone-content'])) { // Update zone output(500, 'Unable to get current serial from zone file.'); // Generate new zone content - $new_zone_content = $matches['soa'] . "\n"; + $new_zone_content = $matches['soa'] . LF; if (strlen($_POST['zone-content']) > ZONE_MAX_CHARACTERS) output(403, 'La zone n\'est pas autorisée à dépasser ' . ZONE_MAX_CHARACTERS . ' caractères.'); foreach (explode("\r\n", $_POST['zone-content']) as $line) { @@ -24,7 +24,7 @@ if (processForm() AND isset($_POST['zone-content'])) { // Update zone output(403, 'Les TTLs inférieurs à ' . MIN_TTL . ' secondes ne sont pas autorisés.'); if ($matches['ttl'] !== '' AND $matches['ttl'] > MAX_TTL) output(403, 'Les TTLs supérieurs à ' . MAX_TTL . ' secondes ne sont pas autorisés.'); - $new_zone_content .= $matches['domain'] . ' ' . (($matches['ttl'] === '') ? DEFAULT_TTL : $matches['ttl']) . ' ' . $matches['type'] . ' ' . $matches['value'] . "\n"; + $new_zone_content .= $matches['domain'] . ' ' . (($matches['ttl'] === '') ? DEFAULT_TTL : $matches['ttl']) . ' ' . $matches['type'] . ' ' . $matches['value'] . LF; } // Send the zone content to kzonecheck's stdin @@ -72,7 +72,7 @@ if (processForm() AND isset($_POST['zone-content'])) { // Update zone ' . $zone . '' . "\n"; + echo ' ' . LF; ?>
@@ -89,23 +89,23 @@ if (processForm()) { // Display zone output(500, 'Unable to read zone file.'); $displayed_zone_content = ''; - foreach(explode("\n", $zone_content) as $zone_line) { + foreach(explode(LF, $zone_content) as $zone_line) { if (empty($zone_line) OR str_starts_with($zone_line, ';')) continue; if (preg_match('/^(?:(?:[a-z0-9_-]{1,63}\.){1,127})?' . preg_quote($_POST['zone'], '/') . '[\t ]+[0-9]{1,8}[\t ]+(?[A-Z]{1,16})[\t ]+.+$/', $zone_line, $matches)) { if (in_array($matches['type'], ALLOWED_TYPES, true) !== true) continue; - $displayed_zone_content .= $zone_line . "\n"; + $displayed_zone_content .= $zone_line . LF; } } - $displayed_zone_content .= "\n"; + $displayed_zone_content .= LF; ?> - +
diff --git a/pages/ns/index.php b/pages/ns/index.php index 615799c..81bcadb 100644 --- a/pages/ns/index.php +++ b/pages/ns/index.php @@ -10,10 +10,10 @@ $zones = query('select', 'zones', ['username' => $_SESSION['username'] ?? ''], 'zone'); if ($zones === []) - echo '

Ce compte n\'héberge aucune zone sur cette instance.

' . "\n"; + echo '

Ce compte n\'héberge aucune zone sur cette instance.

' . LF; else { - echo '

    ' . "\n"; + echo '
      ' . LF; foreach ($zones as $zone) - echo '
    • ' . $zone . '
    • ' . "\n"; - echo '
    ' . "\n"; + echo '
  • ' . $zone . '
  • ' . LF; + echo '
' . LF; } diff --git a/pages/ns/ip.php b/pages/ns/ip.php index 86adf9c..9699591 100644 --- a/pages/ns/ip.php +++ b/pages/ns/ip.php @@ -22,7 +22,7 @@ if (processForm()) {

- +

diff --git a/pages/ns/loc.php b/pages/ns/loc.php index 381615b..d5913d2 100644 --- a/pages/ns/loc.php +++ b/pages/ns/loc.php @@ -25,7 +25,7 @@ if (processForm()) { if (!($_POST['lat-sec'] >= 0 AND $_POST['lat-sec'] <= 59.999)) output(403, 'Wrong value for lat-sec.'); - if ($_POST['lat-dir'] !== "N" AND $_POST['lat-dir'] !== "S") + if ($_POST['lat-dir'] !== 'N' AND $_POST['lat-dir'] !== 'S') output(403, 'Wrong value for lat-dir.'); if (!($_POST['lon-deg'] >= 0 AND $_POST['lon-deg'] <= 180)) @@ -35,7 +35,7 @@ if (processForm()) { if (!($_POST['lon-sec'] >= 0 AND $_POST['lon-sec'] <= 59.999)) output(403, 'Wrong value for lon-sec.'); - if ($_POST['lon-dir'] !== "E" AND $_POST['lon-dir'] !== "W") + if ($_POST['lon-dir'] !== 'E' AND $_POST['lon-dir'] !== 'W') output(403, 'Wrong value for lon-dir.'); if (!($_POST['alt'] >= -100000 AND $_POST['alt'] <= 42849672.95)) @@ -53,7 +53,7 @@ if (processForm()) { knotcZoneExec($_POST['zone'], array( $values['domain'], $values['ttl'], - "LOC", + 'LOC', $_POST['lat-deg'], $_POST['lat-min'], $_POST['lat-sec'], @@ -79,7 +79,7 @@ if (processForm()) { - +
Latitude diff --git a/pages/ns/mx.php b/pages/ns/mx.php index 039fa28..139fbba 100644 --- a/pages/ns/mx.php +++ b/pages/ns/mx.php @@ -11,7 +11,7 @@ if (processForm()) { knotcZoneExec($_POST['zone'], array( $values['domain'], $values['ttl'], - "MX", + 'MX', $_POST['priority'], $_POST['host'] )); @@ -27,7 +27,7 @@ if (processForm()) { - +
diff --git a/pages/ns/ns.php b/pages/ns/ns.php index d4ac8de..c8ffe3f 100644 --- a/pages/ns/ns.php +++ b/pages/ns/ns.php @@ -8,7 +8,7 @@ if (processForm()) { knotcZoneExec($_POST['zone'], array( $values['domain'], $values['ttl'], - "NS", + 'NS', $_POST['ns'] )); @@ -22,7 +22,7 @@ if (processForm()) {

- +

diff --git a/pages/ns/print.php b/pages/ns/print.php index ed55d2a..15e53c8 100644 --- a/pages/ns/print.php +++ b/pages/ns/print.php @@ -15,7 +15,7 @@ " . $zone . "\n"; + echo ' ' . LF; ?>
@@ -46,10 +46,10 @@ if (processForm()) { Contenu '; foreach ($elements as $element) diff --git a/pages/ns/srv.php b/pages/ns/srv.php index 8807489..1cc22da 100644 --- a/pages/ns/srv.php +++ b/pages/ns/srv.php @@ -17,7 +17,7 @@ if (processForm()) { knotcZoneExec($_POST['zone'], array( $values['domain'], $values['ttl'], - "SRV", + 'SRV', $_POST['priority'], $_POST['weight'], $_POST['port'], @@ -35,7 +35,7 @@ if (processForm()) { - +
diff --git a/pages/ns/sshfp.php b/pages/ns/sshfp.php index 98524b7..63fb058 100644 --- a/pages/ns/sshfp.php +++ b/pages/ns/sshfp.php @@ -3,19 +3,19 @@ if (processForm()) { $values = nsParseCommonRequirements(); - if (!($_POST['algo'] === "1" OR $_POST['algo'] === "3" OR $_POST['algo'] === "4")) + if (!($_POST['algo'] === '1' OR $_POST['algo'] === '3' OR $_POST['algo'] === '4')) output(403, 'Wrong value for algo.'); - if (!($_POST['type'] === "2")) + if (!($_POST['type'] === '2')) output(403, 'Wrong value for type.'); - if (!(preg_match("/^[a-z0-9]{64}$/", $_POST['fp']))) + if (!(preg_match('/^[a-z0-9]{64}$/', $_POST['fp']))) output(403, 'Wrong value for fp.'); knotcZoneExec($_POST['zone'], array( $values['domain'], $values['ttl'], - "SSHFP", + 'SSHFP', $_POST['algo'], $_POST['type'], $_POST['fp'] @@ -32,7 +32,7 @@ if (processForm()) { - +
diff --git a/pages/ns/tlsa.php b/pages/ns/tlsa.php index bfba4f7..3e0b3c1 100644 --- a/pages/ns/tlsa.php +++ b/pages/ns/tlsa.php @@ -6,19 +6,19 @@ if (processForm()) { if (!($_POST['use'] >= 0 AND $_POST['use'] <= 3)) output(403, 'Wrong value for use.'); - if (!($_POST['selector'] === "0" OR $_POST['selector'] === "1")) + if (!($_POST['selector'] === '0' OR $_POST['selector'] === '1')) output(403, 'Wrong value for selector.'); if (!($_POST['type'] >= 0 AND $_POST['type'] <= 2)) output(403, 'Wrong value for type.'); - if (!(preg_match("/^[a-zA-Z0-9.-]{1,1024}$/", $_POST['content']))) + if (!(preg_match('/^[a-zA-Z0-9.-]{1,1024}$/', $_POST['content']))) output(403, 'Wrong value for content.'); knotcZoneExec($_POST['zone'], array( $values['domain'], $values['ttl'], - "TLSA", + 'TLSA', $_POST['use'], $_POST['selector'], $_POST['type'], @@ -36,7 +36,7 @@ if (processForm()) { - +
diff --git a/pages/ns/txt.php b/pages/ns/txt.php index e484698..9f1efe3 100644 --- a/pages/ns/txt.php +++ b/pages/ns/txt.php @@ -3,14 +3,14 @@ if (processForm()) { $values = nsParseCommonRequirements(); - if (!(preg_match("/^[a-zA-Z0-9 =:!%$+\/\()[\]_-]{5,8192}$/", $_POST['txt']))) + if (!(preg_match('/^[a-zA-Z0-9 =:!%$+\/\()[\]_-]{5,8192}$/', $_POST['txt']))) output(403, 'Wrong value for txt.'); knotcZoneExec($_POST['zone'], array( $values['domain'], $values['ttl'], - "TXT", - "\"" . $_POST['txt'] . "\"" + 'TXT', + '"' . $_POST['txt'] . '"' )); output(200, 'Enregistrement ajouté/retiré.'); @@ -23,7 +23,7 @@ if (processForm()) {

- +

diff --git a/pages/ns/zone-add.php b/pages/ns/zone-add.php index 7959403..1c74644 100644 --- a/pages/ns/zone-add.php +++ b/pages/ns/zone-add.php @@ -13,7 +13,7 @@ if (processForm()) { checkAbsoluteDomainFormat($parentAuthoritative); exec(CONF['ns']['kdig_path'] . ' ' . $_POST['domain'] . ' NS @' . $parentAuthoritatives[0] . ' +noidn', $results); - if (preg_match('/^' . preg_quote($_POST['domain'], '/') . '[\t ]+[0-9]{1,8}[\t ]+IN[\t ]+NS[\t ]+(?[0-9a-f]{8})-(?[0-9a-f]{32})\.auth-owner.+$/m', implode("\n", $results), $matches) !== 1) + if (preg_match('/^' . preg_quote($_POST['domain'], '/') . '[\t ]+[0-9]{1,8}[\t ]+IN[\t ]+NS[\t ]+(?[0-9a-f]{8})-(?[0-9a-f]{32})\.auth-owner.+$/m', implode(LF, $results), $matches) !== 1) output(403, 'Enregistrement d\'authentification introuvable'); checkAuthToken($matches['salt'], $matches['hash']); @@ -25,7 +25,7 @@ if (processForm()) { 'username' => $_SESSION['username'], ]); - $knotZonePath = CONF['ns']['knot_zones_path'] . "/" . $_POST['domain'] . "zone"; + $knotZonePath = CONF['ns']['knot_zones_path'] . '/' . $_POST['domain'] . 'zone'; $knotZone = implode(' ', [ $_POST['domain'], SOA_VALUES['ttl'], @@ -37,9 +37,9 @@ if (processForm()) { SOA_VALUES['retry'], SOA_VALUES['expire'], SOA_VALUES['negative'], - ]) . "\n"; + ]) . LF; foreach (CONF['ns']['servers'] as $server) - $knotZone .= $_POST['domain'] . ' 86400 NS ' . $server . "\n"; + $knotZone .= $_POST['domain'] . ' 86400 NS ' . $server . LF; if (is_int(file_put_contents($knotZonePath, $knotZone)) !== true) output(500, 'Failed to write new zone file.'); if (chmod($knotZonePath, 0660) !== true) diff --git a/pages/ns/zone-del.php b/pages/ns/zone-del.php index 685e288..ef51420 100644 --- a/pages/ns/zone-del.php +++ b/pages/ns/zone-del.php @@ -17,7 +17,7 @@ if (processForm()) { " . $zone . "\n"; + echo ' ' . LF; ?>
diff --git a/pages/reg/ds.php b/pages/reg/ds.php index 44dcd70..fe4472c 100644 --- a/pages/reg/ds.php +++ b/pages/reg/ds.php @@ -7,18 +7,18 @@ else if (processForm()) { if ( - ($_POST['algo'] !== "8") - AND ($_POST['algo'] !== "13") - AND ($_POST['algo'] !== "14") - AND ($_POST['algo'] !== "15") - AND ($_POST['algo'] !== "16") + ($_POST['algo'] !== '8') + AND ($_POST['algo'] !== '13') + AND ($_POST['algo'] !== '14') + AND ($_POST['algo'] !== '15') + AND ($_POST['algo'] !== '16') ) output(403, 'Wrong value for algo.'); $_POST['keytag'] = intval($_POST['keytag']); - if ((!preg_match("/^[0-9]{1,6}$/", $_POST['keytag'])) OR !($_POST['keytag'] >= 1) OR !($_POST['keytag'] <= 65535)) + if ((!preg_match('/^[0-9]{1,6}$/', $_POST['keytag'])) OR !($_POST['keytag'] >= 1) OR !($_POST['keytag'] <= 65535)) output(403, 'Wrong value for keytag.'); - if ($_POST['dt'] !== "2" AND $_POST['dt'] !== "4") + if ($_POST['dt'] !== '2' AND $_POST['dt'] !== '4') output(403, 'Wrong value for dt.'); regCheckDomainPossession($_POST['zone']); @@ -28,7 +28,7 @@ if (processForm()) { knotcZoneExec(CONF['reg']['registry'], array( $_POST['zone'], CONF['reg']['ttl'], - "DS", + 'DS', $_POST['keytag'], $_POST['algo'], $_POST['dt'], @@ -56,12 +56,9 @@ if (processForm()) {
diff --git a/pages/reg/glue.php b/pages/reg/glue.php index 51b6e32..bf4071b 100644 --- a/pages/reg/glue.php +++ b/pages/reg/glue.php @@ -41,13 +41,10 @@ if (processForm()) {
diff --git a/pages/reg/index.php b/pages/reg/index.php index 82bdfe5..b17e74e 100644 --- a/pages/reg/index.php +++ b/pages/reg/index.php @@ -10,10 +10,10 @@ $domains = query('select', 'registry', ['username' => $_SESSION['username'] ?? ''], 'domain'); if ($domains === []) - echo '

Ce compte n\'a aucun domaine enregistré sur ' . CONF['reg']['registry'] . '

' . "\n"; + echo '

Ce compte n\'a aucun domaine enregistré sur ' . CONF['reg']['registry'] . '

' . LF; else { - echo '

    ' . "\n"; + echo '
      ' . LF; foreach ($domains as $domain) - echo '
    • ' . $domain . '
    • ' . "\n"; - echo '
    ' . "\n"; + echo '
  • ' . $domain . '
  • ' . LF; + echo '
' . LF; } diff --git a/pages/reg/ns.php b/pages/reg/ns.php index cd35e25..4e9e4c1 100644 --- a/pages/reg/ns.php +++ b/pages/reg/ns.php @@ -7,7 +7,7 @@ if (processForm()) { knotcZoneExec(CONF['reg']['registry'], array( $_POST['domain'], CONF['reg']['ttl'], - "NS", + 'NS', $_POST['ns'] )); @@ -33,10 +33,9 @@ if (processForm()) { " . $domain . "\n"; + foreach (regListUserDomains($_SESSION['username']) as $domain) + echo ' ' . LF; ?> -
diff --git a/pages/reg/print.php b/pages/reg/print.php index 1e8e4fb..b03424a 100644 --- a/pages/reg/print.php +++ b/pages/reg/print.php @@ -5,8 +5,8 @@ " . $domain . "\n"; - ?> + echo ' ' . LF; +?>
@@ -21,26 +21,26 @@ if (processForm()) { if ($zoneContent === false) output(500, 'Unable to read registry file.'); - ?> - - - - - - - - +
DomaineTTLTypeContenu
+ + + + + + +\n"; + echo ' ' . LF; foreach ($elements as $element) - echo " \n"; - echo " \n"; + echo ' ' . LF; + echo ' ' . LF; } echo '
DomaineTTLTypeContenu
" . htmlspecialchars($element) . "
' . htmlspecialchars($element) . '
'; diff --git a/pages/reg/register.php b/pages/reg/register.php index 53dccf9..087c8f8 100644 --- a/pages/reg/register.php +++ b/pages/reg/register.php @@ -9,7 +9,7 @@ if (processForm()) { if (query('select', 'registry', ['domain' => $domain], 'domain') !== []) output(403, 'Ce domaine n\'est pas disponible à l\'enregistrement. Il est déjà enregistré.'); - if (in_array($_POST['subdomain'], explode("\n", file_get_contents(CONF['common']['root_path'] . '/pages/reg/reserved.txt')))) + if (in_array($_POST['subdomain'], explode(LF, file_get_contents(CONF['common']['root_path'] . '/pages/reg/reserved.txt')))) output(403, 'Ce domaine n\'est pas disponible à l\'enregistrement. Il est réservé.'); rateLimit(); @@ -17,7 +17,7 @@ if (processForm()) { insert('registry', [ 'domain' => $domain, 'username' => $_SESSION['username'], - 'last_renewal' => date("Y-m-d H:i:s"), + 'last_renewal' => date('Y-m-d H:i:s'), ]); output(200, 'Domaine ajouté au registre.'); diff --git a/pages/reg/unregister.php b/pages/reg/unregister.php index 6a824ed..8ebdfb0 100644 --- a/pages/reg/unregister.php +++ b/pages/reg/unregister.php @@ -22,9 +22,8 @@ if (processForm()) { " . $domain . "\n"; + echo ' ' . LF; ?> -
diff --git a/router.php b/router.php index e8fd6ab..d423972 100644 --- a/router.php +++ b/router.php @@ -1,11 +1,13 @@ 2. TLDs for Testing, & Documentation Examples const PLACEHOLDER_IPV6 = '2001:db8::3'; // From RFC3849: IPv6 Address Prefix Reserved for Documentation @@ -15,15 +17,15 @@ if ($_SERVER['REQUEST_URI'] === '/sftpgo-auth.php') return; $pageAddress = substr($_SERVER['REQUEST_URI'], strlen(CONF['common']['prefix']) + 1); -if (strpos($pageAddress, "?") !== false) { - parse_str(substr($pageAddress, strpos($pageAddress, "?") + 1), $_GET); - $pageAddress = substr($pageAddress, 0, strpos($pageAddress, "?")); +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')); +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')); $pageMetadata = []; function getPageInformations($pages, $pageElements) { @@ -83,7 +85,7 @@ foreach(array_reverse(TITLES_LINEAGE) as $id => $title) ?> ' . "\n"; + echo ' ' . LF; ?> @@ -100,7 +102,7 @@ foreach (glob('css/*.css') as $cssPath) $title) { $lastTitle = (TITLES_LINEAGE[array_key_last(TITLES_LINEAGE)] === $title); - echo '
  • ' . ($lastTitle ? '

    ' : '') . '' . $title . '' . ($lastTitle ? '

    ' : '') . "\n"; + echo '
    • ' . ($lastTitle ? '

      ' : '') . '' . $title . '' . ($lastTitle ? '

      ' : '') . LF; } echo str_repeat('
    ', count(TITLES_LINEAGE)); ?> @@ -114,7 +116,7 @@ if (in_array(SERVICE, ['reg', 'ns', 'ht']) AND CONF[SERVICE]['enabled'] !== true output(403, 'Ce service est désactivé.'); // Protect against cross-site request forgery if a POST request is received -if (empty($_POST) === false AND (isset($_SERVER['HTTP_SEC_FETCH_SITE']) !== true OR $_SERVER['HTTP_SEC_FETCH_SITE'] !== "same-origin")) +if (empty($_POST) === false AND (isset($_SERVER['HTTP_SEC_FETCH_SITE']) !== true OR $_SERVER['HTTP_SEC_FETCH_SITE'] !== 'same-origin')) output(403, 'Anti-CSRF verification failed ! (Wrong or unset Sec-Fetch-Site HTTP header)'); function displayFinalMessage() { @@ -124,7 +126,7 @@ function displayFinalMessage() { } function executePage() { - require "pages/" . PAGE_ADDRESS . ".php"; + require 'pages/' . PAGE_ADDRESS . '.php'; displayFinalMessage(); ?> diff --git a/sftpgo-auth.php b/sftpgo-auth.php index 0492717..236fef2 100644 --- a/sftpgo-auth.php +++ b/sftpgo-auth.php @@ -1,8 +1,8 @@ $authData['username']], 'type')[0] === 'trusted') ? CONF['ht']['user_quota_trusted'] : CONF['ht']['user_quota_testing'];