aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Lib/Activity.php38
-rw-r--r--Zotlabs/Module/Chat.php2
-rw-r--r--Zotlabs/Module/Item.php51
-rw-r--r--Zotlabs/Module/Lockview.php41
-rw-r--r--Zotlabs/Module/Owa.php4
-rw-r--r--Zotlabs/Module/Photo.php19
-rw-r--r--Zotlabs/Module/Rpost.php12
-rw-r--r--Zotlabs/Module/Settings/Privacy.php5
-rw-r--r--Zotlabs/Module/Sse_bs.php14
-rw-r--r--Zotlabs/Module/Wall_attach.php22
-rw-r--r--Zotlabs/Module/Wall_upload.php1
11 files changed, 146 insertions, 63 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index c2acff83f..8bb157347 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -459,6 +459,27 @@ class Activity {
$ret['id'] = ((strpos($i['mid'], 'http') === 0) ? $i['mid'] : z_root() . '/item/' . urlencode($i['mid']));
$ret['diaspora:guid'] = $i['uuid'];
+ $images = [];
+ $has_images = preg_match_all('/\[[zi]mg(.*?)](.*?)\[/ism', $i['body'], $images, PREG_SET_ORDER);
+
+ // provide ocap access token for private media.
+ // set this for descendants even if the current item is not private
+ // because it may have been relayed from a private item.
+
+ $token = get_iconfig($i, 'ocap', 'relay');
+ if ($token && $has_images) {
+ for ($n = 0; $n < count($images); $n++) {
+ $match = $images[$n];
+ if (str_starts_with($match[1], '=http') && str_contains($match[1], z_root() . '/photo/')) {
+ $i['body'] = str_replace($match[1], $match[1] . '?token=' . $token, $i['body']);
+ $images[$n][2] = substr($match[1], 1) . '?token=' . $token;
+ } elseif (str_contains($match[2], z_root() . '/photo/')) {
+ $i['body'] = str_replace($match[2], $match[2] . '?token=' . $token, $i['body']);
+ $images[$n][2] = $match[2] . '?token=' . $token;
+ }
+ }
+ }
+
if ($i['title'])
$ret['name'] = $i['title'];
@@ -627,10 +648,10 @@ class Activity {
}
if (isset($att['type']) && strpos($att['type'], 'image')) {
- $ret[] = ['type' => 'Image', 'url' => $att['href']];
+ $ret[] = ['type' => 'Image', 'mediaType' => $att['type'], 'name' => $att['title'], 'url' => $att['href']];
}
else {
- $ret[] = ['type' => 'Link', 'mediaType' => $att['type'], 'href' => $att['href']];
+ $ret[] = ['type' => 'Link', 'mediaType' => $att['type'], 'name' => $att['title'], 'href' => $att['href']];
}
}
}
@@ -3131,6 +3152,16 @@ class Activity {
}
}
+ // private conversation, but this comment went rogue and was published publicly
+ // hide it from everybody except the channel owner
+
+ if (intval($parent[0]['item_private'])) {
+ if (!intval($item['item_private'])) {
+ $item['item_private'] = intval($parent_item['item_private']);
+ $item['allow_cid'] = '<' . $channel['channel_hash'] . '>';
+ $item['allow_gid'] = $item['deny_cid'] = $item['deny_gid'] = '';
+ }
+ }
}
// An ugly and imperfect way to recognise a mastodon direct message
@@ -3899,12 +3930,11 @@ class Activity {
}
if (array_path_exists('source/mediaType', $act) && array_path_exists('source/content', $act)) {
- if (in_array($act['source']['mediaType'], ['text/bbcode', 'text/x-multicode'])) {
+ if (in_array($act['source']['mediaType'], ['text/bbcode'])) {
$content['bbcode'] = purify_html($act['source']['content']);
}
}
-
return $content;
}
diff --git a/Zotlabs/Module/Chat.php b/Zotlabs/Module/Chat.php
index efe098739..fc74016ab 100644
--- a/Zotlabs/Module/Chat.php
+++ b/Zotlabs/Module/Chat.php
@@ -212,7 +212,7 @@ class Chat extends Controller {
'$online' => t('I am online'),
'$bookmark_link' => $bookmark_link,
'$bookmark' => t('Bookmark this room'),
- '$feature_encrypt' => ((feature_enabled(local_channel(),'content_encrypt')) ? true : false),
+ '$feature_encrypt' => ((feature_enabled(App::$profile['profile_uid'], 'content_encrypt')) ? true : false),
'$cipher' => $cipher,
'$linkurl' => t('Please enter a link URL:'),
'$encrypt' => t('Encrypt text'),
diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php
index a5f66d72e..b564396c9 100644
--- a/Zotlabs/Module/Item.php
+++ b/Zotlabs/Module/Item.php
@@ -218,6 +218,22 @@ class Item extends Controller {
);
}
+ $bear = Activity::token_from_request();
+ if ($bear) {
+ logger('bear: ' . $bear, LOGGER_DEBUG);
+ if (!$i) {
+ $t = q("select * from iconfig where cat = 'ocap' and k = 'relay' and v = '%s'",
+ dbesc($bear)
+ );
+ if ($t) {
+ $i = q("select id as item_id from item where uuid = '%s' and id = %d $item_normal limit 1",
+ dbesc($item_id),
+ intval($t[0]['iid'])
+ );
+ }
+ }
+ }
+
if (!$i) {
http_status_exit(403, 'Forbidden');
}
@@ -286,7 +302,9 @@ class Item extends Controller {
if ((!local_channel()) && (!remote_channel()) && (!x($_REQUEST, 'anonname')))
return;
- $uid = local_channel();
+ $uid = local_channel();
+ $token = '';
+
$channel = null;
$observer = null;
$datarray = [];
@@ -809,7 +827,6 @@ class Item extends Controller {
require_once('include/text.php');
-
// BBCODE alert: the following functions assume bbcode input
// and will require alternatives for alternative content-types (text/html, text/markdown, text/plain, etc.)
// we may need virtual or template classes to implement the possible alternatives
@@ -845,6 +862,21 @@ class Item extends Controller {
$private = 2;
}
+ if ($private && get_pconfig($profile_uid, 'system', 'ocap_enabled')) {
+ // for edited posts, re-use any existing OCAP token (if found).
+ // Otherwise generate a new one.
+
+ if ($iconfig) {
+ foreach ($iconfig as $cfg) {
+ if ($cfg['cat'] === 'ocap' && $cfg['k'] === 'relay') {
+ $token = $cfg['v'];
+ }
+ }
+ }
+ if (!$token) {
+ $token = new_token();
+ }
+ }
/**
*
@@ -866,9 +898,9 @@ class Item extends Controller {
*/
if (!$preview) {
- fix_attached_photo_permissions($profile_uid, $owner_xchan['xchan_hash'], ((strpos($body, '[/crypt]')) ? $_POST['media_str'] : $body), $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
- fix_attached_photo_permissions($profile_uid, $owner_xchan['xchan_hash'], ((strpos($summary, '[/crypt]')) ? $_POST['media_str'] : $summary), $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
- fix_attached_file_permissions($channel, $observer['xchan_hash'], ((strpos($body, '[/crypt]')) ? $_POST['media_str'] : $body), $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
+ fix_attached_permissions($profile_uid, ((strpos($body, '[/crypt]')) ? $_POST['media_str'] : $body), $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny, $token);
+ //fix_attached_photo_permissions($profile_uid, $owner_xchan['xchan_hash'], ((strpos($body, '[/crypt]')) ? $_POST['media_str'] : $body), $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny, $token);
+ //fix_attached_file_permissions($channel, $observer['xchan_hash'], ((strpos($body, '[/crypt]')) ? $_POST['media_str'] : $body), $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny, $token);
}
$attachments = '';
@@ -951,14 +983,12 @@ class Item extends Controller {
}
}
-
$item_unseen = ((local_channel() != $profile_uid) ? 1 : 0);
$item_wall = ((isset($_REQUEST['type']) && ($_REQUEST['type'] === 'wall' || $_REQUEST['type'] === 'wall-comment')) ? 1 : 0);
$item_origin = (($origin) ? 1 : 0);
$item_consensus = (($consensus) ? 1 : 0);
$item_nocomment = (($nocomment) ? 1 : 0);
-
// determine if this is a wall post
if ($parent) {
@@ -1107,8 +1137,13 @@ class Item extends Controller {
if (!empty_acl($datarray))
$datarray['public_policy'] = '';
- if ($iconfig)
+ if ($iconfig) {
$datarray['iconfig'] = $iconfig;
+ }
+
+ if ($token) {
+ IConfig::set($datarray, 'ocap', 'relay', $token);
+ }
// preview mode - prepare the body for display and send it via json
diff --git a/Zotlabs/Module/Lockview.php b/Zotlabs/Module/Lockview.php
index bac3a7eb9..0c8e23f8c 100644
--- a/Zotlabs/Module/Lockview.php
+++ b/Zotlabs/Module/Lockview.php
@@ -15,6 +15,7 @@ class Lockview extends Controller {
$atoken_xchans = [];
$access_list = [];
$guest_access_list = [];
+ $ocap_access_list = [];
if (local_channel()) {
$at = q("select * from atoken where atoken_uid = %d",
@@ -166,6 +167,24 @@ class Lockview extends Controller {
}
}
}
+ $ocap_tokens = [];
+ foreach ($allowed_users as $allowed_user) {
+ $allowed_user = trim($allowed_user, '\'');
+ if (str_starts_with($allowed_user, 'token:')) {
+ $ocap_tokens[] = str_replace('token:', '', $allowed_user);
+ }
+ }
+
+ if ($ocap_tokens) {
+ stringify_array_elms($ocap_tokens, true);
+ $ocap_mids = dbq("select id, mid from item where id in (select iid from iconfig where cat = 'ocap' and k = 'relay' and v in (" . implode(', ', $ocap_tokens) . "))");
+
+ foreach ($ocap_mids as $ocap) {
+ $ocap_access_list[] = '<a href="' . $ocap['mid'] . '" class="dropdown-item-text" target="_blank">' . t('Item') . ' ' . $ocap['id'] . '</a>';
+ }
+
+ }
+
}
$profile_groups = [];
@@ -205,9 +224,6 @@ class Lockview extends Controller {
}
if ($atokens && $allowed_xchans && $url) {
-
- $guest_access_list = [];
-
$allowed_xchans = array_unique($allowed_xchans);
foreach ($atokens as $atoken) {
if (in_array($atoken['xchan_hash'], $allowed_xchans)) {
@@ -216,22 +232,25 @@ class Lockview extends Controller {
}
}
- $access_list_header = '';
+ $access_list_header = '<div class="dropdown-header text-uppercase h6">' . t('Access') . '</div>';
+ $guest_access_list_header = '<div class="dropdown-header text-uppercase h6">' . t('Guest access') . '</div>';
+ $ocap_access_list_header = '<div class="dropdown-header text-uppercase h6">' . t('OCAP access') . '</div>';
+ $divider = '<div class="dropdown-divider"></div>';
+ $str = '';
+
if ($access_list) {
- $access_list_header = '<div class="dropdown-header text-uppercase h6">' . t('Access') . '</div>';
+ $str .= $access_list_header . implode($access_list);
}
- $guest_access_list_header = '';
if ($guest_access_list) {
- $guest_access_list_header = '<div class="dropdown-header text-uppercase h6">' . t('Guest access') . '</div>';
+ $str .= $divider . $guest_access_list_header . implode($guest_access_list);
}
- $divider = '';
- if ($access_list && $guest_access_list) {
- $divider = '<div class="dropdown-divider"></div>';
+ if ($ocap_access_list) {
+ $str .= $divider . $ocap_access_list_header . implode($ocap_access_list);
}
- echo $access_list_header . implode($access_list) . $divider . $guest_access_list_header . implode($guest_access_list);
+ echo $str;
killme();
}
diff --git a/Zotlabs/Module/Owa.php b/Zotlabs/Module/Owa.php
index 920a92240..4de4d32d6 100644
--- a/Zotlabs/Module/Owa.php
+++ b/Zotlabs/Module/Owa.php
@@ -49,6 +49,10 @@ class Owa extends Controller {
if ($r) {
foreach ($r as $hubloc) {
+ // fix friendica accept header for nginx
+ if (str_starts_with($keyId, 'acct:') && $_SERVER['HTTP_ACCEPT'] === 'application/x-zot+json')
+ $_SERVER['HTTP_ACCEPT'] = 'application/x-dfrn+json, application/x-zot+json';
+
$verified = HTTPSig::verify(file_get_contents('php://input'), $hubloc['xchan_pubkey']);
if ($verified && $verified['header_signed'] && $verified['header_valid'] && ($verified['content_valid'] || (! $verified['content_signed']))) {
logger('OWA header: ' . print_r($verified,true),LOGGER_DATA);
diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php
index fa87d96e5..cb83d78d3 100644
--- a/Zotlabs/Module/Photo.php
+++ b/Zotlabs/Module/Photo.php
@@ -46,7 +46,7 @@ class Photo extends \Zotlabs\Web\Controller {
dbesc(argv(1))
);
if ($r) {
- $allowed = attach_can_view($r[0]['uid'],$observer_xchan,argv(1)/*,$bear*/);
+ $allowed = attach_can_view($r[0]['uid'], $observer_xchan, argv(1), $bear);
}
if (! $allowed) {
http_status_exit(404,'Permission denied.');
@@ -154,6 +154,11 @@ class Photo extends \Zotlabs\Web\Controller {
}
else {
+ $bear = Activity::token_from_request();
+ if ($bear) {
+ logger('bear: ' . $bear, LOGGER_DEBUG);
+ }
+
/**
* Other photos
*/
@@ -223,7 +228,7 @@ class Photo extends \Zotlabs\Web\Controller {
}
if($allowed === (-1))
- $allowed = attach_can_view($r[0]['uid'],$observer_xchan,$photo);
+ $allowed = attach_can_view($r[0]['uid'], $observer_xchan, $photo, $bear);
$channel = channelx_by_n($r[0]['uid']);
@@ -262,13 +267,13 @@ class Photo extends \Zotlabs\Web\Controller {
http_status_exit(404,'not found');
}
- if(! $data)
- killme();
+ if(! $data)
+ killme();
- $etag = '"' . md5($data . $modified) . '"';
+ $etag = '"' . md5($data . $modified) . '"';
- if($modified == 0)
- $modified = time();
+ if($modified == 0)
+ $modified = time();
header_remove('Pragma');
if((isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] === $etag) || (!isset($_SERVER['HTTP_IF_NONE_MATCH']) && isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] === gmdate("D, d M Y H:i:s", $modified) . " GMT")) {
diff --git a/Zotlabs/Module/Rpost.php b/Zotlabs/Module/Rpost.php
index 7b84339b1..f0194fdfd 100644
--- a/Zotlabs/Module/Rpost.php
+++ b/Zotlabs/Module/Rpost.php
@@ -169,16 +169,8 @@ class Rpost extends \Zotlabs\Web\Controller {
$channel = \App::get_channel();
- if(isset($_REQUEST['acl']) && $_REQUEST['acl']) {
- $acl = new \Zotlabs\Access\AccessList([]);
- $acl->set($_REQUEST['acl']);
- $channel_acl = $acl->get();
- }
- else {
- $acl = new \Zotlabs\Access\AccessList($channel);
- $channel_acl = $acl->get();
- }
-
+ $acl = new \Zotlabs\Access\AccessList($channel);
+ $channel_acl = $acl->get();
if(isset($_REQUEST['url']) && $_REQUEST['url']) {
$x = z_fetch_url(z_root() . '/linkinfo?f=&url=' . urlencode($_REQUEST['url']));
diff --git a/Zotlabs/Module/Settings/Privacy.php b/Zotlabs/Module/Settings/Privacy.php
index 65d5b538e..24249a865 100644
--- a/Zotlabs/Module/Settings/Privacy.php
+++ b/Zotlabs/Module/Settings/Privacy.php
@@ -25,6 +25,9 @@ class Privacy {
$permit_all_mentions = (((x($_POST, 'permit_all_mentions')) && (intval($_POST['permit_all_mentions']) == 1)) ? 1 : 0);
set_pconfig(local_channel(), 'system', 'permit_all_mentions', $permit_all_mentions);
+ $ocap_enabled = (((x($_POST, 'ocap_enabled')) && (intval($_POST['ocap_enabled']) == 1)) ? 1 : 0);
+ set_pconfig(local_channel(), 'system', 'ocap_enabled', $ocap_enabled);
+
$role = get_pconfig(local_channel(), 'system', 'permissions_role');
if ($role === 'custom') {
@@ -103,6 +106,7 @@ class Privacy {
$index_opt_out = get_pconfig(local_channel(), 'system', 'index_opt_out');
$group_actor = get_pconfig(local_channel(), 'system', 'group_actor');
$permit_all_mentions = get_pconfig(local_channel(), 'system', 'permit_all_mentions');
+ $ocap_enabled = get_pconfig(local_channel(), 'system', 'ocap_enabled');
$permissions_role = get_pconfig(local_channel(), 'system', 'permissions_role', 'custom');
$permission_limits = ($permissions_role === 'custom');
@@ -125,6 +129,7 @@ class Privacy {
'$index_opt_out' => ['index_opt_out', t('Opt-out of search engine indexing'), $index_opt_out, '', [t('No'), t('Yes')]],
'$group_actor' => ['group_actor', t('Group actor'), $group_actor, t('Allow this channel to act as a forum'), [t('No'), t('Yes')]],
'$permit_all_mentions' => ['permit_all_mentions', t('Accept all messages which mention you'), $permit_all_mentions, t('This setting bypasses normal permissions'), [t('No'), t('Yes')]],
+ '$ocap_enabled' => ['ocap_enabled', t('Enable OCAP access'), $ocap_enabled, t('Grant limited posts the right to access linked private media'), [t('No'), t('Yes')]],
]);
return $o;
diff --git a/Zotlabs/Module/Sse_bs.php b/Zotlabs/Module/Sse_bs.php
index 052870cc9..970c482a9 100644
--- a/Zotlabs/Module/Sse_bs.php
+++ b/Zotlabs/Module/Sse_bs.php
@@ -586,29 +586,23 @@ class Sse_bs extends Controller {
$p_str = ids_to_querystr($p, 'parent');
$p_sql = (($p_str) ? "OR parent IN ( $p_str )" : '');
- $r = q("select mid from item
+ $r = q("select count(*) as total from item
where uid = %d and ( owner_xchan = '%s' OR author_xchan = '%s' $p_sql ) and item_unseen = 1 $sql_extra $item_normal",
intval(self::$uid),
dbesc($forums[$x]['xchan_hash']),
dbesc($forums[$x]['xchan_hash'])
);
- if($r) {
- $mids = flatten_array_recursive($r);
- $b64mids = [];
-
- foreach($mids as $mid)
- $b64mids[] = gen_link_id($mid);
+ if($r[0]['total']) {
$forums[$x]['notify_link'] = z_root() . '/network/?f=&pf=1&unseen=1&cid=' . $forums[$x]['abook_id'];
$forums[$x]['name'] = $forums[$x]['xchan_name'];
$forums[$x]['addr'] = $forums[$x]['xchan_addr'] ?? $forums[$x]['xchan_url'];
$forums[$x]['url'] = $forums[$x]['xchan_url'];
$forums[$x]['photo'] = $forums[$x]['xchan_photo_s'];
- $forums[$x]['unseen'] = count($b64mids);
+ $forums[$x]['unseen'] = $r[0]['total'];
$forums[$x]['private_forum'] = ((isset($forums[$x]['private_forum']) && $forums[$x]['private_forum']) ? 'lock' : '');
$forums[$x]['message'] = ((isset($forums[$x]['private_forum']) && $forums[$x]['private_forum']) ? t('Private forum') : t('Public forum'));
- $forums[$x]['mids'] = json_encode($b64mids);
unset($forums[$x]['abook_id']);
unset($forums[$x]['xchan_hash']);
@@ -616,7 +610,7 @@ class Sse_bs extends Controller {
unset($forums[$x]['xchan_url']);
unset($forums[$x]['xchan_photo_s']);
- $i = $i + count($mids);
+ $i = $i + $r[0]['total'];
}
else {
diff --git a/Zotlabs/Module/Wall_attach.php b/Zotlabs/Module/Wall_attach.php
index 2c0eeec77..80892f0f3 100644
--- a/Zotlabs/Module/Wall_attach.php
+++ b/Zotlabs/Module/Wall_attach.php
@@ -18,10 +18,10 @@ class Wall_attach extends \Zotlabs\Web\Controller {
function post() {
-
+
$using_api = false;
- $result = [];
+ $result = [];
if($_REQUEST['api_source'] && array_key_exists('media',$_FILES)) {
$using_api = true;
@@ -69,7 +69,7 @@ class Wall_attach extends \Zotlabs\Web\Controller {
];
}
}
- else {
+ else {
if(! array_key_exists('userfile',$_FILES)) {
$_FILES['userfile'] = [
'name' => $_FILES['files']['name'],
@@ -82,18 +82,18 @@ class Wall_attach extends \Zotlabs\Web\Controller {
}
$observer = \App::get_observer();
-
-
+
+
$def_album = get_pconfig($channel['channel_id'],'system','photo_path');
$def_attach = get_pconfig($channel['channel_id'],'system','attach_path');
-
- $r = attach_store($channel,(($observer) ? $observer['xchan_hash'] : ''),'', array('source' => 'editor', 'visible' => 0, 'album' => $def_album, 'directory' => $def_attach, 'allow_cid' => '<' . $channel['channel_hash'] . '>'));
+
+ $r = attach_store($channel,(($observer) ? $observer['xchan_hash'] : ''),'', array('source' => 'editor', 'visible' => 0, 'album' => $def_album, 'directory' => $def_attach, 'flags' => 1, 'allow_cid' => '<' . $channel['channel_hash'] . '>'));
if(! $r['success']) {
notice( $r['message'] . EOL);
killme();
}
-
+
if(intval($r['data']['is_photo'])) {
$s = "\n\n" . $r['body'] . "\n\n";
}
@@ -130,7 +130,7 @@ class Wall_attach extends \Zotlabs\Web\Controller {
logger('unable to read svg data file: ' . 'store/' . $channel['channel_address'] . '/' . $r['data']['os_path']);
}
}
-
+
$s .= "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n";
}
@@ -144,8 +144,8 @@ class Wall_attach extends \Zotlabs\Web\Controller {
$result['message'] = $s;
json_return_and_die($result);
-
+
}
-
+
}
diff --git a/Zotlabs/Module/Wall_upload.php b/Zotlabs/Module/Wall_upload.php
index 3e979588c..4a6eee8f9 100644
--- a/Zotlabs/Module/Wall_upload.php
+++ b/Zotlabs/Module/Wall_upload.php
@@ -12,7 +12,6 @@ class Wall_upload extends \Zotlabs\Web\Controller {
function post() {
-
$using_api = ((x($_FILES,'media')) ? true : false);
if($using_api) {