-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from talview/add_additional_secure_browser_co…
…nfigurations Add additional secure browser configurations
- Loading branch information
Showing
6 changed files
with
142 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 "<script> window.location='$wrapper_response->signed_url';</script>"; | ||
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://[email protected].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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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://[email protected].sentry.io/5304587' ]); | ||
\Sentry\init(['dsn' => 'https://577c4f60f7bd37671bdd8ad626d63a7d@sentry.talview.org/149' ]); | ||
\Sentry\captureException($error); | ||
die; | ||
?> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ | |
<script> | ||
var childOrigin = '*'; | ||
Sentry.init({ | ||
dsn: 'https://[email protected].sentry.io/5304587' | ||
dsn: 'https://577c4f60f7bd37671bdd8ad626d63a7d@sentry.talview.org/149' | ||
}); | ||
// Defining function for event handling on postMessage from any window | ||
function receiveMessage(event) { | ||
|
@@ -84,17 +84,20 @@ function receiveMessage(event) { | |
|
||
|
||
function startProview( | ||
authToken, | ||
profileId, | ||
session, | ||
session_type = "ai_proctor", | ||
proview_url, | ||
authToken, | ||
profileId, | ||
session, | ||
session_type, | ||
proview_url, | ||
additionalInstruction, | ||
reference_link, | ||
proview_playback_url, | ||
skipHardwareTest, | ||
previewStyle, | ||
clear) { | ||
blacklistedSoftwaresWindows, | ||
blacklistedSoftwaresMac, | ||
isScreenProtectionEnabled, | ||
minimizeOption, | ||
tsbenabled | ||
) { | ||
const referenceLinksArray = reference_link.match(/\[([^\]]+)\]\(([^)]+)\)/g)?.map(markdownLink => { | ||
const match = markdownLink.match(/\[([^\]]+)\]\(([^)]+)\)/); | ||
if (match) { | ||
|
@@ -117,9 +120,14 @@ function startProview( | |
session_type: session_type, | ||
additionalInstruction: additionalInstruction, | ||
referenceLinks: JSON.stringify(referenceLinksArray), | ||
clear: clear || false, | ||
skipHardwareTest: skipHardwareTest || false, | ||
previewStyle: previewStyle || 'position: fixed; bottom: 0px;', | ||
clear: false, | ||
skipHardwareTest: false, | ||
previewStyle: 'position: fixed; bottom: 0px;', | ||
enforceTSB: tsbenabled, | ||
blacklistedSoftwaresWindows: blacklistedSoftwaresWindows, | ||
blacklistedSoftwaresMac: blacklistedSoftwaresMac, | ||
isScreenProtectionEnabled: isScreenProtectionEnabled, | ||
minimizeOption: minimizeOption, | ||
initCallback: createCallback(proview_playback_url, profileId, session_type)/* onProviewStart */ | ||
}); | ||
} | ||
|
@@ -220,7 +228,21 @@ function run(){ | |
response=xmlhttp.responseText; | ||
response=JSON.parse(response); | ||
window.quizPassword = response.quiz_password; | ||
startProview(response.token, response.profile_id, response.session_id, response.session_type, response.proview_url, response.instructions, response.reference_link, response.proview_playback_url); | ||
startProview( | ||
response.token, | ||
response.profile_id, | ||
response.session_id, | ||
response.session_type, | ||
response.proview_url, | ||
response.instructions, | ||
response.reference_link, | ||
response.proview_playback_url, | ||
response.sb_blacklisted_software_windows, | ||
response.sb_blacklisted_software_mac, | ||
response.screen_protection, | ||
response.minimize_permitted, | ||
response.tsb_enabled | ||
); | ||
} | ||
} | ||
xmlhttp.open("GET", "datastore.php?quiz_id=" + urlParams.get('quizId') + "&sesskey=" + "<?php echo $sesskey?>" , true); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters