Файловый менеджер - Редактировать - /var/www/html/HeaderParser.zip
Ðазад
PK ! �w�0 0 Origin.phpnu �Iw�� <?php namespace MediaWiki\Rest\HeaderParser; use Wikimedia\Assert\Assert; /** * A class to assist with the parsing of Origin header according to the RFC 6454 * @link https://tools.ietf.org/html/rfc6454#section-7 * @since 1.36 */ class Origin extends HeaderParserBase { public const HEADER_NAME = 'Origin'; /** @var bool whether the origin was set to null */ private $isNullOrigin; /** @var array List of specified origins */ private $origins = []; /** * Parse an Origin header list as returned by RequestInterface::getHeader(). * * @param string[] $headerList * @return self */ public static function parseHeaderList( array $headerList ): self { $parser = new self( $headerList ); $parser->execute(); return $parser; } /** * Whether the Origin header was explicitly set to `null`. * * @return bool */ public function isNullOrigin(): bool { return $this->isNullOrigin; } /** * Whether the Origin header contains multiple origins. * * @return bool */ public function isMultiOrigin(): bool { return count( $this->getOriginList() ) > 1; } /** * Get the list of origins. * * @return string[] */ public function getOriginList(): array { return $this->origins; } /** * @return string */ public function getSingleOrigin(): string { Assert::precondition( !$this->isMultiOrigin(), 'Cannot get single origin, header specifies multiple' ); return $this->getOriginList()[0]; } /** * Check whether all the origins match at least one of the rules in $allowList. * * @param string[] $allowList * @param string[] $excludeList * @return bool */ public function match( array $allowList, array $excludeList ): bool { if ( $this->isNullOrigin() ) { return false; } foreach ( $this->getOriginList() as $origin ) { if ( !self::matchSingleOrigin( $origin, $allowList, $excludeList ) ) { return false; } } return true; } /** * Checks whether the origin matches at list one of the provided rules in $allowList. * * @param string $origin * @param array $allowList * @param array $excludeList * @return bool */ private static function matchSingleOrigin( string $origin, array $allowList, array $excludeList ): bool { foreach ( $allowList as $rule ) { if ( preg_match( self::wildcardToRegex( $rule ), $origin ) ) { // Rule matches, check exceptions foreach ( $excludeList as $exc ) { if ( preg_match( self::wildcardToRegex( $exc ), $origin ) ) { return false; } } return true; } } return false; } /** * Private constructor. Use the public static functions for public access. * * @param string[] $input */ private function __construct( array $input ) { if ( count( $input ) !== 1 ) { $this->error( 'Only a single Origin header field allowed in HTTP request' ); } $this->setInput( trim( $input[0] ) ); } private function execute() { if ( $this->input === 'null' ) { $this->isNullOrigin = true; } else { $this->isNullOrigin = false; $this->origins = preg_split( '/\s+/', $this->input ); if ( count( $this->origins ) === 0 ) { $this->error( 'Origin header must contain at least one origin' ); } } } /** * Helper function to convert wildcard string into a regex * '*' => '.*?' * '?' => '.' * * @param string $wildcard String with wildcards * @return string Regular expression */ private static function wildcardToRegex( $wildcard ) { $wildcard = preg_quote( $wildcard, '/' ); $wildcard = str_replace( [ '\*', '\?' ], [ '.*?', '.' ], $wildcard ); return "/^https?:\/\/$wildcard$/"; } } PK ! �ږ� � HeaderParserBase.phpnu �Iw�� <?php namespace MediaWiki\Rest\HeaderParser; /** * @internal */ class HeaderParserBase { /** * @var string The input string being processed */ protected $input; /** * @var int The position within $input */ protected $pos; /** * @var int The length of $input */ protected $inputLength; /** * Set the input, and derived convenience properties * * @param string $input */ protected function setInput( $input ) { $this->input = $input; $this->pos = 0; $this->inputLength = strlen( $input ); } /** * Consume a specified string, or throw an exception. * * @param string $s * @throws HeaderParserError */ protected function consumeString( $s ) { if ( $this->pos >= $this->inputLength ) { $this->error( "Expected \"$s\" but got end of string" ); } if ( substr_compare( $this->input, $s, $this->pos, strlen( $s ) ) === 0 ) { $this->pos += strlen( $s ); } else { // (T350852) Give full context for error $this->error( "Expected \"$s\" to be a substring of \"$this->input\" from position \"$this->pos\"" ); } } /** * Skip whitespace at the input position (OWS) */ protected function skipWhitespace() { $this->pos += strspn( $this->input, " \t", $this->pos ); } /** * Throw an exception to indicate a parse error * * @param string $message * @throws HeaderParserError * @return never */ protected function error( $message ) { throw new HeaderParserError( "$message at {$this->pos}" ); } /** * Consume a specified number of digits, or throw an exception * * @param int $numDigits * @return string * @throws HeaderParserError */ protected function consumeFixedDigits( $numDigits ) { $digits = substr( $this->input, $this->pos, $numDigits ); if ( strlen( $digits ) !== $numDigits || !preg_match( '/^[0-9]*$/', $digits ) ) { $this->error( "expected $numDigits digits" ); } $this->pos += $numDigits; return $digits; } /** * If the position is not at the end of the input string, raise an error, * complaining of trailing characters. * * @throws HeaderParserError */ protected function assertEnd() { if ( $this->pos !== $this->inputLength ) { $this->error( "trailing characters" ); } } } PK ! �I5 5 IfNoneMatch.phpnu �Iw�� <?php namespace MediaWiki\Rest\HeaderParser; /** * A class to assist with the parsing of If-None-Match, If-Match and ETag headers */ class IfNoneMatch extends HeaderParserBase { /** @var array[] */ private $results = []; /** @var string|null */ private $lastError; /** * Parse an If-None-Match or If-Match header list as returned by * RequestInterface::getHeader(). * * The return value is an array of tag info arrays. Each tag info array is * an associative array with the following keys: * * - weak: True if the tag is weak, false otherwise * - contents: The contents of the double-quoted opaque-tag, not * including the quotes. * - whole: The whole ETag, including weak indicator and quoted opaque-tag * * In the case of a wildcard header like "If-Match: *", there cannot be any * other tags. The return value is an array with a single tag info array with * 'whole' => '*'. * * If the header was invalid, an empty array will be returned. Further * information about why the parsing failed can be found by calling * getLastError(). * * @param string[] $headerList * @return array[] */ public function parseHeaderList( $headerList ) { $this->lastError = null; if ( count( $headerList ) === 1 && $headerList[0] === '*' ) { return [ [ 'weak' => true, 'contents' => null, 'whole' => '*' ] ]; } $this->results = []; try { foreach ( $headerList as $header ) { $this->parseHeader( $header ); } return $this->results; } catch ( HeaderParserError $e ) { $this->lastError = $e->getMessage(); return []; } } /** * Parse an entity-tag such as might be found in an ETag response header. * The result is an associative array in the same format returned by * parseHeaderList(). * * If parsing failed, null is returned. * * @param string $eTag * @return array|null */ public function parseETag( $eTag ) { $this->setInput( $eTag ); $this->results = []; try { $this->consumeTag(); $this->assertEnd(); } catch ( HeaderParserError $e ) { $this->lastError = $e->getMessage(); return null; } /* @phan-suppress-next-line PhanTypeInvalidDimOffset */ return $this->results[0]; } /** * Get the last parse error message, or null if there was none * * @return string|null */ public function getLastError() { return $this->lastError; } /** * Parse a single header * * @param string $header * @throws HeaderParserError */ private function parseHeader( $header ) { $this->setInput( $header ); $this->consumeTagList(); $this->assertEnd(); } /** * Consume a comma-separated list of entity-tags * * @throws HeaderParserError */ private function consumeTagList() { while ( true ) { $this->skipWhitespace(); $this->consumeTag(); $this->skipWhitespace(); if ( $this->pos === $this->inputLength ) { break; } else { $this->consumeString( ',' ); } } } /** * Consume a single entity-tag and append to the result array * * @throws HeaderParserError */ private function consumeTag() { $weak = false; $whole = ''; if ( substr( $this->input, $this->pos, 2 ) === 'W/' ) { $weak = true; $whole .= 'W/'; $this->pos += 2; } $this->consumeString( '"' ); if ( !preg_match( '/[!#-~\x80-\xff]*/A', $this->input, $m, 0, $this->pos ) ) { $this->error( 'unexpected regex failure' ); } $contents = $m[0]; $this->pos += strlen( $contents ); $this->consumeString( '"' ); $whole .= '"' . $contents . '"'; $this->results[] = [ 'weak' => $weak, 'contents' => $contents, 'whole' => $whole ]; } } PK ! xqQqn n HttpDate.phpnu �Iw�� <?php namespace MediaWiki\Rest\HeaderParser; /** * This is a parser for "HTTP-date" as defined by RFC 7231. * * Normally in MediaWiki, dates in HTTP headers are converted using * ConvertibleTimestamp or strtotime(), and this is encouraged by RFC 7231: * * "Recipients of timestamp values are encouraged to be robust in parsing * timestamps unless otherwise restricted by the field definition." * * In the case of If-Modified-Since, we are in fact otherwise restricted, since * RFC 7232 says: * * "A recipient MUST ignore the If-Modified-Since header field if the * received field-value is not a valid HTTP-date" * * So it is not correct to use strtotime() or ConvertibleTimestamp to parse * If-Modified-Since. */ class HttpDate extends HeaderParserBase { private const DAY_NAMES = [ 'Mon' => true, 'Tue' => true, 'Wed' => true, 'Thu' => true, 'Fri' => true, 'Sat' => true, 'Sun' => true ]; private const MONTHS_BY_NAME = [ 'Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12, ]; private const DAY_NAMES_LONG = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', ]; /** @var string */ private $dayName; /** @var string */ private $day; /** @var int */ private $month; /** @var int */ private $year; /** @var string */ private $hour; /** @var string */ private $minute; /** @var string */ private $second; /** * Parse an HTTP-date string * * @param string $dateString * @return int|null The UNIX timestamp, or null if the date was invalid */ public static function parse( $dateString ) { $parser = new self( $dateString ); if ( $parser->execute() ) { return $parser->getUnixTime(); } else { return null; } } /** * A convenience function to convert a UNIX timestamp to the preferred * IMF-fixdate format for HTTP header output. * * @param int $unixTime * @return false|string */ public static function format( $unixTime ) { return gmdate( 'D, d M Y H:i:s \G\M\T', $unixTime ); } /** * Private constructor. Use the public static functions for public access. * * @param string $input */ private function __construct( $input ) { $this->setInput( $input ); } /** * Parse the input string * * @return bool True for success */ private function execute() { $this->pos = 0; try { $this->consumeFixdate(); $this->assertEnd(); return true; } catch ( HeaderParserError $e ) { } $this->pos = 0; try { $this->consumeRfc850Date(); $this->assertEnd(); return true; } catch ( HeaderParserError $e ) { } $this->pos = 0; try { $this->consumeAsctimeDate(); $this->assertEnd(); return true; } catch ( HeaderParserError $e ) { } return false; } /** * Execute the IMF-fixdate rule, or throw an exception * * @throws HeaderParserError */ private function consumeFixdate() { $this->consumeDayName(); $this->consumeString( ', ' ); $this->consumeDate1(); $this->consumeString( ' ' ); $this->consumeTimeOfDay(); $this->consumeString( ' GMT' ); } /** * Execute the day-name rule, and capture the result. * * @throws HeaderParserError */ private function consumeDayName() { $next3 = substr( $this->input, $this->pos, 3 ); if ( isset( self::DAY_NAMES[$next3] ) ) { $this->dayName = $next3; $this->pos += 3; } else { $this->error( 'expected day-name' ); } } /** * Execute the date1 rule * * @throws HeaderParserError */ private function consumeDate1() { $this->consumeDay(); $this->consumeString( ' ' ); $this->consumeMonth(); $this->consumeString( ' ' ); $this->consumeYear(); } /** * Execute the day rule, and capture the result. * * @throws HeaderParserError */ private function consumeDay() { $this->day = $this->consumeFixedDigits( 2 ); } /** * Execute the month rule, and capture the result * * @throws HeaderParserError */ private function consumeMonth() { $next3 = substr( $this->input, $this->pos, 3 ); if ( isset( self::MONTHS_BY_NAME[$next3] ) ) { $this->month = self::MONTHS_BY_NAME[$next3]; $this->pos += 3; } else { $this->error( 'expected month' ); } } /** * Execute the year rule, and capture the result * * @throws HeaderParserError */ private function consumeYear() { $this->year = (int)$this->consumeFixedDigits( 4 ); } /** * Execute the time-of-day rule * @throws HeaderParserError */ private function consumeTimeOfDay() { $this->hour = $this->consumeFixedDigits( 2 ); $this->consumeString( ':' ); $this->minute = $this->consumeFixedDigits( 2 ); $this->consumeString( ':' ); $this->second = $this->consumeFixedDigits( 2 ); } /** * Execute the rfc850-date rule * * @throws HeaderParserError */ private function consumeRfc850Date() { $this->consumeDayNameLong(); $this->consumeString( ', ' ); $this->consumeDate2(); $this->consumeString( ' ' ); $this->consumeTimeOfDay(); $this->consumeString( ' GMT' ); } /** * Execute the date2 rule. * * @throws HeaderParserError */ private function consumeDate2() { $this->consumeDay(); $this->consumeString( '-' ); $this->consumeMonth(); $this->consumeString( '-' ); $year = $this->consumeFixedDigits( 2 ); // RFC 2626 section 11.2 $currentYear = (int)gmdate( 'Y' ); $startOfCentury = (int)round( $currentYear, -2 ); $this->year = $startOfCentury + intval( $year ); $pivot = $currentYear + 50; if ( $this->year > $pivot ) { $this->year -= 100; } } /** * Execute the day-name-l rule * * @throws HeaderParserError */ private function consumeDayNameLong() { foreach ( self::DAY_NAMES_LONG as $dayName ) { if ( substr_compare( $this->input, $dayName, $this->pos, strlen( $dayName ) ) === 0 ) { $this->dayName = substr( $dayName, 0, 3 ); $this->pos += strlen( $dayName ); return; } } $this->error( 'expected day-name-l' ); } /** * Execute the asctime-date rule * * @throws HeaderParserError */ private function consumeAsctimeDate() { $this->consumeDayName(); $this->consumeString( ' ' ); $this->consumeDate3(); $this->consumeString( ' ' ); $this->consumeTimeOfDay(); $this->consumeString( ' ' ); $this->consumeYear(); } /** * Execute the date3 rule * * @throws HeaderParserError */ private function consumeDate3() { $this->consumeMonth(); $this->consumeString( ' ' ); if ( ( $this->input[$this->pos] ?? '' ) === ' ' ) { $this->pos++; $this->day = '0' . $this->consumeFixedDigits( 1 ); } else { $this->day = $this->consumeFixedDigits( 2 ); } } /** * Convert the captured results to a UNIX timestamp. * This should only be called after parsing succeeds. * * @return int */ private function getUnixTime() { return gmmktime( (int)$this->hour, (int)$this->minute, (int)$this->second, $this->month, (int)$this->day, $this->year ); } } PK ! Jspe e HeaderParserError.phpnu �Iw�� <?php namespace MediaWiki\Rest\HeaderParser; class HeaderParserError extends \RuntimeException { } PK ! �w�0 0 Origin.phpnu �Iw�� PK ! �ږ� � j HeaderParserBase.phpnu �Iw�� PK ! �I5 5 ` IfNoneMatch.phpnu �Iw�� PK ! xqQqn n �% HttpDate.phpnu �Iw�� PK ! Jspe e ~A HeaderParserError.phpnu �Iw�� PK � (B
| ver. 1.1 | |
.
| PHP 8.4.18 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка