Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

UriSigner.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 2.85 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Component\HttpKernel;
013   
014  /**
015   * Signs URIs.
016   *
017   * @author Fabien Potencier <fabien@symfony.com>
018   */
019  class UriSigner
020  {
021      private $secret;
022      private $parameter;
023   
024      /**
025       * @param string $secret    A secret
026       * @param string $parameter Query string parameter to use
027       */
028      public function __construct($secret, $parameter = '_hash')
029      {
030          $this->secret = $secret;
031          $this->parameter = $parameter;
032      }
033   
034      /**
035       * Signs a URI.
036       *
037       * The given URI is signed by adding the query string parameter
038       * which value depends on the URI and the secret.
039       *
040       * @param string $uri A URI to sign
041       *
042       * @return string The signed URI
043       */
044      public function sign($uri)
045      {
046          $url = parse_url($uri);
047          if (isset($url['query'])) {
048              parse_str($url['query'], $params);
049          } else {
050              $params = [];
051          }
052   
053          $uri = $this->buildUrl($url, $params);
054          $params[$this->parameter] = $this->computeHash($uri);
055   
056          return $this->buildUrl($url, $params);
057      }
058   
059      /**
060       * Checks that a URI contains the correct hash.
061       *
062       * @param string $uri A signed URI
063       *
064       * @return bool True if the URI is signed correctly, false otherwise
065       */
066      public function check($uri)
067      {
068          $url = parse_url($uri);
069          if (isset($url['query'])) {
070              parse_str($url['query'], $params);
071          } else {
072              $params = [];
073          }
074   
075          if (empty($params[$this->parameter])) {
076              return false;
077          }
078   
079          $hash = $params[$this->parameter];
080          unset($params[$this->parameter]);
081   
082          return hash_equals($this->computeHash($this->buildUrl($url, $params)), $hash);
083      }
084   
085      private function computeHash($uri)
086      {
087          return base64_encode(hash_hmac('sha256', $uri, $this->secret, true));
088      }
089   
090      private function buildUrl(array $url, array $params = [])
091      {
092          ksort($params, \SORT_STRING);
093          $url['query'] = http_build_query($params, '', '&');
094   
095          $scheme = isset($url['scheme']) ? $url['scheme'].'://' : '';
096          $host = isset($url['host']) ? $url['host'] : '';
097          $port = isset($url['port']) ? ':'.$url['port'] : '';
098          $user = isset($url['user']) ? $url['user'] : '';
099          $pass = isset($url['pass']) ? ':'.$url['pass'] : '';
100          $pass = ($user || $pass) ? "$pass@" : '';
101          $path = isset($url['path']) ? $url['path'] : '';
102          $query = isset($url['query']) && $url['query'] ? '?'.$url['query'] : '';
103          $fragment = isset($url['fragment']) ? '#'.$url['fragment'] : '';
104   
105          return $scheme.$user.$pass.$host.$port.$path.$query.$fragment;
106      }
107  }
108