Exemple #1
0
function log_return_die($message)
{
    global $_POST;
    if (isset($_POST['launch_presentation_return_url'])) {
        $launch_presentation_return_url = $_POST['launch_presentation_return_url'];
        if (strpos($launch_presentation_return_url, '?') > 0) {
            $launch_presentation_return_url .= '&';
        } else {
            $launch_presentation_return_url .= '?';
        }
        $launch_presentation_return_url .= "status=failure";
        $launch_presentation_return_url .= "&lti_errormsg=" . urlencode($message);
        echo '<p><a href="' . $launch_presentation_return_url . '">Continue to launch_presentation_url</a></p>' . "\n";
    }
    lmsDie($message);
}
echo "<ul>\n";
$toolcount = 0;
foreach ($tools as $tool) {
    $path = str_replace("../", "", $tool);
    // echo("Checking $path ...<br/>\n");
    unset($REGISTER_LTI2);
    require $tool;
    if (isset($REGISTER_LTI2) && is_array($REGISTER_LTI2)) {
        if (isset($REGISTER_LTI2['name']) && isset($REGISTER_LTI2['short_name']) && isset($REGISTER_LTI2['description'])) {
        } else {
            lmsDie("Missing required name, short_name, and description in " . $tool);
        }
        $script = isset($REGISTER_LTI2['script']) ? $REGISTER_LTI2['script'] : "index.php";
        $path = "/" . str_replace("register.php", $script, $path);
        $url = $content_return_url;
        $url .= strpos($url, '?') ? '&' : '?';
        $url .= 'return_type=lti_launch_url&url=';
        $url .= urlencode($CFG->wwwroot . $path);
        $url .= "&title=" . urlencode($REGISTER_LTI2['name']);
        $url .= "&text=" . urlencode($REGISTER_LTI2['name']);
        $url .= "&description=" . urlencode($REGISTER_LTI2['description']);
        echo '<li><a href="' . $url;
        echo '">Select Tool: ' . htmlent_utf8($REGISTER_LTI2['name']) . "</a><br/>";
        echo htmlent_utf8($REGISTER_LTI2['description']) . "</li>\n";
        $toolcount++;
    }
}
echo "</ul>\n";
if ($toolcount < 1) {
    lmsDie("No tools to register..");
}
Exemple #3
0
// an existing key.   So the next few lines of code are really critical.
// And we can neither use INSERT / UPDATE because we cannot add the user_id
// to the unique constraint.
if ($re_register) {
    $retval = $PDOX->queryDie("UPDATE {$CFG->dbprefix}lti_key SET updated_at = NOW(), ack = :ACK,\n            new_secret = :SECRET, new_consumer_profile = :PROFILE\n            WHERE key_sha256 = :SHA and user_id = :UID", array(":SECRET" => $shared_secret, ":PROFILE" => $tc_profile_json, ":UID" => $_SESSION['id'], ":SHA" => $key_sha256, ":ACK" => $ack));
    if (!$retval->success) {
        lmsDie("Unable to UPDATE Registration key {$oauth_consumer_key} " . $retval->errorImplode);
    }
    echo_log("LTI2 Key {$oauth_consumer_key} updated.\n");
    // If we do not have a key, insert one, checking carefully for a failed insert
    // due to a unique constraint violation.  If this insert fails, it is likely
    // a race condition between competing INSERTs for the same key_id
} else {
    $retval = $PDOX->queryDie("INSERT INTO {$CFG->dbprefix}lti_key \n            (key_sha256, key_key, user_id, secret, consumer_profile)\n        VALUES\n            (:SHA, :KEY, :UID, :SECRET, :PROFILE)\n        ON DUPLICATE KEY\n            UPDATE secret = :SECRET, consumer_profile = :PROFILE\n        ", array(":SHA" => $key_sha256, ":KEY" => $oauth_consumer_key, ":UID" => $_SESSION['id'], ":SECRET" => $shared_secret, ":PROFILE" => $tc_profile_json));
    if (!$retval->success) {
        lmsDie("Unable to INSERT Registration key {$oauth_consumer_key} " . $retval->errorImplode);
    }
    echo_log("LTI2 Key {$oauth_consumer_key} inserted.\n");
}
if ($last_http_response == 201 || $last_http_response == 200) {
    echo '<p><a href="' . $launch_presentation_return_url . '">Continue to launch_presentation_url</a></p>' . "\n";
    exit;
}
echo "Registration failed, http code=" . $last_http_response . "\n";
// Check to see if they slid us the base string...
if ($responseObject != null && isset($responseObject->base_string)) {
    $base_string = $responseObject->base_string;
    if (strlen($base_string) > 0 && strlen($LastOAuthBodyBaseString) > 0 && $base_string != $LastOAuthBodyBaseString) {
        $compare = LTI::compareBaseStrings($LastOAuthBodyBaseString, $base_string);
        $OUTPUT->togglePre("Compare Base Strings (ours first)", htmlent_utf8($compare));
    }
Exemple #4
0
<?php

require_once "../../../config.php";
require_once $CFG->dirroot . "/lib/lms_lib.php";
require_once "../locations.php";
$address = isset($_GET['address']) ? $_GET['address'] : false;
header('Content-Type: application/json; charset=utf-8');
if ($address === false) {
    sort($LOCATIONS);
    echo jsonIndent(json_encode($LOCATIONS));
    return;
}
$where = array_search($address, $LOCATIONS);
if ($where === false) {
    http_response_code(400);
    $retval = array('error' => 'Address not found in the list of available locations', 'locations' => $LOCATIONS);
    echo jsonIndent(json_encode($retval));
    return;
}
// Check to see if we already have this in the variable
if ($GEODATA !== false) {
    echo $GEODATA[$address];
    return;
}
lmsDie("DIE: Data failure - please contact the instructor");