-
-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from acelaya/feature/gdpr
Fix GDPR compliance
- Loading branch information
Showing
18 changed files
with
272 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ShlinkMigrations; | ||
|
||
use Doctrine\DBAL\DBALException; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
use Shlinkio\Shlink\Common\Exception\WrongIpException; | ||
use Shlinkio\Shlink\Common\Util\IpAddress; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20180913205455 extends AbstractMigration | ||
{ | ||
/** | ||
* @param Schema $schema | ||
*/ | ||
public function up(Schema $schema): void | ||
{ | ||
// Nothing to create | ||
} | ||
|
||
/** | ||
* @param Schema $schema | ||
* @throws DBALException | ||
*/ | ||
public function postUp(Schema $schema): void | ||
{ | ||
$qb = $this->connection->createQueryBuilder(); | ||
$qb->select('id', 'remote_addr') | ||
->from('visits'); | ||
$st = $this->connection->executeQuery($qb->getSQL()); | ||
|
||
$qb = $this->connection->createQueryBuilder(); | ||
$qb->update('visits', 'v') | ||
->set('v.remote_addr', ':obfuscatedAddr') | ||
->where('v.id=:id'); | ||
|
||
while ($row = $st->fetch(\PDO::FETCH_ASSOC)) { | ||
$addr = $row['remote_addr'] ?? null; | ||
if ($addr === null) { | ||
continue; | ||
} | ||
|
||
$qb->setParameters([ | ||
'id' => $row['id'], | ||
'obfuscatedAddr' => $this->determineAddress((string) $addr), | ||
])->execute(); | ||
} | ||
} | ||
|
||
private function determineAddress(string $addr): ?string | ||
{ | ||
if ($addr === IpAddress::LOCALHOST) { | ||
return $addr; | ||
} | ||
|
||
try { | ||
return (string) IpAddress::fromString($addr)->getObfuscatedCopy(); | ||
} catch (WrongIpException $e) { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* @param Schema $schema | ||
*/ | ||
public function down(Schema $schema): void | ||
{ | ||
// Nothing to rollback | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"cityName": { | ||
"type": "string" | ||
}, | ||
"countryCode": { | ||
"type": "string" | ||
}, | ||
"countryName": { | ||
"type": "string" | ||
}, | ||
"latitude": { | ||
"type": "string" | ||
}, | ||
"longitude": { | ||
"type": "string" | ||
}, | ||
"regionName": { | ||
"type": "string" | ||
}, | ||
"timezone": { | ||
"type": "string" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Shlinkio\Shlink\Common\Util; | ||
|
||
use Shlinkio\Shlink\Common\Exception\WrongIpException; | ||
|
||
final class IpAddress | ||
{ | ||
private const IPV4_PARTS_COUNT = 4; | ||
private const OBFUSCATED_OCTET = '0'; | ||
public const LOCALHOST = '127.0.0.1'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $firstOctet; | ||
/** | ||
* @var string | ||
*/ | ||
private $secondOctet; | ||
/** | ||
* @var string | ||
*/ | ||
private $thirdOctet; | ||
/** | ||
* @var string | ||
*/ | ||
private $fourthOctet; | ||
|
||
private function __construct(string $firstOctet, string $secondOctet, string $thirdOctet, string $fourthOctet) | ||
{ | ||
$this->firstOctet = $firstOctet; | ||
$this->secondOctet = $secondOctet; | ||
$this->thirdOctet = $thirdOctet; | ||
$this->fourthOctet = $fourthOctet; | ||
} | ||
|
||
/** | ||
* @param string $address | ||
* @return IpAddress | ||
* @throws WrongIpException | ||
*/ | ||
public static function fromString(string $address): self | ||
{ | ||
$address = \trim($address); | ||
$parts = \explode('.', $address); | ||
if (\count($parts) !== self::IPV4_PARTS_COUNT) { | ||
throw WrongIpException::fromIpAddress($address); | ||
} | ||
|
||
return new self(...$parts); | ||
} | ||
|
||
public function getObfuscatedCopy(): self | ||
{ | ||
return new self( | ||
$this->firstOctet, | ||
$this->secondOctet, | ||
$this->thirdOctet, | ||
self::OBFUSCATED_OCTET | ||
); | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return \implode('.', [ | ||
$this->firstOctet, | ||
$this->secondOctet, | ||
$this->thirdOctet, | ||
$this->fourthOctet, | ||
]); | ||
} | ||
} |
Oops, something went wrong.