|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package WebSockets |
|
4
|
|
|
* @category modules |
|
5
|
|
|
* @author Nazar Mokrynskyi <[email protected]> |
|
6
|
|
|
* @copyright Copyright (c) 2015-2017, Nazar Mokrynskyi |
|
7
|
|
|
* @license MIT License, see license.txt |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace cs\modules\WebSockets; |
|
10
|
|
|
use |
|
11
|
|
|
cs\Config, |
|
12
|
|
|
cs\Language, |
|
13
|
|
|
Ratchet\ConnectionInterface, |
|
|
|
|
|
|
14
|
|
|
Ratchet\Http\HttpServerInterface, |
|
|
|
|
|
|
15
|
|
|
Psr\Http\Message\RequestInterface; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
class Connection_properties_injector implements HttpServerInterface { |
|
18
|
|
|
private $delegate; |
|
19
|
|
|
/** |
|
20
|
|
|
* @inheritdoc |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct (HttpServerInterface $delegate) { |
|
23
|
|
|
$this->delegate = $delegate; |
|
24
|
|
|
} |
|
25
|
|
|
/** |
|
26
|
|
|
* @inheritdoc |
|
27
|
|
|
*/ |
|
28
|
|
|
public function onOpen (ConnectionInterface $conn, RequestInterface $request = null) { |
|
29
|
|
|
$L = Language::instance(); |
|
30
|
|
|
/** @noinspection PhpUndefinedFieldInspection */ |
|
31
|
|
|
/** @noinspection NullPointerExceptionInspection */ |
|
32
|
|
|
$ip = $this->ip( |
|
33
|
|
|
[ |
|
34
|
|
|
$conn->remoteAddress, |
|
35
|
|
|
$request->getHeaderLine('X-Forwarded-For'), |
|
|
|
|
|
|
36
|
|
|
$request->getHeaderLine('Client-IP'), |
|
37
|
|
|
$request->getHeaderLine('X-Forwarded'), |
|
38
|
|
|
$request->getHeaderLine('X-Cluster-Client-IP'), |
|
39
|
|
|
$request->getHeaderLine('Forwarded-For'), |
|
40
|
|
|
$request->getHeaderLine('Forwarded') |
|
41
|
|
|
] |
|
42
|
|
|
); |
|
43
|
|
|
/** @noinspection NullPointerExceptionInspection */ |
|
44
|
|
|
$conn->user_agent = $request->getHeaderLine('User-Agent'); |
|
45
|
|
|
$cookie_name = Config::instance()->core['cookie_prefix'].'session'; |
|
46
|
|
|
/** @noinspection NullPointerExceptionInspection */ |
|
47
|
|
|
foreach ($request->getHeader('Cookie') as $cookie) { |
|
48
|
|
|
$cookie = explode('=', $cookie); |
|
49
|
|
|
if ($cookie[0] === $cookie_name) { |
|
50
|
|
|
$conn->session_id = $cookie[1]; |
|
51
|
|
|
break; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
/** @noinspection PhpUndefinedFieldInspection */ |
|
55
|
|
|
$conn->remote_addr = $conn->remoteAddress; |
|
56
|
|
|
$conn->ip = $ip; |
|
57
|
|
|
/** @noinspection NullPointerExceptionInspection */ |
|
58
|
|
|
$conn->language = $L->url_language($request->getUri()->getPath()) ?: $L->clanguage; |
|
59
|
|
|
$this->delegate->onOpen($conn, $request); |
|
60
|
|
|
} |
|
61
|
|
|
/** |
|
62
|
|
|
* The best guessed IP of client (based on all known headers), `127.0.0.1` by default |
|
63
|
|
|
* |
|
64
|
|
|
* @param string[] $source_ips |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function ip ($source_ips) { |
|
69
|
|
|
foreach ($source_ips as $ip) { |
|
70
|
|
|
$ip = trim(explode(',', $ip)[0]); |
|
71
|
|
|
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
72
|
|
|
return $ip; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
return '127.0.0.1'; |
|
76
|
|
|
} |
|
77
|
|
|
/** |
|
78
|
|
|
* {@inheritdoc} |
|
79
|
|
|
*/ |
|
80
|
|
|
public function onMessage (ConnectionInterface $from, $msg) { |
|
81
|
|
|
$this->delegate->onMessage($from, $msg); |
|
82
|
|
|
} |
|
83
|
|
|
/** |
|
84
|
|
|
* {@inheritdoc} |
|
85
|
|
|
*/ |
|
86
|
|
|
public function onClose (ConnectionInterface $conn) { |
|
87
|
|
|
$this->delegate->onClose($conn); |
|
88
|
|
|
} |
|
89
|
|
|
/** |
|
90
|
|
|
* {@inheritdoc} |
|
91
|
|
|
*/ |
|
92
|
|
|
public function onError (ConnectionInterface $conn, \Exception $e) { |
|
93
|
|
|
$this->delegate->onError($conn, $e); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths