]> git.mxchange.org Git - friendica.git/blob - mod/dfrn_request.php
Move fetch_url
[friendica.git] / mod / dfrn_request.php
1 <?php
2
3 /**
4  * @file mod/dfrn_request.php
5  * @brief Module: dfrn_request
6  *
7  * Purpose: Handles communication associated with the issuance of
8  * friend requests.
9  *
10  * @see PDF with dfrn specs: https://github.com/friendica/friendica/blob/master/spec/dfrn2.pdf
11  *    You also find a graphic which describes the confirmation process at
12  *    https://github.com/friendica/friendica/blob/master/spec/dfrn2_contact_request.png
13  */
14 use Friendica\App;
15 use Friendica\Core\Config;
16 use Friendica\Core\L10n;
17 use Friendica\Core\PConfig;
18 use Friendica\Core\System;
19 use Friendica\Database\DBM;
20 use Friendica\Model\Contact;
21 use Friendica\Model\Group;
22 use Friendica\Model\User;
23 use Friendica\Model\Profile;
24 use Friendica\Module\Login;
25 use Friendica\Network\Probe;
26 use Friendica\Util\Network;
27
28 require_once 'include/enotify.php';
29
30 function dfrn_request_init(App $a)
31 {
32         if ($a->argc > 1) {
33                 $which = $a->argv[1];
34         }
35
36         Profile::load($a, $which);
37         return;
38 }
39
40 /**
41  * Function: dfrn_request_post
42  *
43  * Purpose:
44  * Handles multiple scenarios.
45  *
46  * Scenario 1:
47  * Clicking 'submit' on a friend request page.
48  *
49  * Scenario 2:
50  * Following Scenario 1, we are brought back to our home site
51  * in order to link our friend request with our own server cell.
52  * After logging in, we click 'submit' to approve the linkage.
53  *
54  */
55 function dfrn_request_post(App $a)
56 {
57         if (($a->argc != 2) || (!count($a->profile))) {
58                 logger('Wrong count of argc or profiles: argc=' . $a->argc . ',profile()=' . count($a->profile));
59                 return;
60         }
61
62         if (x($_POST, 'cancel')) {
63                 goaway(System::baseUrl());
64         }
65
66         /*
67          * Scenario 2: We've introduced ourself to another cell, then have been returned to our own cell
68          * to confirm the request, and then we've clicked submit (perhaps after logging in).
69          * That brings us here:
70          */
71         if ((x($_POST, 'localconfirm')) && ($_POST['localconfirm'] == 1)) {
72                 // Ensure this is a valid request
73                 if (local_user() && ($a->user['nickname'] == $a->argv[1]) && (x($_POST, 'dfrn_url'))) {
74                         $dfrn_url = notags(trim($_POST['dfrn_url']));
75                         $aes_allow = (((x($_POST, 'aes_allow')) && ($_POST['aes_allow'] == 1)) ? 1 : 0);
76                         $confirm_key = ((x($_POST, 'confirm_key')) ? $_POST['confirm_key'] : "");
77                         $hidden = ((x($_POST, 'hidden-contact')) ? intval($_POST['hidden-contact']) : 0);
78                         $contact_record = null;
79                         $blocked = 1;
80                         $pending = 1;
81
82                         if (x($dfrn_url)) {
83                                 // Lookup the contact based on their URL (which is the only unique thing we have at the moment)
84                                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND NOT `self` LIMIT 1",
85                                         intval(local_user()),
86                                         dbesc(normalise_link($dfrn_url))
87                                 );
88
89                                 if (DBM::is_result($r)) {
90                                         if (strlen($r[0]['dfrn-id'])) {
91                                                 // We don't need to be here. It has already happened.
92                                                 notice(L10n::t("This introduction has already been accepted.") . EOL);
93                                                 return;
94                                         } else {
95                                                 $contact_record = $r[0];
96                                         }
97                                 }
98
99                                 if (is_array($contact_record)) {
100                                         $r = q("UPDATE `contact` SET `ret-aes` = %d, hidden = %d WHERE `id` = %d",
101                                                 intval($aes_allow),
102                                                 intval($hidden),
103                                                 intval($contact_record['id'])
104                                         );
105                                 } else {
106                                         // Scrape the other site's profile page to pick up the dfrn links, key, fn, and photo
107                                         $parms = Probe::profile($dfrn_url);
108
109                                         if (!count($parms)) {
110                                                 notice(L10n::t('Profile location is not valid or does not contain profile information.') . EOL);
111                                                 return;
112                                         } else {
113                                                 if (!x($parms, 'fn')) {
114                                                         notice(L10n::t('Warning: profile location has no identifiable owner name.') . EOL);
115                                                 }
116                                                 if (!x($parms, 'photo')) {
117                                                         notice(L10n::t('Warning: profile location has no profile photo.') . EOL);
118                                                 }
119                                                 $invalid = Probe::validDfrn($parms);
120                                                 if ($invalid) {
121                                                         notice(L10n::tt("%d required parameter was not found at the given location", "%d required parameters were not found at the given location", $invalid) . EOL);
122                                                         return;
123                                                 }
124                                         }
125
126                                         $dfrn_request = $parms['dfrn-request'];
127
128                                         $photo = $parms["photo"];
129
130                                         // Escape the entire array
131                                         DBM::esc_array($parms);
132
133                                         // Create a contact record on our site for the other person
134                                         $r = q("INSERT INTO `contact` ( `uid`, `created`,`url`, `nurl`, `addr`, `name`, `nick`, `photo`, `site-pubkey`,
135                                                 `request`, `confirm`, `notify`, `poll`, `poco`, `network`, `aes_allow`, `hidden`, `blocked`, `pending`)
136                                                 VALUES ( %d, '%s', '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d)",
137                                                 intval(local_user()),
138                                                 datetime_convert(),
139                                                 dbesc($dfrn_url),
140                                                 dbesc(normalise_link($dfrn_url)),
141                                                 $parms['addr'],
142                                                 $parms['fn'],
143                                                 $parms['nick'],
144                                                 $parms['photo'],
145                                                 $parms['key'],
146                                                 $parms['dfrn-request'],
147                                                 $parms['dfrn-confirm'],
148                                                 $parms['dfrn-notify'],
149                                                 $parms['dfrn-poll'],
150                                                 $parms['dfrn-poco'],
151                                                 dbesc(NETWORK_DFRN),
152                                                 intval($aes_allow),
153                                                 intval($hidden),
154                                                 intval($blocked),
155                                                 intval($pending)
156                                         );
157                                 }
158
159                                 if ($r) {
160                                         info(L10n::t("Introduction complete.") . EOL);
161                                 }
162
163                                 $r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `site-pubkey` = '%s' LIMIT 1",
164                                         intval(local_user()),
165                                         dbesc($dfrn_url),
166                                         $parms['key'] // this was already escaped
167                                 );
168                                 if (DBM::is_result($r)) {
169                                         Group::addMember(User::getDefaultGroup($uid, $r[0]["network"]), $r[0]['id']);
170
171                                         if (isset($photo)) {
172                                                 Contact::updateAvatar($photo, local_user(), $r[0]["id"], true);
173                                         }
174
175                                         $forwardurl = System::baseUrl() . "/contacts/" . $r[0]['id'];
176                                 } else {
177                                         $forwardurl = System::baseUrl() . "/contacts";
178                                 }
179
180                                 // Allow the blocked remote notification to complete
181                                 if (is_array($contact_record)) {
182                                         $dfrn_request = $contact_record['request'];
183                                 }
184
185                                 if (strlen($dfrn_request) && strlen($confirm_key)) {
186                                         $s = Network::fetchURL($dfrn_request . '?confirm_key=' . $confirm_key);
187                                 }
188
189                                 // (ignore reply, nothing we can do it failed)
190                                 // Old: goaway(Profile::zrl($dfrn_url));
191                                 goaway($forwardurl);
192                                 return; // NOTREACHED
193                         }
194                 }
195
196                 // invalid/bogus request
197                 notice(L10n::t('Unrecoverable protocol error.') . EOL);
198                 goaway(System::baseUrl());
199                 return; // NOTREACHED
200         }
201
202         /*
203          * Otherwise:
204          *
205          * Scenario 1:
206          * We are the requestee. A person from a remote cell has made an introduction
207          * on our profile web page and clicked submit. We will use their DFRN-URL to
208          * figure out how to contact their cell.
209          *
210          * Scrape the originating DFRN-URL for everything we need. Create a contact record
211          * and an introduction to show our user next time he/she logs in.
212          * Finally redirect back to the requestor so that their site can record the request.
213          * If our user (the requestee) later confirms this request, a record of it will need
214          * to exist on the requestor's cell in order for the confirmation process to complete..
215          *
216          * It's possible that neither the requestor or the requestee are logged in at the moment,
217          * and the requestor does not yet have any credentials to the requestee profile.
218          *
219          * Who is the requestee? We've already loaded their profile which means their nickname should be
220          * in $a->argv[1] and we should have their complete info in $a->profile.
221          *
222          */
223         if (!(is_array($a->profile) && count($a->profile))) {
224                 notice(L10n::t('Profile unavailable.') . EOL);
225                 return;
226         }
227
228         $nickname       = $a->profile['nickname'];
229         $notify_flags   = $a->profile['notify-flags'];
230         $uid            = $a->profile['uid'];
231         $maxreq         = intval($a->profile['maxreq']);
232         $contact_record = null;
233         $failed         = false;
234         $parms          = null;
235         $blocked = 1;
236         $pending = 1;
237
238         if (x($_POST, 'dfrn_url')) {
239                 // Block friend request spam
240                 if ($maxreq) {
241                         $r = q("SELECT * FROM `intro` WHERE `datetime` > '%s' AND `uid` = %d",
242                                 dbesc(datetime_convert('UTC', 'UTC', 'now - 24 hours')),
243                                 intval($uid)
244                         );
245                         if (DBM::is_result($r) && count($r) > $maxreq) {
246                                 notice(L10n::t('%s has received too many connection requests today.', $a->profile['name']) . EOL);
247                                 notice(L10n::t('Spam protection measures have been invoked.') . EOL);
248                                 notice(L10n::t('Friends are advised to please try again in 24 hours.') . EOL);
249                                 return;
250                         }
251                 }
252
253                 /* Cleanup old introductions that remain blocked.
254                  * Also remove the contact record, but only if there is no existing relationship
255                  */
256                 $r = q("SELECT `intro`.*, `intro`.`id` AS `iid`, `contact`.`id` AS `cid`, `contact`.`rel`
257                         FROM `intro` LEFT JOIN `contact` on `intro`.`contact-id` = `contact`.`id`
258                         WHERE `intro`.`blocked` = 1 AND `contact`.`self` = 0
259                         AND `intro`.`datetime` < UTC_TIMESTAMP() - INTERVAL 30 MINUTE "
260                 );
261                 if (DBM::is_result($r)) {
262                         foreach ($r as $rr) {
263                                 if (!$rr['rel']) {
264                                         q("DELETE FROM `contact` WHERE `id` = %d AND NOT `self`",
265                                                 intval($rr['cid'])
266                                         );
267                                 }
268                                 q("DELETE FROM `intro` WHERE `id` = %d",
269                                         intval($rr['iid'])
270                                 );
271                         }
272                 }
273
274                 $real_name = x($_POST, 'realname') ? notags(trim($_POST['realname'])) : '';
275
276                 $url = trim($_POST['dfrn_url']);
277                 if (!strlen($url)) {
278                         notice(L10n::t("Invalid locator") . EOL);
279                         return;
280                 }
281
282                 $hcard = '';
283
284                 // Detect the network
285                 $data = Probe::uri($url);
286                 $network = $data["network"];
287
288                 // Canonicalise email-style profile locator
289                 $url = Probe::webfingerDfrn($url, $hcard);
290
291                 if (substr($url, 0, 5) === 'stat:') {
292                         // Every time we detect the remote subscription we define this as OStatus.
293                         // We do this even if it is not OStatus.
294                         // we only need to pass this through another section of the code.
295                         if ($network != NETWORK_DIASPORA) {
296                                 $network = NETWORK_OSTATUS;
297                         }
298
299                         $url = substr($url, 5);
300                 } else {
301                         $network = NETWORK_DFRN;
302                 }
303
304                 logger('dfrn_request: url: ' . $url . ',network=' . $network, LOGGER_DEBUG);
305
306                 if ($network === NETWORK_DFRN) {
307                         $ret = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `self` = 0 LIMIT 1",
308                                 intval($uid),
309                                 dbesc($url)
310                         );
311
312                         if (DBM::is_result($ret)) {
313                                 if (strlen($ret[0]['issued-id'])) {
314                                         notice(L10n::t('You have already introduced yourself here.') . EOL);
315                                         return;
316                                 } elseif ($ret[0]['rel'] == CONTACT_IS_FRIEND) {
317                                         notice(L10n::t('Apparently you are already friends with %s.', $a->profile['name']) . EOL);
318                                         return;
319                                 } else {
320                                         $contact_record = $ret[0];
321                                         $parms = ['dfrn-request' => $ret[0]['request']];
322                                 }
323                         }
324
325                         $issued_id = random_string();
326
327                         if (is_array($contact_record)) {
328                                 // There is a contact record but no issued-id, so this
329                                 // is a reciprocal introduction from a known contact
330                                 $r = q("UPDATE `contact` SET `issued-id` = '%s' WHERE `id` = %d",
331                                         dbesc($issued_id),
332                                         intval($contact_record['id'])
333                                 );
334                         } else {
335                                 $url = validate_url($url);
336                                 if (!$url) {
337                                         notice(L10n::t('Invalid profile URL.') . EOL);
338                                         goaway(System::baseUrl() . '/' . $a->cmd);
339                                         return; // NOTREACHED
340                                 }
341
342                                 if (!allowed_url($url)) {
343                                         notice(L10n::t('Disallowed profile URL.') . EOL);
344                                         goaway(System::baseUrl() . '/' . $a->cmd);
345                                         return; // NOTREACHED
346                                 }
347
348                                 if (blocked_url($url)) {
349                                         notice(L10n::t('Blocked domain') . EOL);
350                                         goaway(System::baseUrl() . '/' . $a->cmd);
351                                         return; // NOTREACHED
352                                 }
353
354                                 $parms = Probe::profile(($hcard) ? $hcard : $url);
355
356                                 if (!count($parms)) {
357                                         notice(L10n::t('Profile location is not valid or does not contain profile information.') . EOL);
358                                         goaway(System::baseUrl() . '/' . $a->cmd);
359                                 } else {
360                                         if (!x($parms, 'fn')) {
361                                                 notice(L10n::t('Warning: profile location has no identifiable owner name.') . EOL);
362                                         }
363                                         if (!x($parms, 'photo')) {
364                                                 notice(L10n::t('Warning: profile location has no profile photo.') . EOL);
365                                         }
366                                         $invalid = Probe::validDfrn($parms);
367                                         if ($invalid) {
368                                                 notice(L10n::tt("%d required parameter was not found at the given location", "%d required parameters were not found at the given location", $invalid) . EOL);
369
370                                                 return;
371                                         }
372                                 }
373
374                                 $parms['url'] = $url;
375                                 $parms['issued-id'] = $issued_id;
376                                 $photo = $parms["photo"];
377
378                                 DBM::esc_array($parms);
379                                 $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `name`, `nick`, `issued-id`, `photo`, `site-pubkey`,
380                                         `request`, `confirm`, `notify`, `poll`, `poco`, `network`, `blocked`, `pending` )
381                                         VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
382                                         intval($uid),
383                                         dbesc(datetime_convert()),
384                                         $parms['url'],
385                                         dbesc(normalise_link($url)),
386                                         $parms['addr'],
387                                         $parms['fn'],
388                                         $parms['nick'],
389                                         $parms['issued-id'],
390                                         $parms['photo'],
391                                         $parms['key'],
392                                         $parms['dfrn-request'],
393                                         $parms['dfrn-confirm'],
394                                         $parms['dfrn-notify'],
395                                         $parms['dfrn-poll'],
396                                         $parms['dfrn-poco'],
397                                         dbesc(NETWORK_DFRN),
398                                         intval($blocked),
399                                         intval($pending)
400                                 );
401
402                                 // find the contact record we just created
403                                 if ($r) {
404                                         $r = q("SELECT `id` FROM `contact`
405                                                 WHERE `uid` = %d AND `url` = '%s' AND `issued-id` = '%s' LIMIT 1",
406                                                 intval($uid),
407                                                 $parms['url'],
408                                                 $parms['issued-id']
409                                         );
410                                         if (DBM::is_result($r)) {
411                                                 $contact_record = $r[0];
412                                                 Contact::updateAvatar($photo, $uid, $contact_record["id"], true);
413                                         }
414                                 }
415                         }
416                         if ($r === false) {
417                                 notice(L10n::t('Failed to update contact record.') . EOL);
418                                 return;
419                         }
420
421                         $hash = random_string() . (string) time();   // Generate a confirm_key
422
423                         if (is_array($contact_record)) {
424                                 $ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `note`, `hash`, `datetime`)
425                                         VALUES ( %d, %d, 1, %d, '%s', '%s', '%s' )",
426                                         intval($uid),
427                                         intval($contact_record['id']),
428                                         ((x($_POST,'knowyou') && ($_POST['knowyou'] == 1)) ? 1 : 0),
429                                         dbesc(notags(trim($_POST['dfrn-request-message']))),
430                                         dbesc($hash),
431                                         dbesc(datetime_convert())
432                                 );
433                         }
434
435                         // This notice will only be seen by the requestor if the requestor and requestee are on the same server.
436                         if (!$failed) {
437                                 info(L10n::t('Your introduction has been sent.') . EOL);
438                         }
439
440                         // "Homecoming" - send the requestor back to their site to record the introduction.
441                         $dfrn_url = bin2hex(System::baseUrl() . '/profile/' . $nickname);
442                         $aes_allow = ((function_exists('openssl_encrypt')) ? 1 : 0);
443
444                         goaway($parms['dfrn-request'] . "?dfrn_url=$dfrn_url"
445                                 . '&dfrn_version=' . DFRN_PROTOCOL_VERSION
446                                 . '&confirm_key=' . $hash
447                                 . (($aes_allow) ? "&aes_allow=1" : "")
448                         );
449                         // NOTREACHED
450                         // END $network === NETWORK_DFRN
451                 } elseif (($network != NETWORK_PHANTOM) && ($url != "")) {
452
453                         /* Substitute our user's feed URL into $url template
454                          * Send the subscriber home to subscribe
455                          */
456                         // Diaspora needs the uri in the format user@domain.tld
457                         // Diaspora will support the remote subscription in a future version
458                         if ($network == NETWORK_DIASPORA) {
459                                 $uri = $nickname . '@' . $a->get_hostname();
460
461                                 if ($a->get_path()) {
462                                         $uri .= '/' . $a->get_path();
463                                 }
464
465                                 $uri = urlencode($uri);
466                         } else {
467                                 $uri = System::baseUrl() . '/profile/' . $nickname;
468                         }
469
470                         $url = str_replace('{uri}', $uri, $url);
471                         goaway($url);
472                         // NOTREACHED
473                         // END $network != NETWORK_PHANTOM
474                 } else {
475                         notice(L10n::t("Remote subscription can't be done for your network. Please subscribe directly on your system.") . EOL);
476                         return;
477                 }
478         } return;
479 }
480
481 function dfrn_request_content(App $a)
482 {
483         if (($a->argc != 2) || (!count($a->profile))) {
484                 return "";
485         }
486
487         // "Homecoming". Make sure we're logged in to this site as the correct user. Then offer a confirm button
488         // to send us to the post section to record the introduction.
489         if (x($_GET, 'dfrn_url')) {
490                 if (!local_user()) {
491                         info(L10n::t("Please login to confirm introduction.") . EOL);
492                         /* setup the return URL to come back to this page if they use openid */
493                         return Login::form();
494                 }
495
496                 // Edge case, but can easily happen in the wild. This person is authenticated,
497                 // but not as the person who needs to deal with this request.
498                 if ($a->user['nickname'] != $a->argv[1]) {
499                         notice(L10n::t("Incorrect identity currently logged in. Please login to <strong>this</strong> profile.") . EOL);
500                         return Login::form();
501                 }
502
503                 $dfrn_url = notags(trim(hex2bin($_GET['dfrn_url'])));
504                 $aes_allow = x($_GET, 'aes_allow') && $_GET['aes_allow'] == 1 ? 1 : 0;
505                 $confirm_key = x($_GET, 'confirm_key') ? $_GET['confirm_key'] : "";
506
507                 // Checking fastlane for validity
508                 if (x($_SESSION, "fastlane") && (normalise_link($_SESSION["fastlane"]) == normalise_link($dfrn_url))) {
509                         $_POST["dfrn_url"] = $dfrn_url;
510                         $_POST["confirm_key"] = $confirm_key;
511                         $_POST["localconfirm"] = 1;
512                         $_POST["hidden-contact"] = 0;
513                         $_POST["submit"] = L10n::t('Confirm');
514
515                         dfrn_request_post($a);
516
517                         killme();
518                         return; // NOTREACHED
519                 }
520
521                 $tpl = get_markup_template("dfrn_req_confirm.tpl");
522                 $o = replace_macros($tpl, [
523                         '$dfrn_url' => $dfrn_url,
524                         '$aes_allow' => (($aes_allow) ? '<input type="hidden" name="aes_allow" value="1" />' : "" ),
525                         '$hidethem' => L10n::t('Hide this contact'),
526                         '$hidechecked' => '',
527                         '$confirm_key' => $confirm_key,
528                         '$welcome' => L10n::t('Welcome home %s.', $a->user['username']),
529                         '$please' => L10n::t('Please confirm your introduction/connection request to %s.', $dfrn_url),
530                         '$submit' => L10n::t('Confirm'),
531                         '$uid' => $_SESSION['uid'],
532                         '$nickname' => $a->user['nickname'],
533                         'dfrn_rawurl' => $_GET['dfrn_url']
534                 ]);
535                 return $o;
536         } elseif ((x($_GET, 'confirm_key')) && strlen($_GET['confirm_key'])) {
537                 // we are the requestee and it is now safe to send our user their introduction,
538                 // We could just unblock it, but first we have to jump through a few hoops to
539                 // send an email, or even to find out if we need to send an email.
540                 $intro = q("SELECT * FROM `intro` WHERE `hash` = '%s' LIMIT 1",
541                         dbesc($_GET['confirm_key'])
542                 );
543
544                 if (DBM::is_result($intro)) {
545                         $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
546                                 WHERE `contact`.`id` = %d LIMIT 1",
547                                 intval($intro[0]['contact-id'])
548                         );
549
550                         $auto_confirm = false;
551
552                         if (DBM::is_result($r)) {
553                                 if ($r[0]['page-flags'] != PAGE_NORMAL && $r[0]['page-flags'] != PAGE_PRVGROUP) {
554                                         $auto_confirm = true;
555                                 }
556
557                                 if (!$auto_confirm) {
558                                         notification([
559                                                 'type'         => NOTIFY_INTRO,
560                                                 'notify_flags' => $r[0]['notify-flags'],
561                                                 'language'     => $r[0]['language'],
562                                                 'to_name'      => $r[0]['username'],
563                                                 'to_email'     => $r[0]['email'],
564                                                 'uid'          => $r[0]['uid'],
565                                                 'link'         => System::baseUrl() . '/notifications/intros',
566                                                 'source_name'  => ((strlen(stripslashes($r[0]['name']))) ? stripslashes($r[0]['name']) : L10n::t('[Name Withheld]')),
567                                                 'source_link'  => $r[0]['url'],
568                                                 'source_photo' => $r[0]['photo'],
569                                                 'verb'         => ACTIVITY_REQ_FRIEND,
570                                                 'otype'        => 'intro'
571                                         ]);
572                                 }
573
574                                 if ($auto_confirm) {
575                                         require_once 'mod/dfrn_confirm.php';
576                                         $handsfree = [
577                                                 'uid'      => $r[0]['uid'],
578                                                 'node'     => $r[0]['nickname'],
579                                                 'dfrn_id'  => $r[0]['issued-id'],
580                                                 'intro_id' => $intro[0]['id'],
581                                                 'duplex'   => (($r[0]['page-flags'] == PAGE_FREELOVE) ? 1 : 0),
582                                                 'activity' => intval(PConfig::get($r[0]['uid'], 'system', 'post_newfriend'))
583                                         ];
584                                         dfrn_confirm_post($a, $handsfree);
585                                 }
586                         }
587
588                         if (!$auto_confirm) {
589
590                                 // If we are auto_confirming, this record will have already been nuked
591                                 // in dfrn_confirm_post()
592
593                                 $r = q("UPDATE `intro` SET `blocked` = 0 WHERE `hash` = '%s'",
594                                         dbesc($_GET['confirm_key'])
595                                 );
596                         }
597                 }
598
599                 killme();
600                 return; // NOTREACHED
601         } else {
602                 // Normal web request. Display our user's introduction form.
603                 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
604                         if (!Config::get('system', 'local_block')) {
605                                 notice(L10n::t('Public access denied.') . EOL);
606                                 return;
607                         }
608                 }
609
610                 // Try to auto-fill the profile address
611                 // At first look if an address was provided
612                 // Otherwise take the local address
613                 if (x($_GET, 'addr') && ($_GET['addr'] != "")) {
614                         $myaddr = hex2bin($_GET['addr']);
615                 } elseif (x($_GET, 'address') && ($_GET['address'] != "")) {
616                         $myaddr = $_GET['address'];
617                 } elseif (local_user()) {
618                         if (strlen($a->path)) {
619                                 $myaddr = System::baseUrl() . '/profile/' . $a->user['nickname'];
620                         } else {
621                                 $myaddr = $a->user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
622                         }
623                 } else {
624                         // last, try a zrl
625                         $myaddr = Profile::getMyURL();
626                 }
627
628                 $target_addr = $a->profile['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
629
630                 /* The auto_request form only has the profile address
631                  * because nobody is going to read the comments and
632                  * it doesn't matter if they know you or not.
633                  */
634                 if ($a->profile['page-flags'] == PAGE_NORMAL) {
635                         $tpl = get_markup_template('dfrn_request.tpl');
636                 } else {
637                         $tpl = get_markup_template('auto_request.tpl');
638                 }
639
640                 $page_desc = L10n::t("Please enter your 'Identity Address' from one of the following supported communications networks:");
641
642                 $invite_desc = sprintf(
643                         L10n::t('If you are not yet a member of the free social web, <a href="%s">follow this link to find a public Friendica site and join us today</a>.'),
644                         get_server() . '/servers'
645                 );
646
647                 $o = replace_macros($tpl, [
648                         '$header' => L10n::t('Friend/Connection Request'),
649                         '$desc' => L10n::t('Examples: jojo@demo.friendica.com, http://demo.friendica.com/profile/jojo, testuser@gnusocial.de'),
650                         '$pls_answer' => L10n::t('Please answer the following:'),
651                         '$does_know_you' => ['knowyou', L10n::t('Does %s know you?', $a->profile['name']), false, '', [L10n::t('No'), L10n::t('Yes')]],
652                         '$add_note' => L10n::t('Add a personal note:'),
653                         '$page_desc' => $page_desc,
654                         '$friendica' => L10n::t('Friendica'),
655                         '$statusnet' => L10n::t("GNU Social \x28Pleroma, Mastodon\x29"),
656                         '$diaspora' => L10n::t("Diaspora \x28Socialhome, Hubzilla\x29"),
657                         '$diasnote' => L10n::t(' - please do not use this form.  Instead, enter %s into your Diaspora search bar.', $target_addr),
658                         '$your_address' => L10n::t('Your Identity Address:'),
659                         '$invite_desc' => $invite_desc,
660                         '$submit' => L10n::t('Submit Request'),
661                         '$cancel' => L10n::t('Cancel'),
662                         '$nickname' => $a->argv[1],
663                         '$name' => $a->profile['name'],
664                         '$myaddr' => $myaddr
665                 ]);
666                 return $o;
667         }
668
669         return; // Somebody is fishing.
670 }