<?php
namespace App\Entity;
use App\Repository\VulnerabilityRepository;
use App\Traits\DateTimeTrait;
use Doctrine\ORM\Mapping as ORM;
use Overblog\GraphQLBundle\Annotation\Field;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ReadableCollection;
use App\Attribute\Searchable;
use DateTimeImmutable;
#[ORM\Entity(repositoryClass: VulnerabilityRepository::class)]
#[ORM\HasLifecycleCallbacks]
class Vulnerability extends BasicEntity
{
use DateTimeTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Field(name: "id", type: "int")]
private $id;
#[ORM\Column(type: 'string', length: 255)]
#[Field(name: "title", type: "string")]
#[Searchable(name: 'title')]
private $title;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Field(name: "componenent", type: "string")]
private $componenent;
#[ORM\Column(type: 'text', nullable: true)]
#[Field(name: "metadata", type: "string")]
#[Searchable(name: 'metadata')]
private $metadata;
#[ORM\Column(type: 'text', nullable: true)]
#[Field(name: "description", type: "string")]
private $description;
#[ORM\ManyToOne(targetEntity: VulnerabilityLevel::class)]
#[ORM\JoinColumn(nullable: false)]
#[Field(name: "level", type: "string")]
private $level;
#[ORM\ManyToOne(targetEntity: Domain::class, inversedBy: 'vulnerabilities')]
#[ORM\JoinColumn(nullable: false)]
#[Field(name: "domain")]
private $domain;
#[ORM\Column(type: 'string', length: 255)]
#[Field(name: "uid", type: "string")]
private $uid;
#[ORM\OneToMany(mappedBy: "vulnurability", targetEntity: Recommendation::class, cascade: ["remove"])]
private $recommendations;
#[ORM\Column(type: "boolean", options: ['default' => true])]
#[Field(name: "is_active", type: "boolean")]
private $isActive;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
#[Field(name: "last_seen", type: "string")]
private $lastSeen;
#[ORM\ManyToOne(targetEntity: Status::class, inversedBy: 'exposedIps')]
#[ORM\JoinColumn(nullable: true, options: ['default' => 1])]
#[Field(name: "status")]
private $status;
public function __construct()
{
$this->recommendations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getComponenent(): ?string
{
return $this->componenent;
}
public function setComponenent(?string $componenent): self
{
$this->componenent = $componenent;
return $this;
}
public function getMetadata(): ?string
{
return $this->metadata;
}
public function setMetadata(?string $metadata): self
{
$this->metadata = $metadata;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getLevel(): ?VulnerabilityLevel
{
return $this->level;
}
public function setLevel(?VulnerabilityLevel $level): self
{
$this->level = $level;
return $this;
}
public function getDomain(): ?Domain
{
return $this->domain;
}
public function setDomain(?Domain $domain): self
{
$this->domain = $domain;
return $this;
}
public function getUid(): ?string
{
return $this->uid;
}
public function setUid(string $uid): self
{
$this->uid = $uid;
return $this;
}
/**
* @return Collection|Recommendations[]
*/
public function getRecommendations(): Collection
{
return $this->recommendations;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(?bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getLastSeen(): ?DateTimeImmutable
{
return $this->lastSeen;
}
public function setLastSeen(?DateTimeImmutable $lastSeen): self
{
$this->lastSeen = $lastSeen;
return $this;
}
public function getStatus(): ?Status
{
return $this->status;
}
public function setStatus(?Status $status): self
{
$this->status = $status;
return $this;
}
public function getSubDomain(): ?ExposedSubDomain
{
$metadata = $this->getMetadata();
$subDomain = $this->getDomain()->getExposedSubDomains()
->filter(function(ExposedSubDomain $sub) use ($metadata){
return str_contains(
$metadata,
$sub->getSubDomain().".".str_replace('@', '', $this->getDomain()->getUrl())
);
})->current();
// Check if current() returned false and return null if so
return $subDomain !== false ? $subDomain : null;
}
}