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