]> git.mxchange.org Git - friendica.git/blob - mod/dfrn_confirm.php
6771a21575e8b9f29c679bab79058f54e3939ed9
[friendica.git] / mod / dfrn_confirm.php
1 <?php
2 /**
3  * @file mod/dfrn_confirm.php
4  * @brief Module: dfrn_confirm
5  * Purpose: Friendship acceptance for DFRN contacts
6  *
7  * There are two possible entry points and three scenarios.
8  *
9  *   1. A form was submitted by our user approving a friendship that originated elsewhere.
10  *      This may also be called from dfrn_request to automatically approve a friendship.
11  *
12  *   2. We may be the target or other side of the conversation to scenario 1, and will
13  *      interact with that process on our own user's behalf.
14  *
15  *  @see PDF with dfrn specs: https://github.com/friendica/friendica/blob/master/spec/dfrn2.pdf
16  *    You also find a graphic which describes the confirmation process at
17  *    https://github.com/friendica/friendica/blob/master/spec/dfrn2_contact_confirmation.png
18  */
19
20 use Friendica\App;
21 use Friendica\Core\Config;
22 use Friendica\Core\L10n;
23 use Friendica\Core\Logger;
24 use Friendica\Core\Protocol;
25 use Friendica\Core\System;
26 use Friendica\Database\DBA;
27 use Friendica\Model\Contact;
28 use Friendica\Model\Group;
29 use Friendica\Model\User;
30 use Friendica\Network\Probe;
31 use Friendica\Protocol\Diaspora;
32 use Friendica\Protocol\ActivityPub;
33 use Friendica\Util\Crypto;
34 use Friendica\Util\DateTimeFormat;
35 use Friendica\Util\Network;
36 use Friendica\Util\XML;
37
38 require_once 'include/enotify.php';
39 require_once 'include/items.php';
40
41 function dfrn_confirm_post(App $a, $handsfree = null)
42 {
43         $node = null;
44         if (is_array($handsfree)) {
45                 /*
46                  * We were called directly from dfrn_request due to automatic friend acceptance.
47                  * Any $_POST parameters we may require are supplied in the $handsfree array.
48                  *
49                  */
50                 $node = $handsfree['node'];
51                 $a->interactive = false; // notice() becomes a no-op since nobody is there to see it
52         } elseif ($a->argc > 1) {
53                 $node = $a->argv[1];
54         }
55
56         /*
57          * Main entry point. Scenario 1. Our user received a friend request notification (perhaps
58          * from another site) and clicked 'Approve'.
59          * $POST['source_url'] is not set. If it is, it indicates Scenario 2.
60          *
61          * We may also have been called directly from dfrn_request ($handsfree != null) due to
62          * this being a page type which supports automatic friend acceptance. That is also Scenario 1
63          * since we are operating on behalf of our registered user to approve a friendship.
64          */
65         if (!x($_POST, 'source_url')) {
66                 $uid = defaults($handsfree, 'uid', local_user());
67                 if (!$uid) {
68                         notice(L10n::t('Permission denied.') . EOL);
69                         return;
70                 }
71
72                 $user = DBA::selectFirst('user', [], ['uid' => $uid]);
73                 if (!DBA::isResult($user)) {
74                         notice(L10n::t('Profile not found.') . EOL);
75                         return;
76                 }
77
78                 // These data elements may come from either the friend request notification form or $handsfree array.
79                 if (is_array($handsfree)) {
80                         Logger::log('Confirm in handsfree mode');
81                         $dfrn_id  = $handsfree['dfrn_id'];
82                         $intro_id = $handsfree['intro_id'];
83                         $duplex   = $handsfree['duplex'];
84                         $cid      = 0;
85                         $hidden   = intval(defaults($handsfree, 'hidden'  , 0));
86                 } else {
87                         $dfrn_id  = notags(trim(defaults($_POST, 'dfrn_id'   , '')));
88                         $intro_id =      intval(defaults($_POST, 'intro_id'  , 0));
89                         $duplex   =      intval(defaults($_POST, 'duplex'    , 0));
90                         $cid      =      intval(defaults($_POST, 'contact_id', 0));
91                         $hidden   =      intval(defaults($_POST, 'hidden'    , 0));
92                 }
93
94                 /*
95                  * Ensure that dfrn_id has precedence when we go to find the contact record.
96                  * We only want to search based on contact id if there is no dfrn_id,
97                  * e.g. for OStatus network followers.
98                  */
99                 if (strlen($dfrn_id)) {
100                         $cid = 0;
101                 }
102
103                 Logger::log('Confirming request for dfrn_id (issued) ' . $dfrn_id);
104                 if ($cid) {
105                         Logger::log('Confirming follower with contact_id: ' . $cid);
106                 }
107
108                 /*
109                  * The other person will have been issued an ID when they first requested friendship.
110                  * Locate their record. At this time, their record will have both pending and blocked set to 1.
111                  * There won't be any dfrn_id if this is a network follower, so use the contact_id instead.
112                  */
113                 $r = q("SELECT *
114                         FROM `contact`
115                         WHERE (
116                                 (`issued-id` != '' AND `issued-id` = '%s')
117                                 OR
118                                 (`id` = %d AND `id` != 0)
119                         )
120                         AND `uid` = %d
121                         AND `duplex` = 0
122                         LIMIT 1",
123                         DBA::escape($dfrn_id),
124                         intval($cid),
125                         intval($uid)
126                 );
127                 if (!DBA::isResult($r)) {
128                         Logger::log('Contact not found in DB.');
129                         notice(L10n::t('Contact not found.') . EOL);
130                         notice(L10n::t('This may occasionally happen if contact was requested by both persons and it has already been approved.') . EOL);
131                         return;
132                 }
133
134                 $contact = $r[0];
135
136                 $contact_id   = $contact['id'];
137                 $relation     = $contact['rel'];
138                 $site_pubkey  = $contact['site-pubkey'];
139                 $dfrn_confirm = $contact['confirm'];
140                 $aes_allow    = $contact['aes_allow'];
141
142                 $network = ((strlen($contact['issued-id'])) ? Protocol::DFRN : Protocol::OSTATUS);
143
144                 if ($contact['network']) {
145                         $network = $contact['network'];
146                 }
147
148                 if ($network === Protocol::DFRN) {
149                         /*
150                          * Generate a key pair for all further communications with this person.
151                          * We have a keypair for every contact, and a site key for unknown people.
152                          * This provides a means to carry on relationships with other people if
153                          * any single key is compromised. It is a robust key. We're much more
154                          * worried about key leakage than anybody cracking it.
155                          */
156                         $res = Crypto::newKeypair(4096);
157
158                         $private_key = $res['prvkey'];
159                         $public_key  = $res['pubkey'];
160
161                         // Save the private key. Send them the public key.
162                         q("UPDATE `contact` SET `prvkey` = '%s' WHERE `id` = %d AND `uid` = %d",
163                                 DBA::escape($private_key),
164                                 intval($contact_id),
165                                 intval($uid)
166                         );
167
168                         $params = [];
169
170                         /*
171                          * Per the DFRN protocol, we will verify both ends by encrypting the dfrn_id with our
172                          * site private key (person on the other end can decrypt it with our site public key).
173                          * Then encrypt our profile URL with the other person's site public key. They can decrypt
174                          * it with their site private key. If the decryption on the other end fails for either
175                          * item, it indicates tampering or key failure on at least one site and we will not be
176                          * able to provide a secure communication pathway.
177                          *
178                          * If other site is willing to accept full encryption, (aes_allow is 1 AND we have php5.3
179                          * or later) then we encrypt the personal public key we send them using AES-256-CBC and a
180                          * random key which is encrypted with their site public key.
181                          */
182
183                         $src_aes_key = openssl_random_pseudo_bytes(64);
184
185                         $result = '';
186                         openssl_private_encrypt($dfrn_id, $result, $user['prvkey']);
187
188                         $params['dfrn_id'] = bin2hex($result);
189                         $params['public_key'] = $public_key;
190
191                         $my_url = System::baseUrl() . '/profile/' . $user['nickname'];
192
193                         openssl_public_encrypt($my_url, $params['source_url'], $site_pubkey);
194                         $params['source_url'] = bin2hex($params['source_url']);
195
196                         if ($aes_allow && function_exists('openssl_encrypt')) {
197                                 openssl_public_encrypt($src_aes_key, $params['aes_key'], $site_pubkey);
198                                 $params['aes_key'] = bin2hex($params['aes_key']);
199                                 $params['public_key'] = bin2hex(openssl_encrypt($public_key, 'AES-256-CBC', $src_aes_key));
200                         }
201
202                         $params['dfrn_version'] = DFRN_PROTOCOL_VERSION;
203                         if ($duplex == 1) {
204                                 $params['duplex'] = 1;
205                         }
206
207                         if ($user['page-flags'] == Contact::PAGE_COMMUNITY) {
208                                 $params['page'] = 1;
209                         }
210
211                         if ($user['page-flags'] == Contact::PAGE_PRVGROUP) {
212                                 $params['page'] = 2;
213                         }
214
215                         Logger::log('Confirm: posting data to ' . $dfrn_confirm . ': ' . print_r($params, true), Logger::DATA);
216
217                         /*
218                          *
219                          * POST all this stuff to the other site.
220                          * Temporarily raise the network timeout to 120 seconds because the default 60
221                          * doesn't always give the other side quite enough time to decrypt everything.
222                          *
223                          */
224
225                         $res = Network::post($dfrn_confirm, $params, null, $redirects, 120)->getBody();
226
227                         Logger::log(' Confirm: received data: ' . $res, Logger::DATA);
228
229                         // Now figure out what they responded. Try to be robust if the remote site is
230                         // having difficulty and throwing up errors of some kind.
231
232                         $leading_junk = substr($res, 0, strpos($res, '<?xml'));
233
234                         $res = substr($res, strpos($res, '<?xml'));
235                         if (!strlen($res)) {
236                                 // No XML at all, this exchange is messed up really bad.
237                                 // We shouldn't proceed, because the xml parser might choke,
238                                 // and $status is going to be zero, which indicates success.
239                                 // We can hardly call this a success.
240                                 notice(L10n::t('Response from remote site was not understood.') . EOL);
241                                 return;
242                         }
243
244                         if (strlen($leading_junk) && Config::get('system', 'debugging')) {
245                                 // This might be more common. Mixed error text and some XML.
246                                 // If we're configured for debugging, show the text. Proceed in either case.
247                                 notice(L10n::t('Unexpected response from remote site: ') . EOL . $leading_junk . EOL);
248                         }
249
250                         if (stristr($res, "<status") === false) {
251                                 // wrong xml! stop here!
252                                 Logger::log('Unexpected response posting to ' . $dfrn_confirm);
253                                 notice(L10n::t('Unexpected response from remote site: ') . EOL . htmlspecialchars($res) . EOL);
254                                 return;
255                         }
256
257                         $xml = XML::parseString($res);
258                         $status = (int) $xml->status;
259                         $message = XML::unxmlify($xml->message);   // human readable text of what may have gone wrong.
260                         switch ($status) {
261                                 case 0:
262                                         info(L10n::t("Confirmation completed successfully.") . EOL);
263                                         break;
264                                 case 1:
265                                         // birthday paradox - generate new dfrn-id and fall through.
266                                         $new_dfrn_id = random_string();
267                                         q("UPDATE contact SET `issued-id` = '%s' WHERE `id` = %d AND `uid` = %d",
268                                                 DBA::escape($new_dfrn_id),
269                                                 intval($contact_id),
270                                                 intval($uid)
271                                         );
272
273                                 case 2:
274                                         notice(L10n::t("Temporary failure. Please wait and try again.") . EOL);
275                                         break;
276                                 case 3:
277                                         notice(L10n::t("Introduction failed or was revoked.") . EOL);
278                                         break;
279                         }
280
281                         if (strlen($message)) {
282                                 notice(L10n::t('Remote site reported: ') . $message . EOL);
283                         }
284
285                         if (($status == 0) && $intro_id) {
286                                 $intro = DBA::selectFirst('intro', ['note'], ['id' => $intro_id]);
287                                 if (DBA::isResult($intro)) {
288                                         DBA::update('contact', ['reason' => $intro['note']], ['id' => $contact_id]);
289                                 }
290
291                                 // Success. Delete the notification.
292                                 DBA::delete('intro', ['id' => $intro_id]);
293                         }
294
295                         if ($status != 0) {
296                                 return;
297                         }
298                 }
299
300                 /*
301                  * We have now established a relationship with the other site.
302                  * Let's make our own personal copy of their profile photo so we don't have
303                  * to always load it from their site.
304                  *
305                  * We will also update the contact record with the nature and scope of the relationship.
306                  */
307                 Contact::updateAvatar($contact['photo'], $uid, $contact_id);
308
309                 Logger::log('dfrn_confirm: confirm - imported photos');
310
311                 if ($network === Protocol::DFRN) {
312                         $new_relation = Contact::FOLLOWER;
313
314                         if (($relation == Contact::SHARING) || ($duplex)) {
315                                 $new_relation = Contact::FRIEND;
316                         }
317
318                         if (($relation == Contact::SHARING) && ($duplex)) {
319                                 $duplex = 0;
320                         }
321
322                         $r = q("UPDATE `contact` SET `rel` = %d,
323                                 `name-date` = '%s',
324                                 `uri-date` = '%s',
325                                 `blocked` = 0,
326                                 `pending` = 0,
327                                 `duplex` = %d,
328                                 `hidden` = %d,
329                                 `network` = '%s' WHERE `id` = %d
330                         ",
331                                 intval($new_relation),
332                                 DBA::escape(DateTimeFormat::utcNow()),
333                                 DBA::escape(DateTimeFormat::utcNow()),
334                                 intval($duplex),
335                                 intval($hidden),
336                                 DBA::escape(Protocol::DFRN),
337                                 intval($contact_id)
338                         );
339                 } else {
340                         if ($network == Protocol::ACTIVITYPUB) {
341                                 ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $uid);
342                                 $pending = true;
343                         } else {
344                                 $pending = false;
345                         }
346
347                         // $network !== Protocol::DFRN
348                         $network = defaults($contact, 'network', Protocol::OSTATUS);
349
350                         $arr = Probe::uri($contact['url'], $network);
351
352                         $notify  = defaults($contact, 'notify' , $arr['notify']);
353                         $poll    = defaults($contact, 'poll'   , $arr['poll']);
354
355                         $addr = $arr['addr'];
356
357                         $new_relation = $contact['rel'];
358                         $writable = $contact['writable'];
359
360                         if (in_array($network, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
361                                 if ($duplex) {
362                                         $new_relation = Contact::FRIEND;
363                                 } else {
364                                         $new_relation = Contact::FOLLOWER;
365                                 }
366
367                                 if ($new_relation != Contact::FOLLOWER) {
368                                         $writable = 1;
369                                 }
370                         }
371
372                         DBA::delete('intro', ['id' => $intro_id]);
373
374                         $fields = ['name-date' => DateTimeFormat::utcNow(),
375                                 'uri-date' => DateTimeFormat::utcNow(), 'addr' => $addr,
376                                 'notify' => $notify, 'poll' => $poll, 'blocked' => false,
377                                 'pending' => $pending, 'network' => $network,
378                                 'writable' => $writable, 'hidden' => $hidden, 'rel' => $new_relation];
379                         DBA::update('contact', $fields, ['id' => $contact_id]);
380                 }
381
382                 if (!DBA::isResult($r)) {
383                         notice(L10n::t('Unable to set contact photo.') . EOL);
384                 }
385
386                 // reload contact info
387                 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
388                 if ((isset($new_relation) && $new_relation == Contact::FRIEND)) {
389                         if (DBA::isResult($contact) && ($contact['network'] === Protocol::DIASPORA)) {
390                                 $ret = Diaspora::sendShare($user, $contact);
391                                 Logger::log('share returns: ' . $ret);
392                         }
393                 }
394
395                 Group::addMember(User::getDefaultGroup($uid, $contact["network"]), $contact['id']);
396
397                 if ($network == Protocol::ACTIVITYPUB && $duplex) {
398                         ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid);
399                 }
400
401                 // Let's send our user to the contact editor in case they want to
402                 // do anything special with this new friend.
403                 if ($handsfree === null) {
404                         $a->internalRedirect('contact/' . intval($contact_id));
405                 } else {
406                         return;
407                 }
408                 //NOTREACHED
409         }
410
411         /*
412          * End of Scenario 1. [Local confirmation of remote friend request].
413          *
414          * Begin Scenario 2. This is the remote response to the above scenario.
415          * This will take place on the site that originally initiated the friend request.
416          * In the section above where the confirming party makes a POST and
417          * retrieves xml status information, they are communicating with the following code.
418          */
419         if (x($_POST, 'source_url')) {
420                 // We are processing an external confirmation to an introduction created by our user.
421                 $public_key =         defaults($_POST, 'public_key', '');
422                 $dfrn_id    = hex2bin(defaults($_POST, 'dfrn_id'   , ''));
423                 $source_url = hex2bin(defaults($_POST, 'source_url', ''));
424                 $aes_key    =         defaults($_POST, 'aes_key'   , '');
425                 $duplex     =  intval(defaults($_POST, 'duplex'    , 0));
426                 $page       =  intval(defaults($_POST, 'page'      , 0));
427
428                 $forum = (($page == 1) ? 1 : 0);
429                 $prv   = (($page == 2) ? 1 : 0);
430
431                 Logger::log('dfrn_confirm: requestee contacted: ' . $node);
432
433                 Logger::log('dfrn_confirm: request: POST=' . print_r($_POST, true), Logger::DATA);
434
435                 // If $aes_key is set, both of these items require unpacking from the hex transport encoding.
436
437                 if (x($aes_key)) {
438                         $aes_key = hex2bin($aes_key);
439                         $public_key = hex2bin($public_key);
440                 }
441
442                 // Find our user's account
443                 $user = DBA::selectFirst('user', [], ['nickname' => $node]);
444                 if (!DBA::isResult($user)) {
445                         $message = L10n::t('No user record found for \'%s\' ', $node);
446                         System::xmlExit(3, $message); // failure
447                         // NOTREACHED
448                 }
449
450                 $my_prvkey = $user['prvkey'];
451                 $local_uid = $user['uid'];
452
453
454                 if (!strstr($my_prvkey, 'PRIVATE KEY')) {
455                         $message = L10n::t('Our site encryption key is apparently messed up.');
456                         System::xmlExit(3, $message);
457                 }
458
459                 // verify everything
460
461                 $decrypted_source_url = "";
462                 openssl_private_decrypt($source_url, $decrypted_source_url, $my_prvkey);
463
464
465                 if (!strlen($decrypted_source_url)) {
466                         $message = L10n::t('Empty site URL was provided or URL could not be decrypted by us.');
467                         System::xmlExit(3, $message);
468                         // NOTREACHED
469                 }
470
471                 $contact = DBA::selectFirst('contact', [], ['url' => $decrypted_source_url, 'uid' => $local_uid]);
472                 if (!DBA::isResult($contact)) {
473                         if (strstr($decrypted_source_url, 'http:')) {
474                                 $newurl = str_replace('http:', 'https:', $decrypted_source_url);
475                         } else {
476                                 $newurl = str_replace('https:', 'http:', $decrypted_source_url);
477                         }
478
479                         $contact = DBA::selectFirst('contact', [], ['url' => $newurl, 'uid' => $local_uid]);
480                         if (!DBA::isResult($contact)) {
481                                 // this is either a bogus confirmation (?) or we deleted the original introduction.
482                                 $message = L10n::t('Contact record was not found for you on our site.');
483                                 System::xmlExit(3, $message);
484                                 return; // NOTREACHED
485                         }
486                 }
487
488                 $relation = $contact['rel'];
489
490                 // Decrypt all this stuff we just received
491
492                 $foreign_pubkey = $contact['site-pubkey'];
493                 $dfrn_record = $contact['id'];
494
495                 if (!$foreign_pubkey) {
496                         $message = L10n::t('Site public key not available in contact record for URL %s.', $decrypted_source_url);
497                         System::xmlExit(3, $message);
498                 }
499
500                 $decrypted_dfrn_id = "";
501                 openssl_public_decrypt($dfrn_id, $decrypted_dfrn_id, $foreign_pubkey);
502
503                 if (strlen($aes_key)) {
504                         $decrypted_aes_key = "";
505                         openssl_private_decrypt($aes_key, $decrypted_aes_key, $my_prvkey);
506                         $dfrn_pubkey = openssl_decrypt($public_key, 'AES-256-CBC', $decrypted_aes_key);
507                 } else {
508                         $dfrn_pubkey = $public_key;
509                 }
510
511                 if (DBA::exists('contact', ['dfrn-id' => $decrypted_dfrn_id])) {
512                         $message = L10n::t('The ID provided by your system is a duplicate on our system. It should work if you try again.');
513                         System::xmlExit(1, $message); // Birthday paradox - duplicate dfrn-id
514                         // NOTREACHED
515                 }
516
517                 $r = q("UPDATE `contact` SET `dfrn-id` = '%s', `pubkey` = '%s' WHERE `id` = %d",
518                         DBA::escape($decrypted_dfrn_id),
519                         DBA::escape($dfrn_pubkey),
520                         intval($dfrn_record)
521                 );
522                 if (!DBA::isResult($r)) {
523                         $message = L10n::t('Unable to set your contact credentials on our system.');
524                         System::xmlExit(3, $message);
525                 }
526
527                 // It's possible that the other person also requested friendship.
528                 // If it is a duplex relationship, ditch the issued-id if one exists.
529
530                 if ($duplex) {
531                         q("UPDATE `contact` SET `issued-id` = '' WHERE `id` = %d",
532                                 intval($dfrn_record)
533                         );
534                 }
535
536                 // We're good but now we have to scrape the profile photo and send notifications.
537                 $contact = DBA::selectFirst('contact', ['photo'], ['id' => $dfrn_record]);
538                 if (DBA::isResult($contact)) {
539                         $photo = $contact['photo'];
540                 } else {
541                         $photo = System::baseUrl() . '/images/person-300.jpg';
542                 }
543
544                 Contact::updateAvatar($photo, $local_uid, $dfrn_record);
545
546                 Logger::log('dfrn_confirm: request - photos imported');
547
548                 $new_relation = Contact::SHARING;
549
550                 if (($relation == Contact::FOLLOWER) || ($duplex)) {
551                         $new_relation = Contact::FRIEND;
552                 }
553
554                 if (($relation == Contact::FOLLOWER) && ($duplex)) {
555                         $duplex = 0;
556                 }
557
558                 $r = q("UPDATE `contact` SET
559                         `rel` = %d,
560                         `name-date` = '%s',
561                         `uri-date` = '%s',
562                         `blocked` = 0,
563                         `pending` = 0,
564                         `duplex` = %d,
565                         `forum` = %d,
566                         `prv` = %d,
567                         `network` = '%s' WHERE `id` = %d
568                 ",
569                         intval($new_relation),
570                         DBA::escape(DateTimeFormat::utcNow()),
571                         DBA::escape(DateTimeFormat::utcNow()),
572                         intval($duplex),
573                         intval($forum),
574                         intval($prv),
575                         DBA::escape(Protocol::DFRN),
576                         intval($dfrn_record)
577                 );
578                 if (!DBA::isResult($r)) {       // indicates schema is messed up or total db failure
579                         $message = L10n::t('Unable to update your contact profile details on our system');
580                         System::xmlExit(3, $message);
581                 }
582
583                 // Otherwise everything seems to have worked and we are almost done. Yay!
584                 // Send an email notification
585
586                 Logger::log('dfrn_confirm: request: info updated');
587
588                 $combined = null;
589                 $r = q("SELECT `contact`.*, `user`.*
590                         FROM `contact`
591                         LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
592                         WHERE `contact`.`id` = %d
593                         LIMIT 1",
594                         intval($dfrn_record)
595                 );
596                 if (DBA::isResult($r)) {
597                         $combined = $r[0];
598
599                         if ($combined['notify-flags'] & NOTIFY_CONFIRM) {
600                                 $mutual = ($new_relation == Contact::FRIEND);
601                                 notification([
602                                         'type'         => NOTIFY_CONFIRM,
603                                         'notify_flags' => $combined['notify-flags'],
604                                         'language'     => $combined['language'],
605                                         'to_name'      => $combined['username'],
606                                         'to_email'     => $combined['email'],
607                                         'uid'          => $combined['uid'],
608                                         'link'         => System::baseUrl() . '/contact/' . $dfrn_record,
609                                         'source_name'  => ((strlen(stripslashes($combined['name']))) ? stripslashes($combined['name']) : L10n::t('[Name Withheld]')),
610                                         'source_link'  => $combined['url'],
611                                         'source_photo' => $combined['photo'],
612                                         'verb'         => ($mutual?ACTIVITY_FRIEND:ACTIVITY_FOLLOW),
613                                         'otype'        => 'intro'
614                                 ]);
615                         }
616                 }
617
618                 System::xmlExit(0); // Success
619                 return; // NOTREACHED
620                 ////////////////////// End of this scenario ///////////////////////////////////////////////
621         }
622
623         // somebody arrived here by mistake or they are fishing. Send them to the homepage.
624         $a->internalRedirect();
625         // NOTREACHED
626 }