]> git.mxchange.org Git - friendica.git/blob - mod/dfrn_notify.php
updated private message notification to use HTML, still need the foreign language...
[friendica.git] / mod / dfrn_notify.php
1 <?php
2
3 require_once('simplepie/simplepie.inc');
4 require_once('include/items.php');
5 function dfrn_notify_post(&$a) {
6
7         $dfrn_id      = ((x($_POST,'dfrn_id'))      ? notags(trim($_POST['dfrn_id']))   : '');
8         $dfrn_version = ((x($_POST,'dfrn_version')) ? (float) $_POST['dfrn_version']    : 2.0);
9         $challenge    = ((x($_POST,'challenge'))    ? notags(trim($_POST['challenge'])) : '');
10         $data         = ((x($_POST,'data'))         ? $_POST['data']                    : '');
11         $key          = ((x($_POST,'key'))          ? $_POST['key']                     : '');
12         $dissolve     = ((x($_POST,'dissolve'))     ? intval($_POST['dissolve'])        :  0);
13
14         $direction = (-1);
15         if(strpos($dfrn_id,':') == 1) {
16                 $direction = intval(substr($dfrn_id,0,1));
17                 $dfrn_id = substr($dfrn_id,2);
18         }
19
20         $r = q("SELECT * FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s' LIMIT 1",
21                 dbesc($dfrn_id),
22                 dbesc($challenge)
23         );
24         if(! count($r)) {
25                 logger('dfrn_notify: could not match challenge to dfrn_id ' . $dfrn_id . ' challenge=' . $challenge);
26                 xml_status(3);
27         }
28
29         $r = q("DELETE FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s' LIMIT 1",
30                 dbesc($dfrn_id),
31                 dbesc($challenge)
32         );
33
34         // find the local user who owns this relationship.
35
36         $sql_extra = '';
37         switch($direction) {
38                 case (-1):
39                         $sql_extra = sprintf(" AND ( `issued-id` = '%s' OR `dfrn-id` = '%s' ) ", dbesc($dfrn_id), dbesc($dfrn_id));
40                         break;
41                 case 0:
42                         $sql_extra = sprintf(" AND `issued-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
43                         break;
44                 case 1:
45                         $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
46                         break;
47                 default:
48                         xml_status(3);
49                         break; // NOTREACHED
50         }
51                  
52
53         $r = q("SELECT  `contact`.*, `contact`.`uid` AS `importer_uid`, 
54                                         `contact`.`pubkey` AS `cpubkey`, 
55                                         `contact`.`prvkey` AS `cprvkey`, 
56                                         `contact`.`thumb` AS `thumb`, 
57                                         `contact`.`url` as `url`,
58                                         `contact`.`name` as `senderName`,
59                                         `user`.* 
60                         FROM `contact` 
61                         LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` 
62                         WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0 
63                                 AND `user`.`nickname` = '%s' $sql_extra LIMIT 1",
64                 dbesc($a->argv[1])
65         );
66
67         if(! count($r)) {
68                 logger('dfrn_notify: contact not found for dfrn_id ' . $dfrn_id);
69                 xml_status(3);
70                 //NOTREACHED
71         }
72
73         // $importer in this case contains the contact record for the remote contact joined with the user record of our user. 
74
75         $importer = $r[0];
76
77         logger('dfrn_notify: received notify from ' . $importer['name'] . ' for ' . $importer['username']);
78         logger('dfrn_notify: data: ' . $data, LOGGER_DATA);
79
80         if($dissolve == 1) {
81
82                 /**
83                  * Relationship is dissolved permanently
84                  */
85
86                 require_once('include/Contact.php'); 
87                 contact_remove($importer['id']);
88                 logger('relationship dissolved : ' . $importer['name'] . ' dissolved ' . $importer['username']);
89                 xml_status(0);
90
91         }
92
93         if(strlen($key)) {
94                 $rawkey = hex2bin(trim($key));
95                 logger('rino: md5 raw key: ' . md5($rawkey));
96                 $final_key = '';
97
98                 if($dfrn_version >= 2.1) {
99                         if((($importer['duplex']) && strlen($importer['cprvkey'])) || (! strlen($importer['cpubkey']))) {
100                                 openssl_private_decrypt($rawkey,$final_key,$importer['cprvkey']);
101                         }
102                         else {
103                                 openssl_public_decrypt($rawkey,$final_key,$importer['cpubkey']);
104                         }
105                 }
106                 else {
107                         if((($importer['duplex']) && strlen($importer['cpubkey'])) || (! strlen($importer['cprvkey']))) {
108                                 openssl_public_decrypt($rawkey,$final_key,$importer['cpubkey']);
109                         }
110                         else {
111                                 openssl_private_decrypt($rawkey,$final_key,$importer['cprvkey']);
112                         }
113                 }
114
115                 logger('rino: received key : ' . $final_key);
116                 $data = aes_decrypt(hex2bin($data),$final_key);
117                 logger('rino: decrypted data: ' . $data, LOGGER_DATA);
118         }
119
120
121
122
123         if($importer['readonly']) {
124                 // We aren't receiving stuff from this person. But we will quietly ignore them
125                 // rather than a blatant "go away" message.
126                 logger('dfrn_notify: ignoring');
127                 xml_status(0);
128                 //NOTREACHED
129         }
130
131         // Consume notification feed. This may differ from consuming a public feed in several ways
132         // - might contain email
133         // - might contain remote followup to our message
134         //              - in which case we need to accept it and then notify other conversants
135         // - we may need to send various email notifications
136
137         $feed = new SimplePie();
138         $feed->set_raw_data($data);
139         $feed->enable_order_by_date(false);
140         $feed->init();
141
142         $ismail = false;
143
144         $rawmail = $feed->get_feed_tags( NAMESPACE_DFRN, 'mail' );
145         if(isset($rawmail[0]['child'][NAMESPACE_DFRN])) {
146
147                 logger('dfrn_notify: private message received');
148
149                 $ismail = true;
150                 $base = $rawmail[0]['child'][NAMESPACE_DFRN];
151
152                 $msg = array();
153                 $msg['uid'] = $importer['importer_uid'];
154                 $msg['from-name'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['name'][0]['data']));
155                 $msg['from-photo'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['avatar'][0]['data']));
156                 $msg['from-url'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['uri'][0]['data']));
157                 $msg['contact-id'] = $importer['id'];
158                 $msg['title'] = notags(unxmlify($base['subject'][0]['data']));
159                 $msg['body'] = escape_tags(unxmlify($base['content'][0]['data']));
160                 $msg['seen'] = 0;
161                 $msg['replied'] = 0;
162                 $msg['uri'] = notags(unxmlify($base['id'][0]['data']));
163                 $msg['parent-uri'] = notags(unxmlify($base['in-reply-to'][0]['data']));
164                 $msg['created'] = datetime_convert(notags(unxmlify('UTC','UTC',$base['sentdate'][0]['data'])));
165                 
166                 dbesc_array($msg);
167
168                 $r = dbq("INSERT INTO `mail` (`" . implode("`, `", array_keys($msg)) 
169                         . "`) VALUES ('" . implode("', '", array_values($msg)) . "')" );
170
171                 // send email notification if requested.
172
173                 require_once('bbcode.php');
174                 if($importer['notify-flags'] & NOTIFY_MAIL) {
175
176 //                      $body = html_entity_decode(strip_tags(bbcode(stripslashes(nl2br($msg['body'])))),ENT_QUOTES,'UTF-8');
177 //                      $body = strip_tags(bbcode(stripslashes(nl2br($msg['body']))));
178                         
179                         /*if(function_exists('quoted_printable_encode'))
180                                 $body = quoted_printable_encode($body);
181                         else
182                                 $body = qp($body);*/
183
184                         $msg['body'] = str_replace(array("\\r\\n", "\\r", "\\n"), "<br />", $msg['body']);
185                         $msg['body'] = html_entity_decode(strip_tags(bbcode($msg['body'])));                    
186                         $tpl = load_view_file('view/mail_received_eml.tpl');                    
187                         $email_tpl = replace_macros($tpl, array(
188                                 '$siteName'             => $a->config['sitename'],
189                                 '$siteurl'              => $a->get_baseurl(),
190                                 '$username'             => $importer['username'],
191                                 '$thumb'                => $importer['thumb'],
192                                 '$email'                => $importer['email'],
193                                 '$url'                  => $importer['url'],
194                                 '$senderName'   => $importer['senderName'],
195                                 '$from'                 => $msg['from-name'],
196                                 '$title'                => stripslashes($msg['title']),
197                                 '$body'                 => $msg['body'],
198                                 '$hostname'             => $a->get_hostname()
199                         ));
200                         
201                         $res = mail($importer['email'], t('New mail received at ') . $a->config['sitename'],
202                                 $email_tpl, 
203                                         'From: ' . t('Administrator') . '@' . $a->get_hostname() . "\r\n"
204                                         . 'MIME-Version: 1.0' . "\r\n"
205                                         . 'Content-type: text/html; charset=iso-8859-1' . "\r\n" 
206                                         . 'Content-transfer-encoding: 7-bit' . "\r\n"
207                         );
208                 }
209                 xml_status(0);
210                 // NOTREACHED
211         }       
212         
213         logger('dfrn_notify: feed item count = ' . $feed->get_item_quantity());
214
215         // process any deleted entries
216
217         $del_entries = $feed->get_feed_tags(NAMESPACE_TOMB, 'deleted-entry');
218         if(is_array($del_entries) && count($del_entries)) {
219                 foreach($del_entries as $dentry) {
220                         $deleted = false;
221                         if(isset($dentry['attribs']['']['ref'])) {
222                                 $uri = $dentry['attribs']['']['ref'];
223                                 $deleted = true;
224                                 if(isset($dentry['attribs']['']['when'])) {
225                                         $when = $dentry['attribs']['']['when'];
226                                         $when = datetime_convert('UTC','UTC', $when, 'Y-m-d H:i:s');
227                                 }
228                                 else
229                                         $when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
230                         }
231                         if($deleted) {
232                                 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
233                                         dbesc($uri),
234                                         intval($importer['importer_uid'])
235                                 );
236                                 if(count($r)) {
237                                         $item = $r[0];
238
239                                         if(! $item['deleted'])
240                                                 logger('dfrn_notify: deleting item ' . $item['id'] . ' uri=' . $item['uri'], LOGGER_DEBUG);
241
242                                         if($item['uri'] == $item['parent-uri']) {
243                                                 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s'
244                                                         WHERE `parent-uri` = '%s' AND `uid` = %d",
245                                                         dbesc($when),
246                                                         dbesc(datetime_convert()),
247                                                         dbesc($item['uri']),
248                                                         intval($importer['importer_uid'])
249                                                 );
250                                         }
251                                         else {
252                                                 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' 
253                                                         WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
254                                                         dbesc($when),
255                                                         dbesc(datetime_convert()),
256                                                         dbesc($uri),
257                                                         intval($importer['importer_uid'])
258                                                 );
259                                                 if($item['last-child']) {
260                                                         // ensure that last-child is set in case the comment that had it just got wiped.
261                                                         q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
262                                                                 dbesc(datetime_convert()),
263                                                                 dbesc($item['parent-uri']),
264                                                                 intval($item['uid'])
265                                                         );
266                                                         // who is the last child now? 
267                                                         $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d
268                                                                 ORDER BY `created` DESC LIMIT 1",
269                                                                         dbesc($item['parent-uri']),
270                                                                         intval($importer['importer_uid'])
271                                                         );
272                                                         if(count($r)) {
273                                                                 q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
274                                                                         intval($r[0]['id'])
275                                                                 );
276                                                         }       
277                                                 }
278                                         }       
279                                 }
280                         }
281                 }
282         }
283
284
285         foreach($feed->get_items() as $item) {
286
287                 $is_reply = false;              
288                 $item_id = $item->get_id();
289                 $rawthread = $item->get_item_tags( NAMESPACE_THREAD, 'in-reply-to');
290                 if(isset($rawthread[0]['attribs']['']['ref'])) {
291                         $is_reply = true;
292                         $parent_uri = $rawthread[0]['attribs']['']['ref'];
293                 }
294
295                 if($is_reply) {
296                         if($feed->get_item_quantity() == 1) {
297                                 logger('dfrn_notify: received remote comment');
298                                 $is_like = false;
299                                 // remote reply to our post. Import and then notify everybody else.
300                                 $datarray = get_atom_elements($feed,$item);
301                                 $datarray['type'] = 'remote-comment';
302                                 $datarray['wall'] = 1;
303                                 $datarray['parent-uri'] = $parent_uri;
304                                 $datarray['uid'] = $importer['importer_uid'];
305                                 $datarray['contact-id'] = $importer['id'];
306                                 if(($datarray['verb'] == ACTIVITY_LIKE) || ($datarray['verb'] == ACTIVITY_DISLIKE)) {
307                                         $is_like = true;
308                                         $datarray['type'] = 'activity';
309                                         $datarray['gravity'] = GRAVITY_LIKE;
310                                         $datarray['last-child'] = 0;
311                                 }
312                                 $posted_id = item_store($datarray);
313                                 $parent = 0;
314
315                                 if($posted_id) {
316                                         $r = q("SELECT `parent` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
317                                                 intval($posted_id),
318                                                 intval($importer['importer_uid'])
319                                         );
320                                         if(count($r))
321                                                 $parent = $r[0]['parent'];
322                         
323                                         if(! $is_like) {
324                                                 $r1 = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `uid` = %d AND `parent` = %d",
325                                                         dbesc(datetime_convert()),
326                                                         intval($importer['importer_uid']),
327                                                         intval($r[0]['parent'])
328                                                 );
329
330                                                 $r2 = q("UPDATE `item` SET `last-child` = 1, `changed` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
331                                                         dbesc(datetime_convert()),
332                                                         intval($importer['importer_uid']),
333                                                         intval($posted_id)
334                                                 );
335                                         }
336
337                                         if($posted_id && $parent) {
338                                 
339                                                 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
340
341                                                 proc_run($php_path,"include/notifier.php","comment-import","$posted_id");
342                                         
343                                                 if((! $is_like) && ($importer['notify-flags'] & NOTIFY_COMMENT) && (! $importer['self'])) {
344                                                         require_once('bbcode.php');
345                                                         $from = stripslashes($datarray['author-name']);
346                                                         $tpl = load_view_file('view/cmnt_received_eml.tpl');                    
347                                                         $email_tpl = replace_macros($tpl, array(
348                                                                 '$sitename' => $a->config['sitename'],
349                                                                 '$siteurl' =>  $a->get_baseurl(),
350                                                                 '$username' => $importer['username'],
351                                                                 '$email' => $importer['email'],
352                                                                 '$display' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id, 
353                                                                 '$from' => $from,
354                                                                 '$body' => strip_tags(bbcode(stripslashes($datarray['body'])))
355                                                         ));
356         
357                                                         $res = mail($importer['email'], $from . t(' commented on an item at ') . $a->config['sitename'],
358                                                                 $email_tpl, "From: " . t('Administrator') . '@' . $a->get_hostname() );
359                                                 }
360                                         }
361                                         xml_status(0);
362                                         // NOTREACHED
363                                 }
364                         }
365                         else {
366                                 // regular comment that is part of this total conversation. Have we seen it? If not, import it.
367
368                                 $item_id = $item->get_id();
369
370                                 $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
371                                         dbesc($item_id),
372                                         intval($importer['importer_uid'])
373                                 );
374                                 // FIXME update content if 'updated' changes
375                                 if(count($r)) {
376                                         $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
377                                         if($allow && $allow[0]['data'] != $r[0]['last-child']) {
378                                                 $r = q("UPDATE `item` SET `last-child` = %d, `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
379                                                         intval($allow[0]['data']),
380                                                         dbesc(datetime_convert()),
381                                                         dbesc($item_id),
382                                                         intval($importer['importer_uid'])
383                                                 );
384                                         }
385                                         continue;
386                                 }
387                                 $datarray = get_atom_elements($feed,$item);
388                                 $datarray['parent-uri'] = $parent_uri;
389                                 $datarray['uid'] = $importer['importer_uid'];
390                                 $datarray['contact-id'] = $importer['id'];
391                                 if(($datarray['verb'] == ACTIVITY_LIKE) || ($datarray['verb'] == ACTIVITY_DISLIKE)) {
392                                         $datarray['type'] = 'activity';
393                                         $datarray['gravity'] = GRAVITY_LIKE;
394                                 }
395                                 $r = item_store($datarray);
396
397                                 // find out if our user is involved in this conversation and wants to be notified.
398                         
399                                 if(($datarray['type'] != 'activity') && ($importer['notify-flags'] & NOTIFY_COMMENT)) {
400
401                                         $myconv = q("SELECT `author-link` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 ",
402                                                 dbesc($parent_uri),
403                                                 intval($importer['importer_uid'])
404                                         );
405                                         if(count($myconv)) {
406                                                 $importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname'];
407                                                 foreach($myconv as $conv) {
408                                                         if(! link_compare($conv['author-link'],$importer_url))
409                                                                 continue;
410                                                         require_once('bbcode.php');
411                                                         $from = stripslashes($datarray['author-name']);
412                                                         $tpl = load_view_file('view/cmnt_received_eml.tpl');    
413                                                         $email_tpl = replace_macros($tpl, array(
414                                                                 '$sitename' => $a->config['sitename'],
415                                                                 '$siteurl' =>  $a->get_baseurl(),
416                                                                 '$username' => $importer['username'],
417                                                                 '$email' => $importer['email'],
418                                                                 '$from' => $from,
419                                                                 '$display' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $r,
420                                                                 '$body' => strip_tags(bbcode(stripslashes($datarray['body'])))
421                                                         ));
422
423                                                         $res = mail($importer['email'], $from . t(" commented on an item at ") 
424                                                                 . $a->config['sitename'],
425                                                                 $email_tpl,t("From: Administrator@") . $a->get_hostname() );
426                                                         break;
427                                                 }
428                                         }
429                                 }
430                                 continue;
431                         }
432                 }
433                 else {
434                         // Head post of a conversation. Have we seen it? If not, import it.
435
436                         $item_id = $item->get_id();
437                         $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
438                                 dbesc($item_id),
439                                 intval($importer['importer_uid'])
440                         );
441                         if(count($r)) {
442                                 $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
443                                 if($allow && $allow[0]['data'] != $r[0]['last-child']) {
444                                         $r = q("UPDATE `item` SET `last-child` = %d, `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
445                                                 intval($allow[0]['data']),
446                                                 dbesc(datetime_convert()),
447                                                 dbesc($item_id),
448                                                 intval($importer['importer_uid'])
449                                         );
450                                 }
451                                 continue;
452                         }
453
454
455                         $datarray = get_atom_elements($feed,$item);
456                         $datarray['parent-uri'] = $item_id;
457                         $datarray['uid'] = $importer['importer_uid'];
458                         $datarray['contact-id'] = $importer['id'];
459                         $r = item_store($datarray);
460                         continue;
461                 }
462         }
463
464         xml_status(0);
465         // NOTREACHED
466
467 }
468
469
470 function dfrn_notify_content(&$a) {
471
472         if(x($_GET,'dfrn_id')) {
473
474                 // initial communication from external contact, $direction is their direction.
475                 // If this is a duplex communication, ours will be the opposite.
476
477                 $dfrn_id = notags(trim($_GET['dfrn_id']));
478                 $dfrn_version = (float) $_GET['dfrn_version'];
479
480                 logger('dfrn_notify: new notification dfrn_id=' . $dfrn_id);
481
482                 $direction = (-1);
483                 if(strpos($dfrn_id,':') == 1) {
484                         $direction = intval(substr($dfrn_id,0,1));
485                         $dfrn_id = substr($dfrn_id,2);
486                 }
487
488                 $hash = random_string();
489
490                 $status = 0;
491
492                 $r = q("DELETE FROM `challenge` WHERE `expire` < " . intval(time()));
493
494                 $r = q("INSERT INTO `challenge` ( `challenge`, `dfrn-id`, `expire` )
495                         VALUES( '%s', '%s', %d ) ",
496                         dbesc($hash),
497                         dbesc($dfrn_id),
498                         intval(time() + 90 )
499                 );
500
501                 logger('dfrn_notify: challenge=' . $hash );
502
503                 $sql_extra = '';
504                 switch($direction) {
505                         case (-1):
506                                 $sql_extra = sprintf(" AND ( `issued-id` = '%s' OR `dfrn-id` = '%s' ) ", dbesc($dfrn_id), dbesc($dfrn_id));
507                                 $my_id = $dfrn_id;
508                                 break;
509                         case 0:
510                                 $sql_extra = sprintf(" AND `issued-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
511                                 $my_id = '1:' . $dfrn_id;
512                                 break;
513                         case 1:
514                                 $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
515                                 $my_id = '0:' . $dfrn_id;
516                                 break;
517                         default:
518                                 $status = 1;
519                                 break; // NOTREACHED
520                 }
521
522                 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` 
523                                 WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `user`.`nickname` = '%s' $sql_extra LIMIT 1",
524                                 dbesc($a->argv[1])
525                 );
526
527                 if(! count($r))
528                         $status = 1;
529
530                 $challenge = '';
531                 $encrypted_id = '';
532                 $id_str = $my_id . '.' . mt_rand(1000,9999);
533
534                 if((($r[0]['duplex']) && strlen($r[0]['prvkey'])) || (! strlen($r[0]['pubkey']))) {
535                         openssl_private_encrypt($hash,$challenge,$r[0]['prvkey']);
536                         openssl_private_encrypt($id_str,$encrypted_id,$r[0]['prvkey']);
537                 }
538                 else {
539                         openssl_public_encrypt($hash,$challenge,$r[0]['pubkey']);
540                         openssl_public_encrypt($id_str,$encrypted_id,$r[0]['pubkey']);
541                 }
542
543                 $challenge    = bin2hex($challenge);
544                 $encrypted_id = bin2hex($encrypted_id);
545
546                 $rino = ((function_exists('mcrypt_encrypt')) ? 1 : 0);
547
548                 $rino_enable = get_config('system','rino_encrypt');
549
550                 if(! $rino_enable)
551                         $rino = 0;
552
553
554                 header("Content-type: text/xml");
555
556                 echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n" 
557                         . '<dfrn_notify>' . "\r\n"
558                         . "\t" . '<status>' . $status . '</status>' . "\r\n"
559                         . "\t" . '<dfrn_version>' . DFRN_PROTOCOL_VERSION . '</dfrn_version>' . "\r\n"
560                         . "\t" . '<rino>' . $rino . '</rino>' . "\r\n" 
561                         . "\t" . '<dfrn_id>' . $encrypted_id . '</dfrn_id>' . "\r\n" 
562                         . "\t" . '<challenge>' . $challenge . '</challenge>' . "\r\n"
563                         . '</dfrn_notify>' . "\r\n" ;
564
565                 killme();
566         }
567
568 }