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