]> git.mxchange.org Git - friendica.git/blob - mod/dfrn_confirm.php
Cleaning confirm
[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                         q("UPDATE `contact` SET `prvkey` = '%s' WHERE `id` = %d AND `uid` = %d",
166                                 DBA::escape($private_key),
167                                 intval($contact_id),
168                                 intval($uid)
169                         );
170
171                         $params = [];
172
173                         /*
174                          * Per the DFRN protocol, we will verify both ends by encrypting the dfrn_id with our
175                          * site private key (person on the other end can decrypt it with our site public key).
176                          * Then encrypt our profile URL with the other person's site public key. They can decrypt
177                          * it with their site private key. If the decryption on the other end fails for either
178                          * item, it indicates tampering or key failure on at least one site and we will not be
179                          * able to provide a secure communication pathway.
180                          *
181                          * If other site is willing to accept full encryption, (aes_allow is 1 AND we have php5.3
182                          * or later) then we encrypt the personal public key we send them using AES-256-CBC and a
183                          * random key which is encrypted with their site public key.
184                          */
185
186                         $src_aes_key = openssl_random_pseudo_bytes(64);
187
188                         $result = '';
189                         openssl_private_encrypt($dfrn_id, $result, $user['prvkey']);
190
191                         $params['dfrn_id'] = bin2hex($result);
192                         $params['public_key'] = $public_key;
193
194                         $my_url = System::baseUrl() . '/profile/' . $user['nickname'];
195
196                         openssl_public_encrypt($my_url, $params['source_url'], $site_pubkey);
197                         $params['source_url'] = bin2hex($params['source_url']);
198
199                         if ($aes_allow && function_exists('openssl_encrypt')) {
200                                 openssl_public_encrypt($src_aes_key, $params['aes_key'], $site_pubkey);
201                                 $params['aes_key'] = bin2hex($params['aes_key']);
202                                 $params['public_key'] = bin2hex(openssl_encrypt($public_key, 'AES-256-CBC', $src_aes_key));
203                         }
204
205                         $params['dfrn_version'] = DFRN_PROTOCOL_VERSION;
206                         if ($duplex == 1) {
207                                 $params['duplex'] = 1;
208                         }
209
210                         if ($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) {
211                                 $params['page'] = 1;
212                         }
213
214                         if ($user['page-flags'] == User::PAGE_FLAGS_PRVGROUP) {
215                                 $params['page'] = 2;
216                         }
217
218                         Logger::log('Confirm: posting data to ' . $dfrn_confirm . ': ' . print_r($params, true), Logger::DATA);
219
220                         /*
221                          *
222                          * POST all this stuff to the other site.
223                          * Temporarily raise the network timeout to 120 seconds because the default 60
224                          * doesn't always give the other side quite enough time to decrypt everything.
225                          *
226                          */
227
228                         $res = Network::post($dfrn_confirm, $params, null, $redirects, 120)->getBody();
229
230                         Logger::log(' Confirm: received data: ' . $res, Logger::DATA);
231
232                         // Now figure out what they responded. Try to be robust if the remote site is
233                         // having difficulty and throwing up errors of some kind.
234
235                         $leading_junk = substr($res, 0, strpos($res, '<?xml'));
236
237                         $res = substr($res, strpos($res, '<?xml'));
238                         if (!strlen($res)) {
239                                 // No XML at all, this exchange is messed up really bad.
240                                 // We shouldn't proceed, because the xml parser might choke,
241                                 // and $status is going to be zero, which indicates success.
242                                 // We can hardly call this a success.
243                                 notice(L10n::t('Response from remote site was not understood.') . EOL);
244                                 return;
245                         }
246
247                         if (strlen($leading_junk) && Config::get('system', 'debugging')) {
248                                 // This might be more common. Mixed error text and some XML.
249                                 // If we're configured for debugging, show the text. Proceed in either case.
250                                 notice(L10n::t('Unexpected response from remote site: ') . EOL . $leading_junk . EOL);
251                         }
252
253                         if (stristr($res, "<status") === false) {
254                                 // wrong xml! stop here!
255                                 Logger::log('Unexpected response posting to ' . $dfrn_confirm);
256                                 notice(L10n::t('Unexpected response from remote site: ') . EOL . htmlspecialchars($res) . EOL);
257                                 return;
258                         }
259
260                         $xml = XML::parseString($res);
261                         $status = (int) $xml->status;
262                         $message = XML::unescape($xml->message);   // human readable text of what may have gone wrong.
263                         switch ($status) {
264                                 case 0:
265                                         info(L10n::t("Confirmation completed successfully.") . EOL);
266                                         break;
267                                 case 1:
268                                         // birthday paradox - generate new dfrn-id and fall through.
269                                         $new_dfrn_id = Strings::getRandomHex();
270                                         q("UPDATE contact SET `issued-id` = '%s' WHERE `id` = %d AND `uid` = %d",
271                                                 DBA::escape($new_dfrn_id),
272                                                 intval($contact_id),
273                                                 intval($uid)
274                                         );
275
276                                 case 2:
277                                         notice(L10n::t("Temporary failure. Please wait and try again.") . EOL);
278                                         break;
279                                 case 3:
280                                         notice(L10n::t("Introduction failed or was revoked.") . EOL);
281                                         break;
282                         }
283
284                         if (strlen($message)) {
285                                 notice(L10n::t('Remote site reported: ') . $message . EOL);
286                         }
287
288                         if (($status == 0) && $intro_id) {
289                                 $intro = DBA::selectFirst('intro', ['note'], ['id' => $intro_id]);
290                                 if (DBA::isResult($intro)) {
291                                         DBA::update('contact', ['reason' => $intro['note']], ['id' => $contact_id]);
292                                 }
293
294                                 // Success. Delete the notification.
295                                 DBA::delete('intro', ['id' => $intro_id]);
296                         }
297
298                         if ($status != 0) {
299                                 return;
300                         }
301                 }
302
303                 /*
304                  * We have now established a relationship with the other site.
305                  * Let's make our own personal copy of their profile photo so we don't have
306                  * to always load it from their site.
307                  *
308                  * We will also update the contact record with the nature and scope of the relationship.
309                  */
310                 Contact::updateAvatar($contact['photo'], $uid, $contact_id);
311
312                 Logger::log('dfrn_confirm: confirm - imported photos');
313
314                 if ($network === Protocol::DFRN) {
315                         $new_relation = Contact::FOLLOWER;
316
317                         if (($relation == Contact::SHARING) || ($duplex)) {
318                                 $new_relation = Contact::FRIEND;
319                         }
320
321                         if (($relation == Contact::SHARING) && ($duplex)) {
322                                 $duplex = 0;
323                         }
324
325                         $r = q("UPDATE `contact` SET `rel` = %d,
326                                 `name-date` = '%s',
327                                 `uri-date` = '%s',
328                                 `blocked` = 0,
329                                 `pending` = 0,
330                                 `duplex` = %d,
331                                 `hidden` = %d,
332                                 `network` = '%s' WHERE `id` = %d
333                         ",
334                                 intval($new_relation),
335                                 DBA::escape(DateTimeFormat::utcNow()),
336                                 DBA::escape(DateTimeFormat::utcNow()),
337                                 intval($duplex),
338                                 intval($hidden),
339                                 DBA::escape(Protocol::DFRN),
340                                 intval($contact_id)
341                         );
342                 } else {
343                         if ($network == Protocol::ACTIVITYPUB) {
344                                 ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $uid);
345                                 // Setting "pending" to true on a bidirectional contact request could create a problem when it isn't accepted on the other side
346                                 // Then we have got a situation where - although one direction is accepted - the contact still appears as pending.
347                                 // Possibly we need two different "pending" fields, one for incoming, one for outgoing?
348                                 // This has to be thought over, but for now this here is a better solution.
349                                 // $pending = $duplex;
350                                 $pending = false;
351                         } else {
352                                 $pending = false;
353                         }
354
355                         // $network !== Protocol::DFRN
356                         $network = defaults($contact, 'network', Protocol::OSTATUS);
357
358                         $arr = Probe::uri($contact['url'], $network);
359
360                         $notify  = defaults($contact, 'notify' , $arr['notify']);
361                         $poll    = defaults($contact, 'poll'   , $arr['poll']);
362
363                         $addr = $arr['addr'];
364
365                         $new_relation = $contact['rel'];
366                         $writable = $contact['writable'];
367
368                         if (in_array($network, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) {
369                                 if ($duplex) {
370                                         $new_relation = Contact::FRIEND;
371                                 } else {
372                                         $new_relation = Contact::FOLLOWER;
373                                 }
374
375                                 if ($new_relation != Contact::FOLLOWER) {
376                                         $writable = 1;
377                                 }
378                         }
379
380                         DBA::delete('intro', ['id' => $intro_id]);
381
382                         $fields = ['name-date' => DateTimeFormat::utcNow(),
383                                 'uri-date' => DateTimeFormat::utcNow(), 'addr' => $addr,
384                                 'notify' => $notify, 'poll' => $poll, 'blocked' => false,
385                                 'pending' => $pending, 'network' => $network,
386                                 'writable' => $writable, 'hidden' => $hidden, 'rel' => $new_relation];
387                         DBA::update('contact', $fields, ['id' => $contact_id]);
388                 }
389
390                 if (!DBA::isResult($r)) {
391                         notice(L10n::t('Unable to set contact photo.') . EOL);
392                 }
393
394                 // reload contact info
395                 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
396                 if ((isset($new_relation) && $new_relation == Contact::FRIEND)) {
397                         if (DBA::isResult($contact) && ($contact['network'] === Protocol::DIASPORA)) {
398                                 $ret = Diaspora::sendShare($user, $contact);
399                                 Logger::log('share returns: ' . $ret);
400                         }
401                 }
402
403                 Group::addMember(User::getDefaultGroup($uid, $contact["network"]), $contact['id']);
404
405                 if ($network == Protocol::ACTIVITYPUB && $duplex) {
406                         ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid);
407                 }
408
409                 // Let's send our user to the contact editor in case they want to
410                 // do anything special with this new friend.
411                 if ($handsfree === null) {
412                         $a->internalRedirect('contact/' . intval($contact_id));
413                 } else {
414                         return;
415                 }
416                 //NOTREACHED
417         }
418
419         /*
420          * End of Scenario 1. [Local confirmation of remote friend request].
421          *
422          * Begin Scenario 2. This is the remote response to the above scenario.
423          * This will take place on the site that originally initiated the friend request.
424          * In the section above where the confirming party makes a POST and
425          * retrieves xml status information, they are communicating with the following code.
426          */
427         if (!empty($_POST['source_url'])) {
428                 // We are processing an external confirmation to an introduction created by our user.
429                 $public_key =         defaults($_POST, 'public_key', '');
430                 $dfrn_id    = hex2bin(defaults($_POST, 'dfrn_id'   , ''));
431                 $source_url = hex2bin(defaults($_POST, 'source_url', ''));
432                 $aes_key    =         defaults($_POST, 'aes_key'   , '');
433                 $duplex     =  intval(defaults($_POST, 'duplex'    , 0));
434                 $page       =  intval(defaults($_POST, 'page'      , 0));
435
436                 $forum = (($page == 1) ? 1 : 0);
437                 $prv   = (($page == 2) ? 1 : 0);
438
439                 Logger::log('dfrn_confirm: requestee contacted: ' . $node);
440
441                 Logger::log('dfrn_confirm: request: POST=' . print_r($_POST, true), Logger::DATA);
442
443                 // If $aes_key is set, both of these items require unpacking from the hex transport encoding.
444
445                 if (!empty($aes_key)) {
446                         $aes_key = hex2bin($aes_key);
447                         $public_key = hex2bin($public_key);
448                 }
449
450                 // Find our user's account
451                 $user = DBA::selectFirst('user', [], ['nickname' => $node]);
452                 if (!DBA::isResult($user)) {
453                         $message = L10n::t('No user record found for \'%s\' ', $node);
454                         System::xmlExit(3, $message); // failure
455                         // NOTREACHED
456                 }
457
458                 $my_prvkey = $user['prvkey'];
459                 $local_uid = $user['uid'];
460
461
462                 if (!strstr($my_prvkey, 'PRIVATE KEY')) {
463                         $message = L10n::t('Our site encryption key is apparently messed up.');
464                         System::xmlExit(3, $message);
465                 }
466
467                 // verify everything
468
469                 $decrypted_source_url = "";
470                 openssl_private_decrypt($source_url, $decrypted_source_url, $my_prvkey);
471
472
473                 if (!strlen($decrypted_source_url)) {
474                         $message = L10n::t('Empty site URL was provided or URL could not be decrypted by us.');
475                         System::xmlExit(3, $message);
476                         // NOTREACHED
477                 }
478
479                 $contact = DBA::selectFirst('contact', [], ['url' => $decrypted_source_url, 'uid' => $local_uid]);
480                 if (!DBA::isResult($contact)) {
481                         if (strstr($decrypted_source_url, 'http:')) {
482                                 $newurl = str_replace('http:', 'https:', $decrypted_source_url);
483                         } else {
484                                 $newurl = str_replace('https:', 'http:', $decrypted_source_url);
485                         }
486
487                         $contact = DBA::selectFirst('contact', [], ['url' => $newurl, 'uid' => $local_uid]);
488                         if (!DBA::isResult($contact)) {
489                                 // this is either a bogus confirmation (?) or we deleted the original introduction.
490                                 $message = L10n::t('Contact record was not found for you on our site.');
491                                 System::xmlExit(3, $message);
492                                 return; // NOTREACHED
493                         }
494                 }
495
496                 $relation = $contact['rel'];
497
498                 // Decrypt all this stuff we just received
499
500                 $foreign_pubkey = $contact['site-pubkey'];
501                 $dfrn_record = $contact['id'];
502
503                 if (!$foreign_pubkey) {
504                         $message = L10n::t('Site public key not available in contact record for URL %s.', $decrypted_source_url);
505                         System::xmlExit(3, $message);
506                 }
507
508                 $decrypted_dfrn_id = "";
509                 openssl_public_decrypt($dfrn_id, $decrypted_dfrn_id, $foreign_pubkey);
510
511                 if (strlen($aes_key)) {
512                         $decrypted_aes_key = "";
513                         openssl_private_decrypt($aes_key, $decrypted_aes_key, $my_prvkey);
514                         $dfrn_pubkey = openssl_decrypt($public_key, 'AES-256-CBC', $decrypted_aes_key);
515                 } else {
516                         $dfrn_pubkey = $public_key;
517                 }
518
519                 if (DBA::exists('contact', ['dfrn-id' => $decrypted_dfrn_id])) {
520                         $message = L10n::t('The ID provided by your system is a duplicate on our system. It should work if you try again.');
521                         System::xmlExit(1, $message); // Birthday paradox - duplicate dfrn-id
522                         // NOTREACHED
523                 }
524
525                 $r = q("UPDATE `contact` SET `dfrn-id` = '%s', `pubkey` = '%s' WHERE `id` = %d",
526                         DBA::escape($decrypted_dfrn_id),
527                         DBA::escape($dfrn_pubkey),
528                         intval($dfrn_record)
529                 );
530                 if (!DBA::isResult($r)) {
531                         $message = L10n::t('Unable to set your contact credentials on our system.');
532                         System::xmlExit(3, $message);
533                 }
534
535                 // It's possible that the other person also requested friendship.
536                 // If it is a duplex relationship, ditch the issued-id if one exists.
537
538                 if ($duplex) {
539                         q("UPDATE `contact` SET `issued-id` = '' WHERE `id` = %d",
540                                 intval($dfrn_record)
541                         );
542                 }
543
544                 // We're good but now we have to scrape the profile photo and send notifications.
545                 $contact = DBA::selectFirst('contact', ['photo'], ['id' => $dfrn_record]);
546                 if (DBA::isResult($contact)) {
547                         $photo = $contact['photo'];
548                 } else {
549                         $photo = System::baseUrl() . '/images/person-300.jpg';
550                 }
551
552                 Contact::updateAvatar($photo, $local_uid, $dfrn_record);
553
554                 Logger::log('dfrn_confirm: request - photos imported');
555
556                 $new_relation = Contact::SHARING;
557
558                 if (($relation == Contact::FOLLOWER) || ($duplex)) {
559                         $new_relation = Contact::FRIEND;
560                 }
561
562                 if (($relation == Contact::FOLLOWER) && ($duplex)) {
563                         $duplex = 0;
564                 }
565
566                 $r = q("UPDATE `contact` SET
567                         `rel` = %d,
568                         `name-date` = '%s',
569                         `uri-date` = '%s',
570                         `blocked` = 0,
571                         `pending` = 0,
572                         `duplex` = %d,
573                         `forum` = %d,
574                         `prv` = %d,
575                         `network` = '%s' WHERE `id` = %d
576                 ",
577                         intval($new_relation),
578                         DBA::escape(DateTimeFormat::utcNow()),
579                         DBA::escape(DateTimeFormat::utcNow()),
580                         intval($duplex),
581                         intval($forum),
582                         intval($prv),
583                         DBA::escape(Protocol::DFRN),
584                         intval($dfrn_record)
585                 );
586                 if (!DBA::isResult($r)) {       // indicates schema is messed up or total db failure
587                         $message = L10n::t('Unable to update your contact profile details on our system');
588                         System::xmlExit(3, $message);
589                 }
590
591                 // Otherwise everything seems to have worked and we are almost done. Yay!
592                 // Send an email notification
593
594                 Logger::log('dfrn_confirm: request: info updated');
595
596                 $combined = null;
597                 $r = q("SELECT `contact`.*, `user`.*
598                         FROM `contact`
599                         LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
600                         WHERE `contact`.`id` = %d
601                         LIMIT 1",
602                         intval($dfrn_record)
603                 );
604                 if (DBA::isResult($r)) {
605                         $combined = $r[0];
606
607                         if ($combined['notify-flags'] & NOTIFY_CONFIRM) {
608                                 $mutual = ($new_relation == Contact::FRIEND);
609                                 notification([
610                                         'type'         => NOTIFY_CONFIRM,
611                                         'notify_flags' => $combined['notify-flags'],
612                                         'language'     => $combined['language'],
613                                         'to_name'      => $combined['username'],
614                                         'to_email'     => $combined['email'],
615                                         'uid'          => $combined['uid'],
616                                         'link'         => System::baseUrl() . '/contact/' . $dfrn_record,
617                                         'source_name'  => ((strlen(stripslashes($combined['name']))) ? stripslashes($combined['name']) : L10n::t('[Name Withheld]')),
618                                         'source_link'  => $combined['url'],
619                                         'source_photo' => $combined['photo'],
620                                         'verb'         => ($mutual?ACTIVITY_FRIEND:ACTIVITY_FOLLOW),
621                                         'otype'        => 'intro'
622                                 ]);
623                         }
624                 }
625
626                 System::xmlExit(0); // Success
627                 return; // NOTREACHED
628                 ////////////////////// End of this scenario ///////////////////////////////////////////////
629         }
630
631         // somebody arrived here by mistake or they are fishing. Send them to the homepage.
632         $a->internalRedirect();
633         // NOTREACHED
634 }