]> git.mxchange.org Git - friendica.git/blob - mod/dfrn_confirm.php
Storing the protocol while following a contact
[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                 // an empty DFRN-ID tells us that it had been a request via AP from a Friendica contact
147                 if (($network === Protocol::DFRN) && empty($dfrn_id)) {
148                         $network = Contact::getProtocol($contact['url'], $contact['network']);
149                 }
150
151                 if ($network === Protocol::DFRN) {
152                         /*
153                          * Generate a key pair for all further communications with this person.
154                          * We have a keypair for every contact, and a site key for unknown people.
155                          * This provides a means to carry on relationships with other people if
156                          * any single key is compromised. It is a robust key. We're much more
157                          * worried about key leakage than anybody cracking it.
158                          */
159                         $res = Crypto::newKeypair(4096);
160
161                         $private_key = $res['prvkey'];
162                         $public_key  = $res['pubkey'];
163
164                         // Save the private key. Send them the public key.
165                         $fields = ['prvkey' => $private_key, 'protocol' => Protocol::DFRN];
166                         DBA::update('contact', $fields, ['id' => $contact_id]);
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'] == User::PAGE_FLAGS_COMMUNITY) {
208                                 $params['page'] = 1;
209                         }
210
211                         if ($user['page-flags'] == User::PAGE_FLAGS_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::unescape($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 = Strings::getRandomHex();
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                 } else {
299                         DBA::update('contact', ['protocol' => $network], ['id' => $contact_id]);
300                 }
301
302                 /*
303                  * We have now established a relationship with the other site.
304                  * Let's make our own personal copy of their profile photo so we don't have
305                  * to always load it from their site.
306                  *
307                  * We will also update the contact record with the nature and scope of the relationship.
308                  */
309                 Contact::updateAvatar($contact['photo'], $uid, $contact_id);
310
311                 Logger::log('dfrn_confirm: confirm - imported photos');
312
313                 if ($network === Protocol::DFRN) {
314                         $new_relation = Contact::FOLLOWER;
315
316                         if (($relation == Contact::SHARING) || ($duplex)) {
317                                 $new_relation = Contact::FRIEND;
318                         }
319
320                         if (($relation == Contact::SHARING) && ($duplex)) {
321                                 $duplex = 0;
322                         }
323
324                         $r = q("UPDATE `contact` SET `rel` = %d,
325                                 `name-date` = '%s',
326                                 `uri-date` = '%s',
327                                 `blocked` = 0,
328                                 `pending` = 0,
329                                 `duplex` = %d,
330                                 `hidden` = %d,
331                                 `network` = '%s' WHERE `id` = %d
332                         ",
333                                 intval($new_relation),
334                                 DBA::escape(DateTimeFormat::utcNow()),
335                                 DBA::escape(DateTimeFormat::utcNow()),
336                                 intval($duplex),
337                                 intval($hidden),
338                                 DBA::escape(Protocol::DFRN),
339                                 intval($contact_id)
340                         );
341                 } else {
342                         if ($network == Protocol::ACTIVITYPUB) {
343                                 ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $uid);
344                                 // Setting "pending" to true on a bidirectional contact request could create a problem when it isn't accepted on the other side
345                                 // Then we have got a situation where - although one direction is accepted - the contact still appears as pending.
346                                 // Possibly we need two different "pending" fields, one for incoming, one for outgoing?
347                                 // This has to be thought over, but for now this here is a better solution.
348                                 // $pending = $duplex;
349                                 $pending = false;
350                         } else {
351                                 $pending = false;
352                         }
353
354                         // $network !== Protocol::DFRN
355                         $network = defaults($contact, 'network', Protocol::OSTATUS);
356
357                         $arr = Probe::uri($contact['url'], $network);
358
359                         $notify  = defaults($contact, 'notify' , $arr['notify']);
360                         $poll    = defaults($contact, 'poll'   , $arr['poll']);
361
362                         $addr = $arr['addr'];
363
364                         $new_relation = $contact['rel'];
365                         $writable = $contact['writable'];
366
367                         if (in_array($network, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
368                                 if ($duplex) {
369                                         $new_relation = Contact::FRIEND;
370                                 } else {
371                                         $new_relation = Contact::FOLLOWER;
372                                 }
373
374                                 if ($new_relation != Contact::FOLLOWER) {
375                                         $writable = 1;
376                                 }
377                         }
378
379                         DBA::delete('intro', ['id' => $intro_id]);
380
381                         $fields = ['name-date' => DateTimeFormat::utcNow(),
382                                 'uri-date' => DateTimeFormat::utcNow(), 'addr' => $addr,
383                                 'notify' => $notify, 'poll' => $poll, 'blocked' => false,
384                                 'pending' => $pending, 'network' => $network,
385                                 'writable' => $writable, 'hidden' => $hidden, 'rel' => $new_relation];
386                         DBA::update('contact', $fields, ['id' => $contact_id]);
387                 }
388
389                 if (!DBA::isResult($r)) {
390                         notice(L10n::t('Unable to set contact photo.') . EOL);
391                 }
392
393                 // reload contact info
394                 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
395                 if ((isset($new_relation) && $new_relation == Contact::FRIEND)) {
396                         if (DBA::isResult($contact) && ($contact['network'] === Protocol::DIASPORA)) {
397                                 $ret = Diaspora::sendShare($user, $contact);
398                                 Logger::log('share returns: ' . $ret);
399                         }
400                 }
401
402                 Group::addMember(User::getDefaultGroup($uid, $contact["network"]), $contact['id']);
403
404                 if ($network == Protocol::ACTIVITYPUB && $duplex) {
405                         ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid);
406                 }
407
408                 // Let's send our user to the contact editor in case they want to
409                 // do anything special with this new friend.
410                 if ($handsfree === null) {
411                         $a->internalRedirect('contact/' . intval($contact_id));
412                 } else {
413                         return;
414                 }
415                 //NOTREACHED
416         }
417
418         /*
419          * End of Scenario 1. [Local confirmation of remote friend request].
420          *
421          * Begin Scenario 2. This is the remote response to the above scenario.
422          * This will take place on the site that originally initiated the friend request.
423          * In the section above where the confirming party makes a POST and
424          * retrieves xml status information, they are communicating with the following code.
425          */
426         if (!empty($_POST['source_url'])) {
427                 // We are processing an external confirmation to an introduction created by our user.
428                 $public_key =         defaults($_POST, 'public_key', '');
429                 $dfrn_id    = hex2bin(defaults($_POST, 'dfrn_id'   , ''));
430                 $source_url = hex2bin(defaults($_POST, 'source_url', ''));
431                 $aes_key    =         defaults($_POST, 'aes_key'   , '');
432                 $duplex     =  intval(defaults($_POST, 'duplex'    , 0));
433                 $page       =  intval(defaults($_POST, 'page'      , 0));
434
435                 $forum = (($page == 1) ? 1 : 0);
436                 $prv   = (($page == 2) ? 1 : 0);
437
438                 Logger::log('dfrn_confirm: requestee contacted: ' . $node);
439
440                 Logger::log('dfrn_confirm: request: POST=' . print_r($_POST, true), Logger::DATA);
441
442                 // If $aes_key is set, both of these items require unpacking from the hex transport encoding.
443
444                 if (!empty($aes_key)) {
445                         $aes_key = hex2bin($aes_key);
446                         $public_key = hex2bin($public_key);
447                 }
448
449                 // Find our user's account
450                 $user = DBA::selectFirst('user', [], ['nickname' => $node]);
451                 if (!DBA::isResult($user)) {
452                         $message = L10n::t('No user record found for \'%s\' ', $node);
453                         System::xmlExit(3, $message); // failure
454                         // NOTREACHED
455                 }
456
457                 $my_prvkey = $user['prvkey'];
458                 $local_uid = $user['uid'];
459
460
461                 if (!strstr($my_prvkey, 'PRIVATE KEY')) {
462                         $message = L10n::t('Our site encryption key is apparently messed up.');
463                         System::xmlExit(3, $message);
464                 }
465
466                 // verify everything
467
468                 $decrypted_source_url = "";
469                 openssl_private_decrypt($source_url, $decrypted_source_url, $my_prvkey);
470
471
472                 if (!strlen($decrypted_source_url)) {
473                         $message = L10n::t('Empty site URL was provided or URL could not be decrypted by us.');
474                         System::xmlExit(3, $message);
475                         // NOTREACHED
476                 }
477
478                 $contact = DBA::selectFirst('contact', [], ['url' => $decrypted_source_url, 'uid' => $local_uid]);
479                 if (!DBA::isResult($contact)) {
480                         if (strstr($decrypted_source_url, 'http:')) {
481                                 $newurl = str_replace('http:', 'https:', $decrypted_source_url);
482                         } else {
483                                 $newurl = str_replace('https:', 'http:', $decrypted_source_url);
484                         }
485
486                         $contact = DBA::selectFirst('contact', [], ['url' => $newurl, 'uid' => $local_uid]);
487                         if (!DBA::isResult($contact)) {
488                                 // this is either a bogus confirmation (?) or we deleted the original introduction.
489                                 $message = L10n::t('Contact record was not found for you on our site.');
490                                 System::xmlExit(3, $message);
491                                 return; // NOTREACHED
492                         }
493                 }
494
495                 $relation = $contact['rel'];
496
497                 // Decrypt all this stuff we just received
498
499                 $foreign_pubkey = $contact['site-pubkey'];
500                 $dfrn_record = $contact['id'];
501
502                 if (!$foreign_pubkey) {
503                         $message = L10n::t('Site public key not available in contact record for URL %s.', $decrypted_source_url);
504                         System::xmlExit(3, $message);
505                 }
506
507                 $decrypted_dfrn_id = "";
508                 openssl_public_decrypt($dfrn_id, $decrypted_dfrn_id, $foreign_pubkey);
509
510                 if (strlen($aes_key)) {
511                         $decrypted_aes_key = "";
512                         openssl_private_decrypt($aes_key, $decrypted_aes_key, $my_prvkey);
513                         $dfrn_pubkey = openssl_decrypt($public_key, 'AES-256-CBC', $decrypted_aes_key);
514                 } else {
515                         $dfrn_pubkey = $public_key;
516                 }
517
518                 if (DBA::exists('contact', ['dfrn-id' => $decrypted_dfrn_id])) {
519                         $message = L10n::t('The ID provided by your system is a duplicate on our system. It should work if you try again.');
520                         System::xmlExit(1, $message); // Birthday paradox - duplicate dfrn-id
521                         // NOTREACHED
522                 }
523
524                 $r = q("UPDATE `contact` SET `dfrn-id` = '%s', `pubkey` = '%s' WHERE `id` = %d",
525                         DBA::escape($decrypted_dfrn_id),
526                         DBA::escape($dfrn_pubkey),
527                         intval($dfrn_record)
528                 );
529                 if (!DBA::isResult($r)) {
530                         $message = L10n::t('Unable to set your contact credentials on our system.');
531                         System::xmlExit(3, $message);
532                 }
533
534                 // It's possible that the other person also requested friendship.
535                 // If it is a duplex relationship, ditch the issued-id if one exists.
536
537                 if ($duplex) {
538                         q("UPDATE `contact` SET `issued-id` = '' WHERE `id` = %d",
539                                 intval($dfrn_record)
540                         );
541                 }
542
543                 // We're good but now we have to scrape the profile photo and send notifications.
544                 $contact = DBA::selectFirst('contact', ['photo'], ['id' => $dfrn_record]);
545                 if (DBA::isResult($contact)) {
546                         $photo = $contact['photo'];
547                 } else {
548                         $photo = System::baseUrl() . '/images/person-300.jpg';
549                 }
550
551                 Contact::updateAvatar($photo, $local_uid, $dfrn_record);
552
553                 Logger::log('dfrn_confirm: request - photos imported');
554
555                 $new_relation = Contact::SHARING;
556
557                 if (($relation == Contact::FOLLOWER) || ($duplex)) {
558                         $new_relation = Contact::FRIEND;
559                 }
560
561                 if (($relation == Contact::FOLLOWER) && ($duplex)) {
562                         $duplex = 0;
563                 }
564
565                 $r = q("UPDATE `contact` SET
566                         `rel` = %d,
567                         `name-date` = '%s',
568                         `uri-date` = '%s',
569                         `blocked` = 0,
570                         `pending` = 0,
571                         `duplex` = %d,
572                         `forum` = %d,
573                         `prv` = %d,
574                         `network` = '%s' WHERE `id` = %d
575                 ",
576                         intval($new_relation),
577                         DBA::escape(DateTimeFormat::utcNow()),
578                         DBA::escape(DateTimeFormat::utcNow()),
579                         intval($duplex),
580                         intval($forum),
581                         intval($prv),
582                         DBA::escape(Protocol::DFRN),
583                         intval($dfrn_record)
584                 );
585                 if (!DBA::isResult($r)) {       // indicates schema is messed up or total db failure
586                         $message = L10n::t('Unable to update your contact profile details on our system');
587                         System::xmlExit(3, $message);
588                 }
589
590                 // Otherwise everything seems to have worked and we are almost done. Yay!
591                 // Send an email notification
592
593                 Logger::log('dfrn_confirm: request: info updated');
594
595                 $combined = null;
596                 $r = q("SELECT `contact`.*, `user`.*
597                         FROM `contact`
598                         LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
599                         WHERE `contact`.`id` = %d
600                         LIMIT 1",
601                         intval($dfrn_record)
602                 );
603                 if (DBA::isResult($r)) {
604                         $combined = $r[0];
605
606                         if ($combined['notify-flags'] & NOTIFY_CONFIRM) {
607                                 $mutual = ($new_relation == Contact::FRIEND);
608                                 notification([
609                                         'type'         => NOTIFY_CONFIRM,
610                                         'notify_flags' => $combined['notify-flags'],
611                                         'language'     => $combined['language'],
612                                         'to_name'      => $combined['username'],
613                                         'to_email'     => $combined['email'],
614                                         'uid'          => $combined['uid'],
615                                         'link'         => System::baseUrl() . '/contact/' . $dfrn_record,
616                                         'source_name'  => ((strlen(stripslashes($combined['name']))) ? stripslashes($combined['name']) : L10n::t('[Name Withheld]')),
617                                         'source_link'  => $combined['url'],
618                                         'source_photo' => $combined['photo'],
619                                         'verb'         => ($mutual?ACTIVITY_FRIEND:ACTIVITY_FOLLOW),
620                                         'otype'        => 'intro'
621                                 ]);
622                         }
623                 }
624
625                 System::xmlExit(0); // Success
626                 return; // NOTREACHED
627                 ////////////////////// End of this scenario ///////////////////////////////////////////////
628         }
629
630         // somebody arrived here by mistake or they are fishing. Send them to the homepage.
631         $a->internalRedirect();
632         // NOTREACHED
633 }