Exemplo n.º 1
0
function solvemedia_check_answer($privkey, $remoteip, $challenge, $response, $hashkey = '')
{
    if ($privkey == null || $privkey == '') {
        die("To use solvemedia you must get an API key from <a href='" . ADCOPY_SIGNUP . "'>" . ADCOPY_SIGNUP . "</a>");
    }
    if ($remoteip == null || $remoteip == '') {
        die("For security reasons, you must pass the remote ip to solvemedia");
    }
    if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
        $adcopy_response = new SolveMediaResponse();
        $adcopy_response->is_valid = false;
        $adcopy_response->error = 'incorrect-solution';
        return $adcopy_response;
    }
    $response = _adcopy_http_post(ADCOPY_VERIFY_SERVER, "/papi/verify", array('privatekey' => $privkey, 'remoteip' => $remoteip, 'challenge' => $challenge, 'response' => $response));
    $answers = explode("\n", $response[1]);
    $adcopy_response = new SolveMediaResponse();
    if (strlen($hashkey)) {
        # validate message authenticator
        $hash = sha1($answers[0] . $challenge . $hashkey);
        if ($hash != $answers[2]) {
            $adcopy_response->is_valid = false;
            $adcopy_response->error = 'hash-fail';
            return $adcopy_response;
        }
    }
    if (trim($answers[0]) == 'true') {
        $adcopy_response->is_valid = true;
    } else {
        $adcopy_response->is_valid = false;
        $adcopy_response->error = $answers[1];
    }
    return $adcopy_response;
}
Exemplo n.º 2
0
/**
 * Calls an HTTP POST function to verify if the user's guess was correct
 * @param string $privkey
 * @param string $remoteip
 * @param string $challenge
 * @param string $response
 * @param string $hashkey
 * @return SolveMediaResponse
 */
function solvemedia_check_answer($privkey, $remoteip, $challenge, $response, $hashkey = '')
{
    if ($privkey == 'Dm.c-mjmNP7Fhz-hKOpNz8l.NAMGp0wO' || $privkey == '' || $privkey == null) {
        // Re-declare the default private key and hash in case of null value
        $privkey = 'Dm.c-mjmNP7Fhz-hKOpNz8l.NAMGp0wO';
        $hashkey = 'nePptHN4rt.-UVLPFScpSuddqdtFdu2N';
        $page_file = basename($_SERVER['PHP_SELF']);
        // Get the file generating the page to figure out what key to assign it
        if ($page_file == "register.php") {
            $privkey = 'RfinGw00jddSv9eqIEo.LDUcZSbSEU6S';
            $hashkey = 'SoR.tNYZtGpSkFrMBrLP2kPrpyiYyQpM';
        } elseif ($page_file == "story.php") {
            $privkey = 'MdwcHqbrYQPcJt0JjXSMrgFwROeLY5Ce';
            $hashkey = 'xRJmWazYhZm6zSrrgdZHHctXUTYK6fZa';
        } elseif ($page_file == "submit.php") {
            $privkey = 'gAilaBopkMs8Bk9R9wx6mhRdl1ljt9Ig';
            $hashkey = 'VH9T8Zr8EeUqUiGWfjZpbkS9u.sGf1cp';
        }
    }
    if ($remoteip == null || $remoteip == '') {
        die("For security reasons, you must pass the remote ip to solvemedia");
    }
    //discard spam submissions
    if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
        $adcopy_response = new SolveMediaResponse();
        $adcopy_response->is_valid = false;
        $adcopy_response->error = 'incorrect-solution';
        return $adcopy_response;
    }
    $response = _adcopy_http_post(ADCOPY_VERIFY_SERVER, "/papi/verify", array('privatekey' => $privkey, 'remoteip' => $remoteip, 'challenge' => $challenge, 'response' => $response));
    $answers = explode("\n", $response[1]);
    $adcopy_response = new SolveMediaResponse();
    if (strlen($hashkey)) {
        # validate message authenticator
        $hash = sha1($answers[0] . $challenge . $hashkey);
        if ($hash != $answers[2]) {
            $adcopy_response->is_valid = false;
            $adcopy_response->error = 'hash-fail';
            return $adcopy_response;
        }
    }
    if (trim($answers[0]) == 'true') {
        $adcopy_response->is_valid = true;
    } else {
        $adcopy_response->is_valid = false;
        $adcopy_response->error = $answers[1];
    }
    return $adcopy_response;
}