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