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