From a8e68c2e9edde357b1b879b1fffd5b99c2cc2572 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 30 Sep 2019 19:25:48 -0700 Subject: [PATCH] ocap stuff --- Zotlabs/Lib/Activity.php | 15 +++++++++++---- Zotlabs/Lib/ActivityPub.php | 15 ++++++++++++++- Zotlabs/Module/Activity.php | 2 +- Zotlabs/Module/Item.php | 12 ++++++++++-- boot.php | 4 +++- include/text.php | 16 ++++++++++++++-- 6 files changed, 53 insertions(+), 11 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 8fb52214e..2bdc27dc9 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -822,11 +822,15 @@ class Activity { /* Add mentions only if the targets are individuals */ $m = self::map_acl($i,(($i['allow_gid']) ? false : true)); $ret['tag'] = (($ret['tag']) ? array_merge($ret['tag'],$m) : $m); - $ret['to'] = [ $reply_url ]; - if (is_array($m) && $m && ! $ret['to']) { - $ret['to'] = []; + if ($reply_url) { + $ret['to'] = [ $reply_url ]; + } + if (is_array($m) && $m) { + if (! $ret['to']) { + $ret['to'] = []; + } foreach ($m as $ma) { - if (is_array($ma) && $ma['type'] === 'Mention') { + if (is_array($ma) && $ma['type'] === 'Mention' && $ma['href']) { $ret['to'][] = $ma['href']; } } @@ -866,6 +870,9 @@ class Activity { $list = []; foreach ($i['term'] as $t) { + if (! $t['url']) { + continue; + } if ($t['ttype'] == TERM_MENTION) { $url = self::lookup_term_url($t['url']); $list[] = (($url) ? $url : $t['url']); diff --git a/Zotlabs/Lib/ActivityPub.php b/Zotlabs/Lib/ActivityPub.php index 6b3d1d9e7..491a7ebe7 100644 --- a/Zotlabs/Lib/ActivityPub.php +++ b/Zotlabs/Lib/ActivityPub.php @@ -6,7 +6,7 @@ use Zotlabs\Lib\ActivityStreams; use Zotlabs\Lib\Activity; use Zotlabs\Lib\Queue; use Zotlabs\Daemon\Master; - +use Zotlabs\Lib\IConfig; class ActivityPub { @@ -59,11 +59,24 @@ class ActivityPub { $jmsg = $signed_msg; } else { + $ti = Activity::encode_activity($target_item, true); if (! $ti) { return; } + if ($target_item['mid'] !== $target_item['parent_mid']) { + $token = IConfig::get($target_item['id'],'ocap','relay'); + if ($token) { + if (defined('USE_BEARCAPS')) { + $ti['id'] = 'bear:?u=' . $ti['id'] . '&t=' . $token; + } + else { + $ti['id'] = $ti['id'] . '?token=' . $token; + } + } + } + $msg = array_merge(['@context' => [ ACTIVITYSTREAMS_JSONLD_REV, 'https://w3id.org/security/v1', diff --git a/Zotlabs/Module/Activity.php b/Zotlabs/Module/Activity.php index 73a2aebf5..a4e1ce62c 100644 --- a/Zotlabs/Module/Activity.php +++ b/Zotlabs/Module/Activity.php @@ -23,7 +23,7 @@ class Activity extends Controller { $bear = ZlibActivity::token_from_request(); if ($bear) { logger('bear: ' . $bear, LOGGER_DEBUG); - $t = q("select item.uid, iconfig.v from iconfig left join item on iid = item.id where cat = 'ocaps' and item.uuid = '%s'", + $t = q("select item.uid, iconfig.v from iconfig left join item on iid = item.id where cat = 'ocap' and item.uuid = '%s'", dbesc($item_id) ); if ($t) { diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 4135ca61e..15fce34f0 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -1160,6 +1160,8 @@ class Item extends Controller { $plink = z_root() . '/item/' . $uuid; } + + $datarray['aid'] = $channel['channel_account_id']; $datarray['uid'] = $profile_uid; $datarray['uuid'] = $uuid; @@ -1233,9 +1235,15 @@ class Item extends Controller { if(! empty_acl($datarray)) $datarray['public_policy'] = ''; - if($iconfig) + if ($iconfig) { $datarray['iconfig'] = $iconfig; - + } + if ($private) { + IConfig::set($datarray,'ocap','relay',new_token()); + } + + + // preview mode - prepare the body for display and send it via json if($preview) { diff --git a/boot.php b/boot.php index 744474651..b7c96454f 100755 --- a/boot.php +++ b/boot.php @@ -48,7 +48,7 @@ require_once('include/items.php'); -define ( 'STD_VERSION', '19.9.27' ); +define ( 'STD_VERSION', '19.9.30' ); define ( 'ZOT_REVISION', '6.0' ); define ( 'DB_UPDATE_VERSION', 1236 ); @@ -70,6 +70,8 @@ define ( 'EMPTY_STR', '' ); define ( 'ATOM_TIME', 'Y-m-d\\TH:i:s\\Z' ); // aka ISO 8601 "Zulu" define ( 'TEMPLATE_BUILD_PATH', 'store/[data]/smarty3' ); +//define ( 'USE_BEARCAPS', true); + define ( 'DIRECTORY_MODE_NORMAL', 0x0000); // A directory client define ( 'DIRECTORY_MODE_PRIMARY', 0x0001); // There can only be *one* primary directory server in a directory_realm. define ( 'DIRECTORY_MODE_SECONDARY', 0x0002); // All other mirror directory servers diff --git a/include/text.php b/include/text.php index 7356d4e44..f18698488 100644 --- a/include/text.php +++ b/include/text.php @@ -593,8 +593,20 @@ function photo_new_resource() { } -function new_token() { - return random_string(mt_rand(48,64)); +// provide psuedo random token (string) consisting entirely of US-ASCII letters/numbers +// and with possibly variable length + +function new_token($minlen = 36,$maxlen = 48) { + + $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; + $str = EMPTY_STR; + + $len = (($minlen === $maxlen) ? $minlen : mt_rand($minlen,$maxlen)); + + for($a = 0; $a < $len; $a ++) { + $str .= $chars[mt_rand(0,62)]; + } + return $str; } /**