Merge branch 'container' into dev

This commit is contained in:
Mike Macgirvin 2023-12-21 11:53:34 +11:00
commit 0b334df4a7
15 changed files with 32 additions and 103 deletions

View file

@ -370,13 +370,13 @@ class Notifier implements DaemonInterface
}
$m = ($cmd === 'edit_post') ? '' : ObjCache::Get($target_item['mid'] . '.nomad');
// Re-use existing signature unless the activity type changed to a Tombstone, which won't verify.
if ($m && (! intval($target_item['item_deleted']))) {
self::$encoded_item = json_decode($m, true);
} else {
self::$encoded_item = array_merge(Activity::ap_context(), Activity::encode_activity($target_item, true, Activity::isContainer($target_item)));
self::$encoded_item = array_merge(Activity::ap_context(), Activity::encode_activity($target_item, true));
self::$encoded_item['signature'] = LDSignatures::sign(self::$encoded_item, self::$channel);
}
logger('target_item: ' . print_r($target_item, true), LOGGER_DEBUG);

View file

@ -276,7 +276,7 @@ class Activity
xchan_query($r);
$r = fetch_post_tags($r);
if (in_array($r[0]['verb'], ['Invite', 'Undo'])) {
return self::encode_activity($r[0], $activitypub, self::isContainer($r[0]));
return self::encode_activity($r[0], $activitypub);
}
return self::encode_item($r[0], $activitypub);
}
@ -359,7 +359,7 @@ class Activity
if ($m) {
$t = json_decode($m, true);
} else {
$t = self::encode_activity($i, $activitypub, self::isContainer($i));
$t = self::encode_activity($i, $activitypub);
}
if ($t) {
$x[] = $t;
@ -747,18 +747,13 @@ class Activity
dbesc($item['owner_xchan']),
intval($item['uid'])
);
$isContainer = (bool) $query;
if (! Config::Get('system', '2024')) {
$isContainer = false;
}
return $isContainer;
return (bool) $query;
}
// the $recurse flag encodes the original non-deleted object of a deleted activity
public static function encode_activity($item, $activitypub = false, $isContainer = false, $recurse = false)
public static function encode_activity($item, $activitypub = false, $recurse = false)
{
$new = Config::Get('system', '2024');
$activity = [];
if (intval($item['item_deleted']) && (!$recurse)) {
@ -780,7 +775,7 @@ class Activity
return [];
}
$obj = (($is_response) ? self::encode_activity($item, $activitypub, $isContainer, true) : self::encode_item($item, $activitypub));
$obj = (($is_response) ? self::encode_activity($item, $activitypub, true) : self::encode_item($item, $activitypub));
if ($obj) {
if (array_path_exists('object/id', $obj)) {
$obj['object'] = $obj['object']['id'];
@ -796,7 +791,7 @@ class Activity
return $activity;
}
$activity['type'] = ($isContainer) ? 'Add' : self::activity_mapper($item['verb']);
$activity['type'] = self::activity_mapper($item['verb']);
if (str_contains($item['mid'], z_root() . '/item/')) {
$activity['id'] = str_replace('/item/', '/activity/', $item['mid']);
@ -805,9 +800,6 @@ class Activity
} else {
$activity['id'] = $item['mid'];
}
if ($isContainer) {
$activity['id'] .= '?operation=add';
}
if ($item['title']) {
$activity['name'] = $item['title'];
@ -846,15 +838,11 @@ class Activity
$place->setLatitude(isset($item['lat']) ? $item['lat'] : 0)
->setLongitude(isset($item['lon']) ? $item['lon'] : 0);
}
if (!$new) {
$activity['location'] = $place->toArray();
}
$activity['location'] = $place->toArray();
}
if ($item['mid'] === $item['parent_mid']) {
if (!$new) {
$activity['isContainedConversation'] = true;
}
$activity['isContainedConversation'] = true;
}
else {
// inReplyTo needs to be set in the activity for followup actions (Like, Dislike, Announce, etc.),
@ -891,16 +879,13 @@ class Activity
$cnv = str_replace(['/item/', '/activity/'], ['/conversation/', '/conversation/'], $cnv);
}
$activity['context'] = $cnv;
if (!$new) {
$activity['conversation'] = $cnv;
}
}
if (intval($item['item_private']) === 2) {
$activity['directMessage'] = true;
}
$actor = self::encode_person(($isContainer) ? $item['owner'] : $item['author'], false);
$actor = self::encode_person($item['author'], false);
if ($actor) {
$activity['actor'] = $actor;
} else {
@ -908,7 +893,7 @@ class Activity
}
$replyTo = unserialise($item['replyto']);
if ($replyTo && !$new) {
if ($replyTo) {
$activity['replyTo'] = $replyTo;
$activity['audience'] = $replyTo;
}
@ -992,10 +977,6 @@ class Activity
$activity['target'] = $tgt;
}
}
if ($isContainer) {
$activity['target'] = $activity['context'];
}
$t = self::encode_taxonomy($item);
if ($t) {
foreach($t as $tag) {
@ -1127,8 +1108,6 @@ class Activity
public static function encode_item($item, $activitypub = false)
{
$new = Config::Get('system', '2024');
$activity = [];
$bbopts = (($activitypub) ? 'activitypub' : 'export');
@ -1231,9 +1210,6 @@ class Activity
$activity['attributedTo'] = self::encode_person($item['author'],false);
if ($item['mid'] === $item['parent_mid']) {
if (!$new) {
$activity['isContainedConversation'] = true;
}
if (in_array($activity['commentPolicy'], ['public', 'authenticated'])) {
$activity['canReply'] = ACTIVITY_PUBLIC_INBOX;
} elseif (in_array($activity['commentPolicy'], ['contacts', 'specific'])) {
@ -1242,9 +1218,6 @@ class Activity
$activity['canReply'] = [];
}
}
if ($new) {
unset($activity['commentPolicy']);
}
if ($item['mid'] !== $item['parent_mid']) {
if ($item['approved']) {
@ -1267,9 +1240,6 @@ class Activity
$cnv = str_replace(['/item/', '/activity/'], ['/conversation/', '/conversation/'], $cnv);
}
$activity['context'] = $cnv;
if(!$new) {
$activity['conversation'] = $cnv;
}
}
// provide ocap access token for private media.
@ -1319,7 +1289,7 @@ class Activity
}
$replyTo = unserialise($item['replyto']);
if ($replyTo && !$new) {
if ($replyTo) {
$activity['replyTo'] = $replyTo;
$activity['audience'] = $replyTo;
}
@ -4889,69 +4859,30 @@ class Activity
// $contextType is reserved for future use so that the caller can specify
// a limited subset of the entire schema definition for particular activities.
if (Config::Get('system','2024')) {
return [
'nomad' => z_root() . '/apschema#',
'toot' => 'http://joinmastodon.org/ns#',
'litepub' => 'http://litepub.social/ns#',
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
'oauthRegistrationEndpoint' => 'litepub:oauthRegistrationEndpoint',
'sensitive' => 'as:sensitive',
'movedTo' => 'as:movedTo',
'discoverable' => 'toot:discoverable',
'indexable' => 'toot:indexable',
'capabilities' => 'litepub:capabilities',
'acceptsJoins' => 'litepub:acceptsJoins',
'Hashtag' => 'as:Hashtag',
'canReply' => 'toot:canReply',
'canSearch' => 'nomad:canSearch',
'approval' => 'toot:approval',
'expires' => 'nomad:expires',
'directMessage' => 'nomad:directMessage',
'Category' => 'nomad:Category',
'copiedTo' => 'nomad:copiedTo',
'canSearch' => 'nomad:canSearch',
'searchContent' => 'nomad:searchContent',
'searchTags' => 'nomad:searchTags',
];
}
return [
'nomad' => z_root() . '/apschema#',
'toot' => 'http://joinmastodon.org/ns#',
'litepub' => 'http://litepub.social/ns#',
'sm' => 'http://smithereen.software/ns#',
// 'fep' => 'https://codeberg.org/fediverse/fep#',
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
'oauthRegistrationEndpoint' => 'litepub:oauthRegistrationEndpoint',
'sensitive' => 'as:sensitive',
'movedTo' => 'as:movedTo',
// 'EmojiReact' => 'as:EmojiReact',
'discoverable' => 'toot:discoverable',
'indexable' => 'toot:indexable',
'wall' => 'sm:wall',
'capabilities' => 'litepub:capabilities',
'acceptsJoins' => 'litepub:acceptsJoins',
'nomadicLocations' => 'nomad:nomadicLocations',
'Hashtag' => 'as:Hashtag',
'canReply' => 'toot:canReply',
'canSearch' => 'nomad:canSearch',
'approval' => 'toot:approval',
'Identity' => 'fep:Identity',
'isContainedConversation' => 'nomad:isContainedConversation',
'conversation' => 'nomad:conversation',
'commentPolicy' => 'nomad:commentPolicy',
'eventRepeat' => 'nomad:eventRepeat',
'emojiReaction' => 'nomad:emojiReaction',
'expires' => 'nomad:expires',
'directMessage' => 'nomad:directMessage',
'Category' => 'nomad:Category',
'replyTo' => 'nomad:replyTo',
'copiedTo' => 'nomad:copiedTo',
'canSearch' => 'nomad:canSearch',
'searchContent' => 'nomad:searchContent',
'searchTags' => 'nomad:searchTags',
];
}
public static function get_quote($url, $item) {

View file

@ -57,9 +57,6 @@ class ActivityPub
logger('relayed post with no signed message');
return;
}
if (Config::Get('system','2024') && !$upstream) {
unset($signed_msg);
}
}
if ($purge_all) {
@ -101,7 +98,7 @@ class ActivityPub
Activity::rewrite_mentions_sub($target_item, 1, $target_item['obj']);
$ti = Activity::encode_activity($target_item, true, Activity::isContainer($target_item));
$ti = Activity::encode_activity($target_item, true);
if (!$ti) {
return;

View file

@ -122,7 +122,7 @@ class Activity extends Controller
$isContainer = !empty($operation) && $operation === 'add';
$channel = Channel::from_id($items[0]['uid']);
as_return_and_die(ZlibActivity::encode_activity($items[0], true), $channel, $isContainer);
as_return_and_die(ZlibActivity::encode_activity($items[0], true), $channel);
}
if (Libzot::is_nomad_request()) {

View file

@ -151,7 +151,7 @@ class Security
'$title' => t('Administration'),
'$page' => t('Security'),
'$form_security_token' => get_form_security_token('admin_security'),
'$require_authenticated_fetch' => ['require_authenticated_fetch', t('Require signed fetch requests'), Config::Get('system','require_authenticated_fetch'), ''],
'$require_authenticated_fetch' => ['require_authenticated_fetch', t('Require signed fetch requests'), Config::Get('system','require_authenticated_fetch', true), ''],
'$accept_unsigned_relay' => ['accept_unsigned_relay', t('Accept unsigned relayed activities'), Config::Get('system','accept_unsigned_relay'),''],
'$block_public_search' => array('block_public_search', t("Block public search"), get_config('system', 'block_public_search', 1), t("Prevent access to search content unless you are currently authenticated.")),
'$block_public_dir' => ['block_public_directory', t('Block directory from visitors'), get_config('system', 'block_public_directory', true), t('Only allow authenticated access to directory.')],

View file

@ -34,7 +34,7 @@ class Album extends Controller
http_status_exit(403, 'Permission denied');
}
observer_auth($portable_id);
} elseif (Config::get('system', 'require_authenticated_fetch', false)) {
} elseif (Config::Get('system', 'require_authenticated_fetch', true)) {
http_status_exit(403, 'Permission denied');
}

View file

@ -149,7 +149,7 @@ class Channel extends Controller
observer_auth($portable_id);
}
elseif (Config::Get('system', 'require_authenticated_fetch', false)) {
elseif (Config::Get('system', 'require_authenticated_fetch', true)) {
http_status_exit(403, 'Permission denied');
}
@ -184,8 +184,9 @@ class Channel extends Controller
if ($s && $s[0]['hubloc_sitekey'] && $s[0]['site_crypto']) {
$data = json_encode(Crypto::encapsulate($data, $s[0]['hubloc_sitekey'], Libzot::best_algorithm($s[0]['site_crypto'])));
}
} else {
if (Config::Get('system', 'require_authenticated_fetch', false)) {
}
else {
if (Config::Get('system', 'require_authenticated_fetch', true)) {
http_status_exit(403, 'Permission denied');
}
$data = json_encode(Libzot::zotinfo(['guid_hash' => $channel['channel_hash']]));

View file

@ -60,7 +60,7 @@ class Inspect extends Controller
$output .= '<pre>' . print_array($item) . '</pre>' . EOL . EOL;
$output .= '(encode_activity)' . EOL . '<pre>' . escape_tags(json_encode(Activity::encode_activity($item, true, Activity::isContainer($item)),
$output .= '(encode_activity)' . EOL . '<pre>' . escape_tags(json_encode(Activity::encode_activity($item, true),
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) . '</pre>' . EOL . EOL;
$nomad = ObjCache::Get($item['mid'] . '.nomad');

View file

@ -99,7 +99,7 @@ class Item extends Controller
dbesc($r[0]['parent_mid']),
dbesc($portable_id)
);
} elseif (Config::Get('system', 'require_authenticated_fetch', false)) {
} elseif (Config::Get('system', 'require_authenticated_fetch', true)) {
http_status_exit(403, 'Permission denied');
}
// if we don't have a parent id belonging to the signer see if we can obtain one as a visitor that we have permission to access
@ -249,7 +249,7 @@ class Item extends Controller
dbesc($portable_id)
);
}
elseif (Config::Get('system', 'require_authenticated_fetch', false)) {
elseif (Config::Get('system', 'require_authenticated_fetch', true)) {
http_status_exit(403, 'Permission denied');
}

View file

@ -146,7 +146,7 @@ class Like extends Controller
xchan_query($r, true);
$r = fetch_post_tags($r);
$r[0]['obj'] = json_decode($r[0]['obj'], true);
$object = Activity::encode_activity($r[0], true, Activity::isContainer($r[0]));
$object = Activity::encode_activity($r[0], true);
// do not do either a federated or hard delete on the original reaction
// as we are going to send an Undo to perform this task

View file

@ -56,7 +56,7 @@ class Lists extends Controller
http_status_exit(403, 'Permission denied');
}
observer_auth($portable_id);
} elseif (Config::Get('system', 'require_authenticated_fetch')) {
} elseif (Config::Get('system', 'require_authenticated_fetch', true)) {
http_status_exit(403, 'Permission denied');
}

View file

@ -155,7 +155,7 @@ class New_channel extends Controller
intval($aid)
);
if ($r && (!intval($r[0]['total']))) {
$default_role = get_config('system', 'default_permissions_role', 'social');
$default_role = get_config('system', 'default_permissions_role', 'social_restricted');
}
$limit = ServiceClass::account_fetch(get_account_id(), 'total_identities');
@ -187,7 +187,7 @@ class New_channel extends Controller
$name = ['name', t('Channel name'), ((x($_REQUEST, 'name')) ? $_REQUEST['name'] : ''), $name_help, "*"];
$nickname = ['nickname', t('Choose a short nickname'), ((x($_REQUEST, 'nickname')) ? $_REQUEST['nickname'] : ''), $nick_help, "*"];
$role = ['permissions_role', t('Channel role and privacy'), ($privacy_role) ?: 'social', t('Select a channel permission role compatible with your usage needs and privacy requirements.'), $perm_roles];
$role = ['permissions_role', t('Channel role and privacy'), ($privacy_role) ?: 'social_restricted', t('Select a channel permission role compatible with your usage needs and privacy requirements.'), $perm_roles];
return replace_macros(Theme::get_template('new_channel.tpl'), [
'$title' => t('Create a Channel'),

View file

@ -229,7 +229,7 @@ class Outbox extends Controller
http_status_exit(403, 'Permission denied');
}
observer_auth($portable_id);
} elseif (Config::Get('system', 'require_authenticated_fetch', false)) {
} elseif (Config::Get('system', 'require_authenticated_fetch', true)) {
http_status_exit(403, 'Permission denied');
}
$observer_hash = get_observer_hash();

View file

@ -33,7 +33,7 @@ class Photo extends Controller
http_status_exit(403, 'Permission denied');
}
observer_auth($portable_id);
} elseif (Config::Get('system', 'require_authenticated_fetch', false)) {
} elseif (Config::Get('system', 'require_authenticated_fetch', true)) {
http_status_exit(403, 'Permission denied');
}

View file

@ -4030,7 +4030,7 @@ function zot_feed($uid, $observer_hash, $arr) {
if($encoding === 'zot')
$result[] = encode_item($item);
elseif($encoding === 'activitystreams')
$result[] = Activity::encode_activity($item, true, Activity::isContainer($item));
$result[] = Activity::encode_activity($item, true);
}
return $result;