From e45958b967d3b455167191fa91b0c2b6983b6ad5 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 23 Sep 2015 18:27:04 -0700 Subject: add plugin hooks to channel sync/import/export --- include/zot.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 288493b07..9bddb520d 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3319,6 +3319,8 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { if(array_key_exists('item_id',$arr) && $arr['item_id']) sync_items($channel,$arr['item_id']); + $addon = array('channel' => $channel,'data' => $arr); + call_hooks('process_channel_sync_delivery',$addon); // we should probably do this for all items, but usually we only send one. -- cgit v1.2.3 From 9ab335626cdaad433c8f5b6d7fd4d980c1b37742 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sat, 26 Sep 2015 13:25:34 -0700 Subject: import_xchan_photo: check the return headers to ensure it's an image content-type of some form as imagick chucks a wobbly if you try to initialise an image with an html error page. --- include/zot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 9bddb520d..ee3f603cd 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2866,7 +2866,7 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { // don't pass these elements, they should not be synchronised - $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey','channel_address'); + $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey','channel_address','channel_deleted','channel_removed','channel_system'); if(in_array($k,$disallowed)) continue; -- cgit v1.2.3 From aae51a9b23b974c11dbf7a896991dae5e052aedc Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 27 Sep 2015 16:47:25 -0700 Subject: add some safety checks on the sending side of sync --- include/zot.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index aae429709..c94e9ca6d 100644 --- a/include/zot.php +++ b/include/zot.php @@ -395,12 +395,6 @@ function zot_refresh($them, $channel = null, $force = false) { } } - $r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) > 0 limit 1", - dbesc($x['hash']), - intval($channel['channel_id']), - intval(ABOOK_FLAG_SELF) - ); - if(array_key_exists('profile',$j) && array_key_exists('next_birthday',$j['profile'])) { $next_birthday = datetime_convert('UTC','UTC',$j['profile']['next_birthday']); } @@ -408,8 +402,16 @@ function zot_refresh($them, $channel = null, $force = false) { $next_birthday = NULL_DATE; } + $r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) > 0 limit 1", + dbesc($x['hash']), + intval($channel['channel_id']), + intval(ABOOK_FLAG_SELF) + ); + if($r) { + // connection exists + // if the dob is the same as what we have stored (disregarding the year), keep the one // we have as we may have updated the year after sending a notification; and resetting // to the one we just received would cause us to create duplicated events. @@ -454,6 +456,9 @@ function zot_refresh($them, $channel = null, $force = false) { } } else { + + // new connection + $role = get_pconfig($channel['channel_id'],'system','permissions_role'); if($role) { $xx = get_role_perms($role); @@ -490,6 +495,7 @@ function zot_refresh($them, $channel = null, $force = false) { $new_perms = get_all_perms($channel['channel_id'],$x['hash']); // Send a clone sync packet and a permissions update if permissions have changed + $new_connection = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) > 0 order by abook_created desc limit 1", dbesc($x['hash']), intval($channel['channel_id']), @@ -2802,6 +2808,9 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { $channel = $r[0]; + if(intval($channel['channel_pageflags']) & PAGE_REMOVED) + return; + $h = q("select * from hubloc where hubloc_hash = '%s' and not (hubloc_flags & %d) > 0 and not (hubloc_status & %d) > 0", dbesc($channel['channel_hash']), intval(HUBLOC_FLAGS_DELETED), @@ -2854,6 +2863,9 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { // don't pass these elements, they should not be synchronised + if(($k === 'channel_pageflags') && ($v & PAGE_SYSTEM)) + $v = (string) intval($v - PAGE_SYSTEM); + $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey','channel_address'); if(in_array($k,$disallowed)) @@ -2992,7 +3004,9 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { foreach($arr['abook'] as $abook) { if(array_key_exists('abook_blocked',$abook)) { + // convert from hubzilla + $abook['abook_flags'] = 0; if(intval($abook['abook_blocked'])) $abook['abook_flags'] |= ABOOK_FLAG_BLOCKED; -- cgit v1.2.3 From 67fe8fc4a7aa229857249caeaeb7d746d92ba325 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 27 Sep 2015 18:00:37 -0700 Subject: well there's one problem... --- include/zot.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index c94e9ca6d..6769241cb 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2963,10 +2963,10 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { // These flags cannot be sync'd. // If these bits aren't set locally, remove the bits from the incoming flags. - if((! ($channel['channel_pageflags'] & PAGE_REMOVED)) && ($arr['channel_pageflags'] & PAGE_REMOVED)) - $arr['channel_pageflags'] = $arr['channel_pageflags'] - PAGE_REMOVED; - if((! ($channel['channel_pageflags'] & PAGE_SYSTEM)) && ($arr['channel_pageflags'] & PAGE_SYSTEM)) - $arr['channel_pageflags'] = $arr['channel_pageflags'] - PAGE_SYSTEM; + if((! ($channel['channel_pageflags'] & PAGE_REMOVED)) && ($arr['channel']['channel_pageflags'] & PAGE_REMOVED)) + $arr['channel']['channel_pageflags'] = $arr['channel']['channel_pageflags'] - PAGE_REMOVED; + if((! ($channel['channel_pageflags'] & PAGE_SYSTEM)) && ($arr['channel']['channel_pageflags'] & PAGE_SYSTEM)) + $arr['channel']['channel_pageflags'] = $arr['channel']['channel_pageflags'] - PAGE_SYSTEM; $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey', 'channel_address', 'channel_notifyflags', 'channel_removed', 'channel_system', 'channel_deleted' ); -- cgit v1.2.3 From e5f47cd14b9dd97385d93c2610e05d959e526ce8 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 28 Sep 2015 17:13:11 -0700 Subject: create site records for all queued sites and check for death --- include/zot.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 0c6a2f368..7c9bdca97 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2743,7 +2743,7 @@ function import_site($arr, $pubkey) { // logger('import_site: input: ' . print_r($arr,true)); // logger('import_site: stored: ' . print_r($siterecord,true)); - $r = q("update site set site_dead = 0, site_location = '%s', site_flags = %d, site_access = %d, site_directory = '%s', site_register = %d, site_update = '%s', site_sellpage = '%s', site_realm = '%s' + $r = q("update site set site_dead = 0, site_location = '%s', site_flags = %d, site_access = %d, site_directory = '%s', site_register = %d, site_update = '%s', site_sellpage = '%s', site_realm = '%s', site_type = %d where site_url = '%s'", dbesc($site_location), intval($site_directory), @@ -2753,6 +2753,7 @@ function import_site($arr, $pubkey) { dbesc(datetime_convert()), dbesc($sellpage), dbesc($site_realm), + intval(SITE_TYPE_ZOT), dbesc($url) ); if(! $r) { @@ -2769,7 +2770,7 @@ function import_site($arr, $pubkey) { } else { $update = true; - $r = q("insert into site ( site_location, site_url, site_access, site_flags, site_update, site_directory, site_register, site_sellpage, site_realm ) + $r = q("insert into site ( site_location, site_url, site_access, site_flags, site_update, site_directory, site_register, site_sellpage, site_realm, site_type ) values ( '%s', '%s', %d, %d, '%s', '%s', %d, '%s', '%s' )", dbesc($site_location), dbesc($url), @@ -2779,7 +2780,8 @@ function import_site($arr, $pubkey) { dbesc($directory_url), intval($register_policy), dbesc($sellpage), - dbesc($site_realm) + dbesc($site_realm), + intval(SITE_TYPE_ZOT) ); if(! $r) { logger('import_site: record create failed. ' . print_r($arr,true)); -- cgit v1.2.3 From 3a8e1e04844fea2331525d82d8234b7006a12037 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 28 Sep 2015 19:04:36 -0700 Subject: process_delivery: ignore self --- include/zot.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 6769241cb..635c36774 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1584,6 +1584,12 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $channel = $r[0]; $DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); + if($d['hash'] === $sender['hash']) { + $DR->update('self delivery ignored'); + $result[] = $DR->get(); + continue; + } + // allow public postings to the sys channel regardless of permissions, but not // for comments travelling upstream. Wait and catch them on the way down. -- cgit v1.2.3 From 8a3c909c74285177bc801d94d49122aca274836e Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 28 Sep 2015 19:05:45 -0700 Subject: ignore self delivery in process_delivery --- include/zot.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index 7c9bdca97..c6feb9174 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1588,13 +1588,11 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); -// uncomment this once we find out what's stopping the clone sync of the item from working -// if($d['hash'] === $sender['hash']) { -// $DR->update('self delivery ignored'); -// $result[] = $DR->get(); -// continue; -// } - + if($d['hash'] === $sender['hash']) { + $DR->update('self delivery ignored'); + $result[] = $DR->get(); + continue; + } // allow public postings to the sys channel regardless of permissions, but not // for comments travelling upstream. Wait and catch them on the way down. -- cgit v1.2.3 From 5c526995d8534465602775dfddebd8d77855d2e2 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 28 Sep 2015 19:07:31 -0700 Subject: resolve conflicts --- include/zot.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'include/zot.php') diff --git a/include/zot.php b/include/zot.php index eaaf30fff..ef9f325d0 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1587,13 +1587,6 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $channel = $r[0]; $DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); - if($d['hash'] === $sender['hash']) { - $DR->update('self delivery ignored'); - $result[] = $DR->get(); - continue; - } - - if($d['hash'] === $sender['hash']) { $DR->update('self delivery ignored'); $result[] = $DR->get(); -- cgit v1.2.3