Initial Version

This commit is contained in:
root
2025-12-21 10:09:54 -05:00
commit 4ae6befc7b
422 changed files with 47225 additions and 0 deletions

View File

@@ -0,0 +1,255 @@
<?php
declare(strict_types=1);
namespace KTXC\Models\Firewall;
use KTXF\Json\JsonDeserializable;
/**
* Represents a firewall access log entry for tracking blocked/allowed requests
*/
class FirewallLogObject implements \JsonSerializable, JsonDeserializable
{
public const RESULT_ALLOWED = 'allowed';
public const RESULT_BLOCKED = 'blocked';
public const EVENT_AUTH_FAILURE = 'auth_failure';
public const EVENT_RATE_LIMIT = 'rate_limit';
public const EVENT_BRUTE_FORCE = 'brute_force';
public const EVENT_SUSPICIOUS = 'suspicious';
public const EVENT_RULE_MATCH = 'rule_match';
public const EVENT_ACCESS_CHECK = 'access_check';
private ?string $id = null;
private ?string $tenantId = null;
private ?string $ipAddress = null;
private ?string $deviceFingerprint = null;
private ?string $userAgent = null;
private ?string $requestPath = null;
private ?string $requestMethod = null;
private ?string $eventType = null;
private ?string $result = null; // allowed, blocked
private ?string $ruleId = null; // Which rule triggered (if any)
private ?string $identityId = null; // User ID if authenticated
private ?\DateTimeImmutable $timestamp = null;
private ?array $metadata = null; // Additional context
public function jsonDeserialize(array|string $data): static
{
if (is_string($data)) {
$data = json_decode($data, true);
}
if (array_key_exists('_id', $data)) {
$this->id = $data['_id'] !== null ? (string)$data['_id'] : null;
} elseif (array_key_exists('id', $data)) {
$this->id = $data['id'] !== null ? (string)$data['id'] : null;
}
if (array_key_exists('tenantId', $data)) {
$this->tenantId = $data['tenantId'] !== null ? (string)$data['tenantId'] : null;
}
if (array_key_exists('ipAddress', $data)) {
$this->ipAddress = $data['ipAddress'] !== null ? (string)$data['ipAddress'] : null;
}
if (array_key_exists('deviceFingerprint', $data)) {
$this->deviceFingerprint = $data['deviceFingerprint'] !== null ? (string)$data['deviceFingerprint'] : null;
}
if (array_key_exists('userAgent', $data)) {
$this->userAgent = $data['userAgent'] !== null ? (string)$data['userAgent'] : null;
}
if (array_key_exists('requestPath', $data)) {
$this->requestPath = $data['requestPath'] !== null ? (string)$data['requestPath'] : null;
}
if (array_key_exists('requestMethod', $data)) {
$this->requestMethod = $data['requestMethod'] !== null ? (string)$data['requestMethod'] : null;
}
if (array_key_exists('eventType', $data)) {
$this->eventType = $data['eventType'] !== null ? (string)$data['eventType'] : null;
}
if (array_key_exists('result', $data)) {
$this->result = $data['result'] !== null ? (string)$data['result'] : null;
}
if (array_key_exists('ruleId', $data)) {
$this->ruleId = $data['ruleId'] !== null ? (string)$data['ruleId'] : null;
}
if (array_key_exists('identityId', $data)) {
$this->identityId = $data['identityId'] !== null ? (string)$data['identityId'] : null;
}
if (array_key_exists('timestamp', $data)) {
$this->timestamp = $data['timestamp'] !== null
? new \DateTimeImmutable($data['timestamp'])
: null;
}
if (array_key_exists('metadata', $data)) {
$this->metadata = $data['metadata'] !== null ? (array)$data['metadata'] : null;
}
return $this;
}
public function jsonSerialize(): array
{
return [
'id' => $this->id,
'tenantId' => $this->tenantId,
'ipAddress' => $this->ipAddress,
'deviceFingerprint' => $this->deviceFingerprint,
'userAgent' => $this->userAgent,
'requestPath' => $this->requestPath,
'requestMethod' => $this->requestMethod,
'eventType' => $this->eventType,
'result' => $this->result,
'ruleId' => $this->ruleId,
'identityId' => $this->identityId,
'timestamp' => $this->timestamp?->format(\DateTimeInterface::ATOM),
'metadata' => $this->metadata,
];
}
// Getters and setters
public function getId(): ?string
{
return $this->id;
}
public function setId(?string $id): self
{
$this->id = $id;
return $this;
}
public function getTenantId(): ?string
{
return $this->tenantId;
}
public function setTenantId(?string $tenantId): self
{
$this->tenantId = $tenantId;
return $this;
}
public function getIpAddress(): ?string
{
return $this->ipAddress;
}
public function setIpAddress(?string $ipAddress): self
{
$this->ipAddress = $ipAddress;
return $this;
}
public function getDeviceFingerprint(): ?string
{
return $this->deviceFingerprint;
}
public function setDeviceFingerprint(?string $deviceFingerprint): self
{
$this->deviceFingerprint = $deviceFingerprint;
return $this;
}
public function getUserAgent(): ?string
{
return $this->userAgent;
}
public function setUserAgent(?string $userAgent): self
{
$this->userAgent = $userAgent;
return $this;
}
public function getRequestPath(): ?string
{
return $this->requestPath;
}
public function setRequestPath(?string $requestPath): self
{
$this->requestPath = $requestPath;
return $this;
}
public function getRequestMethod(): ?string
{
return $this->requestMethod;
}
public function setRequestMethod(?string $requestMethod): self
{
$this->requestMethod = $requestMethod;
return $this;
}
public function getEventType(): ?string
{
return $this->eventType;
}
public function setEventType(?string $eventType): self
{
$this->eventType = $eventType;
return $this;
}
public function getResult(): ?string
{
return $this->result;
}
public function setResult(?string $result): self
{
$this->result = $result;
return $this;
}
public function getRuleId(): ?string
{
return $this->ruleId;
}
public function setRuleId(?string $ruleId): self
{
$this->ruleId = $ruleId;
return $this;
}
public function getIdentityId(): ?string
{
return $this->identityId;
}
public function setIdentityId(?string $identityId): self
{
$this->identityId = $identityId;
return $this;
}
public function getTimestamp(): ?\DateTimeImmutable
{
return $this->timestamp;
}
public function setTimestamp(?\DateTimeImmutable $timestamp): self
{
$this->timestamp = $timestamp;
return $this;
}
public function getMetadata(): ?array
{
return $this->metadata;
}
public function setMetadata(?array $metadata): self
{
$this->metadata = $metadata;
return $this;
}
}