3 require_once($G_base . 'Obj/curl-de-sac.phh');
5 define('TOR_CHK_URL', 'http://localhost/curl-de-sac/test/tor_mock.ppp');
6 define('PROXY_CHK_URL', 'http://localhost/curl-de-sac/test/proxy_mock.ppp');
8 class Tor_chk_cmd extends CDS_cmd {
15 function Tor_chk_cmd($cmd_cls, $ch, $ctx, $user_idx, $user_sess, $conn_ip, $is_auth)
17 parent::__construct($cmd_cls, $ch);
19 $this->user_idx = $user_idx;
20 $this->user_sess = $user_sess;
21 $this->conn_ip = $conn_ip;
22 $this->is_auth = $is_auth;
26 class Tor_chk_cmd_cls extends CDS_cmd_cls {
27 function Tor_chk_cmd_cls()
29 parent::__construct("tor_chk", 10);
32 function create($cds, $ctx, $user_idx, $user_sess, $conn_ip, $is_auth)
34 if ($cds->dbg_get() > 0) {
35 printf("'tor_chk'::create url:[%s]\n", 'TOR_CHK_URL');
39 $opts = array( CURLOPT_HEADER => 0,
40 CURLOPT_RETURNTRANSFER => 1,
41 CURLOPT_FORBID_REUSE => true,
42 CURLOPT_HTTPHEADER => array('Connection: close'),
44 CURLOPT_POSTFIELDS => array('QueryIP' => $conn_ip));
46 if (($ch = parent::pre_create($cds, TOR_CHK_URL, $opts)) == FALSE)
49 if (parent::create($cds, $ch) == FALSE)
52 $cmd = new Tor_chk_cmd($this, $ch, $ctx, $user_idx, $user_sess, $conn_ip, $is_auth);
60 function process($cmd, $ret)
62 if ($this->dbg_get() > 2) {
63 printf("CURL: 'tor_chk' process: curl_multi_getcontent\n");
67 $content = curl_multi_getcontent($cmd->ch_get());
68 if ($this->dbg_get() > 0) { printf("'tor_chk' process: [%s]\n", $content); }
71 if (mb_strpos($content,
72 "The IP Address you entered matches one or more active Tor servers",
73 0, "UTF-8") !== FALSE) {
74 // printf("WARNING: stripos ok\n");
77 else if (mb_strpos($content,
78 "The IP Address you entered is NOT an active Tor server",
79 0, "UTF-8") === FALSE) {
80 printf("WARNING: tor check disabled\n");
83 // printf("WARNING: NOT an active Tor server on IP [%s]\n", $cmd->conn_ip);
87 $cmd->ctx->tor_chk_postprocess($cmd->user_idx, $cmd->user_sess, $cmd->conn_ip, $cmd->is_auth, $is_tor);
92 function timeout($cmd)
94 printf("'tor_chk' timeout function reached\n");
98 class Proxy_chk_cmd_cls extends CDS_cmd_cls {
99 function Proxy_chk_cmd_cls()
101 parent::__construct("proxy_chk", 10);
103 $this->scan_headers = array(
105 'HTTP_X_FORWARDED_FOR',
106 'HTTP_FORWARDED_FOR',
110 'HTTP_FORWARDED_FOR_IP',
118 'HTTP_PROXY_CONNECTION'
122 function create($cds, $ctx, $user_idx, $user_sess, $conn_ip, $is_auth, $headers)
124 if ($cds->dbg_get() > 0) {
125 printf("'proxy_chk'::create url:[%s]\n", 'PROXY_CHK_URL');
128 foreach($this->scan_headers as $key){
129 //proxy detected? lets log...
131 // we already are behind a PROXY, this are our headers
132 if ($key == 'X-Proxy-ID') {
133 if ($headers[$key] == '860705422')
136 else if ($key == 'X-Forwarded-For') {
137 if ($headers[$key] == '172.16.9.66')
140 else if ($key == 'Via') {
141 if ($headers[$key] == '1.1 172.16.8.1 (Mikrotik HttpProxy)')
145 $ctx->proxy_chk_postprocess($user_idx, $user_sess, $conn_ip, $is_auth, TRUE);
151 $opts = array( CURLOPT_HEADER => 0,
152 CURLOPT_RETURNTRANSFER => 1,
153 CURLOPT_FORBID_REUSE => true,
154 CURLOPT_HTTPHEADER => array('Connection: close'),
155 CURLOPT_POST => true,
156 CURLOPT_POSTFIELDS => array('conn_ip' => $conn_ip));
158 if (($ch = parent::pre_create($cds, PROXY_CHK_URL, $opts)) == FALSE)
161 if (parent::create($cds, $ch) == FALSE)
164 $cmd = new Proxy_chk_cmd($this, $ch, $ctx, $user_idx, $user_sess, $conn_ip, $is_auth);
172 function process($cmd, $ret)
174 if ($this->dbg_get() > 2) {
175 printf("CURL: 'proxy_chk' process: curl_multi_getcontent\n");
179 $content = curl_multi_getcontent($cmd->ch_get());
180 if ($this->dbg_get() > 0) { printf("'proxy_chk' process: [%s]\n", $content); }
183 if (mb_strpos($content, "is_proxy=true", 0, "UTF-8") !== FALSE) {
184 // printf("WARNING: stripos ok\n");
187 else if (mb_strpos($content, "is_proxy=false", 0, "UTF-8") === FALSE) {
188 printf("WARNING: proxy check disabled\n");
191 // printf("WARNING: NOT an active Proxy server on IP [%s]\n", $cmd->conn_ip);
195 $cmd->ctx->proxy_chk_postprocess($cmd->user_idx, $cmd->user_sess, $cmd->conn_ip, $cmd->is_auth, $is_proxy);
200 function timeout($cmd)
202 printf("'proxy_chk' timeout function reached\n");