X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FHTTPSignature.php;h=1d57f5ea8095ff791750f6eec2e2ff875d715735;hb=46cd39fb34613f4b331793f19c0e562f93125066;hp=f4f0a4e85cc5b48fe9345f73926a18ce5d300871;hpb=d693bc1b2fc1b2e6819ed45b64cfc6d0d6cab90a;p=friendica.git diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index f4f0a4e85c..1d57f5ea80 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -1,6 +1,6 @@ getReturnCode(); return ($return_code >= 200) && ($return_code <= 299); @@ -340,15 +334,26 @@ class HTTPSignature * @param string $url The URL of the inbox * @param boolean $success Transmission status * @param boolean $shared The inbox is a shared inbox + * @param int $gsid Server ID + * @throws \Exception */ - static public function setInboxStatus(string $url, bool $success, bool $shared = false) + static public function setInboxStatus(string $url, bool $success, bool $shared = false, int $gsid = null) { $now = DateTimeFormat::utcNow(); $status = DBA::selectFirst('inbox-status', [], ['url' => $url]); if (!DBA::isResult($status)) { - DBA::insert('inbox-status', ['url' => $url, 'uri-id' => ItemURI::getIdByURI($url), 'created' => $now, 'shared' => $shared], Database::INSERT_IGNORE); + $insertFields = ['url' => $url, 'uri-id' => ItemURI::getIdByURI($url), 'created' => $now, 'shared' => $shared]; + if (!empty($gsid)) { + $insertFields['gsid'] = $gsid; + } + DBA::insert('inbox-status', $insertFields, Database::INSERT_IGNORE); + $status = DBA::selectFirst('inbox-status', [], ['url' => $url]); + if (empty($status)) { + Logger::warning('Unable to insert inbox-status row', $insertFields); + return; + } } if ($success) { @@ -357,6 +362,10 @@ class HTTPSignature $fields = ['failure' => $now]; } + if (!empty($gsid)) { + $fields['gsid'] = $gsid; + } + if ($status['failure'] > DBA::NULL_DATETIME) { $new_previous_stamp = strtotime($status['failure']); $old_previous_stamp = strtotime($status['previous']); @@ -392,6 +401,14 @@ class HTTPSignature } DBA::update('inbox-status', $fields, ['url' => $url]); + + if (!empty($status['gsid'])) { + if ($success) { + GServer::setReachableById($status['gsid'], Protocol::ACTIVITYPUB); + } elseif ($status['shared']) { + GServer::setFailureById($status['gsid']); + } + } } /** @@ -405,7 +422,12 @@ class HTTPSignature */ public static function fetch(string $request, int $uid): array { - $curlResult = self::fetchRaw($request, $uid); + try { + $curlResult = self::fetchRaw($request, $uid); + } catch (\Exception $exception) { + Logger::notice('Error fetching url', ['url' => $request, 'exception' => $exception]); + return []; + } if (empty($curlResult)) { return []; @@ -485,6 +507,31 @@ class HTTPSignature return $curlResult; } + /** + * Fetch the apcontact entry of the keyId in the given header + * + * @param array $http_headers + * + * @return array APContact entry + */ + public static function getKeyIdContact(array $http_headers): array + { + if (empty($http_headers['HTTP_SIGNATURE'])) { + Logger::debug('No HTTP_SIGNATURE header', ['header' => $http_headers]); + return []; + } + + $sig_block = self::parseSigHeader($http_headers['HTTP_SIGNATURE']); + + if (empty($sig_block['keyId'])) { + Logger::debug('No keyId', ['sig_block' => $sig_block]); + return []; + } + + $url = (strpos($sig_block['keyId'], '#') ? substr($sig_block['keyId'], 0, strpos($sig_block['keyId'], '#')) : $sig_block['keyId']); + return APContact::getByURL($url); + } + /** * Gets a signer from a given HTTP request * @@ -580,7 +627,7 @@ class HTTPSignature } if (empty($algorithm)) { - Logger::info('No alagorithm'); + Logger::info('No algorithm'); return false; }