Warnings/Errors reduced - improved relay processing
This commit is contained in:
parent
1db70b8935
commit
ceb88c10e6
|
@ -1330,7 +1330,7 @@ class GServer
|
|||
return false;
|
||||
}
|
||||
|
||||
$xrd = XML::parseString($curlResult->getBody());
|
||||
$xrd = XML::parseString($curlResult->getBody(), true);
|
||||
if (!is_object($xrd)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -50,13 +50,13 @@ class PushSubscription extends BaseApi
|
|||
'endpoint' => $request['subscription']['endpoint'] ?? '',
|
||||
'pubkey' => $request['subscription']['keys']['p256dh'] ?? '',
|
||||
'secret' => $request['subscription']['keys']['auth'] ?? '',
|
||||
Notification::TYPE_FOLLOW => $request['data']['alerts'][Notification::TYPE_FOLLOW] ?? false,
|
||||
Notification::TYPE_LIKE => $request['data']['alerts'][Notification::TYPE_LIKE] ?? false,
|
||||
Notification::TYPE_RESHARE => $request['data']['alerts'][Notification::TYPE_RESHARE] ?? false,
|
||||
Notification::TYPE_MENTION => $request['data']['alerts'][Notification::TYPE_MENTION] ?? false,
|
||||
Notification::TYPE_POLL => $request['data']['alerts'][Notification::TYPE_POLL] ?? false,
|
||||
Notification::TYPE_INTRODUCTION => $request['data']['alerts'][Notification::TYPE_INTRODUCTION] ?? false,
|
||||
Notification::TYPE_POST => $request['data']['alerts'][Notification::TYPE_POST] ?? false,
|
||||
Notification::TYPE_FOLLOW => filter_var($request['data']['alerts'][Notification::TYPE_FOLLOW] ?? false, FILTER_VALIDATE_BOOLEAN),
|
||||
Notification::TYPE_LIKE => filter_var($request['data']['alerts'][Notification::TYPE_LIKE] ?? false, FILTER_VALIDATE_BOOLEAN),
|
||||
Notification::TYPE_RESHARE => filter_var($request['data']['alerts'][Notification::TYPE_RESHARE] ?? false, FILTER_VALIDATE_BOOLEAN),
|
||||
Notification::TYPE_MENTION => filter_var($request['data']['alerts'][Notification::TYPE_MENTION] ?? false, FILTER_VALIDATE_BOOLEAN),
|
||||
Notification::TYPE_POLL => filter_var($request['data']['alerts'][Notification::TYPE_POLL] ?? false, FILTER_VALIDATE_BOOLEAN),
|
||||
Notification::TYPE_INTRODUCTION => filter_var($request['data']['alerts'][Notification::TYPE_INTRODUCTION] ?? false, FILTER_VALIDATE_BOOLEAN),
|
||||
Notification::TYPE_POST => filter_var($request['data']['alerts'][Notification::TYPE_POST] ?? false, FILTER_VALIDATE_BOOLEAN),
|
||||
];
|
||||
|
||||
$ret = Subscription::replace($subscription);
|
||||
|
|
|
@ -113,9 +113,16 @@ class Receiver
|
|||
APContact::unmarkForArchival($apcontact);
|
||||
}
|
||||
|
||||
$sig_contact = HTTPSignature::getKeyIdContact($header);
|
||||
if (APContact::isRelay($sig_contact)) {
|
||||
Logger::info('Message from a relay', ['url' => $sig_contact['url']]);
|
||||
self::processRelayPost($ldactivity, $sig_contact['url']);
|
||||
return;
|
||||
}
|
||||
|
||||
$http_signer = HTTPSignature::getSigner($body, $header);
|
||||
if ($http_signer === false) {
|
||||
Logger::warning('Invalid HTTP signature, message will be discarded.');
|
||||
Logger::warning('Invalid HTTP signature, message will be discarded.', ['uid' => $uid, 'actor' => $actor, 'header' => $header, 'body' => $body]);
|
||||
return;
|
||||
} elseif (empty($http_signer)) {
|
||||
Logger::info('Signer is a tombstone. The message will be discarded, the signer account is deleted.');
|
||||
|
@ -170,18 +177,43 @@ class Receiver
|
|||
{
|
||||
$type = JsonLD::fetchElement($activity, '@type');
|
||||
if (!$type) {
|
||||
Logger::info('Empty type', ['activity' => $activity, 'actor' => $actor]);
|
||||
Logger::notice('Empty type', ['activity' => $activity, 'actor' => $actor]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($type != 'as:Announce') {
|
||||
Logger::info('Not an announcement', ['activity' => $activity, 'actor' => $actor]);
|
||||
return;
|
||||
}
|
||||
$object_type = JsonLD::fetchElement($activity, 'as:object', '@type') ?? '';
|
||||
|
||||
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
|
||||
if (empty($object_id)) {
|
||||
Logger::info('No object id found', ['activity' => $activity, 'actor' => $actor]);
|
||||
Logger::notice('No object id found', ['type' => $type, 'object_type' => $object_type, 'actor' => $actor, 'activity' => $activity]);
|
||||
return;
|
||||
}
|
||||
|
||||
$handle = ($type == 'as:Announce');
|
||||
|
||||
if (!$handle && in_array($type, ['as:Create', 'as:Update'])) {
|
||||
$handle = in_array($object_type, self::CONTENT_TYPES);
|
||||
}
|
||||
|
||||
if (!$handle) {
|
||||
$trust_source = false;
|
||||
$object_data = self::prepareObjectData($activity, 0, false, $trust_source);
|
||||
|
||||
if (!$trust_source) {
|
||||
Logger::notice('Activity trust could not be achieved.', ['type' => $type, 'object_type' => $object_type, 'object_id' => $object_id, 'actor' => $actor, 'activity' => $activity]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($object_data)) {
|
||||
Logger::notice('No object data found', ['type' => $type, 'object_type' => $object_type, 'object_id' => $object_id, 'actor' => $actor, 'activity' => $activity]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (self::routeActivities($object_data, $type, true)) {
|
||||
Logger::debug('Handled activity', ['type' => $type, 'object_type' => $object_type, 'object_id' => $object_id, 'actor' => $actor]);
|
||||
} else {
|
||||
Logger::info('Unhandled activity', ['type' => $type, 'object_type' => $object_type, 'object_id' => $object_id, 'actor' => $actor, 'activity' => $activity]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -196,7 +228,7 @@ class Receiver
|
|||
return;
|
||||
}
|
||||
|
||||
Logger::info('Got relayed message id', ['id' => $object_id, 'actor' => $actor]);
|
||||
Logger::debug('Got relayed message id', ['id' => $object_id, 'actor' => $actor]);
|
||||
|
||||
$item_id = Item::searchByLink($object_id);
|
||||
if ($item_id) {
|
||||
|
|
|
@ -1169,10 +1169,6 @@ class OStatus
|
|||
];
|
||||
XML::addElement($doc, $root, 'link', '', $attributes);
|
||||
break;
|
||||
|
||||
default:
|
||||
Logger::warning('Unsupported type', ['type' => $siteinfo['type'], 'url' => $siteinfo['url'] ?? '']);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!DI::config()->get('system', 'ostatus_not_attach_preview') && ($siteinfo['type'] != 'photo') && isset($siteinfo['image'])) {
|
||||
|
|
|
@ -485,6 +485,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
|
||||
*
|
||||
|
|
|
@ -55,7 +55,7 @@ class UpdateContacts
|
|||
$condition = array_merge(['local-data' => true], $condition);
|
||||
}
|
||||
|
||||
$condition = array_merge(["`next-update` < ?", DateTimeFormat::utcNow()], $condition);
|
||||
$condition = DBA::mergeConditions(["`next-update` < ?", DateTimeFormat::utcNow()], $condition);
|
||||
$contacts = DBA::select('contact', ['id'], $condition, ['order' => ['next-update'], 'limit' => $limit]);
|
||||
$count = 0;
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user