add missing break
[project/cryptolog.git] / lib / Drupal / cryptolog / CryptologManager.php
1 <?php
2
3 /**
4 * @file
5 * Definition of Drupal\cryptolog\CryptologManager.
6 */
7
8 namespace Drupal\cryptolog;
9
10 /**
11 * Cryptolog Manager.
12 */
13 class CryptologManager {
14
15 /**
16 * The memory-based data store.
17 */
18 protected $cache;
19
20 /**
21 * Construct the Cryptolog Manager.
22 */
23 public function __construct() {
24 foreach (array('dmemcache_set' => 'dmemcache_get', 'apc_store' => 'apc_fetch', 'xcache_set' => 'xcache_get') as $set => $get) {
25 if (function_exists($set)) {
26 $this->cache = $get('cryptolog');
27 $day = gmdate('zY');
28 if (!$this->cache || $this->cache['day'] !== $day) {
29 $this->cache = array('day' => $day, 'salt' => drupal_random_bytes(32));
30 $set('cryptolog', $this->cache, 86400);
31 }
32 break;
33 }
34 }
35 }
36
37 /**
38 * Sets the client IP address.
39 */
40 public function setClientIP() {
41 global $request;
42 if ($this->cache) {
43 // Generate a keyed hash in IPv6 address notation.
44 $_SERVER['REMOTE_ADDR'] = inet_ntop(hash_hmac('md5', ip_address(), $this->cache['salt'], TRUE));
45 drupal_static_reset('ip_address');
46 $request->server->set('REMOTE_ADDR', $_SERVER['REMOTE_ADDR']);
47 }
48 }
49
50 }