# brisk_debug="0xffff"
web_path="/home/nastasi/web/curl-de-sacccc"
web_url="http://localhost/curl-de-sac"
+tor_chk_url="http://localhost/curl-de-sac/test/tor_mock.php"
dbg_level=998
# ftok_path="/home/nastasi/brisk-priv/ftok/brisk"
# proxy_path="/home/nastasi/brisk-priv/proxy/brisk"
echo "$1 chk - run lintian on all ph* files."
# echo "$1 pkg - build brisk packages."
- echo "$1 [-w <web_dir>] [-f <conffile>] [-p <outconf>]" # [-W] [-n 3|5] [-t <(n>=4)>] [-T <auth_tab>] [-G <cert_tab>] [-A <apache-conf>] [-a <auth_file_name>] [-U <usock_path>] [-u <sys_user>] [-d <TRUE|FALSE>] [-k <ftok_dir>] [-l <legal_path>] [-y <proxy_path>] [-P <prefix_path>] [-x]"
+ echo "$1 [-w <web_dir>] [-f <conffile>] [-p <outconf>] [-t <tor_chk_url>]" # [-W] [-n 3|5] [-t <(n>=4)>] [-T <auth_tab>] [-G <cert_tab>] [-A <apache-conf>] [-a <auth_file_name>] [-U <usock_path>] [-u <sys_user>] [-d <TRUE|FALSE>] [-k <ftok_dir>] [-l <legal_path>] [-y <proxy_path>] [-P <prefix_path>] [-x]"
# echo "$1 [-W] [-n 3|5] [-t <(n>=4)>] [-T <auth_tab>] [-G <cert_tab>] [-A <apache-conf>] [-a <auth_file_name>] [-f <conffile>] [-p <outconf>] [-U <usock_path>] [-u <sys_user>] [-d <TRUE|FALSE>] [-w <web_dir>] [-k <ftok_dir>] [-l <legal_path>] [-y <proxy_path>] [-P <prefix_path>] [-x]"
echo "$1 [-w <web_dir>]"
echo " -h this help"
echo " -d set debug level - def. $dbg_level"
echo " -w dir where place the web tree - def. \"$web_path\""
echo " -U web url to retrieve test pages - def. \"$web_url\""
+ echo " -t tor chk url - def. \"$tor_chk_url\""
# echo " -k dir where place ftok files - def. \"$ftok_path\""
# echo " -l dir where save logs - def. \"$legal_path\""
# echo " -y dir where place proxy files - def. \"$proxy_path\""
-d*) dbg_level="$(get_param "-d" "$1" "$2")"; sh=$?;;
-w*) web_path="$(get_param "-w" "$1" "$2")"; sh=$?;;
-U*) web_url="$(get_param "-U" "$1" "$2")" ; sh=$?;;
+ -t*) tor_chk_url="$(get_param "-t" "$1" "$2")" ; sh=$?;;
# -k*) ftok_path="$(get_param "-k" "$1" "$2")"; sh=$?;;
# -y*) proxy_path="$(get_param "-y" "$1" "$2")"; sh=$?;;
# -P*) prefix_path="$(get_param "-P" "$1" "$2")"; sh=$?;;
echo " dbg_level: $dbg_level"
echo " web_path: \"$web_path\""
echo " web_url: \"$web_url\""
+echo " tor_chk_url: \"$tor_chk_url\""
+
# echo " ftok_path: \"$ftok_path\""
# echo " legal_path: \"$legal_path\""
# echo " proxy_path: \"$proxy_path\""
echo "dbg_level=$dbg_level"
echo "web_path=\"$web_path\""
echo "web_url=\"$web_url\""
+ echo "tor_chk_url=\"$tor_chk_url\""
# echo "ftok_path=\"$ftok_path\""
# echo "proxy_path=\"$proxy_path\""
# echo "legal_path=\"$legal_path\""
# echo "usock_path=\"$usock_path\""
# echo "sys_user=\"$sys_user\""
# echo "web_only=\"$web_only\""
- # echo "test_add=\"$test_add\""
+ echo "test_add=\"$test_add\""
) > "$outconf"
fi
# sed -i "s/^var G_send_time *= *[0-9]\+/var G_send_time = $send_time/g" $(find ${web_path} -type f -name '*.js' -exec grep -l '^var G_send_time *= *[0-9]\+' {} \;)
# # .ph[pho] substitutions
-sed -i "s@^define *( *'WEB_URL', *'[^']\+' *)@define('WEB_URL', '$web_url')@g;s@define *( *'DBG_LEVEL', *[0-9]\+ *)@define('DBG_LEVEL', $dbg_level)@g" $(find ${web_path} -type f -name '*.ph*')
+sed -i "s@^define *( *'WEB_URL', *'[^']\+' *)@define('WEB_URL', '$web_url')@g;s@define *( *'DBG_LEVEL', *[0-9]\+ *)@define('DBG_LEVEL', $dbg_level)@g;s@define *( *'TOR_CHK_URL', *'[^']\+' *)@define('TOR_CHK_URL', '$tor_chk_url')@g" $(find ${web_path} -type f -name '*.ph*')
# sed -i "s/define *( *'BIN5_PLAYERS_N', *[0-9]\+ *)/define('BIN5_PLAYERS_N', $players_n)/g" $(find ${web_path} -type f -name '*.ph*' -exec grep -l "define *( *'BIN5_PLAYERS_N', *[0-9]\+ *)" {} \;)
TODO LIST
+- pass the callback function to the command class
+
- move name and timeout class to register function
to be able to use the same class different times
--- /dev/null
+<?php
+
+require_once($G_base . 'Obj/curl-de-sac.phh');
+
+define('TOR_CHK_URL', 'http://localhost/curl-de-sac/test/tor_mock.ppp');
+define('PROXY_CHK_URL', 'http://localhost/curl-de-sac/test/proxy_mock.ppp');
+
+class Tor_chk_cmd extends CDS_cmd {
+ var $ctx;
+ var $user_idx;
+ var $user_sess;
+ var $conn_ip;
+ var $is_auth;
+
+ function Tor_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 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, $is_auth)
+ {
+ 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, $is_auth);
+
+ 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 Tor server on IP [%s]\n", $cmd->conn_ip);
+ ;
+ }
+
+ $cmd->ctx->tor_chk_postprocess($cmd->user_idx, $cmd->user_sess, $cmd->conn_ip, $cmd->is_auth, $is_tor);
+
+ return TRUE;
+ }
+
+ function timeout($cmd)
+ {
+ printf("'tor_chk' timeout function reached\n");
+ }
+}
+
+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) {
+ printf("'proxy_chk'::create url:[%s]\n", 'PROXY_CHK_URL');
+ }
+
+ foreach($this->scan_headers as $key){
+ //proxy detected? lets log...
+ if($headers[$key]) {
+ // we already are behind a PROXY, this are our headers
+ if ($key == 'X-Proxy-ID') {
+ if ($headers[$key] == '860705422')
+ continue;
+ }
+ else if ($key == 'X-Forwarded-For') {
+ if ($headers[$key] == '172.16.9.66')
+ continue;
+ }
+ else if ($key == 'Via') {
+ if ($headers[$key] == '1.1 172.16.8.1 (Mikrotik HttpProxy)')
+ continue;
+ }
+
+ $ctx->proxy_chk_postprocess($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);
+
+ return $cmd;
+ } while (FALSE);
+
+ return FALSE;
+ }
+
+ function process($cmd, $ret)
+ {
+ if ($this->dbg_get() > 2) {
+ printf("CURL: 'proxy_chk' process: curl_multi_getcontent\n");
+ print_r($ret);
+ }
+
+ $content = curl_multi_getcontent($cmd->ch_get());
+ if ($this->dbg_get() > 0) { printf("'proxy_chk' process: [%s]\n", $content); }
+
+ $is_proxy = FALSE;
+ if (mb_strpos($content, "is_proxy=true", 0, "UTF-8") !== FALSE) {
+ // printf("WARNING: stripos ok\n");
+ $is_proxy = TRUE;
+ }
+ else if (mb_strpos($content, "is_proxy=false", 0, "UTF-8") === FALSE) {
+ printf("WARNING: proxy check disabled\n");
+ }
+ else {
+ // printf("WARNING: NOT an active Proxy server on IP [%s]\n", $cmd->conn_ip);
+ ;
+ }
+
+ $cmd->ctx->proxy_chk_postprocess($cmd->user_idx, $cmd->user_sess, $cmd->conn_ip, $cmd->is_auth, $is_proxy);
+
+ return TRUE;
+ }
+
+ function timeout($cmd)
+ {
+ printf("'proxy_chk' timeout function reached\n");
+ }
+}
+
+?>
--- /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);
+
+$G_base = "./";
+
+require_once($G_base . 'Obj/curl-de-sac.phh');
+require_once($G_base . '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");
+}
+?>