1 | <?php |
||
10 | class TorDetect |
||
11 | { |
||
12 | /** |
||
13 | * @var object |
||
14 | */ |
||
15 | private static $instance; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $target = null; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private $exithost = null; |
||
26 | |||
27 | /** |
||
28 | * @var integer |
||
29 | */ |
||
30 | private $port = 443; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $cache = array(); |
||
36 | |||
37 | /** |
||
38 | * Constructor |
||
39 | */ |
||
40 | private function __construct() |
||
41 | { |
||
42 | if (isset($_SERVER) && array_key_exists('REMOTE_ADDR', $_SERVER)) { |
||
43 | $this->setTarget($_SERVER['REMOTE_ADDR']); |
||
44 | } |
||
45 | |||
46 | if (isset($_SERVER) && array_key_exists('SERVER_ADDR', $_SERVER)) { |
||
47 | $this->setExithost($_SERVER["SERVER_ADDR"]); |
||
48 | $this->setPort($_SERVER["SERVER_PORT"]); |
||
49 | } |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param $target |
||
54 | * |
||
55 | * @return $this |
||
56 | * @throws \InvalidArgumentException |
||
57 | */ |
||
58 | public function setTarget($target) |
||
70 | |||
71 | /** |
||
72 | * @param $exithost |
||
73 | * @return $this |
||
74 | */ |
||
75 | public function setExithost($exithost) |
||
81 | |||
82 | /** |
||
83 | * @param integer $port |
||
84 | * @return $this |
||
85 | */ |
||
86 | public function setPort($port) |
||
92 | |||
93 | /** |
||
94 | * @return object|TorDetect |
||
95 | */ |
||
96 | public static function getInstance() |
||
104 | |||
105 | /** |
||
106 | * @return mixed |
||
107 | */ |
||
108 | public function isTorActive() |
||
120 | |||
121 | private function doFreshCheck() |
||
139 | |||
140 | /** |
||
141 | * Wrapper for windows < 5.3 and, theoretically for |
||
142 | * linux without dns_get_record() function |
||
143 | * |
||
144 | * @param array $address |
||
145 | * |
||
146 | * @return array |
||
147 | */ |
||
148 | private function dnsGetRecord(array $address) |
||
163 | |||
164 | /** |
||
165 | * @param string $address |
||
166 | * @return array |
||
167 | */ |
||
168 | private function doFallbackCheck($address) |
||
192 | |||
193 | /** |
||
194 | * @param $dns |
||
195 | * @return bool |
||
196 | */ |
||
197 | private function checkRecord($dns) |
||
205 | |||
206 | /** |
||
207 | * @param string $exithost |
||
208 | * @return string |
||
209 | */ |
||
210 | private function prepareExithost($exithost) |
||
214 | } |
||
215 |
If you suppress an error, we recommend checking for the error condition explicitly: