aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Lib')
-rw-r--r--Zotlabs/Lib/Activity.php66
-rw-r--r--Zotlabs/Lib/Config.php4
-rw-r--r--Zotlabs/Lib/IConfig.php32
-rw-r--r--Zotlabs/Lib/Libzot.php8
-rw-r--r--Zotlabs/Lib/ObjCache.php40
5 files changed, 84 insertions, 66 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 22dbaad84..9fca8e4a7 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -382,7 +382,12 @@ class Activity {
if ($items) {
$x = [];
foreach ($items as $i) {
- $m = IConfig::Get($i['id'], 'activitypub', 'rawmsg');
+ $m = ObjCache::Get($i['mid']);
+
+ if (!$m) {
+ $m = IConfig::Get($i['id'], 'activitypub', 'rawmsg');
+ }
+
if ($m) {
if (is_string($m))
$t = json_decode($m, true);
@@ -501,8 +506,8 @@ class Activity {
}
}
- $ret['id'] = ((strpos($i['mid'], 'http') === 0) ? $i['mid'] : z_root() . '/item/' . urlencode($i['mid']));
- $ret['diaspora:guid'] = $i['uuid'];
+ $ret['id'] = ((strpos($i['mid'], 'http') === 0) ? $i['mid'] : z_root() . '/item/' . urlencode($i['mid']));
+ $ret['uuid'] = $i['uuid'];
$images = [];
$audios = [];
@@ -829,8 +834,7 @@ class Activity {
if ($iconfig && array_key_exists('iconfig', $item) && is_array($item['iconfig'])) {
foreach ($item['iconfig'] as $att) {
if ($att['sharing']) {
- $value = ((is_string($att['v']) && preg_match('|^a:[0-9]+:{.*}$|s', $att['v'])) ? unserialize($att['v']) : $att['v']);
- $ret[] = ['type' => 'PropertyValue', 'name' => 'zot.' . $att['cat'] . '.' . $att['k'], 'value' => $value];
+ $ret[] = ['type' => 'PropertyValue', 'name' => 'zot.' . $att['cat'] . '.' . $att['k'], 'value' => unserialise($att['v'])];
}
}
}
@@ -997,7 +1001,7 @@ class Activity {
$ret['id'] = ((strpos($i['mid'], 'http') === 0) ? $i['mid'] : z_root() . '/activity/' . urlencode($i['mid']));
}
- $ret['diaspora:guid'] = $i['uuid'];
+ $ret['uuid'] = $i['uuid'];
if (!empty($i['title']))
$ret['name'] = html2plain(bbcode($i['title']));
@@ -2674,50 +2678,6 @@ class Activity {
$s['item_private'] = 2;
}
- $ap_rawmsg = '';
- $diaspora_rawmsg = '';
- $raw_arr = [];
-
- $raw_arr = json_decode($act->raw, true);
-
- // This is a zot6 packet and the raw activitypub or diaspora message json
- // is possibly available in the attachement.
- if (array_key_exists('signed', $raw_arr) && isset($act->data['attachment']) && is_array($act->data['attachment'])) {
- foreach($act->data['attachment'] as $a) {
- if (
- isset($a['type']) && $a['type'] === 'PropertyValue' &&
- isset($a['name']) && $a['name'] === 'zot.activitypub.rawmsg' &&
- isset($a['value'])
- ) {
- $ap_rawmsg = $a['value'];
- }
- if (
- isset($a['type']) && $a['type'] === 'PropertyValue' &&
- isset($a['name']) && $a['name'] === 'zot.diaspora.fields' &&
- isset($a['value'])
- ) {
- $diaspora_rawmsg = $a['value'];
- }
- }
- }
-
-
- if (!$ap_rawmsg && array_key_exists('signed', $raw_arr)) {
- // zap
- $ap_rawmsg = json_encode($act->data, JSON_UNESCAPED_SLASHES);
- }
-
- if ($ap_rawmsg) {
- IConfig::Set($s, 'activitypub', 'rawmsg', $ap_rawmsg, 1);
- }
- elseif (!array_key_exists('signed', $raw_arr)) {
- IConfig::Set($s, 'activitypub', 'rawmsg', $act->raw, 1);
- }
-
- if ($diaspora_rawmsg) {
- IConfig::Set($s, 'diaspora', 'fields', $diaspora_rawmsg, 1);
- }
-
if ($act->raw_recips) {
IConfig::Set($s, 'activitypub', 'recips', $act->raw_recips);
}
@@ -2726,6 +2686,8 @@ class Activity {
IConfig::Set($s, 'event', 'timezone', $act->objprop('timezone'), true);
}
+ ObjCache::Set($s['mid'], $act->data);
+
$hookinfo = [
'act' => $act,
's' => $s
@@ -2889,7 +2851,7 @@ class Activity {
if (tgroup_check($channel['channel_id'], $item) && (!$is_child_node)) {
// for forum deliveries, make sure we keep a copy of the signed original
- IConfig::Set($item, 'activitypub', 'rawmsg', $act->raw, 1);
+ ObjCache::Set($item['mid'], $act->data);
$allowed = true;
}
@@ -3746,8 +3708,6 @@ class Activity {
'conversation' => 'ostatus:conversation',
- 'guid' => 'diaspora:guid',
-
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
'Hashtag' => 'as:Hashtag',
diff --git a/Zotlabs/Lib/Config.php b/Zotlabs/Lib/Config.php
index cd8b08991..139affa09 100644
--- a/Zotlabs/Lib/Config.php
+++ b/Zotlabs/Lib/Config.php
@@ -132,8 +132,8 @@ class Config {
$value = App::$config[$family][$key];
if (! is_array($value)) {
- if (substr($value, 0, 5) == 'json:') {
- return json_decode(substr($value, 5), true);
+ if (str_starts_with($value, 'json:')) {
+ return unserialise($value);
} else if (preg_match('|^a:[0-9]+:{.*}$|s', $value)) {
// Unserialize in inherently unsafe. Try to mitigate by not
// allowing unserializing objects. Only kept for backwards
diff --git a/Zotlabs/Lib/IConfig.php b/Zotlabs/Lib/IConfig.php
index 3540c2b24..3e3f783f5 100644
--- a/Zotlabs/Lib/IConfig.php
+++ b/Zotlabs/Lib/IConfig.php
@@ -34,8 +34,20 @@ class IConfig {
if(is_array($item) && array_key_exists('iconfig',$item) && is_array($item['iconfig'])) {
foreach($item['iconfig'] as $c) {
- if (isset($c['iid']) && $c['iid'] == $iid && isset($c['cat']) && $c['cat'] == $family && isset($c['k']) && $c['k'] == $key)
+ if (isset($c['iid']) && $c['iid'] == $iid && isset($c['cat']) && $c['cat'] == $family && isset($c['k']) && $c['k'] == $key) {
+ if (is_string($c['v'])) {
+ if (str_starts_with($c['v'], 'json:')) {
+ $c['v'] = unserialise($c['v']);
+ } else if (preg_match('|^a:[0-9]+:{.*}$|s', $c['v'])) {
+ // Unserialize in inherently unsafe. Try to mitigate by not
+ // allowing unserializing objects. Only kept for backwards
+ // compatibility. JSON serialization should be prefered.
+ $c['v'] = unserialize($c['v'], ['allowed_classes' => false]);
+ }
+ }
+
return $c['v'];
+ }
}
}
@@ -44,12 +56,24 @@ class IConfig {
dbesc($family),
dbesc($key)
);
+
if($r) {
- $r[0]['v'] = ((preg_match('|^a:[0-9]+:{.*}$|s',$r[0]['v'])) ? unserialize($r[0]['v']) : $r[0]['v']);
- if($is_item)
+ if (str_starts_with($r[0]['v'], 'json:')) {
+ $r[0]['v'] = unserialise($r[0]['v']);
+ } else if (preg_match('|^a:[0-9]+:{.*}$|s', $r[0]['v'])) {
+ // Unserialize in inherently unsafe. Try to mitigate by not
+ // allowing unserializing objects. Only kept for backwards
+ // compatibility. JSON serialization should be prefered.
+ $r[0]['v'] = unserialize($r[0]['v'], ['allowed_classes' => false]);
+ }
+
+ if ($is_item) {
$item['iconfig'][] = $r[0];
+ }
+
return $r[0]['v'];
}
+
return $default;
}
@@ -73,7 +97,7 @@ class IConfig {
static public function Set(&$item, $family, $key, $value, $sharing = false) {
- $dbvalue = ((is_array($value)) ? serialize($value) : $value);
+ $dbvalue = ((is_array($value)) ? serialise($value) : $value);
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
$is_item = false;
diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php
index 08a3f27c9..e3fa6e9d3 100644
--- a/Zotlabs/Lib/Libzot.php
+++ b/Zotlabs/Lib/Libzot.php
@@ -6,7 +6,6 @@ use App;
use Zotlabs\Access\PermissionLimits;
use Zotlabs\Access\Permissions;
use Zotlabs\Daemon\Master;
-use Zotlabs\Lib\Config;
use Zotlabs\Web\HTTPSig;
require_once('include/crypto.php');
@@ -1298,10 +1297,6 @@ class Libzot {
$item['comment_policy'] = 'authenticated';
}
- if (isset($AS->meta['signed_data']) && $AS->meta['signed_data']) {
- IConfig::Set($item, 'activitypub', 'signed_data', $AS->meta['signed_data'], false);
- }
-
logger('Activity received: ' . print_r($item, true), LOGGER_DATA, LOG_DEBUG);
logger('Activity recipients: ' . print_r($deliveries, true), LOGGER_DATA, LOG_DEBUG);
@@ -2144,10 +2139,9 @@ class Libzot {
}
if (isset($AS->meta['signed_data'])) {
- IConfig::Set($arr, 'activitypub', 'signed_data', $AS->meta['signed_data'], false);
$j = json_decode($AS->meta['signed_data'], true);
if ($j) {
- IConfig::Set($arr, 'activitypub', 'rawmsg', json_encode(JSalmon::unpack($j['data'])), true);
+ ObjCache::Set($arr['mid'], json_encode(JSalmon::unpack($j['data'])));
}
}
diff --git a/Zotlabs/Lib/ObjCache.php b/Zotlabs/Lib/ObjCache.php
new file mode 100644
index 000000000..618522cf2
--- /dev/null
+++ b/Zotlabs/Lib/ObjCache.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Zotlabs\Lib;
+
+class ObjCache
+{
+ public static function Get($path, $type = 'as')
+ {
+ if (!$path) {
+ return [];
+ }
+
+ $localpath = Hashpath::path($path, 'store/[data]/[obj]/' . $type, 2, alg: 'sha256');
+ if (file_exists($localpath)) {
+ return unserialise(file_get_contents($localpath));
+ }
+
+ return [];
+ }
+
+ public static function Set($path, $content, $type = 'as') {
+ if (!$path) {
+ return;
+ }
+
+ $localpath = Hashpath::path($path, 'store/[data]/[obj]/' . $type, 2, alg: 'sha256');
+ file_put_contents($localpath, serialise($content));
+ }
+
+ public static function Delete($path, $type = 'as') {
+ if (!$path) {
+ return;
+ }
+
+ $localpath = Hashpath::path($path, 'store/[data]/[obj]/' . $type, 2, alg: 'sha256');
+ if (file_exists($localpath)) {
+ unlink($localpath);
+ }
+ }
+}