diff --git a/classes/local/api/tracker.php b/classes/local/api/tracker.php index 322402a..51e2fd0 100644 --- a/classes/local/api/tracker.php +++ b/classes/local/api/tracker.php @@ -87,10 +87,66 @@ public static function storeFallbackDetails($attempt_no, $proview_url, $proctor_ ]); return $response; } + private static function redirect_to_wrapper($proctoring_payload, $quiz, $quizaccess_proctor_setting) + { + $wrapper_response = self::create_sb_wrapper($proctoring_payload, $quiz, $quizaccess_proctor_setting); + // redirect($wrapper_response->signed_short_url); + echo ""; + return; + } + + private static function create_sb_wrapper($proctoring_payload, $quiz, $quizaccess_proctor_setting) + { + global $PAGE; + $curl = new \curl(); + $api_base_url = trim(get_config('quizaccess_proctor', 'proview_callback_url')); + $auth_payload = new \stdClass(); + $auth_payload->username = trim(get_config('quizaccess_proctor', 'proview_admin_username')); + $auth_payload->password = trim(get_config('quizaccess_proctor', 'proview_admin_password')); + $auth_response = self::generate_auth_token($api_base_url, $auth_payload); + $auth_token = $auth_response['access_token']; + $url = $api_base_url . '/proview/wrapper/create'; + + $blacklisted_softwares_mac = isset($quizaccess_proctor_setting->blacklisted_softwares_mac) + ? array_filter((array) $quizaccess_proctor_setting->blacklisted_softwares_mac, function($item) { + return !empty($item); + }) + : []; + + $blacklisted_softwares_windows = isset($quizaccess_proctor_setting->blacklisted_softwares_win) + ? array_filter((array) $quizaccess_proctor_setting->blacklisted_softwares_win, function($item) { + return !empty($item); + }) + : []; + + $data = array( + 'session_external_id' => $proctoring_payload->session_id, + 'attendee_external_id' => $proctoring_payload->profile_id, + 'redirect_url' => $PAGE->url->__toString(), + 'expiry' => date(DATE_ISO8601, $quiz->timeclose == 0 ? strtotime("+3 days") : $quiz->timeclose), + 'is_secure_browser' => isset($quizaccess_proctor_setting->tsbenabled) ? boolval($quizaccess_proctor_setting->tsbenabled) : false, + "secure_browser" => [ + "blacklisted_softwares_mac" => $blacklisted_softwares_mac, + "blacklisted_softwares_windows" => $blacklisted_softwares_windows, + "is_record_screen" => isset($quizaccess_proctor_setting->sb_content_protection) ? boolval($quizaccess_proctor_setting->sb_content_protection) : false, + "is_minimize" => isset($quizaccess_proctor_setting->sb_kiosk_mode) ? boolval($quizaccess_proctor_setting->sb_kiosk_mode) : false, + ], + ); + + try { + $curl->setHeader(array('Content-Type: application/json', 'Authorization: Bearer ' . $auth_token)); + $response = $curl->post($url, json_encode($data)); + $decoded_response = json_decode($response, false); + return $decoded_response; + } catch (\Throwable $err) { + self::capture_error($err); + } + } -private static function generate_auth_token($api_base_url, $payload) + + private static function generate_auth_token($api_base_url, $payload) { $curl = new \curl(); $headers = array('Content-Type: application/json'); @@ -115,7 +171,7 @@ private static function generate_auth_token($api_base_url, $payload) private static function capture_error(\Throwable $err) { - \Sentry\init(['dsn' => 'https://61facdc5414c4c73ab2b17fe902bf9ba@o286634.ingest.sentry.io/5304587']); + \Sentry\init(['dsn' => 'https://577c4f60f7bd37671bdd8ad626d63a7d@sentry.talview.org/149']); \Sentry\captureException($err); } @@ -148,6 +204,21 @@ public static function insert_tracking() $attempt = $attempt->attempt; } $template->current_attempt = $attempt; + $quizaccess_proctor_setting = $DB->get_record('quizaccess_proctor', array('quizid' => $quiz->id)); + if ($quizaccess_proctor_setting) { + $template->session_type = $quizaccess_proctor_setting->proctortype; + } else { + $template->session_type = "ai_proctor"; + } + $template->session_id = $template->session_type === "live_proctor" ? $quiz->id.'-'.$USER->id : $quiz->id.'-'.$USER->id.'-'.$attempt; + if (strpos($PAGE->url, ('mod/quiz/attempt')) && + $quizaccess_proctor_setting && + $quizaccess_proctor_setting->proctortype == 'noproctor' && + $quizaccess_proctor_setting->tsbenabled && + strpos($_SERVER ['HTTP_USER_AGENT'], "Proview-SB") === FALSE) { + self::redirect_to_wrapper($template, $quiz, $quizaccess_proctor_setting); + return; + } if (strpos($PAGE->url, ('mod/quiz/report'))) { $quiz_attempts = $DB->get_records('quiz_attempts', array('quiz' => $quiz->id)); @@ -160,6 +231,7 @@ public static function insert_tracking() $template->attempts = json_encode($quiz_attempts); } } + if ($pageinfo && !empty($template->token)) { // The templates only contains a "{js}" block; so we don't care about // the output; only that the $PAGE->requires are filled. diff --git a/classes/local/injector.php b/classes/local/injector.php index 39e291c..fe88bc6 100644 --- a/classes/local/injector.php +++ b/classes/local/injector.php @@ -77,11 +77,15 @@ public static function inject() { if ($PAGE->cm) { $quiz = $DB->get_record('quiz', array('id' => $PAGE->cm->instance)); $quizaccess_proctor_setting = $DB->get_record('quizaccess_proctor', array('quizid' => $quiz->id)); + //Logic for launching Secure Browser without Proctoring Starts if ((!$quizaccess_proctor_setting) || - ($quizaccess_proctor_setting && $quizaccess_proctor_setting->proctortype == 'noproctor')) { + ($quizaccess_proctor_setting && $quizaccess_proctor_setting->proctortype == 'noproctor' && $quizaccess_proctor_setting->tsbenabled)) { + $t = new api\tracker(); + $t::insert_tracking(); self::inject_password($PAGE, $quiz); return; } + //Logic for launching Secure Browser without Proctoring Ends } // Logic for enabling proview for course level and quiz level ends. @@ -126,7 +130,7 @@ public static function inject() { $t::insert_tracking(); return; } catch (\Throwable $error) { - \Sentry\init(['dsn' => 'https://61facdc5414c4c73ab2b17fe902bf9ba@o286634.ingest.sentry.io/5304587' ]); + \Sentry\init(['dsn' => 'https://577c4f60f7bd37671bdd8ad626d63a7d@sentry.talview.org/149' ]); \Sentry\captureException($error); die; ?> diff --git a/datastore.php b/datastore.php index a78e28d..2784801 100644 --- a/datastore.php +++ b/datastore.php @@ -89,6 +89,15 @@ $template->profile_id = $USER->id; $template->instructions = $quizaccess_proctor_setting->instructions; $template->reference_link= $quizaccess_proctor_setting->reference_link; + if ($quizaccess_proctor_setting->tsbenabled === "1" ) { + $template->tsb_enabled = true; + $template->sb_blacklisted_software_windows= isset($quizaccess_proctor_setting->blacklisted_softwares_win) ? $quizaccess_proctor_setting->blacklisted_softwares_win : ''; + $template->sb_blacklisted_software_mac= isset($quizaccess_proctor_setting->blacklisted_softwares_mac) ? $quizaccess_proctor_setting->blacklisted_softwares_mac : ''; + $template->minimize_permitted= isset($quizaccess_proctor_setting->sb_kiosk_mode) ? !boolval($quizaccess_proctor_setting->sb_kiosk_mode) : true; + $template->screen_protection= isset($quizaccess_proctor_setting->sb_content_protection) ? boolval($quizaccess_proctor_setting->sb_content_protection) : false; + }else{ + $template->tsb_enabled = false; + } $template->session_id = $template->session_type === "live_proctor" ? $quizid.'-'.$USER->id : $quizid.'-'.$USER->id.'-'.$attempt; // Do not append attempt number for live proctoring. Re-attempting same quiz not supported in live proctoring. $template->proview_url = trim(get_config('local_proview', 'proview_url')); $template->token = trim(get_config('local_proview', 'token')); diff --git a/frame.php b/frame.php index 8ea05fe..4695e6b 100644 --- a/frame.php +++ b/frame.php @@ -57,7 +57,7 @@