tor check added
[curl-de-sac.git] / web / Obj / curl-de-brisk.phh
1 <?php
2
3 require_once('Obj/curl-de-sac.phh');
4
5 define('TOR_CHK_URL', 'http://localhost/curl-de-sac/test/tor_mock.php');
6
7 class tor_chk_cmd extends CDS_cmd {
8     var $ctx;
9     var $user_idx;
10     var $user_sess;
11     var $conn_ip;
12
13     function tor_chk_cmd($cmd_cls, $ch, $ctx, $user_idx, $user_sess, $conn_ip)
14     {
15         parent::__construct($cmd_cls, $ch);
16         $this->ctx       = $ctx;
17         $this->user_idx  = $user_idx;
18         $this->user_sess = $user_sess;
19         $this->conn_ip   = $conn_ip;
20     }
21 }
22
23 class tor_chk_cmd_cls extends CDS_cmd_cls {
24     function tor_chk_cmd_cls()
25     {
26         parent::__construct("tor_chk", 10);
27     }
28
29     function create($cds, $ctx, $user_idx, $user_sess, $conn_ip)
30     {
31         if ($cds->dbg_get() > 0) {
32             printf("'tor_chk'::create url:[%s]\n", 'TOR_CHK_URL');
33         }
34
35         do {
36             $opts = array( CURLOPT_HEADER => 0,
37                            CURLOPT_RETURNTRANSFER => 1,
38                            CURLOPT_FORBID_REUSE => true,
39                            CURLOPT_HTTPHEADER => array('Connection: close'),
40                            CURLOPT_POST => true,
41                            CURLOPT_POSTFIELDS => array('QueryIP' => $conn_ip));
42
43             if (($ch = parent::pre_create($cds, TOR_CHK_URL, $opts)) == FALSE)
44                 break;
45
46             if (parent::create($cds, $ch) == FALSE)
47                 break;
48
49             $cmd = new tor_chk_cmd($this, $ch, $ctx, $user_idx, $user_sess, $conn_ip);
50
51             return $cmd;
52         } while (FALSE);
53         
54         return FALSE;
55     }
56
57     function process($cmd, $ret)
58     {
59         if ($this->dbg_get() > 2) { 
60             printf("CURL: 'tor_chk' process: curl_multi_getcontent\n");
61             print_r($ret);
62         }
63
64         $content = curl_multi_getcontent($cmd->ch_get());
65         if ($this->dbg_get() > 0) { printf("'tor_chk' process: [%s]\n", $content); }
66
67         $is_tor = FALSE;
68         if (mb_strpos($content,
69                        "The IP Address you entered matches one or more active Tor servers",
70                        0, "UTF-8") !== FALSE) {
71             printf("WARNING: stripos ok\n");
72             $is_tor = TRUE;
73         }
74         else if (mb_strpos($content,
75                        "The IP Address you entered is NOT an active Tor server",
76                             0, "UTF-8") === FALSE) {
77             printf("WARNING: tor check disabled\n");
78         }
79         else {
80             printf("WARNING: NOT an active ...\n");
81         }
82
83         $cmd->ctx->cds_postprocess($cmd->user_idx, $cmd->user_sess, $cmd->conn_ip, $is_tor);
84
85         return TRUE;
86     }
87
88     function timeout($cmd)
89     {
90         printf("'tor_chk' timeout function reached\n");
91     }
92 }
93
94 ?>