cleanup - implement remote purge which has been missing for a long time

This commit is contained in:
zotlabs 2019-05-06 20:22:08 -07:00
parent e7f5ad401c
commit 6634ad9085
6 changed files with 81 additions and 62 deletions

View file

@ -61,6 +61,7 @@ require_once('include/bbcode.php');
* permissions_reject abook_id
* permissions_update abook_id
* refresh_all channel_id
* purge xchan_hash
* purge_all channel_id
* expire channel_id
* relay item_id (item was relayed to owner, we will deliver it as owner)
@ -228,13 +229,21 @@ class Notifier {
self::$private = false;
self::$packet_type = 'refresh';
}
elseif($cmd === 'purge') {
$xchan = argv(3);
logger('notifier: purge: ' . $item_id . ' => ' . $xchan);
if (! $xchan) {
return;
}
self::$channel = channelx_by_n($item_id);
self::$recipients = [ $xchan ];
self::$private = true;
self::$packet_type = 'purge';
}
elseif($cmd === 'purge_all') {
logger('notifier: purge_all: ' . $item_id);
$s = q("select * from channel where channel_id = %d limit 1",
intval($item_id)
);
if($s)
self::$channel = $s[0];
self::$channel = channelx_by_n($item_id);
self::$recipients = array();
$r = q("select abook_xchan from abook where abook_channel = %d and abook_self = 0",

View file

@ -3,6 +3,8 @@
namespace Zotlabs\Lib;
use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\Webfinger;
use Zotlabs\Lib\Zotfinger;
require_once('include/permissions.php');
@ -272,6 +274,8 @@ class Libzotdir {
$ud_flags |= UPDATE_FLAGS_DELETED;
if (is_array($t['flags']) && in_array('forced',$t['flags']))
$ud_flags |= UPDATE_FLAGS_FORCED;
if (is_array($t['flags']) && in_array('censored',$t['flags']))
$ud_flags |= UPDATE_FLAGS_CENSORED;
$z = q("insert into updates ( ud_hash, ud_guid, ud_date, ud_flags, ud_addr )
values ( '%s', '%s', '%s', %d, '%s' ) ",
@ -308,9 +312,9 @@ class Libzotdir {
if ($ud['ud_addr'] && (! ($ud['ud_flags'] & UPDATE_FLAGS_DELETED))) {
$success = false;
$href = \Zotlabs\Lib\Webfinger::zot_url(punify($ud['ud_addr']));
$href = Webfinger::zot_url(punify($ud['ud_addr']));
if($href) {
$zf = \Zotlabs\Lib\Zotfinger::exec($href);
$zf = Zotfinger::exec($href);
}
if(is_array($zf) && array_path_exists('signature/signer',$zf) && $zf['signature']['signer'] === $href && intval($zf['signature']['header_valid'])) {
$xc = Libzot::import_xchan($zf['data'], 0, $ud);
@ -639,7 +643,7 @@ class Libzotdir {
);
}
else {
q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and not (ud_flags & %d)>0 ",
q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and (ud_flags & %d) = 0 ",
intval(UPDATE_FLAGS_UPDATED),
dbesc($addr),
intval(UPDATE_FLAGS_UPDATED)

View file

@ -1,11 +1,15 @@
<?php
namespace Zotlabs\Module;
use App;
use Zotlabs\Web\Controller;
use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\Libsync;
use Zotlabs\Lib\ActivityPub;
use Zotlabs\Lib\Apps;
use Zotlabs\Lib\AccessList;
use Zotlabs\Access\Permissions;
use Zotlabs\Daemon\Master;
/* @file connedit.php
* @brief In this file the connection-editor form is generated and evaluated.
@ -19,7 +23,7 @@ require_once('include/socgraph.php');
require_once('include/photos.php');
class Connedit extends \Zotlabs\Web\Controller {
class Connedit extends Controller {
/* @brief Initialize the connection-editor
*
@ -39,15 +43,15 @@ class Connedit extends \Zotlabs\Web\Controller {
intval(argv(1))
);
if($r) {
\App::$poi = array_shift($r);
App::$poi = array_shift($r);
}
}
$channel = \App::get_channel();
if($channel)
$channel = App::get_channel();
if ($channel) {
head_set_icon($channel['xchan_photo_s']);
}
}
@ -64,7 +68,7 @@ class Connedit extends \Zotlabs\Web\Controller {
if(! $contact_id)
return;
$channel = \App::get_channel();
$channel = App::get_channel();
// TODO if configured for hassle-free permissions, we'll post the form with ajax as soon as the
// connection enable is toggled to a special autopost url and set permissions immediately, leaving
@ -135,7 +139,7 @@ class Connedit extends \Zotlabs\Web\Controller {
$closeness = 80;
}
$all_perms = \Zotlabs\Access\Permissions::Perms();
$all_perms = Permissions::Perms();
$p = EMPTY_STR;
@ -166,17 +170,15 @@ class Connedit extends \Zotlabs\Web\Controller {
// request. The workaround is to approve the connection, then go back and
// adjust permissions as desired.
$p = \Zotlabs\Access\Permissions::connect_perms(local_channel());
$my_perms = \Zotlabs\Access\Permissions::serialise($p['perms']);
if($my_perms) {
$p = Permissions::connect_perms(local_channel());
$my_perms = Permissions::serialise($p['perms']);
if ($my_perms) {
set_abconfig($channel['channel_id'],$orig_record[0]['abook_xchan'],'system','my_perms',$my_perms);
}
}
$abook_pending = (($new_friend) ? 0 : $orig_record[0]['abook_pending']);
$r = q("UPDATE abook SET abook_profile = '%s', abook_closeness = %d, abook_pending = %d,
abook_incl = '%s', abook_excl = '%s'
where abook_id = %d AND abook_channel = %d",
@ -194,12 +196,12 @@ class Connedit extends \Zotlabs\Web\Controller {
else
notice( t('Failed to update connection record.') . EOL);
if(! intval(\App::$poi['abook_self'])) {
if(! intval(App::$poi['abook_self'])) {
if($new_friend) {
\Zotlabs\Daemon\Master::Summon( [ 'Notifier', 'permissions_accept', $contact_id ] );
Master::Summon( [ 'Notifier', 'permissions_accept', $contact_id ] );
}
\Zotlabs\Daemon\Master::Summon( [
Master::Summon( [
'Notifier',
(($new_friend) ? 'permissions_create' : 'permissions_update'),
$contact_id
@ -234,9 +236,9 @@ class Connedit extends \Zotlabs\Web\Controller {
$xarr['deny_gid'] = $channel['channel_deny_gid'];
$xarr['item_private'] = (($xarr['allow_cid']||$xarr['allow_gid']||$xarr['deny_cid']||$xarr['deny_gid']) ? 1 : 0);
$xarr['body'] = '[zrl=' . $channel['xchan_url'] . ']' . $channel['xchan_name'] . '[/zrl]' . ' ' . t('is now connected to') . ' ' . '[zrl=' . \App::$poi['xchan_url'] . ']' . \App::$poi['xchan_name'] . '[/zrl]';
$xarr['body'] = '[zrl=' . $channel['xchan_url'] . ']' . $channel['xchan_name'] . '[/zrl]' . ' ' . t('is now connected to') . ' ' . '[zrl=' . App::$poi['xchan_url'] . ']' . App::$poi['xchan_name'] . '[/zrl]';
$xarr['body'] .= "\n\n\n" . '[zrl=' . \App::$poi['xchan_url'] . '][zmg=80x80]' . \App::$poi['xchan_photo_m'] . '[/zmg][/zrl]';
$xarr['body'] .= "\n\n\n" . '[zrl=' . App::$poi['xchan_url'] . '][zmg=80x80]' . App::$poi['xchan_photo_m'] . '[/zmg][/zrl]';
post_activity_item($xarr);
@ -244,7 +246,7 @@ class Connedit extends \Zotlabs\Web\Controller {
// pull in a bit of content if there is any to pull in
\Zotlabs\Daemon\Master::Summon(array('Onepoll',$contact_id));
Master::Summon( [ 'Onepoll', $contact_id ]);
}
@ -257,7 +259,7 @@ class Connedit extends \Zotlabs\Web\Controller {
intval($contact_id)
);
if($r) {
\App::$poi = $r[0];
App::$poi = $r[0];
}
if($new_friend) {
@ -281,23 +283,23 @@ class Connedit extends \Zotlabs\Web\Controller {
function connedit_clone(&$a) {
if(! \App::$poi)
if(! App::$poi)
return;
$channel = \App::get_channel();
$channel = App::get_channel();
$r = q("SELECT abook.*, xchan.*
FROM abook left join xchan on abook_xchan = xchan_hash
WHERE abook_channel = %d and abook_id = %d LIMIT 1",
intval(local_channel()),
intval(\App::$poi['abook_id'])
intval(App::$poi['abook_id'])
);
if($r) {
\App::$poi = array_shift($r);
App::$poi = array_shift($r);
}
$clone = \App::$poi;
$clone = App::$poi;
unset($clone['abook_id']);
unset($clone['abook_account']);
@ -330,7 +332,7 @@ class Connedit extends \Zotlabs\Web\Controller {
$yes_no = [ t('No'), t('Yes') ];
$connect_perms = \Zotlabs\Access\Permissions::connect_perms(local_channel());
$connect_perms = Permissions::connect_perms(local_channel());
$o .= "<script>function connectDefaultShare() {
\$('.abook-edit-me').each(function() {
@ -365,7 +367,7 @@ class Connedit extends \Zotlabs\Web\Controller {
if($cmd === 'update') {
// pull feed and consume it, which should subscribe to the hub.
\Zotlabs\Daemon\Master::Summon(array('Poller',$contact_id));
Master::Summon( [ 'Poller', $contact_id ]);
goaway(z_root() . '/connedit/' . $contact_id);
}
@ -412,7 +414,7 @@ class Connedit extends \Zotlabs\Web\Controller {
else {
// if you are on a different network we'll force a refresh of the connection basic info
\Zotlabs\Daemon\Master::Summon(array('Notifier','permissions_update',$contact_id));
Master::Summon( [ 'Notifier', 'permissions_update', $contact_id ]);
}
goaway(z_root() . '/connedit/' . $contact_id);
}
@ -470,18 +472,15 @@ class Connedit extends \Zotlabs\Web\Controller {
if($cmd === 'drop') {
// @FIXME
// We need to send either a purge or a refresh packet to the other side (the channel being unfriended).
// The issue is that the abook DB record _may_ get destroyed when we call contact_remove. As the notifier
// runs in the background there could be a race condition preventing this packet from being sent in all
// cases.
// PLACEHOLDER
if($orig_record[0]['xchan_network'] === 'activitypub') {
ActivityPub::contact_remove(local_channel(), $orig_record[0]);
}
contact_remove(local_channel(), $orig_record[0]['abook_id']);
// The purge notification is sent to the xchan_hash as the abook record will have just been removed
Master::Summon( [ 'Notifier' , 'purge', $orig_record[0]['xchan_hash'] ] );
Libsync::build_sync_packet(0 /* use the current local_channel */,
array('abook' => array(array(
'abook_xchan' => $orig_record[0]['abook_xchan'],
@ -497,13 +496,13 @@ class Connedit extends \Zotlabs\Web\Controller {
}
}
if(\App::$poi) {
if(App::$poi) {
$abook_prev = 0;
$abook_next = 0;
$contact_id = \App::$poi['abook_id'];
$contact = \App::$poi;
$contact_id = App::$poi['abook_id'];
$contact = App::$poi;
$cn = q("SELECT abook_id, xchan_name from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and xchan_deleted = 0 order by xchan_name",
intval(local_channel())
@ -700,9 +699,9 @@ class Connedit extends \Zotlabs\Web\Controller {
$perms = array();
$channel = \App::get_channel();
$channel = App::get_channel();
$global_perms = \Zotlabs\Access\Permissions::Perms();
$global_perms = Permissions::Perms();
$existing = get_all_perms(local_channel(),$contact['abook_xchan'],false);
@ -722,7 +721,7 @@ class Connedit extends \Zotlabs\Web\Controller {
$theirs = get_abconfig(local_channel(),$contact['abook_xchan'],'system','their_perms',EMPTY_STR);
$their_perms = \Zotlabs\Access\Permissions::FilledPerms(explode(',',$theirs));
$their_perms = Permissions::FilledPerms(explode(',',$theirs));
foreach($global_perms as $k => $v) {
if(! array_key_exists($k,$their_perms))
$their_perms[$k] = 1;

View file

@ -245,17 +245,22 @@ class Dirsearch extends Controller {
if ($sync) {
// generate sync packet for directory mirrors
$spkt = array('transactions' => [] );
$r = q("select * from updates where ud_date >= '%s' and ud_guid != '' order by ud_date desc",
dbesc($sync)
);
if ($r) {
foreach ($r as $rr) {
$flags = array();
$flags = [];
if ($rr['ud_flags'] & UPDATE_FLAGS_DELETED)
$flags[] = 'deleted';
if ($rr['ud_flags'] & UPDATE_FLAGS_FORCED)
$flags[] = 'forced';
if ($rr['ud_flags'] & UPDATE_FLAGS_CENSORED)
$flags[] = 'censored';
$spkt['transactions'][] = [
'hash' => $rr['ud_hash'],
@ -289,18 +294,17 @@ class Dirsearch extends Controller {
}
json_return_and_die($spkt);
}
else {
// normal directory query
$r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash
where ( $logic $sql_extra ) $hub_query and xchan_network = 'zot6' and xchan_system = 0 and xchan_hidden = 0 and xchan_orphan = 0 and xchan_deleted = 0
$safesql $order $qlimit "
);
// normal directory query
$r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash
where ( $logic $sql_extra ) $hub_query and xchan_network = 'zot6' and xchan_system = 0 and xchan_hidden = 0 and xchan_orphan = 0 and xchan_deleted = 0
$safesql $order $qlimit "
);
$ret['page'] = $page + 1;
$ret['records'] = count($r);
}
$ret['page'] = $page + 1;
$ret['records'] = count($r);
if ($r) {

View file

@ -342,6 +342,7 @@ define ( 'POLL_OVERWRITE', 0x8000); // If you vote twice remove the prior
define ( 'UPDATE_FLAGS_UPDATED', 0x0001);
define ( 'UPDATE_FLAGS_FORCED', 0x0002);
define ( 'UPDATE_FLAGS_CENSORED', 0x0004);
define ( 'UPDATE_FLAGS_DELETED', 0x1000);

View file

@ -1,5 +1,7 @@
<?php /** @file */
use Zotlabs\Daemon\Master;
function abook_store_lowlevel($arr) {
@ -375,7 +377,7 @@ function contact_remove($channel_id, $abook_id) {
// remove items in the background as this can take some time
\Zotlabs\Daemon\Master::Summon( [ 'Delxitems', $channel_id, $abook['abook_xchan'] ] );
Master::Summon( [ 'Delxitems', $channel_id, $abook['abook_xchan'] ] );
q("delete from abook where abook_id = %d and abook_channel = %d",