mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Created migration which parses existing IP addresses, generating hashes and droping already used IPs
This commit is contained in:
@@ -27,13 +27,13 @@ final class IpAddress
|
||||
* @var string
|
||||
*/
|
||||
private $fourthOctet;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isLocalhost;
|
||||
|
||||
private function __construct()
|
||||
private function __construct(string $firstOctet, string $secondOctet, string $thirdOctet, string $fourthOctet)
|
||||
{
|
||||
$this->firstOctet = $firstOctet;
|
||||
$this->secondOctet = $secondOctet;
|
||||
$this->thirdOctet = $thirdOctet;
|
||||
$this->fourthOctet = $fourthOctet;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,17 +49,17 @@ final class IpAddress
|
||||
throw WrongIpException::fromIpAddress($address);
|
||||
}
|
||||
|
||||
$instance = new self();
|
||||
$instance->isLocalhost = $address === self::LOCALHOST;
|
||||
[$instance->firstOctet, $instance->secondOctet, $instance->thirdOctet, $instance->fourthOctet] = $parts;
|
||||
return $instance;
|
||||
return new self(...$parts);
|
||||
}
|
||||
|
||||
public function getObfuscatedCopy(): self
|
||||
{
|
||||
$copy = clone $this;
|
||||
$copy->fourthOctet = $this->isLocalhost ? $this->fourthOctet : self::OBFUSCATED_OCTET;
|
||||
return $copy;
|
||||
return new self(
|
||||
$this->firstOctet,
|
||||
$this->secondOctet,
|
||||
$this->thirdOctet,
|
||||
self::OBFUSCATED_OCTET
|
||||
);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
|
||||
@@ -35,6 +35,7 @@ class Visit extends AbstractEntity implements \JsonSerializable
|
||||
private $remoteAddr;
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="string", length=256, name="remote_addr_hash", nullable=true)
|
||||
*/
|
||||
private $remoteAddrHash;
|
||||
/**
|
||||
@@ -108,8 +109,9 @@ class Visit extends AbstractEntity implements \JsonSerializable
|
||||
|
||||
private function obfuscateAddress(?string $address): ?string
|
||||
{
|
||||
if ($address === null) {
|
||||
return null;
|
||||
// Localhost addresses do not need to be obfuscated
|
||||
if ($address === null || $address === IpAddress::LOCALHOST) {
|
||||
return $address;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -124,6 +126,12 @@ class Visit extends AbstractEntity implements \JsonSerializable
|
||||
return $address ? \hash('sha256', $address) : null;
|
||||
}
|
||||
|
||||
public function resetObfuscatedAddr(): self
|
||||
{
|
||||
$this->remoteAddr = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUserAgent(): string
|
||||
{
|
||||
return $this->userAgent;
|
||||
|
||||
Reference in New Issue
Block a user