X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fredir.php;h=903c6b2a354f074b7f5de0caa039c167b14f2e22;hb=05b15f28249ac83a160cbbdca9fe044c4e664b47;hp=71db74e9a42eb34bd07c456a2084ce22ed588c8a;hpb=38a5358bfa646ae13a4a1a385741890fa88d9b7f;p=friendica.git diff --git a/mod/redir.php b/mod/redir.php index 71db74e9a4..903c6b2a35 100644 --- a/mod/redir.php +++ b/mod/redir.php @@ -1,6 +1,6 @@ isAuthenticated()) { throw new \Friendica\Network\HTTPException\ForbiddenException(DI::l10n()->t('Access denied.')); } $url = $_GET['url'] ?? ''; - $quiet = !empty($_GET['quiet']) ? '&quiet=1' : ''; - if ($a->argc > 1 && intval($a->argv[1])) { - $cid = intval($a->argv[1]); + if (DI::args()->getArgc() > 1 && intval(DI::args()->getArgv()[1])) { + $cid = intval(DI::args()->getArgv()[1]); } else { $cid = 0; } @@ -50,39 +50,39 @@ function redir_init(App $a) { throw new \Friendica\Network\HTTPException\BadRequestException(DI::l10n()->t('Bad Request.')); } - $fields = ['id', 'uid', 'nurl', 'url', 'addr', 'name', 'network', 'poll', 'issued-id', 'dfrn-id', 'duplex', 'pending']; - $contact = DBA::selectFirst('contact', $fields, ['id' => $cid, 'uid' => [0, local_user()]]); + $fields = ['id', 'uid', 'nurl', 'url', 'addr', 'name']; + $contact = DBA::selectFirst('contact', $fields, ['id' => $cid, 'uid' => [0, DI::userSession()->getLocalUserId()]]); if (!DBA::isResult($contact)) { throw new \Friendica\Network\HTTPException\NotFoundException(DI::l10n()->t('Contact not found.')); } $contact_url = $contact['url']; - if (!empty($a->contact['id']) && $a->contact['id'] == $cid) { + if (!empty($a->getContactId()) && $a->getContactId() == $cid) { // Local user is already authenticated. redir_check_url($contact_url, $url); $a->redirect($url ?: $contact_url); } - if ($contact['uid'] == 0 && local_user()) { + if ($contact['uid'] == 0 && DI::userSession()->getLocalUserId()) { // Let's have a look if there is an established connection // between the public contact we have found and the local user. - $contact = DBA::selectFirst('contact', $fields, ['nurl' => $contact['nurl'], 'uid' => local_user()]); + $contact = DBA::selectFirst('contact', $fields, ['nurl' => $contact['nurl'], 'uid' => DI::userSession()->getLocalUserId()]); if (DBA::isResult($contact)) { $cid = $contact['id']; } - if (!empty($a->contact['id']) && $a->contact['id'] == $cid) { + if (!empty($a->getContactId()) && $a->getContactId() == $cid) { // Local user is already authenticated. redir_check_url($contact_url, $url); $target_url = $url ?: $contact_url; - Logger::log($contact['name'] . " is already authenticated. Redirecting to " . $target_url, Logger::DEBUG); + Logger::info($contact['name'] . " is already authenticated. Redirecting to " . $target_url); $a->redirect($target_url); } } - if (remote_user()) { + if (DI::userSession()->getRemoteUserId()) { $host = substr(DI::baseUrl()->getUrlPath() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : ''), strpos(DI::baseUrl()->getUrlPath(), '://') + 3); $remotehost = substr($contact['addr'], strpos($contact['addr'], '@') + 1); @@ -90,42 +90,15 @@ function redir_init(App $a) { // with the local contact. Otherwise the local user would ask the local contact // for authentification everytime he/she is visiting a profile page of the local // contact. - if (($host == $remotehost) && (Session::getRemoteContactID(Session::get('visitor_visiting')) == Session::get('visitor_id'))) { + if (($host == $remotehost) && (DI::userSession()->getRemoteContactID(DI::session()->get('visitor_visiting')) == DI::session()->get('visitor_id'))) { // Remote user is already authenticated. redir_check_url($contact_url, $url); $target_url = $url ?: $contact_url; - Logger::log($contact['name'] . " is already authenticated. Redirecting to " . $target_url, Logger::DEBUG); + Logger::info($contact['name'] . " is already authenticated. Redirecting to " . $target_url); $a->redirect($target_url); } } - // Doing remote auth with dfrn. - if (local_user() && (!empty($contact['dfrn-id']) || !empty($contact['issued-id'])) && empty($contact['pending'])) { - $dfrn_id = $orig_id = (($contact['issued-id']) ? $contact['issued-id'] : $contact['dfrn-id']); - - if ($contact['duplex'] && $contact['issued-id']) { - $orig_id = $contact['issued-id']; - $dfrn_id = '1:' . $orig_id; - } - if ($contact['duplex'] && $contact['dfrn-id']) { - $orig_id = $contact['dfrn-id']; - $dfrn_id = '0:' . $orig_id; - } - - $sec = Strings::getRandomHex(); - - $fields = ['uid' => local_user(), 'cid' => $cid, 'dfrn_id' => $dfrn_id, - 'sec' => $sec, 'expire' => time() + 45]; - DBA::insert('profile_check', $fields); - - Logger::log('mod_redir: ' . $contact['name'] . ' ' . $sec, Logger::DEBUG); - - $dest = (!empty($url) ? '&destination_url=' . $url : ''); - - System::externalRedirect($contact['poll'] . '?dfrn_id=' . $dfrn_id - . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest . $quiet); - } - if (empty($url)) { throw new \Friendica\Network\HTTPException\BadRequestException(DI::l10n()->t('Bad Request.')); } @@ -140,7 +113,7 @@ function redir_init(App $a) { $url .= $separator . 'zrl=' . urlencode($my_profile); } - Logger::log('redirecting to ' . $url, Logger::DEBUG); + Logger::info('redirecting to ' . $url); $a->redirect($url); } @@ -170,7 +143,7 @@ function redir_magic($a, $cid, $url) } // Test for magic auth on the target system - $serverret = DI::httpRequest()->get($basepath . '/magic'); + $serverret = DI::httpClient()->head($basepath . '/magic', [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::HTML]); if ($serverret->isSuccess()) { $separator = strpos($target_url, '?') ? '&' : '?'; $target_url .= $separator . 'zrl=' . urlencode($visitor) . '&addr=' . urlencode($contact_url);