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_reject abook_id
* permissions_update abook_id * permissions_update abook_id
* refresh_all channel_id * refresh_all channel_id
* purge xchan_hash
* purge_all channel_id * purge_all channel_id
* expire channel_id * expire channel_id
* relay item_id (item was relayed to owner, we will deliver it as owner) * relay item_id (item was relayed to owner, we will deliver it as owner)
@ -228,13 +229,21 @@ class Notifier {
self::$private = false; self::$private = false;
self::$packet_type = 'refresh'; 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') { elseif($cmd === 'purge_all') {
logger('notifier: purge_all: ' . $item_id); logger('notifier: purge_all: ' . $item_id);
$s = q("select * from channel where channel_id = %d limit 1", self::$channel = channelx_by_n($item_id);
intval($item_id)
);
if($s)
self::$channel = $s[0];
self::$recipients = array(); self::$recipients = array();
$r = q("select abook_xchan from abook where abook_channel = %d and abook_self = 0", $r = q("select abook_xchan from abook where abook_channel = %d and abook_self = 0",

View file

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

View file

@ -1,11 +1,15 @@
<?php <?php
namespace Zotlabs\Module; namespace Zotlabs\Module;
use App;
use Zotlabs\Web\Controller;
use Zotlabs\Lib\Libzot; use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\Libsync; use Zotlabs\Lib\Libsync;
use Zotlabs\Lib\ActivityPub; use Zotlabs\Lib\ActivityPub;
use Zotlabs\Lib\Apps; use Zotlabs\Lib\Apps;
use Zotlabs\Lib\AccessList; use Zotlabs\Lib\AccessList;
use Zotlabs\Access\Permissions;
use Zotlabs\Daemon\Master;
/* @file connedit.php /* @file connedit.php
* @brief In this file the connection-editor form is generated and evaluated. * @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'); require_once('include/photos.php');
class Connedit extends \Zotlabs\Web\Controller { class Connedit extends Controller {
/* @brief Initialize the connection-editor /* @brief Initialize the connection-editor
* *
@ -39,15 +43,15 @@ class Connedit extends \Zotlabs\Web\Controller {
intval(argv(1)) intval(argv(1))
); );
if($r) { if($r) {
\App::$poi = array_shift($r); App::$poi = array_shift($r);
} }
} }
$channel = \App::get_channel(); $channel = App::get_channel();
if($channel) if ($channel) {
head_set_icon($channel['xchan_photo_s']); head_set_icon($channel['xchan_photo_s']);
}
} }
@ -64,7 +68,7 @@ class Connedit extends \Zotlabs\Web\Controller {
if(! $contact_id) if(! $contact_id)
return; 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 // 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 // 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; $closeness = 80;
} }
$all_perms = \Zotlabs\Access\Permissions::Perms(); $all_perms = Permissions::Perms();
$p = EMPTY_STR; $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 // request. The workaround is to approve the connection, then go back and
// adjust permissions as desired. // adjust permissions as desired.
$p = \Zotlabs\Access\Permissions::connect_perms(local_channel()); $p = Permissions::connect_perms(local_channel());
$my_perms = \Zotlabs\Access\Permissions::serialise($p['perms']); $my_perms = Permissions::serialise($p['perms']);
if($my_perms) { if ($my_perms) {
set_abconfig($channel['channel_id'],$orig_record[0]['abook_xchan'],'system','my_perms',$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']); $abook_pending = (($new_friend) ? 0 : $orig_record[0]['abook_pending']);
$r = q("UPDATE abook SET abook_profile = '%s', abook_closeness = %d, abook_pending = %d, $r = q("UPDATE abook SET abook_profile = '%s', abook_closeness = %d, abook_pending = %d,
abook_incl = '%s', abook_excl = '%s' abook_incl = '%s', abook_excl = '%s'
where abook_id = %d AND abook_channel = %d", where abook_id = %d AND abook_channel = %d",
@ -194,12 +196,12 @@ class Connedit extends \Zotlabs\Web\Controller {
else else
notice( t('Failed to update connection record.') . EOL); notice( t('Failed to update connection record.') . EOL);
if(! intval(\App::$poi['abook_self'])) { if(! intval(App::$poi['abook_self'])) {
if($new_friend) { 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', 'Notifier',
(($new_friend) ? 'permissions_create' : 'permissions_update'), (($new_friend) ? 'permissions_create' : 'permissions_update'),
$contact_id $contact_id
@ -234,9 +236,9 @@ class Connedit extends \Zotlabs\Web\Controller {
$xarr['deny_gid'] = $channel['channel_deny_gid']; $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['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); 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 // 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) intval($contact_id)
); );
if($r) { if($r) {
\App::$poi = $r[0]; App::$poi = $r[0];
} }
if($new_friend) { if($new_friend) {
@ -281,23 +283,23 @@ class Connedit extends \Zotlabs\Web\Controller {
function connedit_clone(&$a) { function connedit_clone(&$a) {
if(! \App::$poi) if(! App::$poi)
return; return;
$channel = \App::get_channel(); $channel = App::get_channel();
$r = q("SELECT abook.*, xchan.* $r = q("SELECT abook.*, xchan.*
FROM abook left join xchan on abook_xchan = xchan_hash FROM abook left join xchan on abook_xchan = xchan_hash
WHERE abook_channel = %d and abook_id = %d LIMIT 1", WHERE abook_channel = %d and abook_id = %d LIMIT 1",
intval(local_channel()), intval(local_channel()),
intval(\App::$poi['abook_id']) intval(App::$poi['abook_id'])
); );
if($r) { 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_id']);
unset($clone['abook_account']); unset($clone['abook_account']);
@ -330,7 +332,7 @@ class Connedit extends \Zotlabs\Web\Controller {
$yes_no = [ t('No'), t('Yes') ]; $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() { $o .= "<script>function connectDefaultShare() {
\$('.abook-edit-me').each(function() { \$('.abook-edit-me').each(function() {
@ -365,7 +367,7 @@ class Connedit extends \Zotlabs\Web\Controller {
if($cmd === 'update') { if($cmd === 'update') {
// pull feed and consume it, which should subscribe to the hub. // 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); goaway(z_root() . '/connedit/' . $contact_id);
} }
@ -412,7 +414,7 @@ class Connedit extends \Zotlabs\Web\Controller {
else { else {
// if you are on a different network we'll force a refresh of the connection basic info // 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); goaway(z_root() . '/connedit/' . $contact_id);
} }
@ -470,18 +472,15 @@ class Connedit extends \Zotlabs\Web\Controller {
if($cmd === 'drop') { 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') { if($orig_record[0]['xchan_network'] === 'activitypub') {
ActivityPub::contact_remove(local_channel(), $orig_record[0]); ActivityPub::contact_remove(local_channel(), $orig_record[0]);
} }
contact_remove(local_channel(), $orig_record[0]['abook_id']); 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 */, Libsync::build_sync_packet(0 /* use the current local_channel */,
array('abook' => array(array( array('abook' => array(array(
'abook_xchan' => $orig_record[0]['abook_xchan'], '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_prev = 0;
$abook_next = 0; $abook_next = 0;
$contact_id = \App::$poi['abook_id']; $contact_id = App::$poi['abook_id'];
$contact = \App::$poi; $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", $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()) intval(local_channel())
@ -700,9 +699,9 @@ class Connedit extends \Zotlabs\Web\Controller {
$perms = array(); $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); $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); $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) { foreach($global_perms as $k => $v) {
if(! array_key_exists($k,$their_perms)) if(! array_key_exists($k,$their_perms))
$their_perms[$k] = 1; $their_perms[$k] = 1;

View file

@ -245,17 +245,22 @@ class Dirsearch extends Controller {
if ($sync) { if ($sync) {
// generate sync packet for directory mirrors
$spkt = array('transactions' => [] ); $spkt = array('transactions' => [] );
$r = q("select * from updates where ud_date >= '%s' and ud_guid != '' order by ud_date desc", $r = q("select * from updates where ud_date >= '%s' and ud_guid != '' order by ud_date desc",
dbesc($sync) dbesc($sync)
); );
if ($r) { if ($r) {
foreach ($r as $rr) { foreach ($r as $rr) {
$flags = array(); $flags = [];
if ($rr['ud_flags'] & UPDATE_FLAGS_DELETED) if ($rr['ud_flags'] & UPDATE_FLAGS_DELETED)
$flags[] = 'deleted'; $flags[] = 'deleted';
if ($rr['ud_flags'] & UPDATE_FLAGS_FORCED) if ($rr['ud_flags'] & UPDATE_FLAGS_FORCED)
$flags[] = 'forced'; $flags[] = 'forced';
if ($rr['ud_flags'] & UPDATE_FLAGS_CENSORED)
$flags[] = 'censored';
$spkt['transactions'][] = [ $spkt['transactions'][] = [
'hash' => $rr['ud_hash'], 'hash' => $rr['ud_hash'],
@ -289,18 +294,17 @@ class Dirsearch extends Controller {
} }
json_return_and_die($spkt); json_return_and_die($spkt);
} }
else {
// normal directory query
$r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash // normal directory query
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 " $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['page'] = $page + 1;
$ret['records'] = count($r); $ret['records'] = count($r);
}
if ($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_UPDATED', 0x0001);
define ( 'UPDATE_FLAGS_FORCED', 0x0002); define ( 'UPDATE_FLAGS_FORCED', 0x0002);
define ( 'UPDATE_FLAGS_CENSORED', 0x0004);
define ( 'UPDATE_FLAGS_DELETED', 0x1000); define ( 'UPDATE_FLAGS_DELETED', 0x1000);

View file

@ -1,5 +1,7 @@
<?php /** @file */ <?php /** @file */
use Zotlabs\Daemon\Master;
function abook_store_lowlevel($arr) { 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 // 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", q("delete from abook where abook_id = %d and abook_channel = %d",