<?php
namespace App\Entity;
use App\Repository\ExposedSubDomainRepository;
use App\Traits\DateTimeTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\ORM\Mapping as ORM;
use Overblog\GraphQLBundle\Annotation\Field;
use App\Attribute\Searchable;
use DateTimeImmutable;
#[ORM\Entity(repositoryClass: ExposedSubDomainRepository::class)]
#[ORM\HasLifecycleCallbacks]
class ExposedSubDomain 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: "sub_domain", type: "string")]
#[Searchable(name: 'sub_domain')]
private $subDomain;
#[ORM\ManyToOne(targetEntity: Domain::class, inversedBy: 'exposedSubDomains')]
#[ORM\JoinColumn(nullable: false)]
#[Field(name: "domain")]
private $domain;
#[ORM\Column(type: 'boolean')]
#[Field(name: "is_normal", type: "boolean")]
private $isNormal;
#[ORM\ManyToOne(inversedBy: 'exposedSubDomains', targetEntity: ExposedIp::class, cascade: ['persist', 'remove'])]
#[Field(name: "exposed_ip", nullable: true)]
private $exposedIp;
#[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: 'exposedSubDomains')]
#[ORM\JoinColumn(nullable: true, options: ['default' => 1])]
#[Field(name: "status")]
private $status;
#[ORM\Column(options: ['default' => false])]
#[Field(name: "is_deleted", type: "boolean")]
private ?bool $isDeleted = null;
public function getId(): ?int
{
return $this->id;
}
public function getSubDomain(): ?string
{
return $this->subDomain;
}
public function setSubDomain(string $subDomain): self
{
$this->subDomain = $subDomain;
return $this;
}
public function getDomain(): ?Domain
{
return $this->domain;
}
public function setDomain(?Domain $domain): self
{
$this->domain = $domain;
return $this;
}
public function getIsNormal(): ?bool
{
return $this->isNormal;
}
public function setIsNormal(bool $isNormal): self
{
$this->isNormal = $isNormal;
return $this;
}
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 getExposedIp(): ?ExposedIp
{
return $this->exposedIp;
}
public function setExposedIp(?ExposedIp $exposedIp): self
{
$this->exposedIp = $exposedIp;
return $this;
}
public function getVulnerabilities(): ReadableCollection
{
$sub = $this->subDomain.".".substr($this->getDomain()->getUrl(), 1);
return $this->getDomain()->getVulnerabilities()
->filter(function(Vulnerability $v) use ($sub){
return str_contains(
$v->getMetadata(),
$sub
);
});
}
public function getIsDeleted(): ?bool
{
return $this->isDeleted;
}
public function setIsDeleted(?bool $isDeleted): self
{
$this->isDeleted = $isDeleted;
return $this;
}
}