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