mirror of
https://github.com/friendica/friendica
synced 2025-04-26 06:30:11 +00:00
Log function
implement log() function.
This commit is contained in:
parent
d6d593d724
commit
14fde5dc9b
122 changed files with 1280 additions and 1161 deletions
|
@ -6,6 +6,7 @@ namespace Friendica\Protocol\ActivityPub;
|
|||
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Util\HTTPSignature;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\APContact;
|
||||
|
@ -59,16 +60,16 @@ class Receiver
|
|||
{
|
||||
$http_signer = HTTPSignature::getSigner($body, $header);
|
||||
if (empty($http_signer)) {
|
||||
logger('Invalid HTTP signature, message will be discarded.', LOGGER_DEBUG);
|
||||
Logger::log('Invalid HTTP signature, message will be discarded.', LOGGER_DEBUG);
|
||||
return;
|
||||
} else {
|
||||
logger('HTTP signature is signed by ' . $http_signer, LOGGER_DEBUG);
|
||||
Logger::log('HTTP signature is signed by ' . $http_signer, LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
$activity = json_decode($body, true);
|
||||
|
||||
if (empty($activity)) {
|
||||
logger('Invalid body.', LOGGER_DEBUG);
|
||||
Logger::log('Invalid body.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -76,31 +77,31 @@ class Receiver
|
|||
|
||||
$actor = JsonLD::fetchElement($ldactivity, 'as:actor');
|
||||
|
||||
logger('Message for user ' . $uid . ' is from actor ' . $actor, LOGGER_DEBUG);
|
||||
Logger::log('Message for user ' . $uid . ' is from actor ' . $actor, LOGGER_DEBUG);
|
||||
|
||||
if (LDSignature::isSigned($activity)) {
|
||||
$ld_signer = LDSignature::getSigner($activity);
|
||||
if (empty($ld_signer)) {
|
||||
logger('Invalid JSON-LD signature from ' . $actor, LOGGER_DEBUG);
|
||||
Logger::log('Invalid JSON-LD signature from ' . $actor, LOGGER_DEBUG);
|
||||
}
|
||||
if (!empty($ld_signer && ($actor == $http_signer))) {
|
||||
logger('The HTTP and the JSON-LD signature belong to ' . $ld_signer, LOGGER_DEBUG);
|
||||
Logger::log('The HTTP and the JSON-LD signature belong to ' . $ld_signer, LOGGER_DEBUG);
|
||||
$trust_source = true;
|
||||
} elseif (!empty($ld_signer)) {
|
||||
logger('JSON-LD signature is signed by ' . $ld_signer, LOGGER_DEBUG);
|
||||
Logger::log('JSON-LD signature is signed by ' . $ld_signer, LOGGER_DEBUG);
|
||||
$trust_source = true;
|
||||
} elseif ($actor == $http_signer) {
|
||||
logger('Bad JSON-LD signature, but HTTP signer fits the actor.', LOGGER_DEBUG);
|
||||
Logger::log('Bad JSON-LD signature, but HTTP signer fits the actor.', LOGGER_DEBUG);
|
||||
$trust_source = true;
|
||||
} else {
|
||||
logger('Invalid JSON-LD signature and the HTTP signer is different.', LOGGER_DEBUG);
|
||||
Logger::log('Invalid JSON-LD signature and the HTTP signer is different.', LOGGER_DEBUG);
|
||||
$trust_source = false;
|
||||
}
|
||||
} elseif ($actor == $http_signer) {
|
||||
logger('Trusting post without JSON-LD signature, The actor fits the HTTP signer.', LOGGER_DEBUG);
|
||||
Logger::log('Trusting post without JSON-LD signature, The actor fits the HTTP signer.', LOGGER_DEBUG);
|
||||
$trust_source = true;
|
||||
} else {
|
||||
logger('No JSON-LD signature, different actor.', LOGGER_DEBUG);
|
||||
Logger::log('No JSON-LD signature, different actor.', LOGGER_DEBUG);
|
||||
$trust_source = false;
|
||||
}
|
||||
|
||||
|
@ -159,7 +160,7 @@ class Receiver
|
|||
{
|
||||
$actor = JsonLD::fetchElement($activity, 'as:actor');
|
||||
if (empty($actor)) {
|
||||
logger('Empty actor', LOGGER_DEBUG);
|
||||
Logger::log('Empty actor', LOGGER_DEBUG);
|
||||
return [];
|
||||
}
|
||||
|
||||
|
@ -175,11 +176,11 @@ class Receiver
|
|||
$receivers = array_merge($receivers, $additional);
|
||||
}
|
||||
|
||||
logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG);
|
||||
Logger::log('Receivers: ' . json_encode($receivers), LOGGER_DEBUG);
|
||||
|
||||
$object_id = JsonLD::fetchElement($activity, 'as:object');
|
||||
if (empty($object_id)) {
|
||||
logger('No object found', LOGGER_DEBUG);
|
||||
Logger::log('No object found', LOGGER_DEBUG);
|
||||
return [];
|
||||
}
|
||||
|
||||
|
@ -192,7 +193,7 @@ class Receiver
|
|||
}
|
||||
$object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source);
|
||||
if (empty($object_data)) {
|
||||
logger("Object data couldn't be processed", LOGGER_DEBUG);
|
||||
Logger::log("Object data couldn't be processed", LOGGER_DEBUG);
|
||||
return [];
|
||||
}
|
||||
// We had been able to retrieve the object data - so we can trust the source
|
||||
|
@ -229,7 +230,7 @@ class Receiver
|
|||
$object_data['actor'] = $actor;
|
||||
$object_data['receiver'] = array_merge(defaults($object_data, 'receiver', []), $receivers);
|
||||
|
||||
logger('Processing ' . $object_data['type'] . ' ' . $object_data['object_type'] . ' ' . $object_data['id'], LOGGER_DEBUG);
|
||||
Logger::log('Processing ' . $object_data['type'] . ' ' . $object_data['object_type'] . ' ' . $object_data['id'], LOGGER_DEBUG);
|
||||
|
||||
return $object_data;
|
||||
}
|
||||
|
@ -272,17 +273,17 @@ class Receiver
|
|||
{
|
||||
$type = JsonLD::fetchElement($activity, '@type');
|
||||
if (!$type) {
|
||||
logger('Empty type', LOGGER_DEBUG);
|
||||
Logger::log('Empty type', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!JsonLD::fetchElement($activity, 'as:object')) {
|
||||
logger('Empty object', LOGGER_DEBUG);
|
||||
Logger::log('Empty object', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!JsonLD::fetchElement($activity, 'as:actor')) {
|
||||
logger('Empty actor', LOGGER_DEBUG);
|
||||
Logger::log('Empty actor', LOGGER_DEBUG);
|
||||
return;
|
||||
|
||||
}
|
||||
|
@ -290,12 +291,12 @@ class Receiver
|
|||
// $trust_source is called by reference and is set to true if the content was retrieved successfully
|
||||
$object_data = self::prepareObjectData($activity, $uid, $trust_source);
|
||||
if (empty($object_data)) {
|
||||
logger('No object data found', LOGGER_DEBUG);
|
||||
Logger::log('No object data found', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$trust_source) {
|
||||
logger('No trust for activity type "' . $type . '", so we quit now.', LOGGER_DEBUG);
|
||||
Logger::log('No trust for activity type "' . $type . '", so we quit now.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -384,7 +385,7 @@ class Receiver
|
|||
break;
|
||||
|
||||
default:
|
||||
logger('Unknown activity: ' . $type . ' ' . $object_data['object_type'], LOGGER_DEBUG);
|
||||
Logger::log('Unknown activity: ' . $type . ' ' . $object_data['object_type'], LOGGER_DEBUG);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -414,9 +415,9 @@ class Receiver
|
|||
$profile = APContact::getByURL($actor);
|
||||
$followers = defaults($profile, 'followers', '');
|
||||
|
||||
logger('Actor: ' . $actor . ' - Followers: ' . $followers, LOGGER_DEBUG);
|
||||
Logger::log('Actor: ' . $actor . ' - Followers: ' . $followers, LOGGER_DEBUG);
|
||||
} else {
|
||||
logger('Empty actor', LOGGER_DEBUG);
|
||||
Logger::log('Empty actor', LOGGER_DEBUG);
|
||||
$followers = '';
|
||||
}
|
||||
|
||||
|
@ -486,7 +487,7 @@ class Receiver
|
|||
return;
|
||||
}
|
||||
|
||||
logger('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' to ActivityPub');
|
||||
Logger::log('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' to ActivityPub');
|
||||
|
||||
$photo = defaults($profile, 'photo', null);
|
||||
unset($profile['photo']);
|
||||
|
@ -500,7 +501,7 @@ class Receiver
|
|||
// Send a new follow request to be sure that the connection still exists
|
||||
if (($uid != 0) && DBA::exists('contact', ['id' => $cid, 'rel' => [Contact::SHARING, Contact::FRIEND]])) {
|
||||
ActivityPub\Transmitter::sendActivity('Follow', $profile['url'], $uid);
|
||||
logger('Send a new follow request to ' . $profile['url'] . ' for user ' . $uid, LOGGER_DEBUG);
|
||||
Logger::log('Send a new follow request to ' . $profile['url'] . ' for user ' . $uid, LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -570,27 +571,27 @@ class Receiver
|
|||
$data = ActivityPub::fetchContent($object_id);
|
||||
if (!empty($data)) {
|
||||
$object = JsonLD::compact($data);
|
||||
logger('Fetched content for ' . $object_id, LOGGER_DEBUG);
|
||||
Logger::log('Fetched content for ' . $object_id, LOGGER_DEBUG);
|
||||
} else {
|
||||
logger('Empty content for ' . $object_id . ', check if content is available locally.', LOGGER_DEBUG);
|
||||
Logger::log('Empty content for ' . $object_id . ', check if content is available locally.', LOGGER_DEBUG);
|
||||
|
||||
$item = Item::selectFirst([], ['uri' => $object_id]);
|
||||
if (!DBA::isResult($item)) {
|
||||
logger('Object with url ' . $object_id . ' was not found locally.', LOGGER_DEBUG);
|
||||
Logger::log('Object with url ' . $object_id . ' was not found locally.', LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
logger('Using already stored item for url ' . $object_id, LOGGER_DEBUG);
|
||||
Logger::log('Using already stored item for url ' . $object_id, LOGGER_DEBUG);
|
||||
$data = ActivityPub\Transmitter::createNote($item);
|
||||
$object = JsonLD::compact($data);
|
||||
}
|
||||
} else {
|
||||
logger('Using original object for url ' . $object_id, LOGGER_DEBUG);
|
||||
Logger::log('Using original object for url ' . $object_id, LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
$type = JsonLD::fetchElement($object, '@type');
|
||||
|
||||
if (empty($type)) {
|
||||
logger('Empty type', LOGGER_DEBUG);
|
||||
Logger::log('Empty type', LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -606,7 +607,7 @@ class Receiver
|
|||
return self::fetchObject($object_id);
|
||||
}
|
||||
|
||||
logger('Unhandled object type: ' . $type, LOGGER_DEBUG);
|
||||
Logger::log('Unhandled object type: ' . $type, LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue