]> git.mxchange.org Git - friendica.git/blob - mod/dfrn_poll.php
Update "storage" console command
[friendica.git] / mod / dfrn_poll.php
1 <?php
2
3 /**
4  * @file mod/dfrn_poll.php
5  */
6
7 use Friendica\App;
8 use Friendica\Core\Config;
9 use Friendica\Core\L10n;
10 use Friendica\Core\Logger;
11 use Friendica\Core\System;
12 use Friendica\Database\DBA;
13 use Friendica\Module\Login;
14 use Friendica\Protocol\DFRN;
15 use Friendica\Protocol\OStatus;
16 use Friendica\Util\Network;
17 use Friendica\Util\Strings;
18 use Friendica\Util\XML;
19
20 function dfrn_poll_init(App $a)
21 {
22         Login::sessionAuth();
23
24         $dfrn_id         = defaults($_GET, 'dfrn_id'        , '');
25         $type            = defaults($_GET, 'type'           , 'data');
26         $last_update     = defaults($_GET, 'last_update'    , '');
27         $destination_url = defaults($_GET, 'destination_url', '');
28         $challenge       = defaults($_GET, 'challenge'      , '');
29         $sec             = defaults($_GET, 'sec'            , '');
30         $dfrn_version    = (float) defaults($_GET, 'dfrn_version'   , 2.0);
31         $perm            = defaults($_GET, 'perm'           , 'r');
32         $quiet                   = !empty($_GET['quiet']);
33
34         // Possibly it is an OStatus compatible server that requests a user feed
35         $user_agent = defaults($_SERVER, 'HTTP_USER_AGENT', '');
36         if (($a->argc > 1) && ($dfrn_id == '') && !strstr($user_agent, 'Friendica')) {
37                 $nickname = $a->argv[1];
38                 header("Content-type: application/atom+xml");
39                 echo OStatus::feed($nickname, $last_update, 10);
40                 exit();
41         }
42
43         $direction = -1;
44
45         if (strpos($dfrn_id, ':') == 1) {
46                 $direction = intval(substr($dfrn_id, 0, 1));
47                 $dfrn_id = substr($dfrn_id, 2);
48         }
49
50         $hidewall = false;
51
52         if (($dfrn_id === '') && empty($_POST['dfrn_id'])) {
53                 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
54                         System::httpExit(403);
55                 }
56
57                 $user = '';
58                 if ($a->argc > 1) {
59                         $r = q("SELECT `hidewall`,`nickname` FROM `user` WHERE `user`.`nickname` = '%s' LIMIT 1",
60                                 DBA::escape($a->argv[1])
61                         );
62                         if (!$r) {
63                                 System::httpExit(404);
64                         }
65
66                         $hidewall = ($r[0]['hidewall'] && !local_user());
67
68                         $user = $r[0]['nickname'];
69                 }
70
71                 Logger::log('dfrn_poll: public feed request from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $user);
72                 header("Content-type: application/atom+xml");
73                 echo DFRN::feed('', $user, $last_update, 0, $hidewall);
74                 exit();
75         }
76
77         if (($type === 'profile') && (!strlen($sec))) {
78                 $sql_extra = '';
79                 switch ($direction) {
80                         case -1:
81                                 $sql_extra = sprintf(" AND ( `dfrn-id` = '%s' OR `issued-id` = '%s' ) ", DBA::escape($dfrn_id), DBA::escape($dfrn_id));
82                                 $my_id = $dfrn_id;
83                                 break;
84                         case 0:
85                                 $sql_extra = sprintf(" AND `issued-id` = '%s' AND `duplex` = 1 ", DBA::escape($dfrn_id));
86                                 $my_id = '1:' . $dfrn_id;
87                                 break;
88                         case 1:
89                                 $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", DBA::escape($dfrn_id));
90                                 $my_id = '0:' . $dfrn_id;
91                                 break;
92                         default:
93                                 $a->internalRedirect();
94                                 break; // NOTREACHED
95                 }
96
97                 $r = q("SELECT `contact`.*, `user`.`username`, `user`.`nickname`
98                         FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
99                         WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0
100                         AND `user`.`nickname` = '%s' $sql_extra LIMIT 1",
101                         DBA::escape($a->argv[1])
102                 );
103
104                 if (DBA::isResult($r)) {
105                         $s = Network::fetchUrl($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check');
106
107                         Logger::log("dfrn_poll: old profile returns " . $s, Logger::DATA);
108
109                         if (strlen($s)) {
110                                 $xml = XML::parseString($s);
111
112                                 if ((int)$xml->status === 1) {
113                                         $_SESSION['authenticated'] = 1;
114                                         if (empty($_SESSION['remote'])) {
115                                                 $_SESSION['remote'] = [];
116                                         }
117
118                                         $_SESSION['remote'][] = ['cid' => $r[0]['id'], 'uid' => $r[0]['uid'], 'url' => $r[0]['url']];
119
120                                         $_SESSION['visitor_id'] = $r[0]['id'];
121                                         $_SESSION['visitor_home'] = $r[0]['url'];
122                                         $_SESSION['visitor_handle'] = $r[0]['addr'];
123                                         $_SESSION['visitor_visiting'] = $r[0]['uid'];
124                                         $_SESSION['my_url'] = $r[0]['url'];
125                                         if (!$quiet) {
126                                                 info(L10n::t('%1$s welcomes %2$s', $r[0]['username'], $r[0]['name']) . EOL);
127                                         }
128
129                                         // Visitors get 1 day session.
130                                         $session_id = session_id();
131                                         $expire = time() + 86400;
132                                         q("UPDATE `session` SET `expire` = '%s' WHERE `sid` = '%s'",
133                                                 DBA::escape($expire),
134                                                 DBA::escape($session_id)
135                                         );
136                                 }
137                         }
138
139                         $profile = (count($r) > 0 && isset($r[0]['nickname']) ? $r[0]['nickname'] : '');
140                         if (!empty($destination_url)) {
141                                 System::externalRedirect($destination_url);
142                         } else {
143                                 $a->internalRedirect('profile/' . $profile);
144                         }
145                 }
146                 $a->internalRedirect();
147         }
148
149         if ($type === 'profile-check' && $dfrn_version < 2.2) {
150                 if ((strlen($challenge)) && (strlen($sec))) {
151                         DBA::delete('profile_check', ["`expire` < ?", time()]);
152                         $r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1",
153                                 DBA::escape($sec)
154                         );
155                         if (!DBA::isResult($r)) {
156                                 System::xmlExit(3, 'No ticket');
157                                 // NOTREACHED
158                         }
159
160                         $orig_id = $r[0]['dfrn_id'];
161                         if (strpos($orig_id, ':')) {
162                                 $orig_id = substr($orig_id, 2);
163                         }
164
165                         $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
166                                 intval($r[0]['cid'])
167                         );
168                         if (!DBA::isResult($c)) {
169                                 System::xmlExit(3, 'No profile');
170                         }
171
172                         $contact = $c[0];
173
174                         $sent_dfrn_id = hex2bin($dfrn_id);
175                         $challenge = hex2bin($challenge);
176
177                         $final_dfrn_id = '';
178
179                         if (($contact['duplex']) && strlen($contact['prvkey'])) {
180                                 openssl_private_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['prvkey']);
181                                 openssl_private_decrypt($challenge, $decoded_challenge, $contact['prvkey']);
182                         } else {
183                                 openssl_public_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['pubkey']);
184                                 openssl_public_decrypt($challenge, $decoded_challenge, $contact['pubkey']);
185                         }
186
187                         $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
188
189                         if (strpos($final_dfrn_id, ':') == 1) {
190                                 $final_dfrn_id = substr($final_dfrn_id, 2);
191                         }
192
193                         if ($final_dfrn_id != $orig_id) {
194                                 Logger::log('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, Logger::DEBUG);
195                                 // did not decode properly - cannot trust this site
196                                 System::xmlExit(3, 'Bad decryption');
197                         }
198
199                         header("Content-type: text/xml");
200                         echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><dfrn_poll><status>0</status><challenge>$decoded_challenge</challenge><sec>$sec</sec></dfrn_poll>";
201                         exit();
202                         // NOTREACHED
203                 } else {
204                         // old protocol
205                         switch ($direction) {
206                                 case 1:
207                                         $dfrn_id = '0:' . $dfrn_id;
208                                         break;
209                                 case 0:
210                                         $dfrn_id = '1:' . $dfrn_id;
211                                         break;
212                                 default:
213                                         break;
214                         }
215
216                         DBA::delete('profile_check', ["`expire` < ?", time()]);
217                         $r = q("SELECT * FROM `profile_check` WHERE `dfrn_id` = '%s' ORDER BY `expire` DESC",
218                                 DBA::escape($dfrn_id));
219                         if (DBA::isResult($r)) {
220                                 System::xmlExit(1);
221                                 return; // NOTREACHED
222                         }
223                         System::xmlExit(0);
224                         return; // NOTREACHED
225                 }
226         }
227 }
228
229 function dfrn_poll_post(App $a)
230 {
231         $dfrn_id      = defaults($_POST, 'dfrn_id'  , '');
232         $challenge    = defaults($_POST, 'challenge', '');
233         $url          = defaults($_POST, 'url'      , '');
234         $sec          = defaults($_POST, 'sec'      , '');
235         $ptype        = defaults($_POST, 'type'     , '');
236         $perm         = defaults($_POST, 'perm'     , 'r');
237         $dfrn_version = !empty($_POST['dfrn_version']) ? (float) $_POST['dfrn_version'] : 2.0;
238
239         if ($ptype === 'profile-check') {
240                 if (strlen($challenge) && strlen($sec)) {
241                         Logger::log('dfrn_poll: POST: profile-check');
242
243                         DBA::delete('profile_check', ["`expire` < ?", time()]);
244                         $r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1",
245                                 DBA::escape($sec)
246                         );
247                         if (!DBA::isResult($r)) {
248                                 System::xmlExit(3, 'No ticket');
249                                 // NOTREACHED
250                         }
251
252                         $orig_id = $r[0]['dfrn_id'];
253                         if (strpos($orig_id, ':')) {
254                                 $orig_id = substr($orig_id, 2);
255                         }
256
257                         $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
258                                 intval($r[0]['cid'])
259                         );
260                         if (!DBA::isResult($c)) {
261                                 System::xmlExit(3, 'No profile');
262                         }
263
264                         $contact = $c[0];
265
266                         $sent_dfrn_id = hex2bin($dfrn_id);
267                         $challenge = hex2bin($challenge);
268
269                         $final_dfrn_id = '';
270
271                         if ($contact['duplex'] && strlen($contact['prvkey'])) {
272                                 openssl_private_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['prvkey']);
273                                 openssl_private_decrypt($challenge, $decoded_challenge, $contact['prvkey']);
274                         } else {
275                                 openssl_public_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['pubkey']);
276                                 openssl_public_decrypt($challenge, $decoded_challenge, $contact['pubkey']);
277                         }
278
279                         $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
280
281                         if (strpos($final_dfrn_id, ':') == 1) {
282                                 $final_dfrn_id = substr($final_dfrn_id, 2);
283                         }
284
285                         if ($final_dfrn_id != $orig_id) {
286                                 Logger::log('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, Logger::DEBUG);
287                                 // did not decode properly - cannot trust this site
288                                 System::xmlExit(3, 'Bad decryption');
289                         }
290
291                         header("Content-type: text/xml");
292                         echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><dfrn_poll><status>0</status><challenge>$decoded_challenge</challenge><sec>$sec</sec></dfrn_poll>";
293                         exit();
294                         // NOTREACHED
295                 }
296         }
297
298         $direction = -1;
299         if (strpos($dfrn_id, ':') == 1) {
300                 $direction = intval(substr($dfrn_id, 0, 1));
301                 $dfrn_id = substr($dfrn_id, 2);
302         }
303
304         $r = q("SELECT * FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s' LIMIT 1",
305                 DBA::escape($dfrn_id),
306                 DBA::escape($challenge)
307         );
308
309         if (!DBA::isResult($r)) {
310                 exit();
311         }
312
313         $type = $r[0]['type'];
314         $last_update = $r[0]['last_update'];
315
316         DBA::delete('challenge', ['dfrn-id' => $dfrn_id, 'challenge' => $challenge]);
317
318         $sql_extra = '';
319         switch ($direction) {
320                 case -1:
321                         $sql_extra = sprintf(" AND `issued-id` = '%s' ", DBA::escape($dfrn_id));
322                         $my_id = $dfrn_id;
323                         break;
324                 case 0:
325                         $sql_extra = sprintf(" AND `issued-id` = '%s' AND `duplex` = 1 ", DBA::escape($dfrn_id));
326                         $my_id = '1:' . $dfrn_id;
327                         break;
328                 case 1:
329                         $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", DBA::escape($dfrn_id));
330                         $my_id = '0:' . $dfrn_id;
331                         break;
332                 default:
333                         $a->internalRedirect();
334                         break; // NOTREACHED
335         }
336
337         $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 $sql_extra LIMIT 1");
338         if (!DBA::isResult($r)) {
339                 exit();
340         }
341
342         $contact = $r[0];
343         $owner_uid = $r[0]['uid'];
344         $contact_id = $r[0]['id'];
345
346         if ($type === 'reputation' && strlen($url)) {
347                 $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
348                         DBA::escape($url),
349                         intval($owner_uid)
350                 );
351                 $reputation = 0;
352                 $text = '';
353
354                 if (DBA::isResult($r)) {
355                         $reputation = $r[0]['rating'];
356                         $text = $r[0]['reason'];
357
358                         if ($r[0]['id'] == $contact_id) { // inquiring about own reputation not allowed
359                                 $reputation = 0;
360                                 $text = '';
361                         }
362                 }
363
364                 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
365                 <reputation>
366                         <url>$url</url>
367                         <rating>$reputation</rating>
368                         <description>$text</description>
369                 </reputation>
370                 ";
371                 exit();
372                 // NOTREACHED
373         } else {
374                 // Update the writable flag if it changed
375                 Logger::log('dfrn_poll: post request feed: ' . print_r($_POST, true), Logger::DATA);
376                 if ($dfrn_version >= 2.21) {
377                         if ($perm === 'rw') {
378                                 $writable = 1;
379                         } else {
380                                 $writable = 0;
381                         }
382
383                         if ($writable != $contact['writable']) {
384                                 q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d",
385                                         intval($writable),
386                                         intval($contact_id)
387                                 );
388                         }
389                 }
390
391                 header("Content-type: application/atom+xml");
392                 $o = DFRN::feed($dfrn_id, $a->argv[1], $last_update, $direction);
393                 echo $o;
394                 exit();
395         }
396 }
397
398 function dfrn_poll_content(App $a)
399 {
400         $dfrn_id         = defaults($_GET, 'dfrn_id'        , '');
401         $type            = defaults($_GET, 'type'           , 'data');
402         $last_update     = defaults($_GET, 'last_update'    , '');
403         $destination_url = defaults($_GET, 'destination_url', '');
404         $sec             = defaults($_GET, 'sec'            , '');
405         $dfrn_version    = !empty($_GET['dfrn_version'])    ? (float) $_GET['dfrn_version'] : 2.0;
406         $quiet           = !empty($_GET['quiet']);
407
408         $direction = -1;
409         if (strpos($dfrn_id, ':') == 1) {
410                 $direction = intval(substr($dfrn_id, 0, 1));
411                 $dfrn_id = substr($dfrn_id, 2);
412         }
413
414         if ($dfrn_id != '') {
415                 // initial communication from external contact
416                 $hash = Strings::getRandomHex();
417
418                 $status = 0;
419
420                 DBA::delete('challenge', ["`expire` < ?", time()]);
421
422                 if ($type !== 'profile') {
423                         $r = q("INSERT INTO `challenge` ( `challenge`, `dfrn-id`, `expire` , `type`, `last_update` )
424                                 VALUES( '%s', '%s', '%s', '%s', '%s' ) ",
425                                 DBA::escape($hash),
426                                 DBA::escape($dfrn_id),
427                                 intval(time() + 60 ),
428                                 DBA::escape($type),
429                                 DBA::escape($last_update)
430                         );
431                 }
432
433                 $sql_extra = '';
434                 switch ($direction) {
435                         case -1:
436                                 if ($type === 'profile') {
437                                         $sql_extra = sprintf(" AND (`dfrn-id` = '%s' OR `issued-id` = '%s') ", DBA::escape($dfrn_id), DBA::escape($dfrn_id));
438                                 } else {
439                                         $sql_extra = sprintf(" AND `issued-id` = '%s' ", DBA::escape($dfrn_id));
440                                 }
441
442                                 $my_id = $dfrn_id;
443                                 break;
444                         case 0:
445                                 $sql_extra = sprintf(" AND `issued-id` = '%s' AND `duplex` = 1 ", DBA::escape($dfrn_id));
446                                 $my_id = '1:' . $dfrn_id;
447                                 break;
448                         case 1:
449                                 $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", DBA::escape($dfrn_id));
450                                 $my_id = '0:' . $dfrn_id;
451                                 break;
452                         default:
453                                 $a->internalRedirect();
454                                 break; // NOTREACHED
455                 }
456
457                 $nickname = $a->argv[1];
458
459                 $r = q("SELECT `contact`.*, `user`.`username`, `user`.`nickname`
460                         FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
461                         WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0
462                         AND `user`.`nickname` = '%s' $sql_extra LIMIT 1",
463                         DBA::escape($nickname)
464                 );
465                 if (DBA::isResult($r)) {
466                         $challenge = '';
467                         $encrypted_id = '';
468                         $id_str = $my_id . '.' . mt_rand(1000, 9999);
469
470                         if (($r[0]['duplex'] && strlen($r[0]['pubkey'])) || !strlen($r[0]['prvkey'])) {
471                                 openssl_public_encrypt($hash, $challenge, $r[0]['pubkey']);
472                                 openssl_public_encrypt($id_str, $encrypted_id, $r[0]['pubkey']);
473                         } else {
474                                 openssl_private_encrypt($hash, $challenge, $r[0]['prvkey']);
475                                 openssl_private_encrypt($id_str, $encrypted_id, $r[0]['prvkey']);
476                         }
477
478                         $challenge = bin2hex($challenge);
479                         $encrypted_id = bin2hex($encrypted_id);
480                 } else {
481                         $status = 1;
482                         $challenge = '';
483                         $encrypted_id = '';
484                 }
485
486                 if (($type === 'profile') && (strlen($sec))) {
487                         // heluecht: I don't know why we don't fail immediately when the user or contact hadn't been found.
488                         // Since it doesn't make sense to continue from this point on, we now fail here. This should be safe.
489                         if (!DBA::isResult($r)) {
490                                 System::httpExit(404, ["title" => L10n::t('Page not found.')]);
491                         }
492
493                         // URL reply
494                         if ($dfrn_version < 2.2) {
495                                 $s = Network::fetchUrl($r[0]['poll']
496                                         . '?dfrn_id=' . $encrypted_id
497                                         . '&type=profile-check'
498                                         . '&dfrn_version=' . DFRN_PROTOCOL_VERSION
499                                         . '&challenge=' . $challenge
500                                         . '&sec=' . $sec
501                                 );
502                         } else {
503                                 $s = Network::post($r[0]['poll'], [
504                                         'dfrn_id' => $encrypted_id,
505                                         'type' => 'profile-check',
506                                         'dfrn_version' => DFRN_PROTOCOL_VERSION,
507                                         'challenge' => $challenge,
508                                         'sec' => $sec
509                                 ])->getBody();
510                         }
511
512                         Logger::log("dfrn_poll: sec profile: " . $s, Logger::DATA);
513
514                         if (strlen($s) && strstr($s, '<?xml')) {
515                                 $xml = XML::parseString($s);
516
517                                 Logger::log('dfrn_poll: profile: parsed xml: ' . print_r($xml, true), Logger::DATA);
518
519                                 Logger::log('dfrn_poll: secure profile: challenge: ' . $xml->challenge . ' expecting ' . $hash);
520                                 Logger::log('dfrn_poll: secure profile: sec: ' . $xml->sec . ' expecting ' . $sec);
521
522                                 if (((int) $xml->status == 0) && ($xml->challenge == $hash) && ($xml->sec == $sec)) {
523                                         $_SESSION['authenticated'] = 1;
524                                         if (empty($_SESSION['remote'])) {
525                                                 $_SESSION['remote'] = [];
526                                         }
527
528                                         $_SESSION['remote'][] = ['cid' => $r[0]['id'], 'uid' => $r[0]['uid'], 'url' => $r[0]['url']];
529                                         $_SESSION['visitor_id'] = $r[0]['id'];
530                                         $_SESSION['visitor_home'] = $r[0]['url'];
531                                         $_SESSION['visitor_visiting'] = $r[0]['uid'];
532                                         $_SESSION['my_url'] = $r[0]['url'];
533                                         if (!$quiet) {
534                                                 info(L10n::t('%1$s welcomes %2$s', $r[0]['username'], $r[0]['name']) . EOL);
535                                         }
536
537                                         // Visitors get 1 day session.
538                                         $session_id = session_id();
539                                         $expire = time() + 86400;
540                                         q("UPDATE `session` SET `expire` = '%s' WHERE `sid` = '%s'",
541                                                 DBA::escape($expire),
542                                                 DBA::escape($session_id)
543                                         );
544                                 }
545                         }
546
547                         $profile = ((DBA::isResult($r) && $r[0]['nickname']) ? $r[0]['nickname'] : $nickname);
548
549                         switch ($destination_url) {
550                                 case 'profile':
551                                         $a->internalRedirect('profile/' . $profile . '?f=&tab=profile');
552                                         break;
553                                 case 'photos':
554                                         $a->internalRedirect('photos/' . $profile);
555                                         break;
556                                 case 'status':
557                                 case '':
558                                         $a->internalRedirect('profile/' . $profile);
559                                         break;
560                                 default:
561                                         $appendix = (strstr($destination_url, '?') ? '&f=&redir=1' : '?f=&redir=1');
562                                         $a->redirect($destination_url . $appendix);
563                                         break;
564                         }
565                         // NOTREACHED
566                 } else {
567                         // XML reply
568                         header("Content-type: text/xml");
569                         echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n"
570                                 . '<dfrn_poll>' . "\r\n"
571                                 . "\t" . '<status>' . $status . '</status>' . "\r\n"
572                                 . "\t" . '<dfrn_version>' . DFRN_PROTOCOL_VERSION . '</dfrn_version>' . "\r\n"
573                                 . "\t" . '<dfrn_id>' . $encrypted_id . '</dfrn_id>' . "\r\n"
574                                 . "\t" . '<challenge>' . $challenge . '</challenge>' . "\r\n"
575                                 . '</dfrn_poll>' . "\r\n";
576                         exit();
577                         // NOTREACHED
578                 }
579         }
580 }