--- /dev/null
+<?php
+
+require_once('Obj/curl-de-sac.phh');
+
+define('TOR_CHK_URL', 'http://localhost/curl-de-sac/test/tor_mock.php');
+
+class tor_chk_cmd extends CDS_cmd {
+ var $ctx;
+ var $user_idx;
+ var $user_sess;
+ var $conn_ip;
+
+ function tor_chk_cmd($cmd_cls, $ch, $ctx, $user_idx, $user_sess, $conn_ip)
+ {
+ parent::__construct($cmd_cls, $ch);
+ $this->ctx = $ctx;
+ $this->user_idx = $user_idx;
+ $this->user_sess = $user_sess;
+ $this->conn_ip = $conn_ip;
+ }
+}
+
+class tor_chk_cmd_cls extends CDS_cmd_cls {
+ function tor_chk_cmd_cls()
+ {
+ parent::__construct("tor_chk", 10);
+ }
+
+ function create($cds, $ctx, $user_idx, $user_sess, $conn_ip)
+ {
+ if ($cds->dbg_get() > 0) {
+ printf("'tor_chk'::create url:[%s]\n", 'TOR_CHK_URL');
+ }
+
+ do {
+ $opts = array( CURLOPT_HEADER => 0,
+ CURLOPT_RETURNTRANSFER => 1,
+ CURLOPT_FORBID_REUSE => true,
+ CURLOPT_HTTPHEADER => array('Connection: close'),
+ CURLOPT_POST => true,
+ CURLOPT_POSTFIELDS => array('QueryIP' => $conn_ip));
+
+ if (($ch = parent::pre_create($cds, TOR_CHK_URL, $opts)) == FALSE)
+ break;
+
+ if (parent::create($cds, $ch) == FALSE)
+ break;
+
+ $cmd = new tor_chk_cmd($this, $ch, $ctx, $user_idx, $user_sess, $conn_ip);
+
+ return $cmd;
+ } while (FALSE);
+
+ return FALSE;
+ }
+
+ function process($cmd, $ret)
+ {
+ if ($this->dbg_get() > 2) {
+ printf("CURL: 'tor_chk' process: curl_multi_getcontent\n");
+ print_r($ret);
+ }
+
+ $content = curl_multi_getcontent($cmd->ch_get());
+ if ($this->dbg_get() > 0) { printf("'tor_chk' process: [%s]\n", $content); }
+
+ $is_tor = FALSE;
+ if (mb_strpos($content,
+ "The IP Address you entered matches one or more active Tor servers",
+ 0, "UTF-8") !== FALSE) {
+ printf("WARNING: stripos ok\n");
+ $is_tor = TRUE;
+ }
+ else if (mb_strpos($content,
+ "The IP Address you entered is NOT an active Tor server",
+ 0, "UTF-8") === FALSE) {
+ printf("WARNING: tor check disabled\n");
+ }
+ else {
+ printf("WARNING: NOT an active ...\n");
+ }
+
+ $cmd->ctx->cds_postprocess($cmd->user_idx, $cmd->user_sess, $cmd->conn_ip, $is_tor);
+
+ return TRUE;
+ }
+
+ function timeout($cmd)
+ {
+ printf("'tor_chk' timeout function reached\n");
+ }
+}
+
+?>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html><head>
+
+
+
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Tor Network Status -- Tor Exit Query</title>
+<link rel="stylesheet" type="text/css" href="tor_exit_query.php_bad_files/main.css">
+</head><body class="BOD">
+<br><br>
+<table border="0" cellpadding="2" cellspacing="2" width="70%" align="center">
+
+<tbody><tr>
+<td class="PT"><br><a href="http://torstatus.blutmagie.de/index.php">Tor Network Status</a> -- Tor Exit Query<br><br></td>
+</tr>
+
+<tr>
+<td class="TRC"><br><br><br><b>You can use this page to determine if an
+IP address is an active Tor server, and optionally see if that Tor
+server's Exit Policy would permit it to exit to a certain destination
+IP address and port.</b><br></td>
+</tr>
+
+<tr>
+<td class="TRC"><br><br><b><font color="#ff0000">-The IP Address you entered is NOT an active Tor server-</font><br><br></b></td>
+</tr>
+
+<tr>
+<td class="TRSCN"><br>
+
+<table border="1" cellpadding="8" cellspacing="2" width="20%" align="center">
+<tbody><tr>
+<td class="TRSCN">
+<br>
+
+<form action="/tor_exit_query.php" method="post">
+<b>IP Address to Query:<br><span class="TRSM">(Required)</span></b><br>
+<input name="QueryIP" class="BOX" maxlength="15" size="20" value="87.0.81.36" type="text"><br><br><br>
+<b>Destination IP Address:<br><span class="TRSM">(Optional)</span></b><br>
+<input name="DestinationIP" class="BOX" maxlength="15" size="20" type="text"><br><br>
+<b>Destination Port:<br><span class="TRSM">(Optional)</span></b><br>
+<input name="DestinationPort" class="BOX" maxlength="5" size="6" type="text"><br><br><br>
+<input value="Submit Query" type="submit"><br><br>
+</form>
+
+</td>
+</tr>
+</tbody></table>
+
+<br><br>
+</td>
+</tr>
+
+</tbody></table>
+
+<br><br><br>
+
+<table border="0" cellpadding="2" cellspacing="2" width="70%" align="center">
+<tbody><tr>
+<td class="TRC"><b><a class="plain" href="http://torstatus.blutmagie.de/index.php">Tor Network Status</a> v3.6.1<br><a class="plain" href="http://torstatus.blutmagie.de/CHANGES" target="_new">View Complete Change History</a><br>Copyright © 2006-2007, Joseph B. Kowalski<br>Portions Copyright © 2007, Kasimir Gabert<br>Source code is available under <a class="plain" href="http://torstatus.blutmagie.de/LICENSE" target="_new">BSD license</a> at <a class="plain" href="http://project.torstatus.kgprog.com/" target="_new">project.torstatus.kgprog.com</a></b></td>
+</tr>
+</tbody></table>
+</body></html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html><head>
+
+
+
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Tor Network Status -- Tor Exit Query</title>
+<link rel="stylesheet" type="text/css" href="tor_exit_query.php_files/main.css">
+</head><body class="BOD">
+<br><br>
+<table border="0" cellpadding="2" cellspacing="2" width="70%" align="center">
+
+<tbody><tr>
+<td class="PT"><br><a href="http://torstatus.blutmagie.de/index.php">Tor Network Status</a> -- Tor Exit Query<br><br></td>
+</tr>
+
+<tr>
+<td class="TRC"><br><br><br><b>You can use this page to determine if an
+IP address is an active Tor server, and optionally see if that Tor
+server's Exit Policy would permit it to exit to a certain destination
+IP address and port.</b><br></td>
+</tr>
+
+<tr>
+<td class="TRC"><br><br><b><font color="#00dd00">-The IP Address you entered matches one or more active Tor servers-</font><br><br>Server name: <a class="plain" href="http://torstatus.blutmagie.de/router_detail.php?FP=89e3170b4e2fc9a430fb97536769fc0abf6c4db3">hviv103</a><br><br></b></td>
+</tr>
+
+<tr>
+<td class="TRSCN"><br>
+
+<table border="1" cellpadding="8" cellspacing="2" width="20%" align="center">
+<tbody><tr>
+<td class="TRSCN">
+<br>
+
+<form action="/tor_exit_query.php" method="post">
+<b>IP Address to Query:<br><span class="TRSM">(Required)</span></b><br>
+<input name="QueryIP" class="BOX" maxlength="15" size="20" value="178.162.193.213" type="text"><br><br><br>
+<b>Destination IP Address:<br><span class="TRSM">(Optional)</span></b><br>
+<input name="DestinationIP" class="BOX" maxlength="15" size="20" type="text"><br><br>
+<b>Destination Port:<br><span class="TRSM">(Optional)</span></b><br>
+<input name="DestinationPort" class="BOX" maxlength="5" size="6" type="text"><br><br><br>
+<input value="Submit Query" type="submit"><br><br>
+</form>
+
+</td>
+</tr>
+</tbody></table>
+
+<br><br>
+</td>
+</tr>
+
+</tbody></table>
+
+<br><br><br>
+
+<table border="0" cellpadding="2" cellspacing="2" width="70%" align="center">
+<tbody><tr>
+<td class="TRC"><b><a class="plain" href="http://torstatus.blutmagie.de/index.php">Tor Network Status</a> v3.6.1<br><a class="plain" href="http://torstatus.blutmagie.de/CHANGES" target="_new">View Complete Change History</a><br>Copyright © 2006-2007, Joseph B. Kowalski<br>Portions Copyright © 2007, Kasimir Gabert<br>Source code is available under <a class="plain" href="http://torstatus.blutmagie.de/LICENSE" target="_new">BSD license</a> at <a class="plain" href="http://project.torstatus.kgprog.com/" target="_new">project.torstatus.kgprog.com</a></b></td>
+</tr>
+</tbody></table>
+</body></html>
\ No newline at end of file
--- /dev/null
+#!/usr/bin/php
+<?php
+
+define('WEB_URL', 'http://localhost/curl-de-sac');
+define('TOR_CHK_URL', 'http://localhost/curl-de-sac/test/tor_mock.php');
+define('DBG_LEVEL', 0);
+
+require_once('Obj/curl-de-sac.phh');
+require_once('Obj/curl-de-brisk.phh');
+
+class Brisk_mock {
+ function cds_postprocess($user_idx, $user_sess, $conn_ip, $is_tor)
+ {
+ printf("user_idx: %d, user_sess: %s, conn_ip: %s, is_tor: %s\n",
+ $user_idx, $user_sess, $conn_ip, ($is_tor ? "YES" : "NO"));
+ }
+}
+
+function main()
+{
+ $brisk = new Brisk_mock();
+ $debug = DBG_LEVEL;
+ // create cds
+ $cds = new Curl_de_sac($debug);
+
+ // create tor_chk_cls
+ $tor_chk_cls = new tor_chk_cmd_cls();
+
+ // registrer tor_chk_cls
+ printf("MAIN: Register 'tor_chk_cls'\n");
+ if (($cds->cmd_cls_register($tor_chk_cls)) == FALSE) {
+ fprintf(STDERR, "MAIN: 'tor_chk_cls' registration failed\n");
+ exit(1);
+ }
+
+ if (($debug & 1) == 1) {
+ printf("MAIN: CDS:\n");
+ print_r($cds);
+ printf("\n");
+ }
+
+ // for ($i = -15 ; $i < 30 ; $i++) {
+ for ($i = 0 ; $i < 10 ; $i++) {
+ printf("MAIN: START ITERATION %d\n", $i);
+
+ if ($i == 2) {
+ // Case OK
+ printf("MAIN: load 'tor_chk'\n");
+ if ($cds->execute("tor_chk", $brisk, 24, "caffe", "178.162.193.213") == FALSE) {
+ printf("MAIN: push 'tor_chk' command failed\n");
+ exit(123);
+ }
+ }
+
+ else if ($i == 4) {
+ // Case Malformed output
+ printf("MAIN: load 'tor_chk'\n");
+ if ($cds->execute("tor_chk", $brisk, 24, "caffe", "178.162.193.214") == FALSE) {
+ printf("MAIN: push 'tor_chk' command failed\n");
+ exit(123);
+ }
+ }
+ else if ($i == 6) {
+ // Case NO
+ printf("MAIN: load 'tor_chk'\n");
+ if ($cds->execute("tor_chk", $brisk, 24, "caffe", "178.162.193.215") == FALSE) {
+ printf("MAIN: push 'tor_chk' command failed\n");
+ exit(123);
+ }
+ }
+
+ printf("MAIN:");
+ if (($debug & 1) == 1) {
+ printf(" CDS:\n");
+ print_r($cds);
+ printf("\n");
+ }
+
+ printf("MAIN: Call process\n");
+ $cds->process();
+ sleep(1);
+ }
+ printf("MAIN: finished, dump cds:\n");
+ print_r($cds);
+ // start loop
+ // print status
+ // if input data execute some command
+ // if end => clean exit
+ exit(0);
+}
+
+main();
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+$query_ip = $_POST['QueryIP'];
+$dest_ip = $_POST['DestinationIP'];
+$dest_port = $_POST['DestinationPort'];
+
+printf("QUERY_IP: [%s]\n", $query_ip);
+
+if ($query_ip == "178.162.193.213") {
+ // <td class="TRC"><br><br><b><font color="#00dd00">-The IP Address you entered matches one or more active Tor servers-</font><br><br>Server name: <a class="plain" href="http://torstatus.blutmagie.de/router_detail.php?FP=89e3170b4e2fc9a430fb97536769fc0abf6c4db3">hviv103</a><br><br></b></td>
+
+ readfile("Data/tor_mock_ok.html");
+}
+else if ($query_ip == "178.162.193.214") {
+ echo "NOTHING NOTHING!";
+}
+else {
+ readfile("Data/tor_mock_bad.html");
+}
+?>
\ No newline at end of file