aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Zot6
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Zot6')
-rw-r--r--Zotlabs/Zot6/Finger.php145
-rw-r--r--Zotlabs/Zot6/IHandler.php10
-rw-r--r--Zotlabs/Zot6/Receiver.php18
-rw-r--r--Zotlabs/Zot6/Zot6Handler.php103
4 files changed, 29 insertions, 247 deletions
diff --git a/Zotlabs/Zot6/Finger.php b/Zotlabs/Zot6/Finger.php
deleted file mode 100644
index cec3f98ab..000000000
--- a/Zotlabs/Zot6/Finger.php
+++ /dev/null
@@ -1,145 +0,0 @@
-<?php
-
-namespace Zotlabs\Zot6;
-
-/**
- * @brief Finger
- *
- */
-class Finger {
-
- static private $token;
-
- /**
- * @brief Look up information about channel.
- *
- * @param string $webbie
- * does not have to be host qualified e.g. 'foo' is treated as 'foo\@thishub'
- * @param array $channel
- * (optional), if supplied permissions will be enumerated specifically for $channel
- * @param boolean $autofallback
- * fallback/failover to http if https connection cannot be established. Default is true.
- *
- * @return zotinfo array (with 'success' => true) or array('success' => false);
- */
-
- static public function run($webbie, $channel = null, $autofallback = true) {
-
- $ret = array('success' => false);
-
- self::$token = random_string();
-
- if (strpos($webbie, '@') === false) {
- $address = $webbie;
- $host = \App::get_hostname();
- } else {
- $address = substr($webbie,0,strpos($webbie,'@'));
- $host = substr($webbie,strpos($webbie,'@')+1);
- if(strpos($host,'/'))
- $host = substr($host,0,strpos($host,'/'));
- }
-
- $xchan_addr = $address . '@' . $host;
-
- if ((! $address) || (! $xchan_addr)) {
- logger('zot_finger: no address :' . $webbie);
-
- return $ret;
- }
-
- logger('using xchan_addr: ' . $xchan_addr, LOGGER_DATA, LOG_DEBUG);
-
- // potential issue here; the xchan_addr points to the primary hub.
- // The webbie we were called with may not, so it might not be found
- // unless we query for hubloc_addr instead of xchan_addr
-
- $r = q("select xchan.*, hubloc.* from xchan
- left join hubloc on xchan_hash = hubloc_hash
- where xchan_addr = '%s' and hubloc_primary = 1 limit 1",
- dbesc($xchan_addr)
- );
-
- if($r) {
- $url = $r[0]['hubloc_url'];
-
- if($r[0]['hubloc_network'] && $r[0]['hubloc_network'] !== 'zot') {
- logger('zot_finger: alternate network: ' . $webbie);
- logger('url: ' . $url . ', net: ' . var_export($r[0]['hubloc_network'],true), LOGGER_DATA, LOG_DEBUG);
- return $ret;
- }
- } else {
- $url = 'https://' . $host;
- }
-
- $rhs = '/.well-known/zot-info';
- $https = ((strpos($url,'https://') === 0) ? true : false);
-
- logger('zot_finger: ' . $address . ' at ' . $url, LOGGER_DEBUG);
-
- if ($channel) {
- $postvars = array(
- 'address' => $address,
- 'target' => $channel['channel_guid'],
- 'target_sig' => $channel['channel_guid_sig'],
- 'key' => $channel['channel_pubkey'],
- 'token' => self::$token
- );
-
- $headers = [];
- $headers['X-Zot-Channel'] = $channel['channel_address'] . '@' . \App::get_hostname();
- $headers['X-Zot-Nonce'] = random_string();
- $xhead = HTTPSig::create_sig($headers,$channel['channel_prvkey'], channel_url($channel));
-
- $retries = 0;
-
- $result = z_post_url($url . $rhs,$postvars,$retries, [ 'headers' => $xhead ]);
-
- if ((! $result['success']) && ($autofallback)) {
- if ($https) {
- logger('zot_finger: https failed. falling back to http');
- $result = z_post_url('http://' . $host . $rhs,$postvars, $retries, [ 'headers' => $xhead ]);
- }
- }
- }
- else {
- $rhs .= '?f=&address=' . urlencode($address) . '&token=' . self::$token;
-
- $result = z_fetch_url($url . $rhs);
- if((! $result['success']) && ($autofallback)) {
- if($https) {
- logger('zot_finger: https failed. falling back to http');
- $result = z_fetch_url('http://' . $host . $rhs);
- }
- }
- }
-
- if(! $result['success']) {
- logger('zot_finger: no results');
-
- return $ret;
- }
-
- $x = json_decode($result['body'], true);
-
- $verify = HTTPSig::verify($result,(($x) ? $x['key'] : ''));
-
- if($x && (! $verify['header_valid'])) {
- $signed_token = ((is_array($x) && array_key_exists('signed_token', $x)) ? $x['signed_token'] : null);
- if($signed_token) {
- $valid = zot_verify('token.' . self::$token, base64url_decode($signed_token), $x['key']);
- if(! $valid) {
- logger('invalid signed token: ' . $url . $rhs, LOGGER_NORMAL, LOG_ERR);
-
- return $ret;
- }
- }
- else {
- logger('No signed token from ' . $url . $rhs, LOGGER_NORMAL, LOG_WARNING);
- return $ret;
- }
- }
-
- return $x;
- }
-
-}
diff --git a/Zotlabs/Zot6/IHandler.php b/Zotlabs/Zot6/IHandler.php
index 53b6caa89..4e7738926 100644
--- a/Zotlabs/Zot6/IHandler.php
+++ b/Zotlabs/Zot6/IHandler.php
@@ -4,15 +4,13 @@ namespace Zotlabs\Zot6;
interface IHandler {
- function Notify($data,$hub);
+ function Notify($data, $hub);
- function Request($data,$hub);
+ function Rekey($sender, $data, $hub);
- function Rekey($sender,$data,$hub);
+ function Refresh($sender, $recipients, $hub, $force);
- function Refresh($sender,$recipients,$hub);
-
- function Purge($sender,$recipients,$hub);
+ function Purge($sender, $recipients, $hub);
}
diff --git a/Zotlabs/Zot6/Receiver.php b/Zotlabs/Zot6/Receiver.php
index 6440c5da5..964c61651 100644
--- a/Zotlabs/Zot6/Receiver.php
+++ b/Zotlabs/Zot6/Receiver.php
@@ -7,7 +7,6 @@ use Zotlabs\Lib\Crypto;
use Zotlabs\Lib\Libzot;
use Zotlabs\Web\HTTPSig;
-
class Receiver {
protected $data;
@@ -174,21 +173,20 @@ class Receiver {
function Dispatch() {
switch ($this->messagetype) {
-
- case 'request':
- $this->response = $this->handler->Request($this->data,$this->hub);
- break;
-
case 'purge':
- $this->response = $this->handler->Purge($this->sender,$this->recipients,$this->hub);
+ $this->response = $this->handler->Purge($this->sender, $this->recipients, $this->hub);
break;
case 'refresh':
- $this->response = $this->handler->Refresh($this->sender,$this->recipients,$this->hub);
+ $this->response = $this->handler->Refresh($this->sender, $this->recipients, $this->hub, false);
+ break;
+
+ case 'force_refresh':
+ $this->response = $this->handler->Refresh($this->sender, $this->recipients, $this->hub, true);
break;
case 'rekey':
- $this->response = $this->handler->Rekey($this->sender, $this->data,$this->hub);
+ $this->response = $this->handler->Rekey($this->sender, $this->data, $this->hub);
break;
case 'activity':
@@ -196,7 +194,7 @@ class Receiver {
case 'sync':
default:
if ($this->sender) {
- $this->response = $this->handler->Notify($this->data,$this->hub);
+ $this->response = $this->handler->Notify($this->data, $this->hub);
}
break;
diff --git a/Zotlabs/Zot6/Zot6Handler.php b/Zotlabs/Zot6/Zot6Handler.php
index bd321c4b1..4dc410f52 100644
--- a/Zotlabs/Zot6/Zot6Handler.php
+++ b/Zotlabs/Zot6/Zot6Handler.php
@@ -7,24 +7,20 @@ use Zotlabs\Lib\Queue;
class Zot6Handler implements IHandler {
- function Notify($data,$hub) {
- return self::reply_notify($data,$hub);
+ function Notify($data, $hub) {
+ return self::reply_notify($data, $hub);
}
- function Request($data,$hub) {
- return self::reply_message_request($data,$hub);
+ function Rekey($sender, $data, $hub) {
+ return self::reply_rekey_request($sender, $data, $hub);
}
- function Rekey($sender,$data,$hub) {
- return self::reply_rekey_request($sender,$data,$hub);
+ function Refresh($sender, $recipients, $hub, $force) {
+ return self::reply_refresh($sender, $recipients, $hub, $force);
}
- function Refresh($sender,$recipients,$hub) {
- return self::reply_refresh($sender,$recipients,$hub);
- }
-
- function Purge($sender,$recipients,$hub) {
- return self::reply_purge($sender,$recipients,$hub);
+ function Purge($sender, $recipients, $hub) {
+ return self::reply_purge($sender, $recipients, $hub);
}
@@ -38,7 +34,7 @@ class Zot6Handler implements IHandler {
logger('notify received from ' . $hub['hubloc_url']);
- $x = Libzot::fetch($data);
+ $x = Libzot::fetch($data, $hub);
$ret['delivery_report'] = $x;
@@ -62,7 +58,7 @@ class Zot6Handler implements IHandler {
*
* @return array
*/
- static function reply_refresh($sender, $recipients, $hub) {
+ static function reply_refresh($sender, $recipients, $hub, $force) {
$ret = array('success' => false);
if($recipients) {
@@ -75,87 +71,18 @@ class Zot6Handler implements IHandler {
where xchan_hash ='%s' limit 1",
dbesc($recip)
);
- /// @FIXME $msgtype is undefined
- $x = Libzot::refresh( [ 'hubloc_id_url' => $hub['hubloc_id_url'] ], $r[0], (($msgtype === 'force_refresh') ? true : false));
+ $x = Libzot::refresh([ 'hubloc_id_url' => $hub['hubloc_id_url']], $r[0], $force);
}
}
else {
// system wide refresh
- /// @FIXME $msgtype is undefined
- $x = Libzot::refresh( [ 'hubloc_id_url' => $hub['hubloc_id_url'] ], null, (($msgtype === 'force_refresh') ? true : false));
+ $x = Libzot::refresh(['hubloc_id_url' => $hub['hubloc_id_url']], null, $force);
}
$ret['success'] = true;
return $ret;
}
-
-
- /**
- * @brief Process a message request.
- *
- * If a site receives a comment to a post but finds they have no parent to attach it with, they
- * may send a 'request' packet containing the message_id of the missing parent. This is the handler
- * for that packet. We will create a message_list array of the entire conversation starting with
- * the missing parent and invoke delivery to the sender of the packet.
- *
- * Zotlabs/Daemon/Deliver.php (for local delivery) and
- * mod/post.php???? @fixme (for web delivery) detect the existence of
- * this 'message_list' at the destination and split it into individual messages which are
- * processed/delivered in order.
- *
- * @param array $data
- * @param array $hub
- * @return array
- */
- static function reply_message_request($data, $hub) {
- $ret = [ 'success' => false ];
-
- $message_id = EMPTY_STR;
-
- if(array_key_exists('data',$data))
- $ptr = $data['data'];
- if(is_array($ptr) && array_key_exists(0,$ptr)) {
- $ptr = $ptr[0];
- }
- if(is_string($ptr)) {
- $message_id = $ptr;
- }
- if(is_array($ptr) && array_key_exists('id',$ptr)) {
- $message_id = $ptr['id'];
- }
-
- if (! $message_id) {
- $ret['message'] = 'no message_id';
- logger('no message_id');
- return $ret;
- }
-
- $sender = $hub['hubloc_hash'];
-
- /*
- * Find the local channel in charge of this post (the first and only recipient of the request packet)
- */
-
- $arr = $data['recipients'][0];
-
- $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) {
- logger('recipient channel not found.');
- $ret['message'] .= 'recipient not found.' . EOL;
- return $ret;
- }
-
- /*
- * fetch the requested conversation
- */
- $messages = zot_feed($c[0]['channel_id'], $sender, [ 'message_id' => $data['message_id'], 'encoding' => 'activitystreams' ]);
-
- return (($messages) ? : [] );
- }
-
static function rekey_request($sender,$data,$hub) {
$ret = array('success' => false);
@@ -174,7 +101,7 @@ class Zot6Handler implements IHandler {
$old = null;
if(Libzot::verify($data['old_guid'],$data['old_guid_sig'],$data['old_key'])) {
- $oldhash = make_xchan_hash($data['old_guid'],$data['old_key']);
+ $oldhash = Libzot::make_xchan_hash($data['old_guid'],$data['old_key']);
$old = q("select * from xchan where xchan_hash = '%s' limit 1",
dbesc($oldhash)
);
@@ -223,6 +150,10 @@ class Zot6Handler implements IHandler {
$ret = array('success' => false);
+ if (! $sender) {
+ return $ret;
+ }
+
if ($recipients) {
// basically this means "unfriend"
foreach ($recipients as $recip) {