docker: gd extension + 2FA Bugfix
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Core\Objects\DatabaseEntity;
|
||||
|
||||
use Core\API\Parameter\Parameter;
|
||||
use Core\Driver\SQL\SQL;
|
||||
use Core\Objects\DatabaseEntity\Attribute\DefaultValue;
|
||||
use Core\Objects\DatabaseEntity\Attribute\ExtendingEnum;
|
||||
use Core\Objects\DatabaseEntity\Attribute\MaxLength;
|
||||
@@ -16,11 +17,16 @@ use Core\Objects\Router\StaticFileRoute;
|
||||
abstract class Route extends DatabaseEntity {
|
||||
|
||||
const PARAMETER_PATTERN = "/^{([^:]+)(:(.*?)(\?)?)?}$/";
|
||||
|
||||
const TYPE_DYNAMIC = "dynamic";
|
||||
const TYPE_STATIC = "static";
|
||||
const TYPE_REDIRECT_PERMANENTLY = "redirect_permanently";
|
||||
const TYPE_REDIRECT_TEMPORARY = "redirect_temporary";
|
||||
const ROUTE_TYPES = [
|
||||
"redirect_temporary" => RedirectRoute::class,
|
||||
"redirect_permanently" => RedirectRoute::class,
|
||||
"static" => StaticFileRoute::class,
|
||||
"dynamic" => DocumentRoute::class
|
||||
self::TYPE_REDIRECT_TEMPORARY => RedirectRoute::class,
|
||||
self::TYPE_REDIRECT_PERMANENTLY => RedirectRoute::class,
|
||||
self::TYPE_STATIC => StaticFileRoute::class,
|
||||
self::TYPE_DYNAMIC => DocumentRoute::class
|
||||
];
|
||||
|
||||
#[MaxLength(128)]
|
||||
@@ -77,6 +83,13 @@ abstract class Route extends DatabaseEntity {
|
||||
|
||||
public abstract function call(Router $router, array $params): string;
|
||||
|
||||
protected function readExtra() { }
|
||||
|
||||
public function postFetch(SQL $sql, array $row) {
|
||||
parent::postFetch($sql, $row);
|
||||
$this->readExtra();
|
||||
}
|
||||
|
||||
protected function getArgs(): array {
|
||||
return [$this->pattern, $this->exact];
|
||||
}
|
||||
@@ -204,4 +217,28 @@ abstract class Route extends DatabaseEntity {
|
||||
"active" => $this->active,
|
||||
];
|
||||
}
|
||||
|
||||
public function setActive(bool $active) {
|
||||
$this->active = $active;
|
||||
}
|
||||
|
||||
public function getType(): string {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function setPattern(string $pattern) {
|
||||
$this->pattern = $pattern;
|
||||
}
|
||||
|
||||
public function setExtra(string $extra) {
|
||||
$this->extra = $extra;
|
||||
}
|
||||
|
||||
public function setTarget(string $target) {
|
||||
$this->target = $target;
|
||||
}
|
||||
|
||||
public function setExact(bool $exact) {
|
||||
$this->exact = $exact;
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ abstract class TwoFactorToken extends DatabaseEntity {
|
||||
#[ExtendingEnum(self::TWO_FACTOR_TOKEN_TYPES)] private string $type;
|
||||
private bool $confirmed;
|
||||
private bool $authenticated;
|
||||
#[MaxLength(512)] private string $data;
|
||||
#[MaxLength(512)] private ?string $data;
|
||||
|
||||
public function __construct(string $type, ?int $id = null, bool $confirmed = false) {
|
||||
parent::__construct($id);
|
||||
@@ -27,6 +27,7 @@ abstract class TwoFactorToken extends DatabaseEntity {
|
||||
$this->type = $type;
|
||||
$this->confirmed = $confirmed;
|
||||
$this->authenticated = $_SESSION["2faAuthenticated"] ?? false;
|
||||
$this->data = null;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array {
|
||||
@@ -63,11 +64,12 @@ abstract class TwoFactorToken extends DatabaseEntity {
|
||||
return $this->confirmed;
|
||||
}
|
||||
|
||||
public function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function isAuthenticated(): bool {
|
||||
return $this->authenticated;
|
||||
}
|
||||
|
||||
public function confirm(SQL $sql): bool {
|
||||
$this->confirmed = true;
|
||||
return $this->save($sql) !== false;
|
||||
}
|
||||
}
|
||||
@@ -93,4 +93,8 @@ class User extends DatabaseEntity {
|
||||
$this->lastOnline = new \DateTime();
|
||||
return $this->save($sql, ["last_online", "language_id"]);
|
||||
}
|
||||
|
||||
public function setTwoFactorToken(TwoFactorToken $twoFactorToken) {
|
||||
$this->twoFactorToken = $twoFactorToken;
|
||||
}
|
||||
}
|
||||
@@ -24,11 +24,16 @@ class DocumentRoute extends Route {
|
||||
$this->extra = json_encode($args);
|
||||
}
|
||||
|
||||
public function postFetch(SQL $sql, array $row) {
|
||||
parent::postFetch($sql, $row);
|
||||
protected function readExtra() {
|
||||
parent::readExtra();
|
||||
$this->args = json_decode($this->extra);
|
||||
}
|
||||
|
||||
public function preInsert(array &$row) {
|
||||
parent::preInsert($row);
|
||||
$this->extra = json_encode($this->args);
|
||||
}
|
||||
|
||||
#[Pure] private function getClassName(): string {
|
||||
return $this->getTarget();
|
||||
}
|
||||
|
||||
@@ -22,11 +22,16 @@ class StaticFileRoute extends Route {
|
||||
$this->extra = json_encode($this->code);
|
||||
}
|
||||
|
||||
public function postFetch(SQL $sql, array $row) {
|
||||
parent::postFetch($sql, $row);
|
||||
protected function readExtra() {
|
||||
parent::readExtra();
|
||||
$this->code = json_decode($this->extra);
|
||||
}
|
||||
|
||||
public function preInsert(array &$row) {
|
||||
parent::preInsert($row);
|
||||
$this->extra = json_encode($this->code);
|
||||
}
|
||||
|
||||
public function call(Router $router, array $params): string {
|
||||
http_response_code($this->code);
|
||||
$this->serveStatic($this->getAbsolutePath(), $router);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Core\Objects\TwoFactor;
|
||||
|
||||
use Core\Driver\SQL\SQL;
|
||||
use Cose\Algorithm\Signature\ECDSA\ECSignature;
|
||||
use Core\Objects\DatabaseEntity\TwoFactorToken;
|
||||
|
||||
@@ -13,8 +14,13 @@ class KeyBasedTwoFactorToken extends TwoFactorToken {
|
||||
private ?string $credentialId;
|
||||
private ?PublicKey $publicKey;
|
||||
|
||||
public function __construct(string $challenge) {
|
||||
parent::__construct(self::TYPE);
|
||||
$this->challenge = $challenge;
|
||||
}
|
||||
|
||||
protected function readData(string $data) {
|
||||
if ($this->isConfirmed()) {
|
||||
if (!$this->isConfirmed()) {
|
||||
$this->challenge = base64_decode($data);
|
||||
$this->credentialId = null;
|
||||
$this->publicKey = null;
|
||||
@@ -27,9 +33,23 @@ class KeyBasedTwoFactorToken extends TwoFactorToken {
|
||||
}
|
||||
|
||||
public function getData(): string {
|
||||
return $this->challenge;
|
||||
if ($this->isConfirmed()) {
|
||||
return base64_encode($this->challenge);
|
||||
} else {
|
||||
return json_encode([
|
||||
"credentialId" => $this->credentialId,
|
||||
"publicKey" => $this->publicKey->jsonSerialize()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function confirmKeyBased(SQL $sql, string $credentialId, PublicKey $publicKey): bool {
|
||||
$this->credentialId = $credentialId;
|
||||
$this->publicKey = $publicKey;
|
||||
return parent::confirm($sql);
|
||||
}
|
||||
|
||||
|
||||
public function getPublicKey(): ?PublicKey {
|
||||
return $this->publicKey;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Core\Objects\TwoFactor;
|
||||
use Base32\Base32;
|
||||
use chillerlan\QRCode\QRCode;
|
||||
use chillerlan\QRCode\QROptions;
|
||||
use Core\Driver\SQL\SQL;
|
||||
use Core\Objects\Context;
|
||||
use Core\Objects\DatabaseEntity\TwoFactorToken;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user