+ if($dfrn_version < 2.2) {
+ $s = fetch_url($r[0]['poll']
+ . '?dfrn_id=' . $encrypted_id
+ . '&type=profile-check'
+ . '&dfrn_version=' . DFRN_PROTOCOL_VERSION
+ . '&challenge=' . $challenge
+ . '&sec=' . $sec
+ );
+ }
+ else {
+ $s = post_url($r[0]['poll'], array(
+ 'dfrn_id' => $encrypted_id,
+ 'type' => 'profile-check',
+ 'dfrn_version' => DFRN_PROTOCOL_VERSION,
+ 'challenge' => $challenge,
+ 'sec' => $sec
+ ));
+ }
+
+ $profile = ((count($r) && $r[0]['nickname']) ? $r[0]['nickname'] : $nickname);
+
+ switch($destination_url) {
+ case 'profile':
+ $dest = $a->get_baseurl() . '/profile/' . $profile . '?f=&tab=profile';
+ break;
+ case 'photos':
+ $dest = $a->get_baseurl() . '/photos/' . $profile;
+ break;
+ case 'status':
+ case '':
+ $dest = $a->get_baseurl() . '/profile/' . $profile;
+ break;
+ default:
+ $dest = $destination_url . '?f=&redir=1';
+ break;
+ }
+
+ logger("dfrn_poll: sec profile: " . $s, LOGGER_DATA);
+
+ if(strlen($s) && strstr($s,'<?xml')) {
+
+ $xml = parse_xml_string($s);
+
+ logger('dfrn_poll: profile: parsed xml: ' . print_r($xml,true), LOGGER_DATA);
+
+ logger('dfrn_poll: secure profile: challenge: ' . $xml->challenge . ' expecting ' . $hash);
+ logger('dfrn_poll: secure profile: sec: ' . $xml->sec . ' expecting ' . $sec);
+
+
+ if(((int) $xml->status == 0) && ($xml->challenge == $hash) && ($xml->sec == $sec)) {
+ $_SESSION['authenticated'] = 1;
+ if(! x($_SESSION,'remote'))
+ $_SESSION['remote'] = array();
+ $_SESSION['remote'][] = array('cid' => $r[0]['id'],'uid' => $r[0]['uid'],'url' => $r[0]['url']);
+ $_SESSION['visitor_id'] = $r[0]['id'];
+ $_SESSION['visitor_home'] = $r[0]['url'];
+ $_SESSION['visitor_visiting'] = $r[0]['uid'];
+ if(!$quiet)
+ info( sprintf(t('%1$s welcomes %2$s'), $r[0]['username'] , $r[0]['name']) . EOL);
+ // Visitors get 1 day session.
+ $session_id = session_id();
+ $expire = time() + 86400;
+ q("UPDATE `session` SET `expire` = '%s' WHERE `sid` = '%s'",
+ dbesc($expire),
+ dbesc($session_id)
+ );
+ }
+
+ goaway($dest);
+ }
+ goaway($dest);
+ // NOTREACHED
+
+ }
+ else {
+ // XML reply
+ header("Content-type: text/xml");
+ echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n"
+ . '<dfrn_poll>' . "\r\n"
+ . "\t" . '<status>' . $status . '</status>' . "\r\n"
+ . "\t" . '<dfrn_version>' . DFRN_PROTOCOL_VERSION . '</dfrn_version>' . "\r\n"
+ . "\t" . '<dfrn_id>' . $encrypted_id . '</dfrn_id>' . "\r\n"
+ . "\t" . '<challenge>' . $challenge . '</challenge>' . "\r\n"
+ . '</dfrn_poll>' . "\r\n" ;
+ killme();
+ // NOTREACHED
+ }
+ }
+}