- if($dfrn_id != '*') {
- // initial communication from external contact
- $hash = random_string();
-
- $status = 0;
-
- $r = q("DELETE FROM `challenge` WHERE `expire` < " . intval(time()));
-
- $r = q("INSERT INTO `challenge` ( `challenge`, `dfrn-id`, `expire` , `type`, `last_update` )
- VALUES( '%s', '%s', '%s', '%s', '%s' ) ",
- dbesc($hash),
- dbesc(notags(trim($_GET['dfrn_id']))),
- intval(time() + 60 ),
- dbesc($type),
- dbesc($last_update)
- );
-
- $r = q("SELECT * FROM `contact` WHERE `issued-id` = '%s' AND `blocked` = 0 LIMIT 1",
- dbesc($_GET['dfrn_id']));
- if((! count($r)) || (! strlen($r[0]['prvkey'])))
- $status = 1;
-
- $challenge = '';
-
- openssl_private_encrypt($hash,$challenge,$r[0]['prvkey']);
- $challenge = bin2hex($challenge);
- echo '<?xml version="1.0" encoding="UTF-8"?><dfrn_poll><status>' .$status . '</status><dfrn_id>' . $_GET['dfrn_id'] . '</dfrn_id>'
- . '<challenge>' . $challenge . '</challenge></dfrn_poll>' . "\r\n" ;
- session_write_close();
- exit;
- }