From 1712eceaf95e5e57d8f5866cb1f6100a0acd28b6 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 26 Jan 2020 15:08:55 +0000 Subject: port Lib/Connect and Module/Follow from zap. Connect with new connections via zot6 --- Zotlabs/Access/Permissions.php | 13 +- Zotlabs/Lib/AccessList.php | 411 +++++++++++++++++++++++++++++++++++++++++ Zotlabs/Lib/Connect.php | 315 +++++++++++++++++++++++++++++++ Zotlabs/Module/Follow.php | 102 +++++++--- include/permissions.php | 20 ++ 5 files changed, 838 insertions(+), 23 deletions(-) create mode 100644 Zotlabs/Lib/AccessList.php create mode 100644 Zotlabs/Lib/Connect.php diff --git a/Zotlabs/Access/Permissions.php b/Zotlabs/Access/Permissions.php index 20dc22a72..35016ed57 100644 --- a/Zotlabs/Access/Permissions.php +++ b/Zotlabs/Access/Permissions.php @@ -283,4 +283,15 @@ class Permissions { return ( [ 'perms' => $my_perms, 'automatic' => $automatic ] ); } -} \ No newline at end of file + static public function serialise($p) { + $n = []; + if($p) { + foreach($p as $k => $v) { + if(intval($v)) { + $n[] = $k; + } + } + } + return implode(',',$n); + } +} diff --git a/Zotlabs/Lib/AccessList.php b/Zotlabs/Lib/AccessList.php new file mode 100644 index 000000000..3c008f8c7 --- /dev/null +++ b/Zotlabs/Lib/AccessList.php @@ -0,0 +1,411 @@ +may apply to this list and any future members. If this is not what you intended, please create another list with a different name.') . EOL); + } + return true; + } + + $hash = new_uuid(); + + $r = q("INSERT INTO pgrp ( hash, uid, visible, gname ) + VALUES( '%s', %d, %d, '%s' ) ", + dbesc($hash), + intval($uid), + intval($public), + dbesc($name) + ); + $ret = $r; + } + + Libsync::build_sync_packet($uid,null,true); + return $ret; + } + + + static function remove($uid,$name) { + $ret = false; + if ($uid && $name) { + $r = q("SELECT id, hash FROM pgrp WHERE uid = %d AND gname = '%s' LIMIT 1", + intval($uid), + dbesc($name) + ); + if ($r) { + $group_id = $r[0]['id']; + $group_hash = $r[0]['hash']; + } + else { + return false; + } + + // remove group from default posting lists + $r = q("SELECT channel_default_group, channel_allow_gid, channel_deny_gid FROM channel WHERE channel_id = %d LIMIT 1", + intval($uid) + ); + if ($r) { + $user_info = array_shift($r); + $change = false; + + if ($user_info['channel_default_group'] == $group_hash) { + $user_info['channel_default_group'] = ''; + $change = true; + } + if (strpos($user_info['channel_allow_gid'], '<' . $group_hash . '>') !== false) { + $user_info['channel_allow_gid'] = str_replace('<' . $group_hash . '>', '', $user_info['channel_allow_gid']); + $change = true; + } + if (strpos($user_info['channel_deny_gid'], '<' . $group_hash . '>') !== false) { + $user_info['channel_deny_gid'] = str_replace('<' . $group_hash . '>', '', $user_info['channel_deny_gid']); + $change = true; + } + + if ($change) { + q("UPDATE channel SET channel_default_group = '%s', channel_allow_gid = '%s', channel_deny_gid = '%s' + WHERE channel_id = %d", + intval($user_info['channel_default_group']), + dbesc($user_info['channel_allow_gid']), + dbesc($user_info['channel_deny_gid']), + intval($uid) + ); + } + } + + // remove all members + $r = q("DELETE FROM pgrp_member WHERE uid = %d AND gid = %d ", + intval($uid), + intval($group_id) + ); + + // remove group + $r = q("UPDATE pgrp SET deleted = 1 WHERE uid = %d AND gname = '%s'", + intval($uid), + dbesc($name) + ); + + $ret = $r; + + } + + Libsync::build_sync_packet($uid,null,true); + + return $ret; + } + + // returns the integer id of an access group owned by $uid and named $name + // or false. + + static function byname($uid,$name) { + if (! ($uid && $name)) { + return false; + } + $r = q("SELECT id FROM pgrp WHERE uid = %d AND gname = '%s' LIMIT 1", + intval($uid), + dbesc($name) + ); + if ($r) { + return $r[0]['id']; + } + return false; + } + + static function by_id($uid,$id) { + if (! ($uid && $id)) { + return false; + } + + $r = q("SELECT * FROM pgrp WHERE uid = %d AND id = %d and deleted = 0", + intval($uid), + intval($id) + ); + if ($r) { + return array_shift($r); + } + return false; + } + + + + static function rec_byhash($uid,$hash) { + if (! ( $uid && $hash)) { + return false; + } + $r = q("SELECT * FROM pgrp WHERE uid = %d AND hash = '%s' LIMIT 1", + intval($uid), + dbesc($hash) + ); + if ($r) { + return array_shift($r); + } + return false; + } + + + static function member_remove($uid,$name,$member) { + $gid = self::byname($uid,$name); + if (! $gid) { + return false; + } + if (! ($uid && $gid && $member)) { + return false; + } + $r = q("DELETE FROM pgrp_member WHERE uid = %d AND gid = %d AND xchan = '%s' ", + intval($uid), + intval($gid), + dbesc($member) + ); + + Libsync::build_sync_packet($uid,null,true); + + return $r; + } + + + static function member_add($uid,$name,$member,$gid = 0) { + if (! $gid) { + $gid = self::byname($uid,$name); + } + if (! ($gid && $uid && $member)) { + return false; + } + + $r = q("SELECT * FROM pgrp_member WHERE uid = %d AND gid = %d AND xchan = '%s' LIMIT 1", + intval($uid), + intval($gid), + dbesc($member) + ); + if ($r) { + return true; // You might question this, but + // we indicate success because the group member was in fact created + // -- It was just created at another time + } + else { + $r = q("INSERT INTO pgrp_member (uid, gid, xchan) + VALUES( %d, %d, '%s' ) ", + intval($uid), + intval($gid), + dbesc($member) + ); + } + Libsync::build_sync_packet($uid,null,true); + return $r; + } + + + static function members($uid, $gid) { + $ret = []; + if (intval($gid)) { + $r = q("SELECT * FROM pgrp_member + LEFT JOIN abook ON abook_xchan = pgrp_member.xchan left join xchan on xchan_hash = abook_xchan + WHERE gid = %d AND abook_channel = %d and pgrp_member.uid = %d and xchan_deleted = 0 and abook_self = 0 and abook_blocked = 0 and abook_pending = 0 ORDER BY xchan_name ASC ", + intval($gid), + intval($uid), + intval($uid) + ); + if ($r) { + $ret = $r; + } + } + return $ret; + } + + static function members_xchan($uid,$gid) { + $ret = []; + if (intval($gid)) { + $r = q("SELECT xchan FROM pgrp_member WHERE gid = %d AND uid = %d", + intval($gid), + intval($uid) + ); + if ($r) { + foreach ($r as $rv) { + $ret[] = $rv['xchan']; + } + } + } + return $ret; + } + + static function members_profile_xchan($uid,$gid) { + $ret = []; + if (intval($gid)) { + $r = q("SELECT abook_xchan as xchan from abook left join profile on abook_profile = profile_guid where profile.id = %d and profile.uid = %d", + intval($gid), + intval($uid) + ); + if ($r) { + foreach($r as $rv) { + $ret[] = $rv['xchan']; + } + } + } + return $ret; + } + + + + + static function select($uid,$group = '') { + + $grps = []; + + $r = q("SELECT * FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC", + intval($uid) + ); + $grps[] = [ 'name' => '', 'hash' => '0', 'selected' => '' ]; + if ($r) { + foreach ($r as $rr) { + $grps[] = [ 'name' => $rr['gname'], 'id' => $rr['hash'], 'selected' => (($group == $rr['hash']) ? 'true' : '') ]; + } + + } + + return replace_macros(get_markup_template('group_selection.tpl'), [ + '$label' => t('Add new connections to this access list'), + '$groups' => $grps + ]); + } + + + static function widget($every="connections",$each="lists",$edit = false, $group_id = 0, $cid = '',$mode = 1) { + + $o = ''; + + $groups = []; + + $r = q("SELECT * FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC", + intval($_SESSION['uid']) + ); + $member_of = []; + if ($cid) { + $member_of = self::containing(local_channel(),$cid); + } + + if ($r) { + foreach ($r as $rr) { + $selected = (($group_id == $rr['id']) ? ' group-selected' : ''); + + if ($edit) { + $groupedit = [ 'href' => "lists/".$rr['id'], 'title' => t('edit') ]; + } + else { + $groupedit = null; + } + + $groups[] = [ + 'id' => $rr['id'], + 'enc_cid' => base64url_encode($cid), + 'cid' => $cid, + 'text' => $rr['gname'], + 'selected' => $selected, + 'href' => (($mode == 0) ? $each.'?f=&gid='.$rr['id'] : $each."/".$rr['id']) . ((x($_GET,'new')) ? '&new=' . $_GET['new'] : '') . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : ''), + 'edit' => $groupedit, + 'ismember' => in_array($rr['id'],$member_of), + ]; + } + } + + return replace_macros(get_markup_template('group_side.tpl'), [ + '$title' => t('Lists'), + '$edittext' => t('Edit list'), + '$createtext' => t('Create new list'), + '$ungrouped' => (($every === 'contacts') ? t('Channels not in any access list') : ''), + '$groups' => $groups, + '$add' => t('add'), + ]); + + } + + + static function expand($g) { + if (! (is_array($g) && count($g))) { + return []; + } + + $ret = []; + $x = []; + + // private profile linked virtual groups + + foreach ($g as $gv) { + if (substr($gv,0,3) === 'vp.') { + $profile_hash = substr($gv,3); + if ($profile_hash) { + $r = q("select abook_xchan from abook where abook_profile = '%s'", + dbesc($profile_hash) + ); + if ($r) { + foreach ($r as $rv) { + $ret[] = $rv['abook_xchan']; + } + } + } + } + else { + $x[] = $gv; + } + } + + if ($x) { + stringify_array_elms($x,true); + $groups = implode(',', $x); + if ($groups) { + $r = q("SELECT xchan FROM pgrp_member WHERE gid IN ( select id from pgrp where hash in ( $groups ))"); + if ($r) { + foreach ($r as $rv) { + $ret[] = $rv['xchan']; + } + } + } + } + return $ret; + } + + + static function member_of($c) { + $r = q("SELECT pgrp.gname, pgrp.id FROM pgrp LEFT JOIN pgrp_member ON pgrp_member.gid = pgrp.id + WHERE pgrp_member.xchan = '%s' AND pgrp.deleted = 0 ORDER BY pgrp.gname ASC ", + dbesc($c) + ); + + return $r; + } + + static function containing($uid,$c) { + + $r = q("SELECT gid FROM pgrp_member WHERE uid = %d AND pgrp_member.xchan = '%s' ", + intval($uid), + dbesc($c) + ); + + $ret = []; + if ($r) { + foreach ($r as $rv) + $ret[] = $rv['gid']; + } + + return $ret; + } +} \ No newline at end of file diff --git a/Zotlabs/Lib/Connect.php b/Zotlabs/Lib/Connect.php new file mode 100644 index 000000000..978a4ce39 --- /dev/null +++ b/Zotlabs/Lib/Connect.php @@ -0,0 +1,315 @@ + false, 'message' => '' ]; + + $my_perms = false; + $protocol = ''; + + if (substr($url,0,1) === '[') { + $x = strpos($url,']'); + if ($x) { + $protocol = substr($url,1,$x-1); + $url = substr($url,$x+1); + } + } + + if (! check_siteallowed($url)) { + $result['message'] = t('Channel is blocked on this site.'); + return $result; + } + + if (! $url) { + $result['message'] = t('Channel location missing.'); + return $result; + } + + // check service class limits + + $r = q("select count(*) as total from abook where abook_channel = %d and abook_self = 0 ", + intval($uid) + ); + if ($r) { + $total_channels = $r[0]['total']; + } + + if (! service_class_allows($uid,'total_channels',$total_channels)) { + $result['message'] = upgrade_message(); + return $result; + } + + $xchan_hash = ''; + $sql_options = (($protocol) ? " and xchan_network = '" . dbesc($protocol) . "' " : ''); + + $r = q("select * from xchan where ( xchan_hash = '%s' or xchan_url = '%s' or xchan_addr = '%s') $sql_options ", + dbesc($url), + dbesc($url), + dbesc($url) + ); + + if ($r) { + + // reset results to the best record or the first if we don't have the best + // note: this is a single record and not an array of results + + $r = Libzot::zot_record_preferred($r,'xchan_network'); + + } + + $singleton = false; + $d = false; + + if (! $r) { + + // not in cache - try discovery + + $wf = discover_by_webbie($url,$protocol); + + if (! $wf) { + $feeds = get_config('system','feed_contacts'); + + if (($feeds) && (in_array($protocol, [ '', 'feed', 'rss' ]))) { + $d = discover_feed($url); + } + else { + $result['message'] = t('Remote channel or protocol unavailable.'); + return $result; + } + } + } + + if ($wf || $d) { + + // something was discovered - find the record which was just created. + + $r = q("select * from xchan where ( xchan_hash = '%s' or xchan_url = '%s' or xchan_addr = '%s' ) $sql_options", + dbesc(($wf) ? $wf : $url), + dbesc($url), + dbesc($url) + ); + + // convert to a single record (once again preferring a zot solution in the case of multiples) + + if ($r) { + $r = Libzot::zot_record_preferred($r,'xchan_network'); + } + } + + // if discovery was a success or the channel was already cached we should have an xchan record in $r + + if ($r) { + $xchan = $r; + $xchan_hash = $r['xchan_hash']; + $their_perms = EMPTY_STR; + } + + // failure case + + if (! $xchan_hash) { + $result['message'] = t('Channel discovery failed.'); + logger('follow: ' . $result['message']); + return $result; + } + + if (! check_channelallowed($xchan_hash)) { + $result['message'] = t('Channel is blocked on this site.'); + logger('follow: ' . $result['message']); + return $result; + + } + + $allowed = ((in_array($xchan['xchan_network'],['rss','zot','zot6'])) ? 1 : 0); + + $hookdata = ['channel_id' => $uid, 'follow_address' => $url, 'xchan' => $xchan, 'allowed' => $allowed, 'singleton' => 0]; + call_hooks('follow_allow',$hookdata); + + if(! $hookdata['allowed']) { + hz_syslog('zesz'); + $result['message'] = t('Protocol disabled.'); + return $result; + } + + $singleton = intval($hookdata['singleton']); + + // Now start processing the new connection + + $aid = $channel['channel_account_id']; + $default_group = $channel['channel_default_group']; + + if (in_array($xchan_hash, [$channel['channel_hash'], $channel['channel_portable_id']])) { + $result['message'] = t('Cannot connect to yourself.'); + return $result; + } + + if ($xchan['xchan_network'] === 'rss') { + + // check service class feed limits + + $t = q("select count(*) as total from abook where abook_account = %d and abook_feed = 1 ", + intval($aid) + ); + if ($t) { + $total_feeds = $t[0]['total']; + } + + if (! service_class_allows($uid,'total_feeds',$total_feeds)) { + $result['message'] = upgrade_message(); + return $result; + } + + // Always set these "remote" permissions for feeds since we cannot interact with them + // to negotiate a suitable permission response + + $p = get_abconfig($uid,$xchan_hash,'system','their_perms',EMPTY_STR); + if ($p) { + $p .= ','; + } + $p .= 'view_stream,republish'; + set_abconfig($uid,$xchan_hash,'system','their_perms',$p); + + } + + + $p = Permissions::connect_perms($uid); + + // parent channels have unencumbered write permission + + if ($sub_channel) { + $p['perms']['post_wall'] = 1; + $p['perms']['post_comments'] = 1; + $p['perms']['write_storage'] = 1; + $p['perms']['post_like'] = 1; + $p['perms']['delegate'] = 0; + $p['perms']['moderated'] = 0; + } + + $my_perms = Permissions::serialise($p['perms']); + + $profile_assign = get_pconfig($uid,'system','profile_assign',''); + + + // See if we are already connected by virtue of having an abook record + + $r = q("select abook_id, abook_xchan, abook_pending, abook_instance from abook + where abook_xchan = '%s' and abook_channel = %d limit 1", + dbesc($xchan_hash), + intval($uid) + ); + + if ($r) { + + $abook_instance = $r[0]['abook_instance']; + + // If they are on a non-nomadic network, add them to this location + + if (($singleton) && strpos($abook_instance,z_root()) === false) { + if ($abook_instance) { + $abook_instance .= ','; + } + $abook_instance .= z_root(); + + $x = q("update abook set abook_instance = '%s', abook_not_here = 0 where abook_id = %d", + dbesc($abook_instance), + intval($r[0]['abook_id']) + ); + } + + // if they have a pending connection, we just followed them so approve the connection request + + if (intval($r[0]['abook_pending'])) { + $x = q("update abook set abook_pending = 0 where abook_id = %d", + intval($r[0]['abook_id']) + ); + } + } + else { + + // create a new abook record + + $closeness = get_pconfig($uid,'system','new_abook_closeness',80); + + $r = abook_store_lowlevel( + [ + 'abook_account' => intval($aid), + 'abook_channel' => intval($uid), + 'abook_closeness' => intval($closeness), + 'abook_xchan' => $xchan_hash, + 'abook_profile' => $profile_assign, + 'abook_feed' => intval(($xchan['xchan_network'] === 'rss') ? 1 : 0), + 'abook_created' => datetime_convert(), + 'abook_updated' => datetime_convert(), + 'abook_instance' => (($singleton) ? z_root() : '') + ] + ); + } + + if (! $r) { + logger('abook creation failed'); + $result['message'] = t('error saving data'); + return $result; + } + + // Set suitable permissions to the connection + + if ($my_perms) { + set_abconfig($uid,$xchan_hash,'system','my_perms',$my_perms); + } + + // fetch the entire record + + $r = q("select abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash + where abook_xchan = '%s' and abook_channel = %d limit 1", + dbesc($xchan_hash), + intval($uid) + ); + + if ($r) { + $result['abook'] = array_shift($r); + Master::Summon([ 'Notifier', 'permission_create', $result['abook']['abook_id'] ]); + } + + $arr = [ 'channel_id' => $uid, 'channel' => $channel, 'abook' => $result['abook'] ]; + + call_hooks('follow', $arr); + + /** If there is a default group for this channel, add this connection to it */ + + if ($default_group) { + $g = AccessList::rec_byhash($uid,$default_group); + if ($g) { + AccessList::member_add($uid,'',$xchan_hash,$g['id']); + } + } + + $result['success'] = true; + return $result; + } +} diff --git a/Zotlabs/Module/Follow.php b/Zotlabs/Module/Follow.php index cbf9d62c5..11febd8fc 100644 --- a/Zotlabs/Module/Follow.php +++ b/Zotlabs/Module/Follow.php @@ -1,31 +1,88 @@ [ + ACTIVITYSTREAMS_JSONLD_REV, + 'https://w3id.org/security/v1', + z_root() . ZOT_APSCHEMA_REV + ]], + [ + 'id' => z_root() . '/follow/' . $r[0]['abook_id'], + 'type' => 'Follow', + 'actor' => $actor, + 'object' => $r[0]['xchan_url'] + ]); + + $headers = []; + $headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ; + $x['signature'] = LDSignatures::sign($x,$chan); + $ret = json_encode($x, JSON_UNESCAPED_SLASHES); + $headers['Date'] = datetime_convert('UTC','UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T'); + $headers['Digest'] = HTTPSig::generate_digest_header($ret); + $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI']; + $h = HTTPSig::create_sig($headers,$chan['channel_prvkey'],channel_url($chan)); + HTTPSig::set_headers($h); + echo $ret; + killme(); + + } + + if (! local_channel()) { return; } - + $uid = local_channel(); $url = notags(trim(punify($_REQUEST['url']))); $return_url = $_SESSION['return_url']; $confirm = intval($_REQUEST['confirm']); $interactive = (($_REQUEST['interactive']) ? intval($_REQUEST['interactive']) : 1); - $channel = \App::get_channel(); + $channel = App::get_channel(); - $result = new_contact($uid,$url,$channel,$interactive,$confirm); + $result = Connect::connect($channel,$url); - if($result['success'] == false) { - if($result['message']) + if ($result['success'] == false) { + if ($result['message']) { notice($result['message']); - if($interactive) { + } + if ($interactive) { goaway($return_url); } else { @@ -36,8 +93,8 @@ class Follow extends \Zotlabs\Web\Controller { info( t('Connection added.') . EOL); $clone = array(); - foreach($result['abook'] as $k => $v) { - if(strpos($k,'abook_') === 0) { + foreach ($result['abook'] as $k => $v) { + if (strpos($k,'abook_') === 0) { $clone[$k] = $v; } } @@ -46,20 +103,21 @@ class Follow extends \Zotlabs\Web\Controller { unset($clone['abook_channel']); $abconfig = load_abconfig($channel['channel_id'],$clone['abook_xchan']); - if($abconfig) + if ($abconfig) { $clone['abconfig'] = $abconfig; + } + Libsync::build_sync_packet(0, [ 'abook' => [ $clone ] ], true); - build_sync_packet(0 /* use the current local_channel */, array('abook' => array($clone)), true); - - $can_view_stream = intval(get_abconfig($channel['channel_id'],$clone['abook_xchan'],'their_perms','view_stream')); + $can_view_stream = their_perms_contains($channel['channel_id'],$clone['abook_xchan'],'view_stream'); // If we can view their stream, pull in some posts - if(($can_view_stream) || ($result['abook']['xchan_network'] === 'rss')) - \Zotlabs\Daemon\Master::Summon(array('Onepoll',$result['abook']['abook_id'])); + if (($can_view_stream) || ($result['abook']['xchan_network'] === 'rss')) { + Master::Summon([ 'Onepoll', $result['abook']['abook_id'] ]); + } - if($interactive) { - goaway(z_root() . '/connedit/' . $result['abook']['abook_id'] . '?f=&follow=1'); + if ($interactive) { + goaway(z_root() . '/connedit/' . $result['abook']['abook_id'] . '?follow=1'); } else { json_return_and_die([ 'success' => true ]); @@ -68,7 +126,7 @@ class Follow extends \Zotlabs\Web\Controller { } function get() { - if(! local_channel()) { + if (! local_channel()) { return login(); } } diff --git a/include/permissions.php b/include/permissions.php index 501b2cc77..ca8ff6e93 100644 --- a/include/permissions.php +++ b/include/permissions.php @@ -554,4 +554,24 @@ function site_default_perms() { return $ret; } +function their_perms_contains($channel_id,$xchan_hash,$perm) { + $x = get_abconfig($channel_id,$xchan_hash,'system','their_perms'); + if($x) { + $y = explode(',',$x); + if(in_array($perm,$y)) { + return true; + } + } + return false; +} +function my_perms_contains($channel_id,$xchan_hash,$perm) { + $x = get_abconfig($channel_id,$xchan_hash,'system','my_perms'); + if($x) { + $y = explode(',',$x); + if(in_array($perm,$y)) { + return true; + } + } + return false; +} -- cgit v1.2.3 From 9545a81166cf52c930dfafda40d93bf93d66260d Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 26 Jan 2020 19:41:52 +0000 Subject: update create_identity() to use Lib/Connect via connect_and_sync() ported from zap --- include/channel.php | 55 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/include/channel.php b/include/channel.php index e7d119b1e..61603fb42 100644 --- a/include/channel.php +++ b/include/channel.php @@ -11,6 +11,8 @@ use Zotlabs\Daemon\Master; use Zotlabs\Lib\System; use Zotlabs\Render\Comanche; use Zotlabs\Lib\Libzot; +use Zotlabs\Lib\Connect; +use Zotlabs\Lib\Libsync; require_once('include/zot.php'); require_once('include/crypto.php'); @@ -346,7 +348,7 @@ function create_identity($arr) { ] ); if(! $r) - logger('Unable to store hub location'); + logger('Unable to store hub location (zot)'); $r = hubloc_store_lowlevel( [ @@ -367,7 +369,7 @@ function create_identity($arr) { ] ); if(! $r) - logger('Unable to store hub location'); + logger('Unable to store hub location (zot6)'); $newuid = $ret['channel']['channel_id']; @@ -393,6 +395,8 @@ function create_identity($arr) { 'xchan_system' => $system ] ); + if(! $r) + logger('Unable to store xchan (zot)'); $r = xchan_store_lowlevel( [ @@ -415,6 +419,8 @@ function create_identity($arr) { 'xchan_system' => $system ] ); + if(! $r) + logger('Unable to store xchan (zot6)'); @@ -521,13 +527,22 @@ function create_identity($arr) { $accts = get_config('system','auto_follow'); if(($accts) && (! $total_identities)) { - require_once('include/follow.php'); if(! is_array($accts)) $accts = array($accts); foreach($accts as $acct) { - if(trim($acct)) - new_contact($newuid,trim($acct),$ret['channel'],false); + $acct = trim($acct); + if($acct) { + $f = connect_and_sync($ret['channel'], $acct); + if($f['success']) { + $can_view_stream = their_perms_contains($ret['channel']['channel_id'],$f['abook']['abook_xchan'],'view_stream'); + + // If we can view their stream, pull in some posts + if(($can_view_stream) || ($f['abook']['xchan_network'] === 'rss')) { + Master::Summon([ 'Onepoll',$f['abook']['abook_id'] ]); + } + } + } } } @@ -539,6 +554,7 @@ function create_identity($arr) { call_hooks('create_identity', $newuid); Master::Summon(array('Directory', $ret['channel']['channel_id'])); + } $ret['success'] = true; @@ -546,6 +562,35 @@ function create_identity($arr) { } +function connect_and_sync($channel,$address, $sub_channel = false) { + + if((! $channel) || (! $address)) { + return false; + } + + $f = Connect::connect($channel,$address, $sub_channel); + if($f['success']) { + $clone = []; + foreach($f['abook'] as $k => $v) { + if(strpos($k,'abook_') === 0) { + $clone[$k] = $v; + } + } + unset($clone['abook_id']); + unset($clone['abook_account']); + unset($clone['abook_channel']); + + $abconfig = load_abconfig($channel['channel_id'],$clone['abook_xchan']); + if($abconfig) { + $clone['abconfig'] = $abconfig; + } + + Libsync::build_sync_packet($channel['channel_id'], [ 'abook' => [ $clone ] ], true); + return $f; + } + return false; +} + function change_channel_keys($channel) { $ret = array('success' => false); -- cgit v1.2.3 From 19bb9e018152ce528846fb955b58d76f1bb6bdec Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 30 Jan 2020 10:12:45 +0000 Subject: zap is storing perms different from hubzilla - revert Lib/Connect to use the hubzilla way. Eventually we might want to streamline this with zap. This will require a DB update to upgrade permissions in abconfig. --- Zotlabs/Lib/Connect.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Zotlabs/Lib/Connect.php b/Zotlabs/Lib/Connect.php index 978a4ce39..5fc0e3fe1 100644 --- a/Zotlabs/Lib/Connect.php +++ b/Zotlabs/Lib/Connect.php @@ -152,7 +152,6 @@ class Connect { call_hooks('follow_allow',$hookdata); if(! $hookdata['allowed']) { - hz_syslog('zesz'); $result['message'] = t('Protocol disabled.'); return $result; } @@ -211,7 +210,7 @@ class Connect { $p['perms']['moderated'] = 0; } - $my_perms = Permissions::serialise($p['perms']); + $my_perms = $p['perms']; $profile_assign = get_pconfig($uid,'system','profile_assign',''); @@ -279,8 +278,10 @@ class Connect { // Set suitable permissions to the connection - if ($my_perms) { - set_abconfig($uid,$xchan_hash,'system','my_perms',$my_perms); + if($my_perms) { + foreach($my_perms as $k => $v) { + set_abconfig($uid,$xchan_hash,'my_perms',$k,$v); + } } // fetch the entire record -- cgit v1.2.3 From 25cd9b49838cb6e3d2643b27ae1aa2a63a7a0e58 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 6 Mar 2020 09:50:53 +0000 Subject: provide tool to transform channels to zot6. WARNING: transformed channels will not yet be functional without additional patches. --- Zotlabs/Module/Z6trans.php | 200 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 Zotlabs/Module/Z6trans.php diff --git a/Zotlabs/Module/Z6trans.php b/Zotlabs/Module/Z6trans.php new file mode 100644 index 000000000..ac8c67c79 --- /dev/null +++ b/Zotlabs/Module/Z6trans.php @@ -0,0 +1,200 @@ + $cols) { + foreach($cols as $col) { + logger("Transforming $table - $col"); + q("UPDATE %s SET %s = replace(%s, '%s', '%s')", + dbesc($table), + dbesc($col), + dbesc($col), + dbesc($zot_xchan), + dbesc($zot6_xchan) + ); + } + logger("$table done."); + } + logger("Transformation completed."); + + + + } + + function get() { + if(!is_site_admin()) + return 'Not Allowed'; + + $path = 'store/z6upgrade.sql'; + + $r = q("SELECT channel.channel_name, channel.channel_hash, xchan.xchan_network FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE xchan.xchan_network = 'zot' AND channel.channel_removed = 0"); + + foreach($r as $rr) { + + $zot_xchan = $rr['channel_hash']; + + $r = q("SELECT xchan_guid FROM xchan WHERE xchan_hash = '%s' AND xchan_network = 'zot'", + dbesc($zot_xchan) + ); + + if(!$r) { + notice(t('Zot xchan not found. Aborting.') . EOL); + return; + } + + $guid = $r[0]['xchan_guid']; + $r = q("SELECT xchan_hash, xchan_guid_sig FROM xchan WHERE xchan_guid = '%s' AND xchan_network = 'zot6'", + dbesc($guid) + ); + + if(!$r) { + notice(t('No zot6 xchan found. Aborting.') . EOL); + return; + } + + $zot6_xchan = $r[0]['xchan_hash']; + $zot6_xchan_guid_sig = $r[0]['xchan_guid_sig']; + + //this should probably happen in a db_update during upgrading + $q .= sprintf("UPDATE channel SET channel_hash = '%s', channel_portable_id = '%s', channel_guid_sig = '%s' WHERE channel_hash = '%s';\r\n", + dbesc($zot6_xchan), + dbesc($zot_xchan), + dbesc($zot6_xchan_guid_sig), + dbesc($zot_xchan) + ); + + $core = self::get_core_cols(); + + foreach($core as $table => $cols) { + + foreach($cols as $col) { + + $q .= sprintf("UPDATE %s SET %s = replace(%s, '%s', '%s');\r\n", + dbesc($table), + dbesc($col), + dbesc($col), + dbesc($zot_xchan), + dbesc($zot6_xchan) + ); + + } + + } + + file_put_contents($path, $q); + + } + + + $o = '

' . t('Transform a single channel') . '

'; + $o .= '
'; + $o .= t('Enter zot xchan to transform: ') . '
'; + $o .= '
'; + $o .= '
'; + $o .= '


'; + + + $o .= '

' . t('To transform all channels') . '

'; + if(ACTIVE_DBTYPE == DBTYPE_MYSQL) + $o .= 'Run source ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . ' from the mysql console to complete the upgrade.'; + else + $o .= 'Run \i ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . ' from the postgresql console to complete the upgrade.'; + + return $o; + + } + + function get_core_cols() { + + $core = [ + 'abconfig' => ['xchan'], + 'abook' => ['abook_xchan'], + 'app' => ['app_author'], + 'attach' => ['creator', 'allow_cid', 'deny_cid'], + 'channel' => ['channel_allow_cid', 'channel_deny_cid'], + 'chat' => ['chat_xchan'], + 'chatpresence' => ['cp_xchan'], + 'chatroom' => ['allow_cid', 'deny_cid'], + 'config' => ['v'], + 'dreport' => ['dreport_recip', 'dreport_xchan'], + 'event' => ['event_xchan', 'allow_cid', 'deny_cid'], + 'iconfig' => ['v'], + 'item' => ['owner_xchan', 'author_xchan', 'source_xchan', 'route', 'allow_cid', 'deny_cid'], + 'mail' => ['from_xchan', 'to_xchan'], + 'menu_item' => ['allow_cid', 'deny_cid'], + 'obj' => ['allow_cid', 'deny_cid'], + 'pconfig' => ['v'], + 'pgrp_member' => ['xchan'], + 'photo' => ['xchan', 'allow_cid', 'deny_cid'], + 'source' => ['src_channel_xchan', 'src_xchan'], + 'updates' => ['ud_hash'], + 'xchat' => ['xchat_xchan'], + 'xconfig' => ['xchan', 'v'], + 'xign' => ['xchan'], + 'xlink' => ['xlink_xchan', 'xlink_link'], + 'xprof' => ['xprof_hash'], + 'xtag' => ['xtag_hash'], + ]; + + return $core; + + } + +} -- cgit v1.2.3 From ce4fc304393001771e906af1f2e2702a1820eaa2 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 6 Mar 2020 10:11:10 +0000 Subject: use 24h time format --- include/text.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/text.php b/include/text.php index 3c1d4c996..5d1cf6eff 100644 --- a/include/text.php +++ b/include/text.php @@ -1881,7 +1881,7 @@ function format_poll($item,$s,$opts) { } } if ($item['comments_closed'] > NULL_DATE) { - $t = datetime_convert('UTC',date_default_timezone_get(), $item['comments_closed'], 'Y-m-d h:i'); + $t = datetime_convert('UTC',date_default_timezone_get(), $item['comments_closed'], 'Y-m-d H:i'); $closed = ((datetime_convert() > $item['comments_closed']) ? true : false); if ($closed) { $message = t('Poll has ended.'); -- cgit v1.2.3 From 720d3dcedc96c7aaf6c4444c8b45acd46b8718b0 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 11 Mar 2020 10:34:25 +0000 Subject: z6trans preparation for db update 1236 --- Zotlabs/Module/Z6trans.php | 118 +++++++++------------------------------------ 1 file changed, 24 insertions(+), 94 deletions(-) diff --git a/Zotlabs/Module/Z6trans.php b/Zotlabs/Module/Z6trans.php index ac8c67c79..98832ad98 100644 --- a/Zotlabs/Module/Z6trans.php +++ b/Zotlabs/Module/Z6trans.php @@ -12,116 +12,50 @@ use Zotlabs\Web\Controller; class Z6trans extends Controller { - function post() { - if(!is_site_admin()) - return; - - $zot_xchan = trim($_POST['zot_xchan']); - - $r = q("SELECT xchan_guid FROM xchan WHERE xchan_hash = '%s' AND xchan_network = 'zot'", - dbesc($zot_xchan) - ); - - if(!$r) { - notice(t('Zot xchan not found. Aborting.') . EOL); - return; - } - - $guid = $r[0]['xchan_guid']; - $r = q("SELECT xchan_hash, xchan_guid_sig FROM xchan WHERE xchan_guid = '%s' AND xchan_network = 'zot6'", - dbesc($guid) - ); - - if(!$r) { - notice(t('No zot6 xchan found. Aborting.') . EOL); - return; - } - - $zot6_xchan = $r[0]['xchan_hash']; - $zot6_xchan_guid_sig = $r[0]['xchan_guid_sig']; - - - $r = q("SELECT * FROM channel WHERE channel_hash = '%s'", - dbesc($zot_xchan) - ); - - // We got everything we need - start transforming. - - if($r) { - logger("Transforming channel $zot_xchan"); - q("UPDATE channel SET channel_hash = '%s', channel_portable_id = '%s', channel_guid_sig = '%s' WHERE channel_hash = '%s'", - dbesc($zot6_xchan), - dbesc($zot_xchan), - dbesc($zot6_xchan_guid_sig), - dbesc($zot_xchan) - ); - } - - $core = self::get_core_cols(); - - foreach($core as $table => $cols) { - foreach($cols as $col) { - logger("Transforming $table - $col"); - q("UPDATE %s SET %s = replace(%s, '%s', '%s')", - dbesc($table), - dbesc($col), - dbesc($col), - dbesc($zot_xchan), - dbesc($zot6_xchan) - ); - } - logger("$table done."); - } - logger("Transformation completed."); - - - - } - function get() { if(!is_site_admin()) return 'Not Allowed'; - $path = 'store/z6upgrade.sql'; + $path = 'store/z6trans.sql'; - $r = q("SELECT channel.channel_name, channel.channel_hash, xchan.xchan_network FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE xchan.xchan_network = 'zot' AND channel.channel_removed = 0"); + $r = q("SELECT channel.channel_name, channel.channel_portable_id, xchan.xchan_network FROM channel + LEFT JOIN xchan ON channel_portable_id = xchan_hash + WHERE xchan.xchan_network = 'zot' + AND channel.channel_removed = 0" + ); + + $q = ''; foreach($r as $rr) { - $zot_xchan = $rr['channel_hash']; + $zot_xchan = $rr['channel_portable_id']; $r = q("SELECT xchan_guid FROM xchan WHERE xchan_hash = '%s' AND xchan_network = 'zot'", dbesc($zot_xchan) ); if(!$r) { - notice(t('Zot xchan not found. Aborting.') . EOL); - return; + $q .= '-- ' . $zot_xchan . 'failed: zot xchan not found' . "\r\n"; + continue; } $guid = $r[0]['xchan_guid']; + $r = q("SELECT xchan_hash, xchan_guid_sig FROM xchan WHERE xchan_guid = '%s' AND xchan_network = 'zot6'", dbesc($guid) ); if(!$r) { - notice(t('No zot6 xchan found. Aborting.') . EOL); - return; + $q .= '-- ' . $zot_xchan . 'failed: zot6 xchan not found' . "\r\n"; + continue; } $zot6_xchan = $r[0]['xchan_hash']; - $zot6_xchan_guid_sig = $r[0]['xchan_guid_sig']; - - //this should probably happen in a db_update during upgrading - $q .= sprintf("UPDATE channel SET channel_hash = '%s', channel_portable_id = '%s', channel_guid_sig = '%s' WHERE channel_hash = '%s';\r\n", - dbesc($zot6_xchan), - dbesc($zot_xchan), - dbesc($zot6_xchan_guid_sig), - dbesc($zot_xchan) - ); $core = self::get_core_cols(); + $q .= '-- Transforming ' . $rr['channel_name'] . "\r\n"; + foreach($core as $table => $cols) { foreach($cols as $col) { @@ -138,24 +72,20 @@ class Z6trans extends Controller { } - file_put_contents($path, $q); - } + if($q) + file_put_contents($path, $q); - $o = '

' . t('Transform a single channel') . '

'; - $o .= '
'; - $o .= t('Enter zot xchan to transform: ') . '
'; - $o .= '
'; - $o .= '
'; - $o .= '


'; - + $o = '

' . t('Update to Hubzilla 5.0 setp 2') . '


'; - $o .= '

' . t('To transform all channels') . '

'; + $o .= '

' . t('To complete the update please run') . '

'; if(ACTIVE_DBTYPE == DBTYPE_MYSQL) - $o .= 'Run source ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . ' from the mysql console to complete the upgrade.'; + $o .= 'source ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . '

from the mysql console.

'; else - $o .= 'Run \i ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . ' from the postgresql console to complete the upgrade.'; + $o .= '\i ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . '

from the postgresql console.

'; + + $o .= '

' . t('INFO: this command can take a very long time depending on your DB size.') . '

'; return $o; -- cgit v1.2.3 From b23751128bafdc0e2d546517cab48f8095eed315 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 11 Mar 2020 10:43:19 +0000 Subject: port create_identity() to zot6 --- include/channel.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/include/channel.php b/include/channel.php index 4aad64f3d..e48420fa0 100644 --- a/include/channel.php +++ b/include/channel.php @@ -230,12 +230,16 @@ function create_identity($arr) { return $ret; } - $guid = zot_new_uid($nick); + $guid = Libzot::new_uid($nick); $key = new_keypair(4096); - $sig = base64url_encode(rsa_sign($guid,$key['prvkey'])); - $hash = make_xchan_hash($guid,$sig); - $zhash = Libzot::make_xchan_hash($guid,$key['pubkey']); + // legacy zot + $zsig = base64url_encode(rsa_sign($guid,$key['prvkey'])); + $zhash = make_xchan_hash($guid,$sig); + + // zot6 + $sig = Libzot::sign($guid,$key['prvkey']); + $hash = Libzot::make_xchan_hash($guid,$key['pubkey']); // Force a few things on the short term until we can provide a theme or app with choice @@ -334,8 +338,8 @@ function create_identity($arr) { $r = hubloc_store_lowlevel( [ 'hubloc_guid' => $guid, - 'hubloc_guid_sig' => $sig, - 'hubloc_hash' => $hash, + 'hubloc_guid_sig' => $zsig, + 'hubloc_hash' => $zhash, 'hubloc_addr' => channel_reddress($ret['channel']), 'hubloc_primary' => intval($primary), 'hubloc_url' => z_root(), @@ -353,13 +357,13 @@ function create_identity($arr) { $r = hubloc_store_lowlevel( [ 'hubloc_guid' => $guid, - 'hubloc_guid_sig' => 'sha256.' . $sig, - 'hubloc_hash' => $zhash, + 'hubloc_guid_sig' => $sig, + 'hubloc_hash' => $hash, 'hubloc_id_url' => channel_url($ret['channel']), 'hubloc_addr' => channel_reddress($ret['channel']), 'hubloc_primary' => intval($primary), 'hubloc_url' => z_root(), - 'hubloc_url_sig' => 'sha256.' . base64url_encode(rsa_sign(z_root(),$ret['channel']['channel_prvkey'])), + 'hubloc_url_sig' => Libzot::sign(z_root(),$ret['channel']['channel_prvkey']), 'hubloc_site_id' => Libzot::make_xchan_hash(z_root(),get_config('system','pubkey')), 'hubloc_host' => App::get_hostname(), 'hubloc_callback' => z_root() . '/zot', @@ -376,9 +380,9 @@ function create_identity($arr) { $r = xchan_store_lowlevel( [ - 'xchan_hash' => $hash, + 'xchan_hash' => $zhash, 'xchan_guid' => $guid, - 'xchan_guid_sig' => $sig, + 'xchan_guid_sig' => $zsig, 'xchan_pubkey' => $key['pubkey'], 'xchan_photo_mimetype' => (($photo_type) ? $photo_type : 'image/png'), 'xchan_photo_l' => z_root() . "/photo/profile/l/{$newuid}", @@ -400,9 +404,9 @@ function create_identity($arr) { $r = xchan_store_lowlevel( [ - 'xchan_hash' => $zhash, + 'xchan_hash' => $hash, 'xchan_guid' => $guid, - 'xchan_guid_sig' => 'sha256.' . $sig, + 'xchan_guid_sig' => $sig, 'xchan_pubkey' => $key['pubkey'], 'xchan_photo_mimetype' => (($photo_type) ? $photo_type : 'image/png'), 'xchan_photo_l' => z_root() . "/photo/profile/l/{$newuid}", -- cgit v1.2.3 From c358aa2806717d1af6e47697f87e54b7c9967c9e Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 12 Mar 2020 18:27:16 +0000 Subject: first batch of zot6 transition patches. basic communication with transitioned channels *should* work now --- Zotlabs/Daemon/Notifier.php | 14 ++++++--- Zotlabs/Lib/Libzot.php | 48 +++++++++++++++--------------- Zotlabs/Zot6/Zot6Handler.php | 8 ++--- include/zot.php | 70 ++++++++++++++++++++++---------------------- 4 files changed, 73 insertions(+), 67 deletions(-) diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php index 00c6fb077..fdf0148a6 100644 --- a/Zotlabs/Daemon/Notifier.php +++ b/Zotlabs/Daemon/Notifier.php @@ -542,11 +542,10 @@ class Notifier { // Now we have collected recipients (except for external mentions, FIXME) // Let's reduce this to a set of hubs; checking that the site is not dead. - $r = q("select hubloc.*, site.site_crypto, site.site_flags from hubloc left join site on site_url = hubloc_url where hubloc_hash in (" . protect_sprintf(implode(',',$recipients)) . ") + $r = q("select hubloc.*, site.site_crypto, site.site_flags, site.site_version, site.site_project from hubloc left join site on site_url = hubloc_url where hubloc_hash in (" . protect_sprintf(implode(',',$recipients)) . ") and hubloc_error = 0 and hubloc_deleted = 0 and ( site_dead = 0 OR site_dead is null ) " - ); + ); - if(! $r) { logger('notifier: no hubs', LOGGER_NORMAL, LOG_NOTICE); return; @@ -735,7 +734,14 @@ class Notifier { $packet = zot_build_packet($channel,'notify',$env, (($private) ? $hub['hubloc_sitekey'] : null), $hub['site_crypto'],$hash); } - } + } + + if(stripos($hub['site_project'], 'hubzilla') !== false && version_compare($hub['site_version'], '4.7.3', '<=')) { + $encoded_item['owner']['network'] = 'zot'; + $encoded_item['owner']['guid_sig'] = str_replace('sha256.', '', $encoded_item['owner']['guid_sig']); + $encoded_item['author']['network'] = 'zot'; + $encoded_item['author']['guid_sig'] = str_replace('sha256.', '', $encoded_item['author']['guid_sig']); + } queue_insert( [ diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 42e706754..5e212ad70 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -105,7 +105,7 @@ class Libzot { $data = [ 'type' => $type, 'encoding' => $encoding, - 'sender' => $channel['channel_portable_id'], + 'sender' => $channel['channel_hash'], 'site_id' => self::make_xchan_hash(z_root(), get_config('system','pubkey')), 'version' => System::get_zot_revision(), ]; @@ -422,7 +422,7 @@ class Libzot { [ 'type' => NOTIFY_INTRO, 'from_xchan' => $x['hash'], - 'to_xchan' => $channel['channel_portable_id'], + 'to_xchan' => $channel['channel_hash'], 'link' => z_root() . '/connedit/' . $new_connection[0]['abook_id'] ] ); @@ -788,7 +788,7 @@ class Libzot { // 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_portable_id = '%s' limit 1", + $local = q("select channel_account_id, channel_id from channel where channel_hash = '%s' limit 1", dbesc($xchan_hash) ); if($local) { @@ -1151,7 +1151,7 @@ class Libzot { if($recip_arr) { stringify_array_elms($recip_arr,true); $recips = implode(',',$recip_arr); - $r = q("select channel_portable_id as hash from channel where channel_portable_id in ( " . $recips . " ) and channel_removed = 0 "); + $r = q("select channel_hash as hash from channel where channel_hash in ( " . $recips . " ) and channel_removed = 0 "); } if(! $r) { @@ -1368,12 +1368,12 @@ class Libzot { $r = []; - $c = q("select channel_id, channel_portable_id from channel where channel_removed = 0"); + $c = q("select channel_id, channel_hash from channel where channel_removed = 0"); if($c) { foreach($c as $cc) { if(perm_is_allowed($cc['channel_id'],$msg['sender'],$perm)) { - $r[] = $cc['channel_portable_id']; + $r[] = $cc['channel_hash']; } } } @@ -1381,7 +1381,7 @@ class Libzot { if($include_sys) { $sys = get_sys_channel(); if($sys) - $r[] = $sys['channel_portable_id']; + $r[] = $sys['channel_hash']; } @@ -1397,7 +1397,7 @@ class Libzot { if($tag['type'] === 'Mention' && (strpos($tag['href'],z_root()) !== false)) { $address = basename($tag['href']); if($address) { - $z = q("select channel_portable_id as hash from channel where channel_address = '%s' + $z = q("select channel_hash as hash from channel where channel_address = '%s' and channel_removed = 0 limit 1", dbesc($address) ); @@ -1418,7 +1418,7 @@ class Libzot { $thread_parent = self::find_parent($msg,$act); if($thread_parent) { - $z = q("select channel_portable_id as hash from channel left join item on channel.channel_id = item.uid where ( item.thr_parent = '%s' OR item.parent_mid = '%s' ) ", + $z = q("select channel_hash as hash from channel left join item on channel.channel_id = item.uid where ( item.thr_parent = '%s' OR item.parent_mid = '%s' ) ", dbesc($thread_parent), dbesc($thread_parent) ); @@ -1473,7 +1473,7 @@ class Libzot { $DR = new DReport(z_root(),$sender,$d,$arr['mid']); - $channel = channelx_by_portid($d); + $channel = channelx_by_hash($d); if (! $channel) { $DR->update('recipient not found'); @@ -1510,7 +1510,7 @@ class Libzot { * access checks. */ - if($sender === $channel['channel_portable_id'] && $arr['author_xchan'] === $channel['channel_portable_id'] && $arr['mid'] === $arr['parent_mid']) { + if($sender === $channel['channel_hash'] && $arr['author_xchan'] === $channel['channel_hash'] && $arr['mid'] === $arr['parent_mid']) { $DR->update('self delivery ignored'); $result[] = $DR->get(); continue; @@ -1827,7 +1827,7 @@ class Libzot { $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'])) { + && ($stored['author_xchan'] === $channel['channel_hash'] || $stored['author_xchan'] === $channel['channel_hash'])) { retain_item($stored['item']['parent']); } @@ -1949,9 +1949,9 @@ class Libzot { } logger('FOF Activity received: ' . print_r($arr,true), LOGGER_DATA, LOG_DEBUG); - logger('FOF Activity recipient: ' . $channel['channel_portable_id'], LOGGER_DATA, LOG_DEBUG); + logger('FOF Activity recipient: ' . $channel['channel_hash'], LOGGER_DATA, LOG_DEBUG); - $result = self::process_delivery($arr['owner_xchan'],$AS, $arr, [ $channel['channel_portable_id'] ],false,false,true); + $result = self::process_delivery($arr['owner_xchan'],$AS, $arr, [ $channel['channel_hash'] ],false,false,true); if ($result) { $ret = array_merge($ret, $result); } @@ -2207,7 +2207,7 @@ class Libzot { $DR = new DReport(z_root(),$sender,$d,$arr['mid']); - $r = q("select * from channel where channel_portable_id = '%s' limit 1", + $r = q("select * from channel where channel_hash = '%s' limit 1", dbesc($d['hash']) ); @@ -2362,7 +2362,7 @@ class Libzot { $loc = $locations[0]; - $r = q("select * from channel where channel_portable_id = '%s' limit 1", + $r = q("select * from channel where channel_hash = '%s' limit 1", dbesc($sender_hash) ); @@ -2370,7 +2370,7 @@ class Libzot { return; if($loc['url'] !== z_root()) { - $x = q("update channel set channel_moved = '%s' where channel_portable_id = '%s' limit 1", + $x = q("update channel set channel_moved = '%s' where channel_hash = '%s' limit 1", dbesc($loc['url']), dbesc($sender_hash) ); @@ -2404,7 +2404,7 @@ class Libzot { static function encode_locations($channel) { $ret = []; - $x = self::get_hublocs($channel['channel_portable_id']); + $x = self::get_hublocs($channel['channel_hash']); if($x && count($x)) { foreach($x as $hub) { @@ -2752,13 +2752,13 @@ class Libzot { $r = null; if(strlen($zhash)) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash - where channel_portable_id = '%s' limit 1", + $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash + where channel_hash = '%s' limit 1", dbesc($zhash) ); } elseif(strlen($zguid) && strlen($zguid_sig)) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash + $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", dbesc($zguid), dbesc($zguid_sig) @@ -2766,7 +2766,7 @@ class Libzot { } elseif(strlen($zaddr)) { if(strpos($zaddr,'[system]') === false) { /* normal address lookup */ - $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash + $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash where ( channel_address = '%s' or xchan_addr = '%s' ) limit 1", dbesc($zaddr), dbesc($zaddr) @@ -2786,10 +2786,10 @@ class Libzot { * */ - $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash + $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = 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_portable_id = xchan_hash + $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash where channel_removed = 0 order by channel_id limit 1"); } } diff --git a/Zotlabs/Zot6/Zot6Handler.php b/Zotlabs/Zot6/Zot6Handler.php index 37ce11980..d717b147b 100644 --- a/Zotlabs/Zot6/Zot6Handler.php +++ b/Zotlabs/Zot6/Zot6Handler.php @@ -71,7 +71,7 @@ class Zot6Handler implements IHandler { foreach ($recipients as $recip) { $r = q("select channel.*,xchan.* from channel - left join xchan on channel_portable_id = xchan_hash + left join xchan on channel_hash = xchan_hash where xchan_hash ='%s' limit 1", dbesc($recip) ); @@ -139,7 +139,7 @@ class Zot6Handler implements IHandler { $arr = $data['recipients'][0]; - $c = q("select * from channel left join xchan on channel_portable_id = xchan_hash where channel_portable_id = '%s' limit 1", + $c = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_hash = '%s' limit 1", dbesc($arr['portable_id']) ); if (! $c) { @@ -227,8 +227,8 @@ class Zot6Handler implements IHandler { // basically this means "unfriend" foreach ($recipients as $recip) { $r = q("select channel.*,xchan.* from channel - left join xchan on channel_portable_id = xchan_hash - where channel_portable_id = '%s' limit 1", + left join xchan on channel_hash = xchan_hash + where channel_hash = '%s' limit 1", dbesc($recip) ); if ($r) { diff --git a/include/zot.php b/include/zot.php index 5d5ac8424..ca33b6c48 100644 --- a/include/zot.php +++ b/include/zot.php @@ -578,7 +578,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 +921,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 +1299,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 +1385,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 +1596,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 +1610,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 +1624,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 +1727,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 +1776,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'); @@ -2076,7 +2076,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 +2344,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 +2555,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 +2563,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) ); @@ -2826,13 +2826,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) { @@ -3301,7 +3301,7 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { 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']) + dbesc(($keychange) ? $packet['keychange']['old_hash'] : $channel['channel_portable_id']) ); if(! $h) @@ -3325,7 +3325,7 @@ 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; @@ -3446,7 +3446,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { $keychange = ((array_key_exists('keychange',$arr)) ? true : false); foreach ($deliveries as $d) { - $r = q("select * from channel where channel_hash = '%s' limit 1", + $r = q("select * from channel where channel_portable_id = '%s' limit 1", dbesc(($keychange) ? $arr['keychange']['old_hash'] : $d['hash']) ); @@ -3460,8 +3460,8 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { $max_friends = service_class_fetch($channel['channel_id'],'total_channels'); $max_feeds = account_service_class_fetch($channel['channel_account_id'],'total_feeds'); - if($channel['channel_hash'] != $sender['hash']) { - logger('Possible forgery. Sender ' . $sender['hash'] . ' is not ' . $channel['channel_hash']); + if($channel['channel_portable_id'] != $sender['hash']) { + logger('Possible forgery. Sender ' . $sender['hash'] . ' is not ' . $channel['channel_portable_id']); $result[] = array($d['hash'],'channel mismatch',$channel['channel_name'],''); continue; } @@ -3478,7 +3478,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { $r = q("update channel set channel_prvkey = '%s', channel_pubkey = '%s', channel_guid_sig = '%s', - channel_hash = '%s' where channel_id = %d", + channel_portable_id = '%s' where channel_id = %d", dbesc($arr['channel']['channel_prvkey']), dbesc($arr['channel']['channel_pubkey']), dbesc($sig), @@ -4192,7 +4192,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) { @@ -4338,13 +4338,13 @@ 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) @@ -4352,7 +4352,7 @@ function zotinfo($arr) { } 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) @@ -4372,10 +4372,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"); } } @@ -4699,14 +4699,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, @@ -4761,7 +4761,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) @@ -5107,7 +5107,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) { @@ -5174,7 +5174,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']) @@ -5227,7 +5227,7 @@ 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 + 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']) -- cgit v1.2.3 From 3b4503c971cda9e78d8cb310ab7c2e62987efffd Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 12 Mar 2020 19:09:34 +0000 Subject: use xchan_guid_sig instead of channel_guid_sig since it slightly differs depending on *default* protocol --- include/zot.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/include/zot.php b/include/zot.php index ca33b6c48..7d7df9ece 100644 --- a/include/zot.php +++ b/include/zot.php @@ -407,8 +407,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'] = $channel['xchan_guid_sig']; $postvars['key'] = $channel['channel_pubkey']; } @@ -426,7 +426,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']) { @@ -5228,11 +5227,10 @@ function zot_reply_refresh($sender, $recipients) { foreach ($recipients as $recip) { $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", + 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'], -- cgit v1.2.3 From b2de12442d3064ee3899583661efef28c4efd38f Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 13 Mar 2020 19:32:59 +0000 Subject: wrong variable --- include/channel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/channel.php b/include/channel.php index e48420fa0..25eb93cac 100644 --- a/include/channel.php +++ b/include/channel.php @@ -235,7 +235,7 @@ function create_identity($arr) { // legacy zot $zsig = base64url_encode(rsa_sign($guid,$key['prvkey'])); - $zhash = make_xchan_hash($guid,$sig); + $zhash = make_xchan_hash($guid,$zsig); // zot6 $sig = Libzot::sign($guid,$key['prvkey']); -- cgit v1.2.3 From c5365261960150a2070b915d27b2b96337651f3d Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 16 Mar 2020 20:12:30 +0000 Subject: Update 1236 and bump version to 4.7.4 --- Zotlabs/Update/_1236.php | 115 +++++++++++++++++++++++++++++++++++++++++++++++ boot.php | 4 +- 2 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 Zotlabs/Update/_1236.php diff --git a/Zotlabs/Update/_1236.php b/Zotlabs/Update/_1236.php new file mode 100644 index 000000000..c5f84626b --- /dev/null +++ b/Zotlabs/Update/_1236.php @@ -0,0 +1,115 @@ + Date: Mon, 16 Mar 2020 21:55:59 +0000 Subject: typo --- Zotlabs/Update/_1236.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Update/_1236.php b/Zotlabs/Update/_1236.php index c5f84626b..1ebafcc0b 100644 --- a/Zotlabs/Update/_1236.php +++ b/Zotlabs/Update/_1236.php @@ -19,7 +19,7 @@ class _1236 { foreach($r as $rr) { $zot_xchan = $rr['channel_hash']; - $guid = $r[0]['xchan_guid']; + $guid = $rr[0]['xchan_guid']; $xchan = q("SELECT xchan_hash, xchan_guid_sig FROM xchan WHERE xchan_guid = '%s' AND xchan_network = 'zot6'", dbesc($guid) -- cgit v1.2.3 From eb3dbcce7b1e942fc313b904d1170ac01af2efe8 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 16 Mar 2020 22:04:28 +0000 Subject: one more typo --- Zotlabs/Update/_1236.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Update/_1236.php b/Zotlabs/Update/_1236.php index 1ebafcc0b..d40cc9e25 100644 --- a/Zotlabs/Update/_1236.php +++ b/Zotlabs/Update/_1236.php @@ -19,7 +19,7 @@ class _1236 { foreach($r as $rr) { $zot_xchan = $rr['channel_hash']; - $guid = $rr[0]['xchan_guid']; + $guid = $rr['xchan_guid']; $xchan = q("SELECT xchan_hash, xchan_guid_sig FROM xchan WHERE xchan_guid = '%s' AND xchan_network = 'zot6'", dbesc($guid) -- cgit v1.2.3 From 4eaddd12796cd49e9ee5d5527e2eaa519279d57e Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 24 Mar 2020 08:32:37 +0000 Subject: do not sync with incompatible hubs --- include/zot.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/zot.php b/include/zot.php index 7d7df9ece..bb5537d2e 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3299,7 +3299,7 @@ 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", + $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']) ); @@ -3312,6 +3312,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']) ); @@ -3326,6 +3334,7 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { $r = q("select xchan_guid, xchan_guid_sig from xchan where xchan_hash = '%s' limit 1", dbesc($channel['channel_portable_id']) ); + if(! $r) return; -- cgit v1.2.3 From 0c1c386a0af1e8dabaf7acf345dffa5cf5ad89eb Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 25 Mar 2020 11:29:00 +0000 Subject: do not use channel_portable_id in process_channel_sync_delivery(). we should only accept sync packages from channels which are already transitioned to zot6. --- Zotlabs/Lib/Libsync.php | 2 +- include/zot.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index c39720735..de389c0a9 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -1022,4 +1022,4 @@ class Libsync { } -} \ No newline at end of file +} diff --git a/include/zot.php b/include/zot.php index bb5537d2e..5cf357d40 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3454,7 +3454,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { $keychange = ((array_key_exists('keychange',$arr)) ? true : false); foreach ($deliveries as $d) { - $r = q("select * from channel where channel_portable_id = '%s' limit 1", + $r = q("select * from channel where channel_hash = '%s' limit 1", dbesc(($keychange) ? $arr['keychange']['old_hash'] : $d['hash']) ); @@ -3468,8 +3468,8 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { $max_friends = service_class_fetch($channel['channel_id'],'total_channels'); $max_feeds = account_service_class_fetch($channel['channel_account_id'],'total_feeds'); - if($channel['channel_portable_id'] != $sender['hash']) { - logger('Possible forgery. Sender ' . $sender['hash'] . ' is not ' . $channel['channel_portable_id']); + if($channel['channel_hash'] != $sender['hash']) { + logger('Possible forgery. Sender ' . $sender['hash'] . ' is not ' . $channel['channel_hash']); $result[] = array($d['hash'],'channel mismatch',$channel['channel_name'],''); continue; } @@ -3486,7 +3486,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { $r = q("update channel set channel_prvkey = '%s', channel_pubkey = '%s', channel_guid_sig = '%s', - channel_portable_id = '%s' where channel_id = %d", + channel_hash = '%s' where channel_id = %d", dbesc($arr['channel']['channel_prvkey']), dbesc($arr['channel']['channel_pubkey']), dbesc($sig), -- cgit v1.2.3 From 0271f2a1ae5175fc5f1a7ec4f860a5d6372d7aeb Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 26 Mar 2020 08:14:20 +0000 Subject: fix z6_discover() to do the right thing after transition --- include/hubloc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/hubloc.php b/include/hubloc.php index 4a1f77733..059a4dadc 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -317,7 +317,7 @@ function z6_discover() { if ($c) { foreach ($c as $entry) { $q1 = q("select * from hubloc left join site on hubloc_url = site_url where hubloc_deleted = 0 and site_dead = 0 and hubloc_hash = '%s' and hubloc_url != '%s'", - dbesc($entry['channel_hash']), + dbesc($entry['channel_portable_id']), dbesc(z_root()) ); if (! $q1) { @@ -327,7 +327,7 @@ function z6_discover() { // does this particular server have a zot6 clone registered on our site for this channel? foreach ($q1 as $q) { $q2 = q("select * from hubloc left join site on hubloc_url = site_url where hubloc_deleted = 0 and site_dead = 0 and hubloc_hash = '%s' and hubloc_url = '%s'", - dbesc($entry['channel_portable_id']), + dbesc($entry['channel_hash']), dbesc($q['hubloc_url']) ); if ($q2) { -- cgit v1.2.3 From bcdd75b8178309e5c4e65d170505ab60678c2159 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 28 Mar 2020 09:29:49 +0000 Subject: prevent mod fhublocs breaking things. it needs porting to zot6 but has no priority for now. --- Zotlabs/Module/Fhublocs.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Zotlabs/Module/Fhublocs.php b/Zotlabs/Module/Fhublocs.php index 42c119da3..8393d26d6 100644 --- a/Zotlabs/Module/Fhublocs.php +++ b/Zotlabs/Module/Fhublocs.php @@ -10,6 +10,9 @@ require_once('include/crypto.php'); class Fhublocs extends \Zotlabs\Web\Controller { function get() { + + //TODO: this needs updating to zot6!!! + return; if(! is_site_admin()) return; -- cgit v1.2.3 From f49010bb12731c71c278dad8300e8dd117641bf9 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 29 Mar 2020 08:33:42 +0000 Subject: port fhublocs to zot6 and fix issue with primary detection --- Zotlabs/Module/Fhublocs.php | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/Zotlabs/Module/Fhublocs.php b/Zotlabs/Module/Fhublocs.php index 8393d26d6..989456f66 100644 --- a/Zotlabs/Module/Fhublocs.php +++ b/Zotlabs/Module/Fhublocs.php @@ -1,6 +1,8 @@ $rr['channel_guid'], @@ -75,7 +74,26 @@ class Fhublocs extends \Zotlabs\Web\Controller { 'hubloc_sitekey' => $sitekey ] ); - +*/ + $h = hubloc_store_lowlevel( + [ + 'hubloc_guid' => $rr['channel_guid'], + 'hubloc_guid_sig' => $rr['channel_guid_sig'], + 'hubloc_hash' => $rr['channel_hash'], + 'hubloc_id_url' => channel_url($rr), + 'hubloc_addr' => channel_reddress($rr), + 'hubloc_primary' => intval($primary), + 'hubloc_url' => z_root(), + 'hubloc_url_sig' => Libzot::sign(z_root(), $rr['channel_prvkey']), + 'hubloc_site_id' => Libzot::make_xchan_hash(z_root(), $sitekey), + 'hubloc_host' => \App::get_hostname(), + 'hubloc_callback' => z_root() . '/zot', + 'hubloc_sitekey' => $sitekey, + 'hubloc_network' => 'zot6', + 'hubloc_updated' => datetime_convert() + ] + ); + if($h) $o . 'local hubloc created for ' . $rr['channel_name'] . EOL; else -- cgit v1.2.3 From b1590ad645eca3f9d35e6fb7250547f2244c3140 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 29 Mar 2020 10:47:22 +0000 Subject: fix check for existing hublocs --- Zotlabs/Module/Fhublocs.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Zotlabs/Module/Fhublocs.php b/Zotlabs/Module/Fhublocs.php index 989456f66..dcd399a1f 100644 --- a/Zotlabs/Module/Fhublocs.php +++ b/Zotlabs/Module/Fhublocs.php @@ -26,7 +26,8 @@ class Fhublocs extends \Zotlabs\Web\Controller { $found = false; $primary_address = ''; - $x = zot_get_hublocs($rr['channel_hash']); + $x = Libzot::get_hublocs($rr['channel_hash']); + if($x) { foreach($x as $xx) { if($xx['hubloc_url'] === z_root() && $xx['hubloc_sitekey'] === $sitekey) { -- cgit v1.2.3 From b739f91caa1522522a4ce093d7c63f0f4c777085 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 29 Mar 2020 15:18:49 +0000 Subject: use Libsync::build_sync_packet() in mod item, default Lib/Queue driver to zot6 and some whitespace cleanup in queue_deliver() --- Zotlabs/Lib/Libsync.php | 1 + Zotlabs/Lib/Queue.php | 2 +- Zotlabs/Module/Item.php | 7 +++-- include/queue_fn.php | 80 ++++++++++++++++++++++++------------------------- 4 files changed, 46 insertions(+), 44 deletions(-) diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index de389c0a9..b7cda1770 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -150,6 +150,7 @@ class Libsync { 'account_id' => $channel['channel_account_id'], 'channel_id' => $channel['channel_id'], 'posturl' => $hub['hubloc_callback'], + 'driver' => $hub['hubloc_network'], 'notify' => $n, 'msg' => EMPTY_STR )); diff --git a/Zotlabs/Lib/Queue.php b/Zotlabs/Lib/Queue.php index 49891a55b..6acc58bc5 100644 --- a/Zotlabs/Lib/Queue.php +++ b/Zotlabs/Lib/Queue.php @@ -116,7 +116,7 @@ class Queue { dbesc($arr['hash']), intval($arr['account_id']), intval($arr['channel_id']), - dbesc(($arr['driver']) ? $arr['driver'] : 'zot'), + dbesc(($arr['driver']) ? $arr['driver'] : 'zot6'), dbesc($arr['posturl']), intval(1), intval(($arr['priority']) ? $arr['priority'] : 0), diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 86b5c1c7a..fcc040e01 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -11,6 +11,7 @@ use Zotlabs\Lib\ActivityStreams; use Zotlabs\Lib\LDSignatures; use Zotlabs\Web\HTTPSig; use Zotlabs\Lib\Libzot; +use Zotlabs\Lib\Libsync; use Zotlabs\Lib\ThreadListener; use App; @@ -1155,7 +1156,7 @@ class Item extends Controller { if($r) { xchan_query($r); $sync_item = fetch_post_tags($r); - build_sync_packet($profile_uid,array('item' => array(encode_item($sync_item[0],true)))); + Libsync::build_sync_packet($profile_uid,array('item' => array(encode_item($sync_item[0],true)))); } } if(! $nopush) @@ -1258,7 +1259,7 @@ class Item extends Controller { if($r) { xchan_query($r); $sync_item = fetch_post_tags($r); - build_sync_packet($profile_uid,array('item' => array(encode_item($sync_item[0],true)))); + Libsync::build_sync_packet($profile_uid,array('item' => array(encode_item($sync_item[0],true)))); } } @@ -1360,7 +1361,7 @@ class Item extends Controller { if($r) { xchan_query($r); $sync_item = fetch_post_tags($r); - build_sync_packet($i[0]['uid'],array('item' => array(encode_item($sync_item[0],true)))); + Libsync::build_sync_packet($i[0]['uid'],array('item' => array(encode_item($sync_item[0],true)))); } if($complex) { diff --git a/include/queue_fn.php b/include/queue_fn.php index 865228041..b72730d2f 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -228,49 +228,49 @@ function queue_deliver($outq, $immediate = false) { // normal zot delivery - logger('deliver: dest: ' . $outq['outq_posturl'], LOGGER_DEBUG); + logger('deliver: dest: ' . $outq['outq_posturl'] . ' driver: ' . $outq['outq_driver'], LOGGER_DEBUG); if($outq['outq_driver'] === 'zot6') { - if($outq['outq_posturl'] === z_root() . '/zot') { - // local delivery - $zot = new Receiver(new Zot6Handler(),$outq['outq_notify']); - $result = $zot->run(true); - logger('returned_json: ' . json_encode($result,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES), LOGGER_DATA); - logger('deliver: local zot6 delivery succeeded to ' . $outq['outq_posturl']); - Libzot::process_response($outq['outq_posturl'],[ 'success' => true, 'body' => json_encode($result) ], $outq); - } - else { - logger('remote'); - $channel = null; - - if($outq['outq_channel']) { - $channel = channelx_by_n($outq['outq_channel']); - } - - $host_crypto = null; - if($channel && $base) { - $h = q("select hubloc_sitekey, site_crypto from hubloc left join site on hubloc_url = site_url where site_url = '%s' and hubloc_network = 'zot6' order by hubloc_id desc limit 1", - dbesc($base) - ); - if($h) { - $host_crypto = $h[0]; - } - } - - $msg = $outq['outq_notify']; - - $result = Libzot::zot($outq['outq_posturl'],$msg,$channel,$host_crypto); - - if($result['success']) { - logger('deliver: remote zot6 delivery succeeded to ' . $outq['outq_posturl']); - Libzot::process_response($outq['outq_posturl'],$result, $outq); - } - else { - logger('deliver: remote zot6 delivery failed to ' . $outq['outq_posturl']); - logger('deliver: remote zot6 delivery fail data: ' . print_r($result,true), LOGGER_DATA); - update_queue_item($outq['outq_hash'],10); - } + if($outq['outq_posturl'] === z_root() . '/zot') { + // local delivery + $zot = new Receiver(new Zot6Handler(),$outq['outq_notify']); + $result = $zot->run(true); + logger('returned_json: ' . json_encode($result,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES), LOGGER_DATA); + logger('deliver: local zot6 delivery succeeded to ' . $outq['outq_posturl']); + Libzot::process_response($outq['outq_posturl'],[ 'success' => true, 'body' => json_encode($result) ], $outq); + } + else { + logger('remote'); + $channel = null; + + if($outq['outq_channel']) { + $channel = channelx_by_n($outq['outq_channel']); + } + + $host_crypto = null; + if($channel && $base) { + $h = q("select hubloc_sitekey, site_crypto from hubloc left join site on hubloc_url = site_url where site_url = '%s' and hubloc_network = 'zot6' order by hubloc_id desc limit 1", + dbesc($base) + ); + if($h) { + $host_crypto = $h[0]; + } + } + + $msg = $outq['outq_notify']; + + $result = Libzot::zot($outq['outq_posturl'],$msg,$channel,$host_crypto); + + if($result['success']) { + logger('deliver: remote zot6 delivery succeeded to ' . $outq['outq_posturl']); + Libzot::process_response($outq['outq_posturl'],$result, $outq); + } + else { + logger('deliver: remote zot6 delivery failed to ' . $outq['outq_posturl']); + logger('deliver: remote zot6 delivery fail data: ' . print_r($result,true), LOGGER_DATA); + update_queue_item($outq['outq_hash'],10); + } } return; -- cgit v1.2.3