diff options
Diffstat (limited to 'include/zot.php')
-rw-r--r-- | include/zot.php | 145 |
1 files changed, 106 insertions, 39 deletions
diff --git a/include/zot.php b/include/zot.php index d08146287..8a2177de7 100644 --- a/include/zot.php +++ b/include/zot.php @@ -9,6 +9,8 @@ */ use Zotlabs\Lib\DReport; +use Zotlabs\Lib\Libzot; +use Zotlabs\Lib\Activity; require_once('include/crypto.php'); require_once('include/items.php'); @@ -407,8 +409,8 @@ function zot_refresh($them, $channel = null, $force = false) { $postvars['token'] = $token; if($channel) { - $postvars['target'] = $channel['channel_guid']; - $postvars['target_sig'] = $channel['channel_guid_sig']; + $postvars['target'] = $channel['xchan_guid']; + $postvars['target_sig'] = str_replace('sha256.', '', $channel['xchan_guid_sig']); $postvars['key'] = $channel['channel_pubkey']; } @@ -426,7 +428,6 @@ function zot_refresh($them, $channel = null, $force = false) { logger('zot_refresh: ' . $url, LOGGER_DATA, LOG_INFO); - $result = z_post_url($url . $rhs,$postvars); if ($result['success']) { @@ -578,7 +579,7 @@ function zot_refresh($them, $channel = null, $force = false) { [ 'type' => NOTIFY_INTRO, 'from_xchan' => $x['hash'], - 'to_xchan' => $channel['channel_hash'], + 'to_xchan' => $channel['channel_portable_id'], 'link' => z_root() . '/connedit/' . $new_connection[0]['abook_id'] ] ); @@ -921,7 +922,7 @@ function import_xchan($arr, $ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) { // see if this is a channel clone that's hosted locally - which we treat different from other xchans/connections - $local = q("select channel_account_id, channel_id from channel where channel_hash = '%s' limit 1", + $local = q("select channel_account_id, channel_id from channel where channel_portable_id = '%s' limit 1", dbesc($xchan_hash) ); @@ -1299,7 +1300,7 @@ function zot_fetch($arr) { * * @returns array * Suitable for logging remotely, enumerating the processing results of each message/recipient combination - * * [0] => \e string $channel_hash + * * [0] => \e string $channel_portable_id * * [1] => \e string $delivery_status * * [2] => \e string $address */ @@ -1385,7 +1386,7 @@ function zot_import($arr, $sender_url) { if($recip_arr) { stringify_array_elms($recip_arr); $recips = implode(',',$recip_arr); - $r = q("select channel_hash as hash from channel where channel_hash in ( " . $recips . " ) + $r = q("select channel_portable_id as hash from channel where channel_portable_id in ( " . $recips . " ) and channel_removed = 0 "); } @@ -1596,11 +1597,11 @@ function public_recips($msg) { $r = array(); - $c = q("select channel_id, channel_hash from channel where channel_removed = 0"); + $c = q("select channel_id, channel_portable_id from channel where channel_removed = 0"); if($c) { foreach($c as $cc) { if(perm_is_allowed($cc['channel_id'],$msg['notify']['sender']['hash'],$perm)) { - $r[] = [ 'hash' => $cc['channel_hash'] ]; + $r[] = [ 'hash' => $cc['channel_portable_id'] ]; } } } @@ -1610,7 +1611,7 @@ function public_recips($msg) { if($include_sys && array_key_exists('public_scope',$msg['message']) && $msg['message']['public_scope'] === 'public') { $sys = get_sys_channel(); if($sys) - $r[] = [ 'hash' => $sys['channel_hash'] ]; + $r[] = [ 'hash' => $sys['channel_portable_id'] ]; } // look for any public mentions on this site @@ -1624,7 +1625,7 @@ function public_recips($msg) { if(($tag['type'] === 'mention' || $tag['type'] === 'forum') && (strpos($tag['url'],z_root()) !== false)) { $address = basename($tag['url']); if($address) { - $z = q("select channel_hash as hash from channel where channel_address = '%s' + $z = q("select channel_portable_id as hash from channel where channel_address = '%s' and channel_removed = 0 limit 1", dbesc($address) ); @@ -1727,7 +1728,7 @@ function allowed_public_recips($msg) { $condensed_recips[] = $rr['hash']; $results = array(); - $r = q("select channel_hash as hash, channel_id from channel left join abook on abook_channel = channel_id where abook_xchan = '%s' and channel_removed = 0 ", + $r = q("select channel_portable_id as hash, channel_id from channel left join abook on abook_channel = channel_id where abook_xchan = '%s' and channel_removed = 0 ", dbesc($hash) ); if($r) { @@ -1776,7 +1777,7 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $DR = new Zotlabs\Lib\DReport(z_root(),$sender['hash'],$d['hash'],$arr['mid']); - $channel = channelx_by_hash($d['hash']); + $channel = channelx_by_portid($d['hash']); if(! $channel) { $DR->update('recipient not found'); @@ -1953,6 +1954,34 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ intval($channel['channel_id']), dbesc($arr['owner_xchan']) ); + + if(! $ab) { + + $best_owner_xchan = find_best_zot_identity($arr['owner_xchan']); + + $ab = q("select * from abook where abook_channel = %d and abook_xchan = '%s'", + intval($channel['channel_id']), + dbesc($best_owner_xchan) + ); + + if($ab) { + logger('rewrite owner: ' . $arr['owner_xchan'] . ' > ' . $best_owner_xchan); + $arr['owner_xchan'] = $best_owner_xchan; + } + } + + $best_author_xchan = find_best_zot_identity($arr['author_xchan']); + + $ab_author = q("select * from abook where abook_channel = %d and abook_xchan = '%s'", + intval($channel['channel_id']), + dbesc($best_author_xchan) + ); + + if($ab_author) { + logger('rewrite author: ' . $arr['author_xchan'] . ' > ' . $best_author_xchan); + $arr['author_xchan'] = $best_author_xchan; + } + $abook = (($ab) ? $ab[0] : null); if(intval($arr['item_deleted'])) { @@ -2076,7 +2105,7 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $stored = (($item_result && $item_result['item']) ? $item_result['item'] : false); if((is_array($stored)) && ($stored['id'] != $stored['parent']) - && ($stored['author_xchan'] === $channel['channel_hash'])) { + && ($stored['author_xchan'] === $channel['channel_portable_id'])) { retain_item($stored['item']['parent']); } @@ -2344,7 +2373,7 @@ function process_mail_delivery($sender, $arr, $deliveries) { $DR = new Zotlabs\Lib\DReport(z_root(),$sender['hash'],$d['hash'],$arr['mid']); - $r = q("select * from channel where channel_hash = '%s' limit 1", + $r = q("select * from channel where channel_portable_id = '%s' limit 1", dbesc($d['hash']) ); @@ -2555,7 +2584,7 @@ function check_location_move($sender_hash, $locations) { $loc = $locations[0]; - $r = q("select * from channel where channel_hash = '%s' limit 1", + $r = q("select * from channel where channel_portable_id = '%s' limit 1", dbesc($sender_hash) ); @@ -2563,7 +2592,7 @@ function check_location_move($sender_hash, $locations) { return; if($loc['url'] !== z_root()) { - $x = q("update channel set channel_moved = '%s' where channel_hash = '%s' limit 1", + $x = q("update channel set channel_moved = '%s' where channel_portable_id = '%s' limit 1", dbesc($loc['url']), dbesc($sender_hash) ); @@ -2764,6 +2793,8 @@ function sync_locations($sender, $arr, $absolute = false) { } logger('New hub: ' . $location['url']); + $addr_arr = explode('@', $location['address']); + $r = hubloc_store_lowlevel( [ 'hubloc_guid' => $sender['guid'], @@ -2778,7 +2809,8 @@ function sync_locations($sender, $arr, $absolute = false) { 'hubloc_callback' => $location['callback'], 'hubloc_sitekey' => $location['sitekey'], 'hubloc_updated' => datetime_convert(), - 'hubloc_connected' => datetime_convert() + 'hubloc_connected' => datetime_convert(), + 'hubloc_id_url' => $location['url'] . '/channel/' . $addr_arr[0] ] ); @@ -2826,13 +2858,13 @@ function sync_locations($sender, $arr, $absolute = false) { * * @see zot_get_hublocs() * @param array $channel an associative array which must contain - * * \e string \b channel_hash the hash of the channel + * * \e string \b channel_portable_id the hash of the channel * @return array an array with associative arrays */ function zot_encode_locations($channel) { $ret = array(); - $x = zot_get_hublocs($channel['channel_hash']); + $x = zot_get_hublocs($channel['channel_portable_id']); if($x && count($x)) { foreach($x as $hub) { @@ -3300,8 +3332,8 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { if(intval($channel['channel_removed'])) return; - $h = q("select hubloc.*, site.site_crypto from hubloc left join site on site_url = hubloc_url where hubloc_hash = '%s' and hubloc_deleted = 0", - dbesc(($keychange) ? $packet['keychange']['old_hash'] : $channel['channel_hash']) + $h = q("select hubloc.*, site.site_crypto, site.site_version, site.site_project from hubloc left join site on site_url = hubloc_url where hubloc_hash = '%s' and hubloc_deleted = 0", + dbesc(($keychange) ? $packet['keychange']['old_hash'] : $channel['channel_portable_id']) ); if(! $h) @@ -3313,6 +3345,14 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { if($x['hubloc_host'] == App::get_hostname()) continue; + if(stripos($x['site_project'], 'hubzilla') !== false && version_compare($x['site_version'], '4.7.3', '<=')) { + + logger('Dismiss sync due to incompatible version.'); + // logger(print_r($x,true)); + continue; + + } + $y = q("select site_dead from site where site_url = '%s' limit 1", dbesc($x['hubloc_url']) ); @@ -3325,8 +3365,9 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { return; $r = q("select xchan_guid, xchan_guid_sig from xchan where xchan_hash = '%s' limit 1", - dbesc($channel['channel_hash']) + dbesc($channel['channel_portable_id']) ); + if(! $r) return; @@ -3611,6 +3652,12 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { if(array_key_exists('app',$arr) && $arr['app']) sync_apps($channel,$arr['app']); + if(array_key_exists('addressbook',$arr) && $arr['addressbook']) + sync_addressbook($channel,$arr['addressbook']); + + if(array_key_exists('calendar',$arr) && $arr['calendar']) + sync_calendar($channel,$arr['calendar']); + if(array_key_exists('chatroom',$arr) && $arr['chatroom']) sync_chatrooms($channel,$arr['chatroom']); @@ -4186,7 +4233,7 @@ function zot_reply_message_request($data) { $arr = $data['recipients'][0]; $recip_hash = make_xchan_hash($arr['guid'],$arr['guid_sig']); - $c = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_hash = '%s' limit 1", + $c = q("select * from channel left join xchan on channel_portable_id = xchan_hash where channel_portable_id = '%s' limit 1", dbesc($recip_hash) ); if (! $c) { @@ -4332,21 +4379,21 @@ function zotinfo($arr) { $r = null; if(strlen($zhash)) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash - where channel_hash = '%s' limit 1", + $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash + where channel_portable_id = '%s' limit 1", dbesc($zhash) ); } elseif(strlen($zguid) && strlen($zguid_sig)) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash + $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash where channel_guid = '%s' and channel_guid_sig = '%s' limit 1", dbesc($zguid), - dbesc($zguid_sig) + dbesc('sha256.' . $zguid_sig) ); } elseif(strlen($zaddr)) { if(strpos($zaddr,'[system]') === false) { /* normal address lookup */ - $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash + $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash where ( channel_address = '%s' or xchan_addr = '%s' ) limit 1", dbesc($zaddr), dbesc($zaddr) @@ -4366,10 +4413,10 @@ function zotinfo($arr) { * */ - $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash + $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash where channel_system = 1 order by channel_id limit 1"); if(! $r) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash + $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash where channel_removed = 0 order by channel_id limit 1"); } } @@ -4693,14 +4740,14 @@ function check_zotinfo($channel, $locations, &$ret) { // for the sys channel as normal channels will be trickier. q("delete from hubloc where hubloc_hash = '%s'", - dbesc($channel['channel_hash']) + dbesc($channel['channel_portable_id']) ); $r = hubloc_store_lowlevel( [ 'hubloc_guid' => $channel['channel_guid'], 'hubloc_guid_sig' => $channel['channel_guid_sig'], - 'hubloc_hash' => $channel['channel_hash'], + 'hubloc_hash' => $channel['channel_portable_id'], 'hubloc_addr' => channel_reddress($channel), 'hubloc_network' => 'zot', 'hubloc_primary' => 1, @@ -4755,7 +4802,7 @@ function delivery_report_is_storable($dr) { // Is the sender one of our channels? - $c = q("select channel_id from channel where channel_hash = '%s' limit 1", + $c = q("select channel_id from channel where channel_portable_id = '%s' limit 1", dbesc($dr['sender']) ); if(! $c) @@ -5101,7 +5148,7 @@ function zot_reply_auth_check($data,$encrypted_packet) { $arr = $data['recipients'][0]; $recip_hash = make_xchan_hash($arr['guid'], $arr['guid_sig']); - $c = q("select channel_id, channel_account_id, channel_prvkey from channel where channel_hash = '%s' limit 1", + $c = q("select channel_id, channel_account_id, channel_prvkey from channel where channel_portable_id = '%s' limit 1", dbesc($recip_hash) ); if (! $c) { @@ -5168,7 +5215,7 @@ function zot_reply_purge($sender, $recipients) { // basically this means "unfriend" foreach ($recipients as $recip) { $r = q("select channel.*,xchan.* from channel - left join xchan on channel_hash = xchan_hash + left join xchan on channel_portable_id = xchan_hash where channel_guid = '%s' and channel_guid_sig = '%s' limit 1", dbesc($recip['guid']), dbesc($recip['guid_sig']) @@ -5221,12 +5268,11 @@ function zot_reply_refresh($sender, $recipients) { foreach ($recipients as $recip) { $r = q("select channel.*,xchan.* from channel - left join xchan on channel_hash = xchan_hash - where channel_guid = '%s' and channel_guid_sig = '%s' limit 1", + left join xchan on channel_portable_id = xchan_hash + where xchan_guid = '%s' and xchan_guid_sig = '%s' limit 1", dbesc($recip['guid']), dbesc($recip['guid_sig']) ); - $x = zot_refresh(array( 'xchan_guid' => $sender['guid'], 'xchan_guid_sig' => $sender['guid_sig'], @@ -5325,3 +5371,24 @@ function zot_record_preferred($arr, $check = 'hubloc_network') { return $arr[0]; } + +function find_best_zot_identity($xchan) { + + $r = q("select hubloc_addr from hubloc where hubloc_hash = '%s' and hubloc_network in ('zot6', 'zot') and hubloc_deleted = 0", + dbesc($xchan) + ); + + if ($r) { + + $r = q("select hubloc_hash, hubloc_network from hubloc where hubloc_addr = '%s' and hubloc_network in ('zot6', 'zot') and hubloc_deleted = 0", + dbesc($r[0]['hubloc_addr']) + ); + if ($r) { + $r = Libzot::zot_record_preferred($r); + logger('find_best_zot_identity: ' . $xchan . ' > ' . $r['hubloc_hash']); + return $r['hubloc_hash']; + } + } + + return $xchan; +} |