+ fprintf(STDERR, "WARNING: tor check disabled\n");
+ }
+ else {
+ // fprintf(STDERR, "WARNING: NOT an active Tor server on IP [%s]\n", $cmd->conn_ip);
+ ;
+ }
+
+ tor_chk_postprocess($cmd->ctx, $cmd->user_idx, $cmd->user_sess, $cmd->conn_ip, $cmd->is_auth, $is_tor);
+
+ return TRUE;
+ }
+
+ function timeout($cmd)
+ {
+ tor_chk_timeout_cb($cmd->ctx, $cmd->user_idx, $cmd->user_sess, $cmd->conn_ip, $cmd->is_auth);
+ }
+}
+
+class Proxy_chk_cmd extends CDS_cmd {
+ var $ctx;
+ var $user_idx;
+ var $user_sess;
+ var $conn_ip;
+ var $is_auth;
+
+ function Proxy_chk_cmd($cmd_cls, $ch, $ctx, $user_idx, $user_sess, $conn_ip, $is_auth)
+ {
+ parent::__construct($cmd_cls, $ch);
+ $this->ctx = $ctx;
+ $this->user_idx = $user_idx;
+ $this->user_sess = $user_sess;
+ $this->conn_ip = $conn_ip;
+ $this->is_auth = $is_auth;
+ }
+}
+
+class Proxy_chk_cmd_cls extends CDS_cmd_cls {
+ function Proxy_chk_cmd_cls()
+ {
+ parent::__construct("proxy_chk", 10);
+
+ $this->scan_headers = array(
+ 'Http-Via',
+ 'Http-X-Forwarded-For',
+ 'Http-Forwarded-For',
+ 'Http-X-Forwarded',
+ 'Http-Forwarded',
+ 'Http-Client-Ip',
+ 'Http-Forwarded-For-Ip',
+ 'Via',
+ 'X-Forwarded-For',
+ 'Forwarded-For',
+ 'X-Forwarded',
+ 'Forwarded',
+ 'Client-Ip',
+ 'Forwarded-For-Ip',
+ 'Http-Proxy-Connection'
+ );
+ }
+
+ function create($cds, $ctx, $user_idx, $user_sess, $conn_ip, $is_auth, $headers)
+ {
+ if ($cds->dbg_get() > 0) {
+ fprintf(STDERR, "'proxy_chk'::create url:[%s]\n", 'PROXY_CHK_URL');
+ }
+
+ foreach($this->scan_headers as $key){
+ //proxy detected? lets log...
+ if(array_key_exists($key, $headers)) {
+ // we already are behind a PROXY, this are our headers
+ proxy_chk_postprocess($ctx, $user_idx, $user_sess, $conn_ip, $is_auth, TRUE);
+ return TRUE;
+ }
+ }
+
+ do {
+ $opts = array( CURLOPT_HEADER => 0,
+ CURLOPT_RETURNTRANSFER => 1,
+ CURLOPT_FORBID_REUSE => true,
+ CURLOPT_HTTPHEADER => array('Connection: close'),
+ CURLOPT_POST => true,
+ CURLOPT_POSTFIELDS => array('conn_ip' => $conn_ip));
+
+ if (($ch = parent::pre_create($cds, PROXY_CHK_URL, $opts)) == FALSE)
+ break;
+
+ if (parent::create($cds, $ch) == FALSE)
+ break;
+
+ $cmd = new Proxy_chk_cmd($this, $ch, $ctx, $user_idx, $user_sess, $conn_ip, $is_auth);
+ $ctx->user[$user_idx]->pend_async++;
+
+ return $cmd;
+ } while (FALSE);
+
+ return FALSE;
+ }
+
+ function process($cmd, $ret)
+ {
+ if ($this->dbg_get() > 2) {
+ fprintf(STDERR, "CURL: 'proxy_chk' process: curl_multi_getcontent\n");
+ fprintf(STDERR, "%s", print_r($ret, TRUE));
+ }
+
+ $content = curl_multi_getcontent($cmd->ch_get());
+ if ($this->dbg_get() > 0) { fprintf(STDERR, "'proxy_chk' process: [%s]\n", $content); }
+
+ $is_proxy = FALSE;
+ if (mb_strpos($content, "is_proxy=true", 0, "UTF-8") !== FALSE) {
+ // fprintf(STDERR, "WARNING: stripos ok\n");
+ $is_proxy = TRUE;
+ }
+ else if (mb_strpos($content, "is_proxy=false", 0, "UTF-8") === FALSE) {
+ fprintf(STDERR, "WARNING: proxy check disabled\n");