add proxy check management and change API interface
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Tue, 30 Sep 2014 16:35:49 +0000 (18:35 +0200)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Tue, 30 Sep 2014 16:35:49 +0000 (18:35 +0200)
INSTALL.sh
web/Obj/curl-de-brisk.phh
webtest/cds_test02.php

index 042ea51..e6e869d 100755 (executable)
@@ -10,6 +10,7 @@ apache_conf="/etc/apache2/sites-available/default"
 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"
+proxy_chk_url="http://localhost/curl-de-sac/test/proxy_mock.php"
 dbg_level=998
 # ftok_path="/home/nastasi/brisk-priv/ftok/brisk"
 # proxy_path="/home/nastasi/brisk-priv/proxy/brisk"
@@ -27,7 +28,7 @@ function usage () {
 
     echo "$1 chk                          - run lintian on all ph* files."
 #    echo "$1 pkg                          - build brisk packages."
-    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 <web_dir>] [-f <conffile>] [-p <outconf>] [-t <tor_chk_url>] [-P <proxy_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"
@@ -44,6 +45,7 @@ function usage () {
     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 "  -P proxy chk url                  - def. \"$proxy_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\""
@@ -153,6 +155,7 @@ while [ $# -gt 0 ]; do
         -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=$?;;
+        -P*) proxy_chk_url="$(get_param "-P" "$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=$?;;
@@ -190,6 +193,7 @@ echo "    dbg_level:  $dbg_level"
 echo "    web_path:   \"$web_path\""
 echo "    web_url:    \"$web_url\""
 echo "    tor_chk_url:    \"$tor_chk_url\""
+echo "    proxy_chk_url:    \"$proxy_chk_url\""
 
 # echo "    ftok_path:  \"$ftok_path\""
 # echo "    legal_path: \"$legal_path\""
@@ -216,6 +220,7 @@ if [ ! -z "$outconf" ]; then
     echo "web_path=\"$web_path\""
     echo "web_url=\"$web_url\""
     echo "tor_chk_url=\"$tor_chk_url\""
+    echo "proxy_chk_url=\"$proxy_chk_url\""
     # echo "ftok_path=\"$ftok_path\""
     # echo "proxy_path=\"$proxy_path\""
     # echo "legal_path=\"$legal_path\""
@@ -302,7 +307,10 @@ 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;s@define *( *'TOR_CHK_URL', *'[^']\+' *)@define('TOR_CHK_URL', '$tor_chk_url')@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;\
+s@define *( *'PROXY_CHK_URL', *'[^']\+' *)@define('PROXY_CHK_URL', '$proxy_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]\+ *)" {} \;)
 
index 8dd8889..5c23651 100755 (executable)
@@ -5,6 +5,51 @@ 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');
 
+/*
+ *  Operational Brisk stuff
+ */
+function brisk_cds_reload($brisk)
+{
+    if ($brisk->cds != NULL) {
+        $brisk->cds->cmd_cls_deregister_all();
+        unset($brisk->cds);
+        $brisk->cds = NULL;
+    }
+    // create cds
+    $brisk->cds = new Curl_de_sac();
+
+    // create tor_chk_cls and proxy_chk_cls
+    $tor_chk_cls = new Tor_chk_cmd_cls();
+    $proxy_chk_cls = new Proxy_chk_cmd_cls();
+
+    // registrer tor_chk_cls and proxy_chk_cls
+    printf("MAIN: Register 'tor_chk_cls'\n");
+    if (($brisk->cds->cmd_cls_register($tor_chk_cls)) == FALSE) {
+        fprintf(STDERR, "MAIN: 'tor_chk_cls' registration failed\n");
+        return (FALSE);
+    }
+    printf("MAIN: Register 'proxy_chk_cls'\n");
+    if (($brisk->cds->cmd_cls_register($proxy_chk_cls)) == FALSE) {
+        fprintf(STDERR, "MAIN: 'proxy_chk_cls' registration failed\n");
+        return (FALSE);
+    }
+
+    return (TRUE);
+}
+
+function brisk_cds_execute($brisk, $real_idx, $sess, $ip, $authenticate)
+{
+    if ($brisk->cds->execute("tor_chk", $brisk, $ghost, $sess, $ip, $authenticate != FALSE) == FALSE) {
+        log_main("cds_execute failed");
+    }
+    if ($brisk->cds->execute("proxy_chk", $brisk, $ghost, $sess, $ip, $authenticate != FALSE) == FALSE) {
+        log_main("cds_execute failed");
+    }
+}
+
+/*
+ * CDS commands stuff
+ */
 class Tor_chk_cmd extends CDS_cmd {
     var $ctx;
     var $user_idx;
@@ -84,14 +129,32 @@ class Tor_chk_cmd_cls extends CDS_cmd_cls {
             ;
         }
 
-        $cmd->ctx->tor_chk_postprocess($cmd->user_idx, $cmd->user_sess, $cmd->conn_ip, $cmd->is_auth, $is_tor);
+        tor_chk_postprocess($cmd->ctx, $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");
+        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;
     }
 }
 
@@ -142,7 +205,7 @@ class Proxy_chk_cmd_cls extends CDS_cmd_cls {
                         continue;
                 }
 
-                $ctx->proxy_chk_postprocess($user_idx, $user_sess, $conn_ip, $is_auth, TRUE);
+                proxy_chk_postprocess($ctx, $user_idx, $user_sess, $conn_ip, $is_auth, TRUE);
                 return TRUE;
             }
         }
@@ -192,15 +255,39 @@ class Proxy_chk_cmd_cls extends CDS_cmd_cls {
             ;
         }
 
-        $cmd->ctx->proxy_chk_postprocess($cmd->user_idx, $cmd->user_sess, $cmd->conn_ip, $cmd->is_auth, $is_proxy);
+        proxy_chk_postprocess($cmd->ctx, $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");
+        proxy_chk_timeout_cb($cmd->ctx, $cmd->user_idx, $cmd->user_sess, $cmd->conn_ip, $cmd->is_auth);
     }
 }
 
+function tor_chk_postprocess($brisk, $user_idx, $user_sess, $conn_ip, $is_auth, $is_tor)
+{
+    log_cds(sprintf("tor: user_idx: %d, user_sess: %s, conn_ip: %s, is_auth: %s, is_tor: %s",
+                    $user_idx, $user_sess, $conn_ip, ($is_auth ? "YES" : "NO"), ($is_tor ? "YES" : "NO")));
+}
+
+function tor_chk_timeout_cb($brisk, $user_idx, $user_sess, $conn_ip, $is_auth)
+{
+    log_cds(sprintf("tor: user_idx: %d, user_sess: %s, conn_ip: %s, is_auth: %s",
+                    $user_idx, $user_sess, $conn_ip, ($is_auth ? "YES" : "NO")));
+}
+
+function proxy_chk_postprocess($brisk, $user_idx, $user_sess, $conn_ip, $is_auth, $is_proxy)
+{
+    log_cds(sprintf("proxy: user_idx: %d, user_sess: %s, conn_ip: %s, is_auth: %s, is_proxy: %s",
+                    $user_idx, $user_sess, $conn_ip, ($is_auth ? "YES" : "NO"), ($is_proxy ? "YES" : "NO")));
+}
+
+function proxy_chk_timeout_cb($brisk, $user_idx, $user_sess, $conn_ip, $is_auth)
+{
+    log_cds(sprintf("proxy timeout: user_idx: %d, user_sess: %s, conn_ip: %s, is_auth: %s",
+                    $user_idx, $user_sess, $conn_ip, ($is_auth ? "YES" : "NO")));
+}
+
 ?>
index 5dec4b4..e5fc092 100755 (executable)
@@ -2,11 +2,15 @@
 <?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 = "./";
 
+function log_cds()
+{
+    printf("log_cds\n");
+}
+
 require_once($G_base . 'Obj/curl-de-sac.phh');
 require_once($G_base . 'Obj/curl-de-brisk.phh');
 
@@ -48,7 +52,7 @@ function main()
          if ($i == 2) {
              // Case OK
             printf("MAIN: load 'tor_chk'\n");
-            if ($cds->execute("tor_chk", $brisk, 24, "caffe", "178.162.193.213") == FALSE) {
+            if ($cds->execute("tor_chk", $brisk, 24, "caffe", "178.162.193.213", TRUE) == FALSE) {
                 printf("MAIN: push 'tor_chk' command failed\n");
                 exit(123);
             }
@@ -57,7 +61,7 @@ function main()
          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) {
+            if ($cds->execute("tor_chk", $brisk, 24, "caffe", "178.162.193.214", FALSE) == FALSE) {
                 printf("MAIN: push 'tor_chk' command failed\n");
                 exit(123);
             }
@@ -65,7 +69,7 @@ function main()
          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) {
+            if ($cds->execute("tor_chk", $brisk, 24, "caffe", "178.162.193.215", TRUE) == FALSE) {
                 printf("MAIN: push 'tor_chk' command failed\n");
                 exit(123);
             }