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