@@ -22,67 +22,67 @@ |
||
22 | 22 | |
23 | 23 | class AuthenticationManager |
24 | 24 | { |
25 | - const AUTH_OK = 1; |
|
26 | - const AUTH_FAIL = 2; |
|
27 | - const AUTH_REQUIRE_NEXT_STAGE = 3; |
|
28 | - private $typeMap = array(); |
|
29 | - /** |
|
30 | - * @var PdoDatabase |
|
31 | - */ |
|
32 | - private $database; |
|
25 | + const AUTH_OK = 1; |
|
26 | + const AUTH_FAIL = 2; |
|
27 | + const AUTH_REQUIRE_NEXT_STAGE = 3; |
|
28 | + private $typeMap = array(); |
|
29 | + /** |
|
30 | + * @var PdoDatabase |
|
31 | + */ |
|
32 | + private $database; |
|
33 | 33 | |
34 | - /** |
|
35 | - * AuthenticationManager constructor. |
|
36 | - * |
|
37 | - * @param PdoDatabase $database |
|
38 | - * @param SiteConfiguration $siteConfiguration |
|
39 | - * @param HttpHelper $httpHelper |
|
40 | - */ |
|
41 | - public function __construct(PdoDatabase $database, SiteConfiguration $siteConfiguration, HttpHelper $httpHelper) |
|
42 | - { |
|
43 | - // setup providers |
|
44 | - // note on type map: this *must* be the value in the database, as this is what it maps. |
|
45 | - $this->typeMap['password'] = new PasswordCredentialProvider($database, $siteConfiguration); |
|
46 | - $this->typeMap['yubikeyotp'] = new YubikeyOtpCredentialProvider($database, $siteConfiguration, $httpHelper); |
|
47 | - $this->typeMap['totp'] = new TotpCredentialProvider($database, $siteConfiguration); |
|
48 | - $this->typeMap['scratch'] = new ScratchTokenCredentialProvider($database, $siteConfiguration); |
|
49 | - $this->typeMap['u2f'] = new U2FCredentialProvider($database, $siteConfiguration); |
|
50 | - $this->database = $database; |
|
51 | - } |
|
34 | + /** |
|
35 | + * AuthenticationManager constructor. |
|
36 | + * |
|
37 | + * @param PdoDatabase $database |
|
38 | + * @param SiteConfiguration $siteConfiguration |
|
39 | + * @param HttpHelper $httpHelper |
|
40 | + */ |
|
41 | + public function __construct(PdoDatabase $database, SiteConfiguration $siteConfiguration, HttpHelper $httpHelper) |
|
42 | + { |
|
43 | + // setup providers |
|
44 | + // note on type map: this *must* be the value in the database, as this is what it maps. |
|
45 | + $this->typeMap['password'] = new PasswordCredentialProvider($database, $siteConfiguration); |
|
46 | + $this->typeMap['yubikeyotp'] = new YubikeyOtpCredentialProvider($database, $siteConfiguration, $httpHelper); |
|
47 | + $this->typeMap['totp'] = new TotpCredentialProvider($database, $siteConfiguration); |
|
48 | + $this->typeMap['scratch'] = new ScratchTokenCredentialProvider($database, $siteConfiguration); |
|
49 | + $this->typeMap['u2f'] = new U2FCredentialProvider($database, $siteConfiguration); |
|
50 | + $this->database = $database; |
|
51 | + } |
|
52 | 52 | |
53 | - public function authenticate(User $user, $data, $stage) |
|
54 | - { |
|
55 | - $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0 ORDER BY priority ASC'; |
|
56 | - $statement = $this->database->prepare($sql); |
|
57 | - $statement->execute(array(':user' => $user->getId(), ':stage' => $stage)); |
|
58 | - $options = $statement->fetchAll(PDO::FETCH_COLUMN); |
|
53 | + public function authenticate(User $user, $data, $stage) |
|
54 | + { |
|
55 | + $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0 ORDER BY priority ASC'; |
|
56 | + $statement = $this->database->prepare($sql); |
|
57 | + $statement->execute(array(':user' => $user->getId(), ':stage' => $stage)); |
|
58 | + $options = $statement->fetchAll(PDO::FETCH_COLUMN); |
|
59 | 59 | |
60 | - $sql = 'SELECT count(DISTINCT factor) FROM credential WHERE user = :user AND factor > :stage AND disabled = 0 AND type <> :scratch'; |
|
61 | - $statement = $this->database->prepare($sql); |
|
62 | - $statement->execute(array(':user' => $user->getId(), ':stage' => $stage, ':scratch' => 'scratch')); |
|
63 | - $requiredFactors = $statement->fetchColumn(); |
|
60 | + $sql = 'SELECT count(DISTINCT factor) FROM credential WHERE user = :user AND factor > :stage AND disabled = 0 AND type <> :scratch'; |
|
61 | + $statement = $this->database->prepare($sql); |
|
62 | + $statement->execute(array(':user' => $user->getId(), ':stage' => $stage, ':scratch' => 'scratch')); |
|
63 | + $requiredFactors = $statement->fetchColumn(); |
|
64 | 64 | |
65 | - // prep the correct OK response based on how many factors are ahead of this one |
|
66 | - $success = self::AUTH_OK; |
|
67 | - if ($requiredFactors > 0) { |
|
68 | - $success = self::AUTH_REQUIRE_NEXT_STAGE; |
|
69 | - } |
|
65 | + // prep the correct OK response based on how many factors are ahead of this one |
|
66 | + $success = self::AUTH_OK; |
|
67 | + if ($requiredFactors > 0) { |
|
68 | + $success = self::AUTH_REQUIRE_NEXT_STAGE; |
|
69 | + } |
|
70 | 70 | |
71 | - foreach ($options as $type) { |
|
72 | - if (!isset($this->typeMap[$type])) { |
|
73 | - // does this type have a credentialProvider registered? |
|
74 | - continue; |
|
75 | - } |
|
71 | + foreach ($options as $type) { |
|
72 | + if (!isset($this->typeMap[$type])) { |
|
73 | + // does this type have a credentialProvider registered? |
|
74 | + continue; |
|
75 | + } |
|
76 | 76 | |
77 | - /** @var ICredentialProvider $credentialProvider */ |
|
78 | - $credentialProvider = $this->typeMap[$type]; |
|
79 | - if ($credentialProvider->authenticate($user, $data)) { |
|
80 | - return $success; |
|
81 | - } |
|
82 | - } |
|
77 | + /** @var ICredentialProvider $credentialProvider */ |
|
78 | + $credentialProvider = $this->typeMap[$type]; |
|
79 | + if ($credentialProvider->authenticate($user, $data)) { |
|
80 | + return $success; |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | - // We've iterated over all the available providers for this stage. |
|
85 | - // They all hate you. |
|
86 | - return self::AUTH_FAIL; |
|
87 | - } |
|
84 | + // We've iterated over all the available providers for this stage. |
|
85 | + // They all hate you. |
|
86 | + return self::AUTH_FAIL; |
|
87 | + } |
|
88 | 88 | } |
89 | 89 | \ No newline at end of file |
@@ -14,9 +14,9 @@ |
||
14 | 14 | |
15 | 15 | function smarty_modifier_nlimplode($list, $conjunction = 'or') |
16 | 16 | { |
17 | - $last = array_pop($list); |
|
18 | - if ($list) { |
|
19 | - return implode(', ', $list) . ', ' . $conjunction . ' ' . $last; |
|
20 | - } |
|
21 | - return $last; |
|
17 | + $last = array_pop($list); |
|
18 | + if ($list) { |
|
19 | + return implode(', ', $list) . ', ' . $conjunction . ' ' . $last; |
|
20 | + } |
|
21 | + return $last; |
|
22 | 22 | } |
23 | 23 | \ No newline at end of file |
@@ -16,7 +16,7 @@ |
||
16 | 16 | { |
17 | 17 | $last = array_pop($list); |
18 | 18 | if ($list) { |
19 | - return implode(', ', $list) . ', ' . $conjunction . ' ' . $last; |
|
19 | + return implode(', ', $list).', '.$conjunction.' '.$last; |
|
20 | 20 | } |
21 | 21 | return $last; |
22 | 22 | } |
23 | 23 | \ No newline at end of file |
@@ -8,10 +8,10 @@ |
||
8 | 8 | |
9 | 9 | function smarty_modifier_demodhex($input) |
10 | 10 | { |
11 | - $hex = preg_replace( |
|
12 | - array('/c/', '/b/', '/d/', '/e/', '/f/', '/g/', '/h/', '/i/', '/j/', '/k/', '/l/', '/n/', '/r/', '/t/', '/u/', '/v/'), |
|
13 | - array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'), |
|
14 | - $input); |
|
11 | + $hex = preg_replace( |
|
12 | + array('/c/', '/b/', '/d/', '/e/', '/f/', '/g/', '/h/', '/i/', '/j/', '/k/', '/l/', '/n/', '/r/', '/t/', '/u/', '/v/'), |
|
13 | + array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'), |
|
14 | + $input); |
|
15 | 15 | |
16 | - return hexdec($hex); |
|
16 | + return hexdec($hex); |
|
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -15,56 +15,56 @@ |
||
15 | 15 | |
16 | 16 | class PasswordCredentialProvider extends CredentialProviderBase |
17 | 17 | { |
18 | - const PASSWORD_COST = 10; |
|
19 | - const PASSWORD_ALGO = PASSWORD_BCRYPT; |
|
18 | + const PASSWORD_COST = 10; |
|
19 | + const PASSWORD_ALGO = PASSWORD_BCRYPT; |
|
20 | 20 | |
21 | - public function __construct(PdoDatabase $database, SiteConfiguration $configuration) |
|
22 | - { |
|
23 | - parent::__construct($database, $configuration, 'password'); |
|
24 | - } |
|
21 | + public function __construct(PdoDatabase $database, SiteConfiguration $configuration) |
|
22 | + { |
|
23 | + parent::__construct($database, $configuration, 'password'); |
|
24 | + } |
|
25 | 25 | |
26 | - public function authenticate(User $user, $data) |
|
27 | - { |
|
28 | - $storedData = $this->getCredentialData($user->getId()); |
|
29 | - if($storedData === null) |
|
30 | - { |
|
31 | - // No available credential matching these parameters |
|
32 | - return false; |
|
33 | - } |
|
26 | + public function authenticate(User $user, $data) |
|
27 | + { |
|
28 | + $storedData = $this->getCredentialData($user->getId()); |
|
29 | + if($storedData === null) |
|
30 | + { |
|
31 | + // No available credential matching these parameters |
|
32 | + return false; |
|
33 | + } |
|
34 | 34 | |
35 | - if($storedData->getVersion() !== 2) { |
|
36 | - // Non-2 versions are not supported. |
|
37 | - return false; |
|
38 | - } |
|
35 | + if($storedData->getVersion() !== 2) { |
|
36 | + // Non-2 versions are not supported. |
|
37 | + return false; |
|
38 | + } |
|
39 | 39 | |
40 | - if(password_verify($data, $storedData->getData())) { |
|
41 | - if(password_needs_rehash($storedData->getData(), self::PASSWORD_ALGO, array('cost' => self::PASSWORD_COST))){ |
|
42 | - $this->setCredential($user, $storedData->getFactor(), $data); |
|
43 | - } |
|
40 | + if(password_verify($data, $storedData->getData())) { |
|
41 | + if(password_needs_rehash($storedData->getData(), self::PASSWORD_ALGO, array('cost' => self::PASSWORD_COST))){ |
|
42 | + $this->setCredential($user, $storedData->getFactor(), $data); |
|
43 | + } |
|
44 | 44 | |
45 | - return true; |
|
46 | - } |
|
45 | + return true; |
|
46 | + } |
|
47 | 47 | |
48 | - return false; |
|
49 | - } |
|
48 | + return false; |
|
49 | + } |
|
50 | 50 | |
51 | - public function setCredential(User $user, $factor, $password) |
|
52 | - { |
|
53 | - $storedData = $this->getCredentialData($user->getId()); |
|
51 | + public function setCredential(User $user, $factor, $password) |
|
52 | + { |
|
53 | + $storedData = $this->getCredentialData($user->getId()); |
|
54 | 54 | |
55 | - if($storedData === null){ |
|
56 | - $storedData = $this->createNewCredential($user); |
|
57 | - } |
|
55 | + if($storedData === null){ |
|
56 | + $storedData = $this->createNewCredential($user); |
|
57 | + } |
|
58 | 58 | |
59 | - $storedData->setData(password_hash($password, self::PASSWORD_ALGO, array('cost' => self::PASSWORD_COST))); |
|
60 | - $storedData->setFactor($factor); |
|
61 | - $storedData->setVersion(2); |
|
59 | + $storedData->setData(password_hash($password, self::PASSWORD_ALGO, array('cost' => self::PASSWORD_COST))); |
|
60 | + $storedData->setFactor($factor); |
|
61 | + $storedData->setVersion(2); |
|
62 | 62 | |
63 | - $storedData->save(); |
|
64 | - } |
|
63 | + $storedData->save(); |
|
64 | + } |
|
65 | 65 | |
66 | - public function deleteCredential(User $user) |
|
67 | - { |
|
68 | - throw new ApplicationLogicException('Deletion of password credential is not allowed.'); |
|
69 | - } |
|
66 | + public function deleteCredential(User $user) |
|
67 | + { |
|
68 | + throw new ApplicationLogicException('Deletion of password credential is not allowed.'); |
|
69 | + } |
|
70 | 70 | } |
@@ -26,19 +26,19 @@ discard block |
||
26 | 26 | public function authenticate(User $user, $data) |
27 | 27 | { |
28 | 28 | $storedData = $this->getCredentialData($user->getId()); |
29 | - if($storedData === null) |
|
29 | + if ($storedData === null) |
|
30 | 30 | { |
31 | 31 | // No available credential matching these parameters |
32 | 32 | return false; |
33 | 33 | } |
34 | 34 | |
35 | - if($storedData->getVersion() !== 2) { |
|
35 | + if ($storedData->getVersion() !== 2) { |
|
36 | 36 | // Non-2 versions are not supported. |
37 | 37 | return false; |
38 | 38 | } |
39 | 39 | |
40 | - if(password_verify($data, $storedData->getData())) { |
|
41 | - if(password_needs_rehash($storedData->getData(), self::PASSWORD_ALGO, array('cost' => self::PASSWORD_COST))){ |
|
40 | + if (password_verify($data, $storedData->getData())) { |
|
41 | + if (password_needs_rehash($storedData->getData(), self::PASSWORD_ALGO, array('cost' => self::PASSWORD_COST))) { |
|
42 | 42 | $this->setCredential($user, $storedData->getFactor(), $data); |
43 | 43 | } |
44 | 44 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | { |
53 | 53 | $storedData = $this->getCredentialData($user->getId()); |
54 | 54 | |
55 | - if($storedData === null){ |
|
55 | + if ($storedData === null) { |
|
56 | 56 | $storedData = $this->createNewCredential($user); |
57 | 57 | } |
58 | 58 |
@@ -26,8 +26,7 @@ discard block |
||
26 | 26 | public function authenticate(User $user, $data) |
27 | 27 | { |
28 | 28 | $storedData = $this->getCredentialData($user->getId()); |
29 | - if($storedData === null) |
|
30 | - { |
|
29 | + if($storedData === null) { |
|
31 | 30 | // No available credential matching these parameters |
32 | 31 | return false; |
33 | 32 | } |
@@ -38,7 +37,7 @@ discard block |
||
38 | 37 | } |
39 | 38 | |
40 | 39 | if(password_verify($data, $storedData->getData())) { |
41 | - if(password_needs_rehash($storedData->getData(), self::PASSWORD_ALGO, array('cost' => self::PASSWORD_COST))){ |
|
40 | + if(password_needs_rehash($storedData->getData(), self::PASSWORD_ALGO, array('cost' => self::PASSWORD_COST))) { |
|
42 | 41 | $this->setCredential($user, $storedData->getFactor(), $data); |
43 | 42 | } |
44 | 43 | |
@@ -52,7 +51,7 @@ discard block |
||
52 | 51 | { |
53 | 52 | $storedData = $this->getCredentialData($user->getId()); |
54 | 53 | |
55 | - if($storedData === null){ |
|
54 | + if($storedData === null) { |
|
56 | 55 | $storedData = $this->createNewCredential($user); |
57 | 56 | } |
58 | 57 |
@@ -7,46 +7,46 @@ |
||
7 | 7 | ******************************************************************************/ |
8 | 8 | |
9 | 9 | $toolList = array( |
10 | - 'tparis-pcount' => '//tools.wmflabs.org/supercount/index.php?user=%DATA%&project=en.wikipedia', |
|
11 | - 'guc' => '//tools.wmflabs.org/guc/?by=date&user=%DATA%', |
|
12 | - 'oq-whois' => 'https://whois.domaintools.com/%DATA%', |
|
13 | - 'tl-whois' => 'https://tools.wmflabs.org/whois/gateway.py?lookup=true&ip=%DATA%', |
|
14 | - 'honeypot' => 'https://www.projecthoneypot.org/ip_%DATA%', |
|
15 | - 'stopforumspam' => 'https://www.stopforumspam.com/ipcheck/%DATA%', |
|
16 | - 'google' => 'https://www.google.com/search?q=%DATA%', |
|
17 | - 'domain' => 'http://%DATA%/', |
|
18 | - 'rangefinder' => 'https://tools.wmflabs.org/rangeblockfinder/?ip=%DATA%', |
|
10 | + 'tparis-pcount' => '//tools.wmflabs.org/supercount/index.php?user=%DATA%&project=en.wikipedia', |
|
11 | + 'guc' => '//tools.wmflabs.org/guc/?by=date&user=%DATA%', |
|
12 | + 'oq-whois' => 'https://whois.domaintools.com/%DATA%', |
|
13 | + 'tl-whois' => 'https://tools.wmflabs.org/whois/gateway.py?lookup=true&ip=%DATA%', |
|
14 | + 'honeypot' => 'https://www.projecthoneypot.org/ip_%DATA%', |
|
15 | + 'stopforumspam' => 'https://www.stopforumspam.com/ipcheck/%DATA%', |
|
16 | + 'google' => 'https://www.google.com/search?q=%DATA%', |
|
17 | + 'domain' => 'http://%DATA%/', |
|
18 | + 'rangefinder' => 'https://tools.wmflabs.org/rangeblockfinder/?ip=%DATA%', |
|
19 | 19 | 'ipcheck' => 'https://ipcheck.toolforge.org/index.php?ip=%DATA%', |
20 | 20 | 'bgpview' => 'https://bgpview.io/ip/%DATA%' |
21 | 21 | ); |
22 | 22 | |
23 | 23 | if (!isset($_GET['tool']) |
24 | - || !isset($toolList[$_GET['tool']]) |
|
25 | - || !isset($_GET['data']) |
|
24 | + || !isset($toolList[$_GET['tool']]) |
|
25 | + || !isset($_GET['data']) |
|
26 | 26 | ) { |
27 | - header("HTTP/1.1 403 Forbidden"); |
|
27 | + header("HTTP/1.1 403 Forbidden"); |
|
28 | 28 | |
29 | - return; |
|
29 | + return; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | if (isset($_GET['round2'])) { |
33 | - $data = $_GET['data']; |
|
34 | - $tool = $_GET['tool']; |
|
33 | + $data = $_GET['data']; |
|
34 | + $tool = $_GET['tool']; |
|
35 | 35 | |
36 | - if ($tool === 'domain') { |
|
37 | - // quick security check - if you want to exploit something, you better be sure your exploit resolves via dns. |
|
38 | - // this is not intended to catch everything, just as a quick sanity check. |
|
39 | - if (gethostbyname($data) == $data) { |
|
40 | - echo 'Error resolving hostname, it doesn\'t look like this domain exists.'; |
|
41 | - die(); |
|
42 | - } |
|
43 | - } |
|
44 | - else { |
|
45 | - $data = urlencode($data); |
|
46 | - } |
|
36 | + if ($tool === 'domain') { |
|
37 | + // quick security check - if you want to exploit something, you better be sure your exploit resolves via dns. |
|
38 | + // this is not intended to catch everything, just as a quick sanity check. |
|
39 | + if (gethostbyname($data) == $data) { |
|
40 | + echo 'Error resolving hostname, it doesn\'t look like this domain exists.'; |
|
41 | + die(); |
|
42 | + } |
|
43 | + } |
|
44 | + else { |
|
45 | + $data = urlencode($data); |
|
46 | + } |
|
47 | 47 | |
48 | - echo '<script>window.location.href=' . json_encode(str_replace("%DATA%", $data, $toolList[$tool])) . '</script>'; |
|
48 | + echo '<script>window.location.href=' . json_encode(str_replace("%DATA%", $data, $toolList[$tool])) . '</script>'; |
|
49 | 49 | } |
50 | 50 | else { |
51 | - header("Location: " . $_SERVER["REQUEST_URI"] . "&round2=true"); |
|
51 | + header("Location: " . $_SERVER["REQUEST_URI"] . "&round2=true"); |
|
52 | 52 | } |
@@ -45,8 +45,8 @@ |
||
45 | 45 | $data = urlencode($data); |
46 | 46 | } |
47 | 47 | |
48 | - echo '<script>window.location.href=' . json_encode(str_replace("%DATA%", $data, $toolList[$tool])) . '</script>'; |
|
48 | + echo '<script>window.location.href='.json_encode(str_replace("%DATA%", $data, $toolList[$tool])).'</script>'; |
|
49 | 49 | } |
50 | 50 | else { |
51 | - header("Location: " . $_SERVER["REQUEST_URI"] . "&round2=true"); |
|
51 | + header("Location: ".$_SERVER["REQUEST_URI"]."&round2=true"); |
|
52 | 52 | } |
@@ -21,107 +21,107 @@ |
||
21 | 21 | */ |
22 | 22 | class IpLocationProvider implements ILocationProvider |
23 | 23 | { |
24 | - /** @var string */ |
|
25 | - private $apiKey; |
|
26 | - /** @var PdoDatabase */ |
|
27 | - private $database; |
|
28 | - /** @var HttpHelper */ |
|
29 | - private $httpHelper; |
|
30 | - |
|
31 | - /** |
|
32 | - * IpLocationProvider constructor. |
|
33 | - * |
|
34 | - * @param PdoDatabase $database |
|
35 | - * @param string $apiKey |
|
36 | - * @param HttpHelper $httpHelper |
|
37 | - */ |
|
38 | - public function __construct(PdoDatabase $database, $apiKey, HttpHelper $httpHelper) |
|
39 | - { |
|
40 | - $this->database = $database; |
|
41 | - $this->apiKey = $apiKey; |
|
42 | - $this->httpHelper = $httpHelper; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @param string $address |
|
47 | - * |
|
48 | - * @return array|null |
|
49 | - * @throws Exception |
|
50 | - * @throws OptimisticLockFailedException |
|
51 | - */ |
|
52 | - public function getIpLocation($address) |
|
53 | - { |
|
54 | - $address = trim($address); |
|
55 | - |
|
56 | - // lets look in our database first. |
|
57 | - $location = GeoLocation::getByAddress($address, $this->database, true); |
|
58 | - |
|
59 | - if ($location != null) { |
|
60 | - // touch cache timer |
|
61 | - $location->save(); |
|
62 | - |
|
63 | - return $location->getData(); |
|
64 | - } |
|
65 | - |
|
66 | - // OK, it's not there, let's do an IP2Location lookup. |
|
67 | - $result = $this->getResult($address); |
|
68 | - |
|
69 | - if ($result != null) { |
|
70 | - $location = new GeoLocation(); |
|
71 | - $location->setDatabase($this->database); |
|
72 | - $location->setAddress($address); |
|
73 | - $location->setData($result); |
|
74 | - $location->save(); |
|
75 | - |
|
76 | - return $result; |
|
77 | - } |
|
78 | - |
|
79 | - return null; |
|
80 | - } |
|
81 | - |
|
82 | - // adapted from http://www.ipinfodb.com/ip_location_api.php |
|
83 | - |
|
84 | - /** |
|
85 | - * @param string $ip |
|
86 | - * |
|
87 | - * @return array|null |
|
88 | - */ |
|
89 | - private function getResult($ip) |
|
90 | - { |
|
91 | - try { |
|
92 | - if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
|
93 | - $xml = $this->httpHelper->get($this->getApiBase(), array( |
|
94 | - 'key' => $this->apiKey, |
|
95 | - 'ip' => $ip, |
|
96 | - 'format' => 'xml', |
|
97 | - )); |
|
98 | - |
|
99 | - $response = @new SimpleXMLElement($xml); |
|
100 | - |
|
101 | - $result = array(); |
|
102 | - |
|
103 | - foreach ($response as $field => $value) { |
|
104 | - $result[(string)$field] = (string)$value; |
|
105 | - } |
|
106 | - |
|
107 | - return $result; |
|
108 | - } |
|
109 | - } |
|
110 | - catch (Exception $ex) { |
|
111 | - return null; |
|
112 | - |
|
113 | - // LOGME: do something smart here, or wherever we use this value. |
|
114 | - // This is just a temp hack to squash errors on the UI for now. |
|
115 | - } |
|
116 | - |
|
117 | - return null; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - protected function getApiBase() |
|
124 | - { |
|
125 | - return "http://api.ipinfodb.com/v3/ip-city/"; |
|
126 | - } |
|
24 | + /** @var string */ |
|
25 | + private $apiKey; |
|
26 | + /** @var PdoDatabase */ |
|
27 | + private $database; |
|
28 | + /** @var HttpHelper */ |
|
29 | + private $httpHelper; |
|
30 | + |
|
31 | + /** |
|
32 | + * IpLocationProvider constructor. |
|
33 | + * |
|
34 | + * @param PdoDatabase $database |
|
35 | + * @param string $apiKey |
|
36 | + * @param HttpHelper $httpHelper |
|
37 | + */ |
|
38 | + public function __construct(PdoDatabase $database, $apiKey, HttpHelper $httpHelper) |
|
39 | + { |
|
40 | + $this->database = $database; |
|
41 | + $this->apiKey = $apiKey; |
|
42 | + $this->httpHelper = $httpHelper; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @param string $address |
|
47 | + * |
|
48 | + * @return array|null |
|
49 | + * @throws Exception |
|
50 | + * @throws OptimisticLockFailedException |
|
51 | + */ |
|
52 | + public function getIpLocation($address) |
|
53 | + { |
|
54 | + $address = trim($address); |
|
55 | + |
|
56 | + // lets look in our database first. |
|
57 | + $location = GeoLocation::getByAddress($address, $this->database, true); |
|
58 | + |
|
59 | + if ($location != null) { |
|
60 | + // touch cache timer |
|
61 | + $location->save(); |
|
62 | + |
|
63 | + return $location->getData(); |
|
64 | + } |
|
65 | + |
|
66 | + // OK, it's not there, let's do an IP2Location lookup. |
|
67 | + $result = $this->getResult($address); |
|
68 | + |
|
69 | + if ($result != null) { |
|
70 | + $location = new GeoLocation(); |
|
71 | + $location->setDatabase($this->database); |
|
72 | + $location->setAddress($address); |
|
73 | + $location->setData($result); |
|
74 | + $location->save(); |
|
75 | + |
|
76 | + return $result; |
|
77 | + } |
|
78 | + |
|
79 | + return null; |
|
80 | + } |
|
81 | + |
|
82 | + // adapted from http://www.ipinfodb.com/ip_location_api.php |
|
83 | + |
|
84 | + /** |
|
85 | + * @param string $ip |
|
86 | + * |
|
87 | + * @return array|null |
|
88 | + */ |
|
89 | + private function getResult($ip) |
|
90 | + { |
|
91 | + try { |
|
92 | + if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
|
93 | + $xml = $this->httpHelper->get($this->getApiBase(), array( |
|
94 | + 'key' => $this->apiKey, |
|
95 | + 'ip' => $ip, |
|
96 | + 'format' => 'xml', |
|
97 | + )); |
|
98 | + |
|
99 | + $response = @new SimpleXMLElement($xml); |
|
100 | + |
|
101 | + $result = array(); |
|
102 | + |
|
103 | + foreach ($response as $field => $value) { |
|
104 | + $result[(string)$field] = (string)$value; |
|
105 | + } |
|
106 | + |
|
107 | + return $result; |
|
108 | + } |
|
109 | + } |
|
110 | + catch (Exception $ex) { |
|
111 | + return null; |
|
112 | + |
|
113 | + // LOGME: do something smart here, or wherever we use this value. |
|
114 | + // This is just a temp hack to squash errors on the UI for now. |
|
115 | + } |
|
116 | + |
|
117 | + return null; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + protected function getApiBase() |
|
124 | + { |
|
125 | + return "http://api.ipinfodb.com/v3/ip-city/"; |
|
126 | + } |
|
127 | 127 | } |
@@ -20,74 +20,74 @@ |
||
20 | 20 | */ |
21 | 21 | class SiteNotice extends DataObject |
22 | 22 | { |
23 | - /** @var string */ |
|
24 | - private $content; |
|
23 | + /** @var string */ |
|
24 | + private $content; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Get a message. |
|
28 | - * |
|
29 | - * @param PdoDatabase $database |
|
30 | - * |
|
31 | - * @return string The content for display |
|
32 | - */ |
|
33 | - public static function get(PdoDatabase $database) |
|
34 | - { |
|
35 | - /** @var SiteNotice $message */ |
|
36 | - $message = self::getById(1, $database); |
|
26 | + /** |
|
27 | + * Get a message. |
|
28 | + * |
|
29 | + * @param PdoDatabase $database |
|
30 | + * |
|
31 | + * @return string The content for display |
|
32 | + */ |
|
33 | + public static function get(PdoDatabase $database) |
|
34 | + { |
|
35 | + /** @var SiteNotice $message */ |
|
36 | + $message = self::getById(1, $database); |
|
37 | 37 | |
38 | - return $message->getContent(); |
|
39 | - } |
|
38 | + return $message->getContent(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Saves the object |
|
43 | - * @throws Exception |
|
44 | - */ |
|
45 | - public function save() |
|
46 | - { |
|
47 | - if ($this->isNew()) { |
|
48 | - // insert |
|
49 | - throw new Exception('Not allowed to create new site notice object'); |
|
50 | - } |
|
51 | - else { |
|
52 | - // update |
|
53 | - $statement = $this->dbObject->prepare(<<<SQL |
|
41 | + /** |
|
42 | + * Saves the object |
|
43 | + * @throws Exception |
|
44 | + */ |
|
45 | + public function save() |
|
46 | + { |
|
47 | + if ($this->isNew()) { |
|
48 | + // insert |
|
49 | + throw new Exception('Not allowed to create new site notice object'); |
|
50 | + } |
|
51 | + else { |
|
52 | + // update |
|
53 | + $statement = $this->dbObject->prepare(<<<SQL |
|
54 | 54 | UPDATE sitenotice |
55 | 55 | SET content = :content, updateversion = updateversion + 1 |
56 | 56 | WHERE updateversion = :updateversion; |
57 | 57 | SQL |
58 | - ); |
|
59 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
58 | + ); |
|
59 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
60 | 60 | |
61 | - $statement->bindValue(':content', $this->content); |
|
61 | + $statement->bindValue(':content', $this->content); |
|
62 | 62 | |
63 | - if (!$statement->execute()) { |
|
64 | - throw new Exception($statement->errorInfo()); |
|
65 | - } |
|
63 | + if (!$statement->execute()) { |
|
64 | + throw new Exception($statement->errorInfo()); |
|
65 | + } |
|
66 | 66 | |
67 | - if ($statement->rowCount() !== 1) { |
|
68 | - throw new OptimisticLockFailedException(); |
|
69 | - } |
|
67 | + if ($statement->rowCount() !== 1) { |
|
68 | + throw new OptimisticLockFailedException(); |
|
69 | + } |
|
70 | 70 | |
71 | - $this->updateversion++; |
|
72 | - } |
|
73 | - } |
|
71 | + $this->updateversion++; |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Gets the content of the message |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function getContent() |
|
80 | - { |
|
81 | - return $this->content; |
|
82 | - } |
|
75 | + /** |
|
76 | + * Gets the content of the message |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function getContent() |
|
80 | + { |
|
81 | + return $this->content; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Sets the content of the message |
|
86 | - * |
|
87 | - * @param string $content |
|
88 | - */ |
|
89 | - public function setContent($content) |
|
90 | - { |
|
91 | - $this->content = $content; |
|
92 | - } |
|
84 | + /** |
|
85 | + * Sets the content of the message |
|
86 | + * |
|
87 | + * @param string $content |
|
88 | + */ |
|
89 | + public function setContent($content) |
|
90 | + { |
|
91 | + $this->content = $content; |
|
92 | + } |
|
93 | 93 | } |
@@ -19,109 +19,109 @@ |
||
19 | 19 | */ |
20 | 20 | class RDnsCache extends DataObject |
21 | 21 | { |
22 | - private $address; |
|
23 | - private $data; |
|
24 | - private $creation; |
|
25 | - |
|
26 | - /** |
|
27 | - * @param string $address |
|
28 | - * @param PdoDatabase $database |
|
29 | - * |
|
30 | - * @return RDnsCache|false |
|
31 | - */ |
|
32 | - public static function getByAddress($address, PdoDatabase $database) |
|
33 | - { |
|
34 | - // @todo add cache invalidation (timestamp?) |
|
35 | - $statement = $database->prepare("SELECT * FROM rdnscache WHERE address = :id LIMIT 1;"); |
|
36 | - $statement->bindValue(":id", $address); |
|
37 | - |
|
38 | - $statement->execute(); |
|
39 | - |
|
40 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
41 | - |
|
42 | - if ($resultObject != false) { |
|
43 | - $resultObject->setDatabase($database); |
|
44 | - } |
|
45 | - |
|
46 | - return $resultObject; |
|
47 | - } |
|
48 | - |
|
49 | - public function save() |
|
50 | - { |
|
51 | - if ($this->isNew()) { |
|
52 | - // insert |
|
53 | - $statement = $this->dbObject->prepare(<<<SQL |
|
22 | + private $address; |
|
23 | + private $data; |
|
24 | + private $creation; |
|
25 | + |
|
26 | + /** |
|
27 | + * @param string $address |
|
28 | + * @param PdoDatabase $database |
|
29 | + * |
|
30 | + * @return RDnsCache|false |
|
31 | + */ |
|
32 | + public static function getByAddress($address, PdoDatabase $database) |
|
33 | + { |
|
34 | + // @todo add cache invalidation (timestamp?) |
|
35 | + $statement = $database->prepare("SELECT * FROM rdnscache WHERE address = :id LIMIT 1;"); |
|
36 | + $statement->bindValue(":id", $address); |
|
37 | + |
|
38 | + $statement->execute(); |
|
39 | + |
|
40 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
41 | + |
|
42 | + if ($resultObject != false) { |
|
43 | + $resultObject->setDatabase($database); |
|
44 | + } |
|
45 | + |
|
46 | + return $resultObject; |
|
47 | + } |
|
48 | + |
|
49 | + public function save() |
|
50 | + { |
|
51 | + if ($this->isNew()) { |
|
52 | + // insert |
|
53 | + $statement = $this->dbObject->prepare(<<<SQL |
|
54 | 54 | INSERT INTO `rdnscache` (address, data) VALUES (:address, :data); |
55 | 55 | SQL |
56 | - ); |
|
57 | - $statement->bindValue(":address", $this->address); |
|
58 | - $statement->bindValue(":data", $this->data); |
|
59 | - |
|
60 | - if ($statement->execute()) { |
|
61 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
62 | - } |
|
63 | - else { |
|
64 | - throw new Exception($statement->errorInfo()); |
|
65 | - } |
|
66 | - } |
|
67 | - else { |
|
68 | - // update |
|
69 | - $statement = $this->dbObject->prepare(<<<SQL |
|
56 | + ); |
|
57 | + $statement->bindValue(":address", $this->address); |
|
58 | + $statement->bindValue(":data", $this->data); |
|
59 | + |
|
60 | + if ($statement->execute()) { |
|
61 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
62 | + } |
|
63 | + else { |
|
64 | + throw new Exception($statement->errorInfo()); |
|
65 | + } |
|
66 | + } |
|
67 | + else { |
|
68 | + // update |
|
69 | + $statement = $this->dbObject->prepare(<<<SQL |
|
70 | 70 | UPDATE `rdnscache` |
71 | 71 | SET address = :address, data = :data, updateversion = updateversion + 1 |
72 | 72 | WHERE id = :id AND updateversion = :updateversion; |
73 | 73 | SQL |
74 | - ); |
|
75 | - |
|
76 | - $statement->bindValue(':id', $this->id); |
|
77 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
78 | - |
|
79 | - $statement->bindValue(':address', $this->address); |
|
80 | - $statement->bindValue(':data', $this->data); |
|
81 | - |
|
82 | - if (!$statement->execute()) { |
|
83 | - throw new Exception($statement->errorInfo()); |
|
84 | - } |
|
85 | - |
|
86 | - if ($statement->rowCount() !== 1) { |
|
87 | - throw new OptimisticLockFailedException(); |
|
88 | - } |
|
89 | - |
|
90 | - $this->updateversion++; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - public function getAddress() |
|
95 | - { |
|
96 | - return $this->address; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param string $address |
|
101 | - */ |
|
102 | - public function setAddress($address) |
|
103 | - { |
|
104 | - $this->address = $address; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function getData() |
|
111 | - { |
|
112 | - return unserialize($this->data); |
|
113 | - } |
|
114 | - |
|
115 | - public function setData($data) |
|
116 | - { |
|
117 | - $this->data = serialize($data); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return DateTimeImmutable |
|
122 | - */ |
|
123 | - public function getCreation() |
|
124 | - { |
|
125 | - return new DateTimeImmutable($this->creation); |
|
126 | - } |
|
74 | + ); |
|
75 | + |
|
76 | + $statement->bindValue(':id', $this->id); |
|
77 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
78 | + |
|
79 | + $statement->bindValue(':address', $this->address); |
|
80 | + $statement->bindValue(':data', $this->data); |
|
81 | + |
|
82 | + if (!$statement->execute()) { |
|
83 | + throw new Exception($statement->errorInfo()); |
|
84 | + } |
|
85 | + |
|
86 | + if ($statement->rowCount() !== 1) { |
|
87 | + throw new OptimisticLockFailedException(); |
|
88 | + } |
|
89 | + |
|
90 | + $this->updateversion++; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + public function getAddress() |
|
95 | + { |
|
96 | + return $this->address; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param string $address |
|
101 | + */ |
|
102 | + public function setAddress($address) |
|
103 | + { |
|
104 | + $this->address = $address; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function getData() |
|
111 | + { |
|
112 | + return unserialize($this->data); |
|
113 | + } |
|
114 | + |
|
115 | + public function setData($data) |
|
116 | + { |
|
117 | + $this->data = serialize($data); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return DateTimeImmutable |
|
122 | + */ |
|
123 | + public function getCreation() |
|
124 | + { |
|
125 | + return new DateTimeImmutable($this->creation); |
|
126 | + } |
|
127 | 127 | } |
@@ -21,110 +21,110 @@ |
||
21 | 21 | */ |
22 | 22 | class GeoLocation extends DataObject |
23 | 23 | { |
24 | - private $address; |
|
25 | - private $data; |
|
26 | - private $creation; |
|
27 | - |
|
28 | - /** |
|
29 | - * @param string $address |
|
30 | - * @param PdoDatabase $database |
|
31 | - * @param bool $forUpdate |
|
32 | - * @return GeoLocation |
|
33 | - */ |
|
34 | - public static function getByAddress($address, PdoDatabase $database, $forUpdate = false) |
|
35 | - { |
|
36 | - $lockMode = $forUpdate ? ' FOR UPDATE' : ''; |
|
37 | - $sql = "SELECT * FROM geolocation WHERE address = :id LIMIT 1" . $lockMode; |
|
38 | - |
|
39 | - $statement = $database->prepare($sql); |
|
40 | - $statement->bindValue(":id", $address); |
|
41 | - |
|
42 | - $statement->execute(); |
|
43 | - |
|
44 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
45 | - |
|
46 | - if ($resultObject != false) { |
|
47 | - $resultObject->setDatabase($database); |
|
48 | - } |
|
49 | - |
|
50 | - return $resultObject; |
|
51 | - } |
|
52 | - |
|
53 | - public function save() |
|
54 | - { |
|
55 | - if ($this->isNew()) { |
|
56 | - // insert |
|
57 | - $statement = $this->dbObject->prepare("INSERT INTO `geolocation` (address, data) VALUES (:address, :data) ON DUPLICATE KEY UPDATE address = address;"); |
|
58 | - |
|
59 | - $statement->bindValue(":address", $this->address); |
|
60 | - $statement->bindValue(":data", $this->data); |
|
61 | - |
|
62 | - if ($statement->execute()) { |
|
63 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
64 | - } |
|
65 | - else { |
|
66 | - throw new Exception($statement->errorInfo()); |
|
67 | - } |
|
68 | - } |
|
69 | - else { |
|
70 | - // update |
|
71 | - $statement = $this->dbObject->prepare(<<<SQL |
|
24 | + private $address; |
|
25 | + private $data; |
|
26 | + private $creation; |
|
27 | + |
|
28 | + /** |
|
29 | + * @param string $address |
|
30 | + * @param PdoDatabase $database |
|
31 | + * @param bool $forUpdate |
|
32 | + * @return GeoLocation |
|
33 | + */ |
|
34 | + public static function getByAddress($address, PdoDatabase $database, $forUpdate = false) |
|
35 | + { |
|
36 | + $lockMode = $forUpdate ? ' FOR UPDATE' : ''; |
|
37 | + $sql = "SELECT * FROM geolocation WHERE address = :id LIMIT 1" . $lockMode; |
|
38 | + |
|
39 | + $statement = $database->prepare($sql); |
|
40 | + $statement->bindValue(":id", $address); |
|
41 | + |
|
42 | + $statement->execute(); |
|
43 | + |
|
44 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
45 | + |
|
46 | + if ($resultObject != false) { |
|
47 | + $resultObject->setDatabase($database); |
|
48 | + } |
|
49 | + |
|
50 | + return $resultObject; |
|
51 | + } |
|
52 | + |
|
53 | + public function save() |
|
54 | + { |
|
55 | + if ($this->isNew()) { |
|
56 | + // insert |
|
57 | + $statement = $this->dbObject->prepare("INSERT INTO `geolocation` (address, data) VALUES (:address, :data) ON DUPLICATE KEY UPDATE address = address;"); |
|
58 | + |
|
59 | + $statement->bindValue(":address", $this->address); |
|
60 | + $statement->bindValue(":data", $this->data); |
|
61 | + |
|
62 | + if ($statement->execute()) { |
|
63 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
64 | + } |
|
65 | + else { |
|
66 | + throw new Exception($statement->errorInfo()); |
|
67 | + } |
|
68 | + } |
|
69 | + else { |
|
70 | + // update |
|
71 | + $statement = $this->dbObject->prepare(<<<SQL |
|
72 | 72 | UPDATE `geolocation` |
73 | 73 | SET address = :address, data = :data, updateversion = updateversion + 1 |
74 | 74 | WHERE id = :id AND updateversion = :updateversion; |
75 | 75 | SQL |
76 | - ); |
|
77 | - |
|
78 | - $statement->bindValue(":id", $this->id); |
|
79 | - $statement->bindValue(":updateversion", $this->updateversion); |
|
80 | - |
|
81 | - $statement->bindValue(":address", $this->address); |
|
82 | - $statement->bindValue(":data", $this->data); |
|
83 | - |
|
84 | - if (!$statement->execute()) { |
|
85 | - throw new Exception($statement->errorInfo()); |
|
86 | - } |
|
87 | - |
|
88 | - if ($statement->rowCount() !== 1) { |
|
89 | - throw new OptimisticLockFailedException(); |
|
90 | - } |
|
91 | - |
|
92 | - $this->updateversion++; |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - public function getAddress() |
|
97 | - { |
|
98 | - return $this->address; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param string $address |
|
103 | - */ |
|
104 | - public function setAddress($address) |
|
105 | - { |
|
106 | - $this->address = $address; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public function getData() |
|
113 | - { |
|
114 | - return unserialize($this->data); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param array $data |
|
119 | - */ |
|
120 | - public function setData($data) |
|
121 | - { |
|
122 | - $this->data = serialize($data); |
|
123 | - } |
|
124 | - |
|
125 | - /** @return DateTimeImmutable */ |
|
126 | - public function getCreation() |
|
127 | - { |
|
128 | - return new DateTimeImmutable($this->creation); |
|
129 | - } |
|
76 | + ); |
|
77 | + |
|
78 | + $statement->bindValue(":id", $this->id); |
|
79 | + $statement->bindValue(":updateversion", $this->updateversion); |
|
80 | + |
|
81 | + $statement->bindValue(":address", $this->address); |
|
82 | + $statement->bindValue(":data", $this->data); |
|
83 | + |
|
84 | + if (!$statement->execute()) { |
|
85 | + throw new Exception($statement->errorInfo()); |
|
86 | + } |
|
87 | + |
|
88 | + if ($statement->rowCount() !== 1) { |
|
89 | + throw new OptimisticLockFailedException(); |
|
90 | + } |
|
91 | + |
|
92 | + $this->updateversion++; |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + public function getAddress() |
|
97 | + { |
|
98 | + return $this->address; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param string $address |
|
103 | + */ |
|
104 | + public function setAddress($address) |
|
105 | + { |
|
106 | + $this->address = $address; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public function getData() |
|
113 | + { |
|
114 | + return unserialize($this->data); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param array $data |
|
119 | + */ |
|
120 | + public function setData($data) |
|
121 | + { |
|
122 | + $this->data = serialize($data); |
|
123 | + } |
|
124 | + |
|
125 | + /** @return DateTimeImmutable */ |
|
126 | + public function getCreation() |
|
127 | + { |
|
128 | + return new DateTimeImmutable($this->creation); |
|
129 | + } |
|
130 | 130 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | public static function getByAddress($address, PdoDatabase $database, $forUpdate = false) |
35 | 35 | { |
36 | 36 | $lockMode = $forUpdate ? ' FOR UPDATE' : ''; |
37 | - $sql = "SELECT * FROM geolocation WHERE address = :id LIMIT 1" . $lockMode; |
|
37 | + $sql = "SELECT * FROM geolocation WHERE address = :id LIMIT 1".$lockMode; |
|
38 | 38 | |
39 | 39 | $statement = $database->prepare($sql); |
40 | 40 | $statement->bindValue(":id", $address); |