aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Module')
-rw-r--r--Zotlabs/Module/Fhublocs.php38
-rw-r--r--Zotlabs/Module/Follow.php102
-rw-r--r--Zotlabs/Module/Item.php7
-rw-r--r--Zotlabs/Module/Z6trans.php130
4 files changed, 244 insertions, 33 deletions
diff --git a/Zotlabs/Module/Fhublocs.php b/Zotlabs/Module/Fhublocs.php
index 42c119da3..dcd399a1f 100644
--- a/Zotlabs/Module/Fhublocs.php
+++ b/Zotlabs/Module/Fhublocs.php
@@ -1,6 +1,8 @@
<?php
namespace Zotlabs\Module;
+use Zotlabs\Lib\Libzot;
+
require_once('include/zot.php');
require_once('include/crypto.php');
@@ -10,7 +12,7 @@ require_once('include/crypto.php');
class Fhublocs extends \Zotlabs\Web\Controller {
function get() {
-
+
if(! is_site_admin())
return;
@@ -21,9 +23,11 @@ class Fhublocs extends \Zotlabs\Web\Controller {
if($r) {
foreach($r as $rr) {
+
$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) {
@@ -42,13 +46,12 @@ class Fhublocs extends \Zotlabs\Web\Controller {
if($y)
$primary_address = $y[0]['xchan_addr'];
- $hub_address = channel_reddress($rr['channel']);
-
-
+ $hub_address = channel_reddress($rr);
+
$primary = (($hub_address === $primary_address) ? 1 : 0);
if(! $y)
$primary = 1;
-
+
$m = q("delete from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' ",
dbesc($rr['channel_hash']),
dbesc(z_root())
@@ -56,7 +59,7 @@ class Fhublocs extends \Zotlabs\Web\Controller {
// Create a verified hub location pointing to this site.
-
+/*
$h = hubloc_store_lowlevel(
[
'hubloc_guid' => $rr['channel_guid'],
@@ -72,7 +75,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
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/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/Zotlabs/Module/Z6trans.php b/Zotlabs/Module/Z6trans.php
new file mode 100644
index 000000000..98832ad98
--- /dev/null
+++ b/Zotlabs/Module/Z6trans.php
@@ -0,0 +1,130 @@
+<?php
+/**
+ * @file Zotlabs/Module/Z6trans.php
+ *
+ * @brief replace all occurances of an zot xchan with the zot6 xchan in DB.
+ *
+ */
+
+namespace Zotlabs\Module;
+
+use Zotlabs\Web\Controller;
+
+class Z6trans extends Controller {
+
+ function get() {
+ if(!is_site_admin())
+ return 'Not Allowed';
+
+ $path = 'store/z6trans.sql';
+
+ $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_portable_id'];
+
+ $r = q("SELECT xchan_guid FROM xchan WHERE xchan_hash = '%s' AND xchan_network = 'zot'",
+ dbesc($zot_xchan)
+ );
+
+ if(!$r) {
+ $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) {
+ $q .= '-- ' . $zot_xchan . 'failed: zot6 xchan not found' . "\r\n";
+ continue;
+ }
+
+ $zot6_xchan = $r[0]['xchan_hash'];
+
+ $core = self::get_core_cols();
+
+ $q .= '-- Transforming ' . $rr['channel_name'] . "\r\n";
+
+ 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)
+ );
+
+ }
+
+ }
+
+ }
+
+ if($q)
+ file_put_contents($path, $q);
+
+ $o = '<h2>' . t('Update to Hubzilla 5.0 setp 2') . '</h2><br>';
+
+ $o .= '<h3>' . t('To complete the update please run') . '</h3>';
+ if(ACTIVE_DBTYPE == DBTYPE_MYSQL)
+ $o .= '<code>source ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . '</code><h3>from the mysql console.</h3>';
+ else
+ $o .= '<code>\i ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . '</code><h3>from the postgresql console.</h3>';
+
+ $o .= '<br><h3>' . t('INFO: this command can take a very long time depending on your DB size.') . '</h3>';
+
+ 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;
+
+ }
+
+}