aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2020-03-28 11:12:22 +0100
committerMario <mario@mariovavti.com>2020-03-28 11:12:22 +0100
commit6e1c3b6d48224c7670b0291d3c7eb25475b1594d (patch)
treece6e5592f090595f390ab073e3ad4edaa727c8ee
parent720d3dcedc96c7aaf6c4444c8b45acd46b8718b0 (diff)
parentbcdd75b8178309e5c4e65d170505ab60678c2159 (diff)
downloadvolse-hubzilla-6e1c3b6d48224c7670b0291d3c7eb25475b1594d.tar.gz
volse-hubzilla-6e1c3b6d48224c7670b0291d3c7eb25475b1594d.tar.bz2
volse-hubzilla-6e1c3b6d48224c7670b0291d3c7eb25475b1594d.zip
Merge branch 'z6connect' into 'dev'
Transition to zot6 See merge request hubzilla/core!1823
-rw-r--r--Zotlabs/Access/Permissions.php13
-rw-r--r--Zotlabs/Daemon/Notifier.php14
-rw-r--r--Zotlabs/Lib/AccessList.php411
-rw-r--r--Zotlabs/Lib/Connect.php316
-rw-r--r--Zotlabs/Lib/Libsync.php2
-rw-r--r--Zotlabs/Lib/Libzot.php48
-rw-r--r--Zotlabs/Module/Fhublocs.php3
-rw-r--r--Zotlabs/Module/Follow.php102
-rw-r--r--Zotlabs/Update/_1236.php115
-rw-r--r--Zotlabs/Zot6/Zot6Handler.php8
-rwxr-xr-xboot.php4
-rw-r--r--include/channel.php85
-rw-r--r--include/hubloc.php4
-rw-r--r--include/permissions.php20
-rw-r--r--include/zot.php81
15 files changed, 1111 insertions, 115 deletions
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/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/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 @@
+<?php
+
+namespace Zotlabs\Lib;
+
+use Zotlabs\Lib\Libsync;
+
+
+class AccessList {
+
+ static function add($uid,$name,$public = 0) {
+
+ $ret = false;
+ if ($uid && $name) {
+ $r = self::byname($uid,$name); // check for dups
+ if ($r !== false) {
+
+ // This could be a problem.
+ // Let's assume we've just created a list which we once deleted
+ // all the old members are gone, but the list remains so we don't break any security
+ // access lists. What we're doing here is reviving the dead list, but old content which
+ // was restricted to this list may now be seen by the new list members.
+
+ $z = q("SELECT * FROM pgrp WHERE id = %d LIMIT 1",
+ intval($r)
+ );
+ if(($z) && $z[0]['deleted']) {
+ q('UPDATE pgrp SET deleted = 0 WHERE id = %d', intval($z[0]['id']));
+ notice( t('A deleted list with this name was revived. Existing item permissions <strong>may</strong> 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..5fc0e3fe1
--- /dev/null
+++ b/Zotlabs/Lib/Connect.php
@@ -0,0 +1,316 @@
+<?php /** @file */
+
+namespace Zotlabs\Lib;
+
+use App;
+use Zotlabs\Access\Permissions;
+use Zotlabs\Daemon\Master;
+
+
+
+class Connect {
+
+ /**
+ * Takes a $channel and a $url/handle and adds a new connection
+ *
+ * Returns array
+ * $return['success'] boolean true if successful
+ * $return['abook'] Address book entry joined with xchan if successful
+ * $return['message'] error text if success is false.
+ *
+ * This function does NOT send sync packets to clones. The caller is responsible for doing this
+ */
+
+ static function connect($channel, $url, $sub_channel = false) {
+
+ $uid = $channel['channel_id'];
+
+ if (strpos($url,'@') === false && strpos($url,'/') === false) {
+ $url = $url . '@' . App::get_hostname();
+ }
+
+ $result = [ 'success' => 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']) {
+ $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 = $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) {
+ foreach($my_perms as $k => $v) {
+ set_abconfig($uid,$xchan_hash,'my_perms',$k,$v);
+ }
+ }
+
+ // 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/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/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/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;
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 @@
<?php
namespace Zotlabs\Module;
+use App;
+use Zotlabs\Web\Controller;
+use Zotlabs\Lib\Libsync;
+use Zotlabs\Lib\ActivityStreams;
+use Zotlabs\Lib\Activity;
+use Zotlabs\Web\HTTPSig;
+use Zotlabs\Lib\LDSignatures;
+use Zotlabs\Lib\Connect;
+use Zotlabs\Daemon\Master;
-require_once('include/follow.php');
-
-
-class Follow extends \Zotlabs\Web\Controller {
+class Follow extends Controller {
function init() {
- if(! local_channel()) {
+ if (ActivityStreams::is_as_request() && argc() == 2) {
+
+ $abook_id = intval(argv(1));
+ if(! $abook_id)
+ return;
+
+ $r = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d",
+ intval($abook_id)
+ );
+ if (! $r) {
+ return;
+ }
+
+ $chan = channelx_by_n($r[0]['abook_channel']);
+
+ if (! $chan) {
+ http_status_exit(404, 'Not found');
+ }
+
+ $actor = Activity::encode_person($chan,true,true);
+ if (! $actor) {
+ http_status_exit(404, 'Not found');
+ }
+
+ $x = array_merge(['@context' => [
+ 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/Zotlabs/Update/_1236.php b/Zotlabs/Update/_1236.php
new file mode 100644
index 000000000..d40cc9e25
--- /dev/null
+++ b/Zotlabs/Update/_1236.php
@@ -0,0 +1,115 @@
+<?php
+
+namespace Zotlabs\Update;
+
+use Zotlabs\Lib\Libzot;
+
+class _1236 {
+
+ function run() {
+
+ $r = q("SELECT channel.channel_address, channel.channel_hash, xchan.xchan_guid, channel.channel_pubkey, channel.channel_portable_id FROM channel
+ LEFT JOIN xchan ON channel_hash = xchan_hash
+ WHERE xchan.xchan_network = 'zot'
+ AND channel.channel_removed = 0"
+ );
+
+ $i = 0;
+
+ foreach($r as $rr) {
+
+ $zot_xchan = $rr['channel_hash'];
+ $guid = $rr['xchan_guid'];
+
+ $xchan = q("SELECT xchan_hash, xchan_guid_sig FROM xchan WHERE xchan_guid = '%s' AND xchan_network = 'zot6'",
+ dbesc($guid)
+ );
+
+ if(!$xchan) {
+ // This should not actually happen.
+ // A zot6 xchan for every channel should have been
+ // created in update _1226.
+
+ // In case this failed, we will try to fix it here.
+ logger('No zot6 xchan found for: ' . $rr['channel_hash']);
+
+ $zhash = $rr['channel_portable_id'];
+
+ if(!$zhash) {
+ $zhash = Libzot::make_xchan_hash($rr['xchan_guid'], $rr['channel_pubkey']);
+
+ q("UPDATE channel SET channel_portable_id = '%s' WHERE channel_hash = '%s'",
+ dbesc($zhash),
+ dbesc($zot_xchan)
+ );
+ }
+
+ if(!$zhash) {
+ logger('Could not create zot6 xchan_hash for: ' . $rr['channel_hash']);
+ continue;
+ }
+
+ $x = q("SELECT * FROM xchan WHERE xchan_hash = '%s' LIMIT 1",
+ dbesc($rr['channel_hash'])
+ );
+
+ if($x) {
+ $rec = $x[0];
+ $rec['xchan_hash'] = $zhash;
+ $rec['xchan_guid_sig'] = 'sha256.' . $rec['xchan_guid_sig'];
+ $rec['xchan_network'] = 'zot6';
+ xchan_store_lowlevel($rec);
+ }
+
+ $h = q("SELECT * FROM hubloc WHERE hubloc_hash = '%s' AND hubloc_url = '%s' LIMIT 1",
+ dbesc($zot_xchan),
+ dbesc(z_root())
+ );
+
+ if($h) {
+ $rec = $h[0];
+ $rec['hubloc_hash'] = $zhash;
+ $rec['hubloc_guid_sig'] = 'sha256.' . $rec['hubloc_guid_sig'];
+ $rec['hubloc_network'] = 'zot6';
+ $rec['hubloc_url_sig'] = 'sha256.' . $rec['hubloc_url_sig'];
+ $rec['hubloc_callback'] = z_root() . '/zot';
+ $rec['hubloc_id_url'] = channel_url($rr);
+ $rec['hubloc_site_id'] = Libzot::make_xchan_hash(z_root(),get_config('system','pubkey'));
+ hubloc_store_lowlevel($rec);
+ }
+
+ // Now try again
+ $xchan = q("SELECT xchan_hash, xchan_guid_sig FROM xchan WHERE xchan_guid = '%s' AND xchan_network = 'zot6'",
+ dbesc($guid)
+ );
+
+ if(!$xchan) {
+ logger('Could not create zot6 xchan record for: ' . $zot_xchan);
+ continue;
+ }
+
+ }
+
+ $zot6_xchan = $xchan[0]['xchan_hash'];
+ $zot6_xchan_guid_sig = $xchan[0]['xchan_guid_sig'];
+
+ 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)
+ );
+
+ $i++;
+
+ }
+
+ if(count($r) == $i)
+ return UPDATE_SUCCESS;
+ else
+ return UPDATE_FAILED;
+
+ }
+
+}
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/boot.php b/boot.php
index ec96045e9..4bd51f09c 100755
--- a/boot.php
+++ b/boot.php
@@ -50,10 +50,10 @@ require_once('include/attach.php');
require_once('include/bbcode.php');
define ( 'PLATFORM_NAME', 'hubzilla' );
-define ( 'STD_VERSION', '4.7.3' );
+define ( 'STD_VERSION', '4.7.4' );
define ( 'ZOT_REVISION', '6.0a' );
-define ( 'DB_UPDATE_VERSION', 1235 );
+define ( 'DB_UPDATE_VERSION', 1236 );
define ( 'PROJECT_BASE', __DIR__ );
diff --git a/include/channel.php b/include/channel.php
index 991d4675b..25eb93cac 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');
@@ -228,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,$zsig);
+
+ // 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
@@ -332,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(),
@@ -346,18 +352,18 @@ function create_identity($arr) {
]
);
if(! $r)
- logger('Unable to store hub location');
+ logger('Unable to store hub location (zot)');
$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',
@@ -367,16 +373,16 @@ function create_identity($arr) {
]
);
if(! $r)
- logger('Unable to store hub location');
+ logger('Unable to store hub location (zot6)');
$newuid = $ret['channel']['channel_id'];
$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}",
@@ -393,12 +399,14 @@ function create_identity($arr) {
'xchan_system' => $system
]
);
+ if(! $r)
+ logger('Unable to store xchan (zot)');
$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}",
@@ -415,6 +423,8 @@ function create_identity($arr) {
'xchan_system' => $system
]
);
+ if(! $r)
+ logger('Unable to store xchan (zot6)');
@@ -521,13 +531,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 +558,7 @@ function create_identity($arr) {
call_hooks('create_identity', $newuid);
Master::Summon(array('Directory', $ret['channel']['channel_id']));
+
}
$ret['success'] = true;
@@ -546,6 +566,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);
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) {
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;
+}
diff --git a/include/zot.php b/include/zot.php
index 5d5ac8424..5cf357d40 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']) {
@@ -578,7 +577,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 +920,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 +1298,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 +1384,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 +1595,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 +1609,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 +1623,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 +1726,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 +1775,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 +2075,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 +2343,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 +2554,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 +2562,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 +2825,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 +3299,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 +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'])
);
@@ -3325,8 +3332,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;
@@ -4192,7 +4200,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 +4346,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 +4360,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 +4380,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 +4707,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 +4769,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 +5115,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 +5182,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,12 +5235,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'],