Ejemplo n.º 1
0
 public static function forward($tid, $sid, $hash, $values, $btn_name, $debug, $time, $resume_from_last_template = false)
 {
     $session = null;
     $result = array();
     if ($sid != null && $hash != null) {
         $session = TestSession::authorized_session($sid, $hash);
         if ($session != null) {
             if ($values == null) {
                 $values = array();
             }
             if ($btn_name != null) {
                 array_push($values, json_encode(array("name" => "LAST_PRESSED_BUTTON_NAME", "value" => $btn_name)));
             }
             if (Ini::$timer_tamper_prevention && $session->time_limit > 0 && $time - $session->time_tamper_prevention - Ini::$timer_tamper_prevention_tolerance > $session->time_limit) {
                 if ($session->debug == 1) {
                     TestSession::unregister($session->id);
                 } else {
                     $session->close();
                 }
                 $result = array("data" => array("HASH" => $hash, "TIME_LIMIT" => 0, "HTML" => "", "TEST_ID" => 0, "TEST_SESSION_ID" => $sid, "STATUS" => TestSession::TEST_SESSION_STATUS_TAMPERED, "TEMPLATE_ID" => 0, "HEAD" => "", "FINISHED" => 1));
                 if ($session->debug == 1) {
                     $result["debug"] = array("code" => 0, "return" => "", "output" => "");
                 }
             } else {
                 if (!$resume_from_last_template) {
                     $result = $session->resume($values);
                 } else {
                     $ts = TestSection::from_mysql_id($session->Template_TestSection_id);
                     if ($ts == null) {
                         $result = $session->resume($values);
                     } else {
                         $result = $session->run_Test($ts->counter, $values);
                     }
                 }
             }
         } else {
             $result = array("data" => array("HASH" => $hash, "TIME_LIMIT" => 0, "HTML" => "", "TEST_ID" => 0, "TEST_SESSION_ID" => $sid, "STATUS" => TestSession::TEST_SESSION_STATUS_TAMPERED, "TEMPLATE_ID" => 0, "HEAD" => "", "FINISHED" => 1), "debug" => array("code" => 0, "return" => "", "output" => ""));
         }
     } else {
         if ($tid != null) {
             if ($debug == 1) {
                 $debug = true;
             } else {
                 $debug = false;
             }
             $session = TestSession::start_new($tid, $debug);
             if ($values == null) {
                 $values = array();
             }
             $test = $session->get_Test();
             if ($test != null) {
                 $values = $test->verified_input_values($values);
             } else {
                 $result = array("data" => array("HASH" => $hash, "TIME_LIMIT" => 0, "HTML" => "", "TEST_ID" => $tid, "TEST_SESSION_ID" => $sid, "STATUS" => TestSession::TEST_SESSION_STATUS_TAMPERED, "TEMPLATE_ID" => 0, "HEAD" => "", "FINISHED" => 1), "debug" => array("code" => 0, "return" => "", "output" => ""));
                 return $result;
             }
             $result = $session->run_test(null, $values);
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 public static function forward($tid, $sid, $hash, $values, $btn_name, $debug, $time, $wid = null, $resume_from_last_template = false, $code = null)
 {
     $workspace = UserWorkspace::from_mysql_id($wid);
     if ($workspace != null) {
         mysql_select_db($workspace->db_name);
     } else {
         return false;
     }
     if (is_string($values)) {
         $values = json_decode($values, true);
     }
     $session = null;
     $result = array();
     if ($wid != null && $sid != null && $hash != null) {
         $session = TestSession::authorized_session($wid, $sid, $hash);
         if ($session != null) {
             if ($btn_name != null) {
                 if ($values != null) {
                     $values["LAST_PRESSED_BUTTON_NAME"] = $btn_name;
                 }
             }
             if (Ini::$timer_tamper_prevention && $session->time_limit > 0 && $time - $session->time_tamper_prevention - Ini::$timer_tamper_prevention_tolerance > $session->time_limit) {
                 if ($session->debug == 1) {
                     TestSession::unregister($session->UserWorkspace_id . "-" . $session->id, $session->UserWorkspace_id);
                 } else {
                     $session->close();
                 }
                 $result = array("data" => array("HASH" => $hash, "TIME_LIMIT" => 0, "HTML" => "", "TEST_ID" => 0, "TEST_SESSION_ID" => $sid, "STATUS" => TestSession::TEST_SESSION_STATUS_TAMPERED, "TEMPLATE_ID" => 0, "HEAD" => "", "FINISHED" => 1));
                 if ($session->debug == 1) {
                     $result["debug"] = array("return" => 0, "output" => "", "state" => "[]");
                 }
             } else {
                 $result = $session->RCall($values, $code, $resume_from_last_template);
             }
         } else {
             $result = array("data" => array("HASH" => $hash, "TIME_LIMIT" => 0, "HTML" => "", "TEST_ID" => 0, "TEST_SESSION_ID" => $sid, "STATUS" => TestSession::TEST_SESSION_STATUS_TAMPERED, "TEMPLATE_ID" => 0, "HEAD" => "", "FINISHED" => 1), "debug" => array("return" => 0, "output" => "", "state" => "[]"));
         }
     } else {
         if ($wid != null && $tid != null) {
             if ($debug == 1) {
                 $debug = true;
             } else {
                 $debug = false;
             }
             $test = Test::from_mysql_id($tid);
             if ($test->type != 2) {
                 $session = TestSession::start_new($wid, $tid, $debug);
             }
             if ($values == null) {
                 $values = array();
             }
             if ($test != null && $test->type != 2) {
                 $values = $test->verified_input_values($values);
             } else {
                 $result = array("data" => array("HASH" => $hash, "TIME_LIMIT" => 0, "HTML" => "", "TEST_ID" => $tid, "TEST_SESSION_ID" => $sid, "STATUS" => TestSession::TEST_SESSION_STATUS_TAMPERED, "TEMPLATE_ID" => 0, "HEAD" => "", "FINISHED" => 1), "debug" => array("return" => 0, "output" => "", "state" => "[]"));
                 return $result;
             }
             $result = $result = $session->RCall($values, $code, $resume_from_last_template);
         }
     }
     return $result;
 }
Ejemplo n.º 3
0
 private function authorize_client($client_sock, $input)
 {
     if (Ini::$log_server_events) {
         self::log_debug("TestServer->authorize_client() --- Client authorization started");
     }
     $data = json_decode($input);
     TestSession::change_db($data->workspace_id);
     $session = TestSession::authorized_session($data->workspace_id, $data->session_id, $data->hash);
     if ($session == null) {
         if (Ini::$log_server_events) {
             self::log_debug("TestServer->authorize_client() --- Client authorization failed");
         }
         if (!socket_write($client_sock, json_encode(array("return" => -1)) . chr(0))) {
             if (Ini::$log_server_events) {
                 self::log_debug("TestServer->authorize_client() --- Error: (socket_write) " . socket_last_error() . " - " . socket_strerror(socket_last_error()));
             }
         }
         return false;
     }
     if (!array_key_exists("sid" . $data->workspace_id . "-" . $data->session_id, $this->instances) && $session->status != TestSession::TEST_SESSION_STATUS_SERIALIZED && $session->status != TestSession::TEST_SESSION_STATUS_NEW) {
         if (Ini::$log_server_events) {
             self::log_debug("TestServer->authorize_client() --- Client authorization failed - invalid session");
         }
         if (!socket_write($client_sock, json_encode(array("return" => -1)) . chr(0))) {
             if (Ini::$log_server_events) {
                 self::log_debug("TestServer->authorize_client() --- Error: (socket_write) " . socket_last_error() . " - " . socket_strerror(socket_last_error()));
             }
         }
         return false;
     }
     if (Ini::$log_server_events) {
         self::log_debug("TestServer->authorize_client() --- Client authorization succeeded");
     }
     return true;
 }