<?php
namespace App\Entity;
use App\Attribute\Searchable;
use App\Repository\ExposedIpRepository;
use App\Traits\DateTimeTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Overblog\GraphQLBundle\Annotation\Field;
use DateTimeImmutable;
#[ORM\Entity(repositoryClass: ExposedIpRepository::class)]
#[ORM\HasLifecycleCallbacks]
class ExposedIp extends BasicEntity
{
use DateTimeTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: "integer")]
#[Field(name: "id", type: "int")]
private $id;
#[ORM\Column(type: "string", length: 15)]
#[Field(name: "ip", type: "string")]
#[Searchable(name: 'ip')]
private $ip;
#[ORM\ManyToMany(targetEntity: Port::class, inversedBy:'exposedIps', cascade: ["persist", "remove"])]
private $ports;
#[ORM\ManyToOne(targetEntity: Organisation::class, inversedBy: "exposedIps")]
#[ORM\JoinColumn(nullable: false)]
#[Field(name: "organisation")]
private $organisation;
#[ORM\Column(type: "boolean", nullable: true)]
#[Field(name: "is_exposed", type: "boolean")]
private $isExposed;
#[ORM\Column(type: "boolean", nullable: true)]
#[Field(name: "is_normal", type: "boolean")]
private $isNormal;
#[ORM\Column(type: "boolean", nullable: true)]
#[Field(name: "is_cdn", type: "boolean")]
private $isCdn;
#[ORM\OneToMany(mappedBy: "exposedIp", targetEntity: ExposedSubDomain::class, cascade: ["persist", "remove"])]
private $exposedSubDomains;
#[ORM\OneToMany(mappedBy: "exposedIp", targetEntity: OpenPort::class, cascade: ["persist", "remove"])]
private $openPorts;
#[ORM\ManyToOne(inversedBy: 'exposedIps')]
private ?Domain $domain = null;
#[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->ports = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getIp(): ?string
{
return $this->ip;
}
public function setIp(string $ip): self
{
$this->ip = $ip;
return $this;
}
/**
* @return Collection|Port[]
*/
public function getPorts(): Collection
{
return $this->ports;
}
public function addPort(Port $port): self
{
if (!$this->ports->contains($port)) {
$this->ports[] = $port;
}
return $this;
}
public function removePort(Port $port): self
{
$this->ports->removeElement($port);
return $this;
}
public function getOrganisation(): ?Organisation
{
return $this->organisation;
}
public function setOrganisation(?Organisation $organisation): self
{
$this->organisation = $organisation;
return $this;
}
public function getIsExposed(): ?bool
{
return $this->isExposed;
}
public function setIsExposed(?bool $isExposed): self
{
$this->isExposed = $isExposed;
return $this;
}
public function getIsNormal(): ?bool
{
return $this->isNormal;
}
public function setIsNormal(?bool $isNormal): self
{
$this->isNormal = $isNormal;
return $this;
}
public function getIsCdn(): ?bool
{
return $this->isCdn;
}
public function setIsCdn(?bool $isCdn): self
{
$this->isCdn = $isCdn;
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 getExposedSubDomains(): Collection
{
return $this->exposedSubDomains->filter(function($exposedSubdomain) {
return !$exposedSubdomain->getIsDeleted();
});
}
// Optionally add a method for getting all subdomains, including deleted ones
public function getAllExposedSubdomains(): Collection
{
return $this->exposedSubDomains;
}
public function setExposedSubDomains(?Collection $exposedSubDomains): self
{
// unset the owning side of the relation if necessary
if ($exposedSubDomains === null && $this->exposedSubDomains !== null) {
$this->exposedSubDomains->setExposedIp(null);
}
// set the owning side of the relation if necessary
if ($exposedSubDomains !== null && $exposedSubDomains->getExposedIp() !== $this) {
$exposedSubDomains->setExposedIp($this);
}
$this->exposedSubDomains = $exposedSubDomains;
return $this;
}
// Optionally add a method for getting all subdomains, including deleted ones
public function getOpenPorts(): Collection
{
return $this->openPorts;
}
public function setOpenPorts(?Collection $openPorts): self
{
$this->openPorts = $openPorts;
return $this;
}
public function getDomain(): ?Domain
{
return $this->domain;
}
public function setDomain(?Domain $domain): static
{
$this->domain = $domain;
return $this;
}
public function getStatus(): ?Status
{
return $this->status;
}
public function setStatus(?Status $status): self
{
$this->status = $status;
return $this;
}
}