Now sending does finally work - and some AP standards are improved as well
This commit is contained in:
parent
e4d28629e4
commit
699a4140f9
5 changed files with 27 additions and 20 deletions
|
@ -77,7 +77,7 @@ function display_init(App $a)
|
||||||
displayShowFeed($item["id"], false);
|
displayShowFeed($item["id"], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json')) {
|
if (ActivityPub::isRequest()) {
|
||||||
$wall_item = Item::selectFirst(['id', 'uid'], ['guid' => $item['guid'], 'wall' => true]);
|
$wall_item = Item::selectFirst(['id', 'uid'], ['guid' => $item['guid'], 'wall' => true]);
|
||||||
if ($wall_item['uid'] == 180) {
|
if ($wall_item['uid'] == 180) {
|
||||||
$data = ActivityPub::createActivityFromItem($wall_item['id']);
|
$data = ActivityPub::createActivityFromItem($wall_item['id']);
|
||||||
|
|
|
@ -50,7 +50,7 @@ function profile_init(App $a)
|
||||||
DFRN::autoRedir($a, $which);
|
DFRN::autoRedir($a, $which);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json')) {
|
if (ActivityPub::isRequest()) {
|
||||||
$user = DBA::selectFirst('user', ['uid'], ['nickname' => $which]);
|
$user = DBA::selectFirst('user', ['uid'], ['nickname' => $which]);
|
||||||
if ($user['uid'] == 180) {
|
if ($user['uid'] == 180) {
|
||||||
$data = ActivityPub::profile($user['uid']);
|
$data = ActivityPub::profile($user['uid']);
|
||||||
|
|
|
@ -47,6 +47,6 @@ class Inbox extends BaseModule
|
||||||
|
|
||||||
ActivityPub::processInbox($postdata, $_SERVER, $uid);
|
ActivityPub::processInbox($postdata, $_SERVER, $uid);
|
||||||
|
|
||||||
System::httpExit(202);
|
System::httpExit(201);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,12 @@ class ActivityPub
|
||||||
{
|
{
|
||||||
const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public';
|
const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public';
|
||||||
|
|
||||||
|
public static function isRequest()
|
||||||
|
{
|
||||||
|
return stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json') ||
|
||||||
|
stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/ld+json');
|
||||||
|
}
|
||||||
|
|
||||||
public static function transmit($data, $target, $uid)
|
public static function transmit($data, $target, $uid)
|
||||||
{
|
{
|
||||||
$owner = User::getOwnerDataById($uid);
|
$owner = User::getOwnerDataById($uid);
|
||||||
|
@ -66,19 +72,19 @@ class ActivityPub
|
||||||
$content = json_encode($data);
|
$content = json_encode($data);
|
||||||
|
|
||||||
// Header data that is about to be signed.
|
// Header data that is about to be signed.
|
||||||
/// @todo Add "digest"
|
|
||||||
$host = parse_url($target, PHP_URL_HOST);
|
$host = parse_url($target, PHP_URL_HOST);
|
||||||
$path = parse_url($target, PHP_URL_PATH);
|
$path = parse_url($target, PHP_URL_PATH);
|
||||||
$date = date('r');
|
$digest = 'SHA-256=' . base64_encode(hash('sha256', $content, true));
|
||||||
$content_length = strlen($content);
|
$content_length = strlen($content);
|
||||||
|
|
||||||
$headers = ['Host: ' . $host, 'Date: ' . $date, 'Content-Length: ' . $content_length];
|
$headers = ['Content-Length: ' . $content_length, 'Digest: ' . $digest, 'Host: ' . $host];
|
||||||
|
|
||||||
$signed_data = "(request-target): post " . $path . "\nhost: " . $host . "\ndate: " . $date . "\ncontent-length: " . $content_length;
|
$signed_data = "(request-target): post " . $path . "\ncontent-length: " . $content_length . "\ndigest: " . $digest . "\nhost: " . $host;
|
||||||
|
|
||||||
$signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256'));
|
$signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256'));
|
||||||
|
|
||||||
$headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",headers="(request-target) host date content-length",signature="' . $signature . '"';
|
$headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",algorithm="rsa-sha256",headers="(request-target) content-length digest host",signature="' . $signature . '"';
|
||||||
|
|
||||||
$headers[] = 'Content-Type: application/activity+json';
|
$headers[] = 'Content-Type: application/activity+json';
|
||||||
|
|
||||||
Network::post($target, $content, $headers);
|
Network::post($target, $content, $headers);
|
||||||
|
@ -157,7 +163,7 @@ class ActivityPub
|
||||||
'toot' => 'http://joinmastodon.org/ns#']]];
|
'toot' => 'http://joinmastodon.org/ns#']]];
|
||||||
|
|
||||||
$data['type'] = 'Create';
|
$data['type'] = 'Create';
|
||||||
$data['id'] = $item['uri'];
|
$data['id'] = $item['uri'] . '/activity';
|
||||||
$data['actor'] = $item['author-link'];
|
$data['actor'] = $item['author-link'];
|
||||||
$data['to'] = 'https://www.w3.org/ns/activitystreams#Public';
|
$data['to'] = 'https://www.w3.org/ns/activitystreams#Public';
|
||||||
$data['object'] = self::createNote($item);
|
$data['object'] = self::createNote($item);
|
||||||
|
@ -210,7 +216,8 @@ class ActivityPub
|
||||||
'id' => System::baseUrl() . '/activity/' . System::createGUID(),
|
'id' => System::baseUrl() . '/activity/' . System::createGUID(),
|
||||||
'type' => $activity,
|
'type' => $activity,
|
||||||
'actor' => $owner['url'],
|
'actor' => $owner['url'],
|
||||||
'object' => $profile['url']];
|
'object' => $profile['url'],
|
||||||
|
'to' => $profile['url']];
|
||||||
|
|
||||||
logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG);
|
logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG);
|
||||||
return self::transmit($data, $profile['notify'], $uid);
|
return self::transmit($data, $profile['notify'], $uid);
|
||||||
|
@ -227,7 +234,8 @@ class ActivityPub
|
||||||
'actor' => $owner['url'],
|
'actor' => $owner['url'],
|
||||||
'object' => ['id' => $id, 'type' => 'Follow',
|
'object' => ['id' => $id, 'type' => 'Follow',
|
||||||
'actor' => $profile['url'],
|
'actor' => $profile['url'],
|
||||||
'object' => $owner['url']]];
|
'object' => $owner['url']],
|
||||||
|
'to' => $profile['url']];
|
||||||
|
|
||||||
logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
|
logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
|
||||||
return self::transmit($data, $profile['notify'], $uid);
|
return self::transmit($data, $profile['notify'], $uid);
|
||||||
|
@ -244,7 +252,8 @@ class ActivityPub
|
||||||
'actor' => $owner['url'],
|
'actor' => $owner['url'],
|
||||||
'object' => ['id' => $id, 'type' => 'Follow',
|
'object' => ['id' => $id, 'type' => 'Follow',
|
||||||
'actor' => $profile['url'],
|
'actor' => $profile['url'],
|
||||||
'object' => $owner['url']]];
|
'object' => $owner['url']],
|
||||||
|
'to' => $profile['url']];
|
||||||
|
|
||||||
logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
|
logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
|
||||||
return self::transmit($data, $profile['notify'], $uid);
|
return self::transmit($data, $profile['notify'], $uid);
|
||||||
|
@ -263,7 +272,8 @@ class ActivityPub
|
||||||
'actor' => $owner['url'],
|
'actor' => $owner['url'],
|
||||||
'object' => ['id' => $id, 'type' => 'Follow',
|
'object' => ['id' => $id, 'type' => 'Follow',
|
||||||
'actor' => $owner['url'],
|
'actor' => $owner['url'],
|
||||||
'object' => $profile['url']]];
|
'object' => $profile['url']],
|
||||||
|
'to' => $profile['url']];
|
||||||
|
|
||||||
logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
|
logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
|
||||||
return self::transmit($data, $profile['notify'], $uid);
|
return self::transmit($data, $profile['notify'], $uid);
|
||||||
|
@ -277,7 +287,7 @@ class ActivityPub
|
||||||
*/
|
*/
|
||||||
public static function fetchContent($url)
|
public static function fetchContent($url)
|
||||||
{
|
{
|
||||||
$ret = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json']);
|
$ret = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json, application/ld+json']);
|
||||||
if (!$ret['success'] || empty($ret['body'])) {
|
if (!$ret['success'] || empty($ret['body'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -440,24 +440,21 @@ q *
|
||||||
// send comments and likes to owner to relay
|
// send comments and likes to owner to relay
|
||||||
logger('ActivityPub followup: ' . $loc);
|
logger('ActivityPub followup: ' . $loc);
|
||||||
$data = ActivityPub::createActivityFromItem($target_item['id']);
|
$data = ActivityPub::createActivityFromItem($target_item['id']);
|
||||||
$content = json_encode($data);
|
ActivityPub::transmit($data, $contact['notify'], $owner['uid']);
|
||||||
ActivityPub::transmit($content, $contact['notify'], $owner['uid']);
|
|
||||||
// ActivityPub::sendFollowup($target_item, $owner, $contact, $public_message);
|
// ActivityPub::sendFollowup($target_item, $owner, $contact, $public_message);
|
||||||
return;
|
return;
|
||||||
} elseif ($target_item['uri'] !== $target_item['parent-uri']) {
|
} elseif ($target_item['uri'] !== $target_item['parent-uri']) {
|
||||||
// we are the relay - send comments, likes and relayable_retractions to our conversants
|
// we are the relay - send comments, likes and relayable_retractions to our conversants
|
||||||
logger('ActivityPub relay: ' . $loc);
|
logger('ActivityPub relay: ' . $loc);
|
||||||
$data = ActivityPub::createActivityFromItem($target_item['id']);
|
$data = ActivityPub::createActivityFromItem($target_item['id']);
|
||||||
$content = json_encode($data);
|
ActivityPub::transmit($data, $contact['notify'], $owner['uid']);
|
||||||
ActivityPub::transmit($content, $contact['notify'], $owner['uid']);
|
|
||||||
// ActivityPub::sendRelay($target_item, $owner, $contact, $public_message);
|
// ActivityPub::sendRelay($target_item, $owner, $contact, $public_message);
|
||||||
return;
|
return;
|
||||||
} elseif ($top_level && !$walltowall) {
|
} elseif ($top_level && !$walltowall) {
|
||||||
// currently no workable solution for sending walltowall
|
// currently no workable solution for sending walltowall
|
||||||
logger('ActivityPub status: ' . $loc);
|
logger('ActivityPub status: ' . $loc);
|
||||||
$data = ActivityPub::createActivityFromItem($target_item['id']);
|
$data = ActivityPub::createActivityFromItem($target_item['id']);
|
||||||
$content = json_encode($data);
|
ActivityPub::transmit($data, $contact['notify'], $owner['uid']);
|
||||||
ActivityPub::transmit($content, $contact['notify'], $owner['uid']);
|
|
||||||
// ActivityPub::sendStatus($target_item, $owner, $contact, $public_message);
|
// ActivityPub::sendStatus($target_item, $owner, $contact, $public_message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue