Replace more things with Index implementations, also bump QR Code library.
This commit is contained in:
parent
ef4921949b
commit
469b4f7859
12 changed files with 50 additions and 282 deletions
|
@ -4,7 +4,7 @@
|
|||
"erusev/parsedown": "~1.6",
|
||||
"geoip2/geoip2": "~2.0",
|
||||
"jublonet/codebird-php": "^3.1",
|
||||
"chillerlan/php-qrcode": "^3.0",
|
||||
"chillerlan/php-qrcode": "^4.3",
|
||||
"whichbrowser/parser": "^2.0",
|
||||
"symfony/mailer": "^6.0"
|
||||
},
|
||||
|
|
75
composer.lock
generated
75
composer.lock
generated
|
@ -4,30 +4,30 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "4d6120e23f666aa6c5e45c2e2709199f",
|
||||
"content-hash": "d3c39d122a38515484c9d439ecee240b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "chillerlan/php-qrcode",
|
||||
"version": "3.4.1",
|
||||
"version": "4.3.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/chillerlan/php-qrcode.git",
|
||||
"reference": "468603b687a5fe75c1ff33857a45f1726c7b95a9"
|
||||
"reference": "6356b246948ac1025882b3f55e7c68ebd4515ae3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/chillerlan/php-qrcode/zipball/468603b687a5fe75c1ff33857a45f1726c7b95a9",
|
||||
"reference": "468603b687a5fe75c1ff33857a45f1726c7b95a9",
|
||||
"url": "https://api.github.com/repos/chillerlan/php-qrcode/zipball/6356b246948ac1025882b3f55e7c68ebd4515ae3",
|
||||
"reference": "6356b246948ac1025882b3f55e7c68ebd4515ae3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"chillerlan/php-settings-container": "^1.2.2",
|
||||
"chillerlan/php-settings-container": "^2.1",
|
||||
"ext-mbstring": "*",
|
||||
"php": "^7.2 || ^8.0"
|
||||
"php": "^7.4 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phan/phan": "^3.2.2",
|
||||
"phpunit/phpunit": "^8.5",
|
||||
"phan/phan": "^5.3",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"setasign/fpdf": "^1.8.2"
|
||||
},
|
||||
"suggest": {
|
||||
|
@ -59,7 +59,7 @@
|
|||
"homepage": "https://github.com/chillerlan/php-qrcode/graphs/contributors"
|
||||
}
|
||||
],
|
||||
"description": "A QR code generator. PHP 7.2+",
|
||||
"description": "A QR code generator. PHP 7.4+",
|
||||
"homepage": "https://github.com/chillerlan/php-qrcode",
|
||||
"keywords": [
|
||||
"phpqrcode",
|
||||
|
@ -70,7 +70,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/chillerlan/php-qrcode/issues",
|
||||
"source": "https://github.com/chillerlan/php-qrcode/tree/3.4.1"
|
||||
"source": "https://github.com/chillerlan/php-qrcode/tree/4.3.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -82,28 +82,29 @@
|
|||
"type": "ko_fi"
|
||||
}
|
||||
],
|
||||
"time": "2021-09-03T17:54:45+00:00"
|
||||
"time": "2021-11-25T22:38:09+00:00"
|
||||
},
|
||||
{
|
||||
"name": "chillerlan/php-settings-container",
|
||||
"version": "1.2.2",
|
||||
"version": "2.1.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/chillerlan/php-settings-container.git",
|
||||
"reference": "d1b5284d6eb3a767459738bb0b20073f0cb3eeaf"
|
||||
"reference": "ec834493a88682dd69652a1eeaf462789ed0c5f5"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/d1b5284d6eb3a767459738bb0b20073f0cb3eeaf",
|
||||
"reference": "d1b5284d6eb3a767459738bb0b20073f0cb3eeaf",
|
||||
"url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/ec834493a88682dd69652a1eeaf462789ed0c5f5",
|
||||
"reference": "ec834493a88682dd69652a1eeaf462789ed0c5f5",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"php": "^7.2 || ^8.0"
|
||||
"php": "^7.4 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.4"
|
||||
"phan/phan": "^4.0",
|
||||
"phpunit/phpunit": "^9.5"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
|
@ -122,7 +123,7 @@
|
|||
"homepage": "https://github.com/codemasher"
|
||||
}
|
||||
],
|
||||
"description": "A container class for immutable settings objects. Not a DI container. PHP 7.2+",
|
||||
"description": "A container class for immutable settings objects. Not a DI container. PHP 7.4+",
|
||||
"homepage": "https://github.com/chillerlan/php-settings-container",
|
||||
"keywords": [
|
||||
"PHP7",
|
||||
|
@ -144,7 +145,7 @@
|
|||
"type": "ko_fi"
|
||||
}
|
||||
],
|
||||
"time": "2021-09-03T17:33:25+00:00"
|
||||
"time": "2021-09-06T15:17:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "composer/ca-bundle",
|
||||
|
@ -375,16 +376,16 @@
|
|||
},
|
||||
{
|
||||
"name": "doctrine/lexer",
|
||||
"version": "1.2.2",
|
||||
"version": "1.2.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/lexer.git",
|
||||
"reference": "9c50f840f257bbb941e6f4a0e94ccf5db5c3f76c"
|
||||
"reference": "c268e882d4dbdd85e36e4ad69e02dc284f89d229"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/doctrine/lexer/zipball/9c50f840f257bbb941e6f4a0e94ccf5db5c3f76c",
|
||||
"reference": "9c50f840f257bbb941e6f4a0e94ccf5db5c3f76c",
|
||||
"url": "https://api.github.com/repos/doctrine/lexer/zipball/c268e882d4dbdd85e36e4ad69e02dc284f89d229",
|
||||
"reference": "c268e882d4dbdd85e36e4ad69e02dc284f89d229",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -392,7 +393,7 @@
|
|||
},
|
||||
"require-dev": {
|
||||
"doctrine/coding-standard": "^9.0",
|
||||
"phpstan/phpstan": "1.3",
|
||||
"phpstan/phpstan": "^1.3",
|
||||
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
|
||||
"vimeo/psalm": "^4.11"
|
||||
},
|
||||
|
@ -431,7 +432,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/doctrine/lexer/issues",
|
||||
"source": "https://github.com/doctrine/lexer/tree/1.2.2"
|
||||
"source": "https://github.com/doctrine/lexer/tree/1.2.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -447,7 +448,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-01-12T08:27:12+00:00"
|
||||
"time": "2022-02-28T11:07:21+00:00"
|
||||
},
|
||||
{
|
||||
"name": "egulias/email-validator",
|
||||
|
@ -1170,16 +1171,16 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/mailer",
|
||||
"version": "v6.0.3",
|
||||
"version": "v6.0.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/mailer.git",
|
||||
"reference": "d958befe7dbee9d2b2157ef6dfa9b103efa94f82"
|
||||
"reference": "0f4772db6521a1beb44529aa2c0c1e56f671be8f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/mailer/zipball/d958befe7dbee9d2b2157ef6dfa9b103efa94f82",
|
||||
"reference": "d958befe7dbee9d2b2157ef6dfa9b103efa94f82",
|
||||
"url": "https://api.github.com/repos/symfony/mailer/zipball/0f4772db6521a1beb44529aa2c0c1e56f671be8f",
|
||||
"reference": "0f4772db6521a1beb44529aa2c0c1e56f671be8f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1224,7 +1225,7 @@
|
|||
"description": "Helps sending emails",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/mailer/tree/v6.0.3"
|
||||
"source": "https://github.com/symfony/mailer/tree/v6.0.5"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -1240,7 +1241,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-01-02T09:55:41+00:00"
|
||||
"time": "2022-02-25T10:48:52+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/mime",
|
||||
|
@ -1357,12 +1358,12 @@
|
|||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Ctype\\": ""
|
||||
},
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
]
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Ctype\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
namespace Misuzu;
|
||||
|
||||
use Index\Serialisation\Serialiser;
|
||||
|
||||
require_once '../misuzu.php';
|
||||
|
||||
$acceptedProtocols = ['http', 'https'];
|
||||
|
@ -24,7 +26,7 @@ if(empty($proxyHash) || empty($proxyUrl)) {
|
|||
return;
|
||||
}
|
||||
|
||||
$proxyUrlDecoded = Base64::decode($proxyUrl, true);
|
||||
$proxyUrlDecoded = Serialiser::uriBase64()->deserialise($proxyUrl, true);
|
||||
$parsedUrl = parse_url($proxyUrlDecoded);
|
||||
|
||||
if(empty($parsedUrl['scheme'])
|
||||
|
|
|
@ -3,6 +3,7 @@ namespace Misuzu;
|
|||
|
||||
use Misuzu\Users\User;
|
||||
use Misuzu\Users\UserSession;
|
||||
use Index\Serialisation\Serialiser;
|
||||
|
||||
class AuthToken {
|
||||
public const VERSION = 1;
|
||||
|
@ -60,7 +61,7 @@ class AuthToken {
|
|||
public function pack(bool $base64 = true): string {
|
||||
$packed = pack('CNH*', self::VERSION, $this->getUserId(), $this->getSessionToken());
|
||||
if($base64)
|
||||
$packed = Base64::encode($packed, true);
|
||||
$packed = Serialiser::uriBase64()->serialise($packed);
|
||||
return $packed;
|
||||
}
|
||||
|
||||
|
@ -70,7 +71,7 @@ class AuthToken {
|
|||
if(empty($data))
|
||||
return $obj;
|
||||
if($base64)
|
||||
$data = Base64::decode($data, true);
|
||||
$data = Serialiser::uriBase64()->deserialise($data);
|
||||
|
||||
$data = str_pad($data, self::WIDTH, "\x00");
|
||||
$data = unpack('Cversion/Nuser/H*token', $data);
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
namespace Misuzu;
|
||||
|
||||
final class Base32 {
|
||||
public const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
||||
|
||||
public static function decode(string $str): string {
|
||||
$out = '';
|
||||
$length = strlen($str);
|
||||
$char = $shift = 0;
|
||||
|
||||
for($i = 0; $i < $length; $i++) {
|
||||
$char <<= 5;
|
||||
$char += stripos(self::CHARS, $str[$i]);
|
||||
$shift = ($shift + 5) % 8;
|
||||
$out .= $shift < 5 ? chr(($char & (0xFF << $shift)) >> $shift) : '';
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
public static function encode(string $data): string {
|
||||
$bin = '';
|
||||
$encoded = '';
|
||||
$length = strlen($data);
|
||||
|
||||
for($i = 0; $i < $length; $i++) {
|
||||
$bin .= sprintf('%08b', ord($data[$i]));
|
||||
}
|
||||
|
||||
$bin = str_split($bin, 5);
|
||||
$last = array_pop($bin);
|
||||
$bin[] = str_pad($last, 5, '0', STR_PAD_RIGHT);
|
||||
|
||||
foreach($bin as $part) {
|
||||
$encoded .= self::CHARS[bindec($part)];
|
||||
}
|
||||
|
||||
return $encoded;
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
namespace Misuzu;
|
||||
|
||||
final class Base64 {
|
||||
public static function encode(string $data, bool $url = false): string {
|
||||
$data = base64_encode($data);
|
||||
|
||||
if($url)
|
||||
$data = rtrim(strtr($data, '+/', '-_'), '=');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function decode(string $data, bool $url = false): string {
|
||||
if($url)
|
||||
$data = str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT);
|
||||
|
||||
return base64_decode($data);
|
||||
}
|
||||
|
||||
public static function jsonEncode($data): string {
|
||||
return self::encode(json_encode($data), true);
|
||||
}
|
||||
|
||||
public static function jsonDecode(string $data) {
|
||||
return json_decode(self::decode($data, true));
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
namespace Misuzu\Debug;
|
||||
|
||||
final class Stopwatch {
|
||||
private $startTime = 0;
|
||||
private $stopTime = 0;
|
||||
private $laps = [];
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
public function __call(string $name, array $args) {
|
||||
if($name[0] === '_')
|
||||
return null;
|
||||
return $this->{'_' . $name}(...$args);
|
||||
}
|
||||
|
||||
public static function __callStatic(string $name, array $args) {
|
||||
if($name[0] === '_')
|
||||
return null;
|
||||
if(self::$instance === null)
|
||||
self::$instance = new static;
|
||||
return self::$instance->{'_' . $name}(...$args);
|
||||
}
|
||||
|
||||
private static function time() {
|
||||
return microtime(true);
|
||||
}
|
||||
|
||||
public function _start(): void {
|
||||
$this->startTime = self::time();
|
||||
}
|
||||
|
||||
public function _lap(string $text): void {
|
||||
$this->laps[$text] = self::time();
|
||||
}
|
||||
|
||||
public function _stop(): void {
|
||||
$this->stopTime = self::time();
|
||||
}
|
||||
|
||||
public function _reset(): void {
|
||||
$this->laps = [];
|
||||
$this->startTime = 0;
|
||||
$this->stopTime = 0;
|
||||
}
|
||||
|
||||
public function _elapsed(): float {
|
||||
return $this->stopTime - $this->startTime;
|
||||
}
|
||||
|
||||
public function _laps(): array {
|
||||
$laps = [];
|
||||
foreach($this->laps as $name => $time)
|
||||
$laps[$name] = $time - $this->startTime;
|
||||
return $laps;
|
||||
}
|
||||
|
||||
public function _dump(bool $trimmed = false): void {
|
||||
header('X-Misuzu-Elapsed: ' . $this->_elapsed());
|
||||
foreach($this->_laps() as $text => $time)
|
||||
header('X-Misuzu-Lap: ' . ($trimmed ? number_format($time, 6) : $time) . ' ' . $text, false);
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
<?php
|
||||
namespace Misuzu;
|
||||
|
||||
interface HasQualityInterface {
|
||||
public function getQuality(): float;
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
namespace Misuzu\Http\Handlers;
|
||||
|
||||
use Misuzu\AuthToken;
|
||||
use Misuzu\Base64;
|
||||
use Misuzu\Config;
|
||||
use Misuzu\DB;
|
||||
use Misuzu\Emoticon;
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
<?php
|
||||
namespace Misuzu;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class MediaType implements HasQualityInterface {
|
||||
private $type = '';
|
||||
private $subtype = '';
|
||||
private $suffix = '';
|
||||
private $params = [];
|
||||
|
||||
public function __construct(string $mediaType) {
|
||||
if(preg_match('#^([A-Za-z0-9\!\#\$%&\'\*\+\.\-_\{\}\|]+)/([A-Za-z0-9\!\#\$%&\'\*\+\.\-_\{\}\|]+)(?: ?; ?([A-Za-z0-9\!\#\$%&\'\*\+\.\-_\{\}\|\=; ]+))?$#', $mediaType, $matches) !== 1)
|
||||
throw new InvalidArgumentException('Invalid media type supplied.');
|
||||
|
||||
$this->type = $matches[1];
|
||||
|
||||
$subTypeSplit = explode('+', $matches[2], 2);
|
||||
$this->subtype = $subTypeSplit[0];
|
||||
if(isset($subTypeSplit[1]))
|
||||
$this->suffix = $subTypeSplit[1];
|
||||
|
||||
if(isset($matches[3])) {
|
||||
$params = explode(';', $matches[3]);
|
||||
foreach($params as $param) {
|
||||
$parts = explode('=', trim($param), 2);
|
||||
if(!isset($parts[1]))
|
||||
continue;
|
||||
$this->params[$parts[0]] = $parts[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getType(): string {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getSubtype(): string {
|
||||
return $this->subtype;
|
||||
}
|
||||
|
||||
public function getSuffix(): string {
|
||||
return $this->subtype;
|
||||
}
|
||||
|
||||
public function getParams(): array {
|
||||
return $this->params;
|
||||
}
|
||||
public function getParam(string $name, int $filter = FILTER_DEFAULT, $options = 0) {
|
||||
if(!isset($this->params[$name]))
|
||||
return null;
|
||||
return filter_var($this->params[$name], $filter, $options);
|
||||
}
|
||||
|
||||
public function getCharset(): string {
|
||||
return $this->getParam('charset') ?? 'utf-8';
|
||||
}
|
||||
public function getQuality(): float {
|
||||
return max(min(round($this->getParam('q') ?? 1, 2), 1), 0);
|
||||
}
|
||||
|
||||
public function match($other): bool {
|
||||
if(is_string($other))
|
||||
return $this->matchPattern($other);
|
||||
if($other instanceof self)
|
||||
return $this->matchType($other);
|
||||
return false;
|
||||
}
|
||||
public function matchPattern(string $pattern): bool {
|
||||
try {
|
||||
$mediaType = new MediaType($pattern);
|
||||
} catch(InvalidArgumentException $ex) {
|
||||
return false;
|
||||
}
|
||||
return $this->matchType($mediaType);
|
||||
}
|
||||
public function matchType(MediaType $other): bool {
|
||||
return ($other->getType() === '*' && $other->getSubtype() === '*')
|
||||
|| (
|
||||
($other->getType() === $this->getType())
|
||||
&& ($other->getSubtype() === '*' || $other->getSubtype() === $this->getSubtype())
|
||||
);
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$string = $this->type . '/';
|
||||
$string .= $this->subtype;
|
||||
if(!empty($this->suffix))
|
||||
$string .= '+' . $this->suffix;
|
||||
if(!empty($this->params))
|
||||
foreach($this->params as $key => $value) {
|
||||
$string .= ';';
|
||||
if(!empty($key))
|
||||
$string .= $key . '=';
|
||||
$string .= $value;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
namespace Misuzu;
|
||||
|
||||
use Index\Serialisation\Serialiser;
|
||||
|
||||
class TOTP {
|
||||
public const DIGITS = 6;
|
||||
public const INTERVAL = 30;
|
||||
|
@ -13,7 +15,7 @@ class TOTP {
|
|||
}
|
||||
|
||||
public static function generateKey(): string {
|
||||
return Base32::encode(random_bytes(16));
|
||||
return Serialiser::base32()->serialise(random_bytes(16));
|
||||
}
|
||||
|
||||
public static function timecode(?int $timestamp = null, int $interval = self::INTERVAL): int {
|
||||
|
@ -22,7 +24,7 @@ class TOTP {
|
|||
}
|
||||
|
||||
public function generate(?int $timestamp = null): string {
|
||||
$hash = hash_hmac(self::HASH_ALGO, pack('J', self::timecode($timestamp)), Base32::decode($this->secretKey), true);
|
||||
$hash = hash_hmac(self::HASH_ALGO, pack('J', self::timecode($timestamp)), Serialiser::base32()->deserialise($this->secretKey), true);
|
||||
$offset = ord($hash[strlen($hash) - 1]) & 0x0F;
|
||||
|
||||
$bin = 0;
|
||||
|
|
|
@ -252,7 +252,7 @@ function url_proxy_media(?string $url): ?string {
|
|||
}
|
||||
|
||||
$secret = \Misuzu\Config::get('media_proxy.secret', \Misuzu\Config::TYPE_STR, 'insecure');
|
||||
$url = \Misuzu\Base64::encode($url, true);
|
||||
$url = \Index\Serialisation\Serialiser::uriBase64()->serialise($url);
|
||||
$hash = hash_hmac('sha256', $url, $secret);
|
||||
|
||||
return url('media-proxy', compact('hash', 'url'));
|
||||
|
|
Loading…
Add table
Reference in a new issue