diff options
author | zotlabs <mike@macgirvin.com> | 2019-02-18 18:16:50 -0800 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2019-02-18 18:16:50 -0800 |
commit | 175f78fa844ca196a02a441c9270c5b1e34c6c27 (patch) | |
tree | 621e3bf477d1d358b8a21a5e5a6f692f593b4f48 /Zotlabs/Lib/ZotURL.php | |
parent | b5109d2a1ae6056ec845c66ad89ccb02b4de0a05 (diff) | |
download | volse-hubzilla-175f78fa844ca196a02a441c9270c5b1e34c6c27.tar.gz volse-hubzilla-175f78fa844ca196a02a441c9270c5b1e34c6c27.tar.bz2 volse-hubzilla-175f78fa844ca196a02a441c9270c5b1e34c6c27.zip |
support zot location independent urls
Diffstat (limited to 'Zotlabs/Lib/ZotURL.php')
-rw-r--r-- | Zotlabs/Lib/ZotURL.php | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/Zotlabs/Lib/ZotURL.php b/Zotlabs/Lib/ZotURL.php new file mode 100644 index 000000000..d1c705fcb --- /dev/null +++ b/Zotlabs/Lib/ZotURL.php @@ -0,0 +1,91 @@ +<?php + +namespace Zotlabs\Lib; + +use Zotlabs\Zot6\HTTPSig; + + +class ZotURL { + + static public function fetch($url,$channel) { + + $ret = [ 'success' => false ]; + + if(strpos($url,'x-zot:') !== 0) { + return $ret; + } + + + if(! $url) { + return $ret; + } + + $portable_url = substr($url,6); + $u = explode('/',$portable_url); + $portable_id = $u[0]; + + $hosts = self::lookup($portable_id); + + if(! $hosts) { + return $ret; + } + + foreach($hosts as $h) { + $newurl = $h . '/id/' . $portable_url; + + $m = parse_url($newurl); + + $data = json_encode([ 'zot_token' => random_string() ]); + + if($channel && $m) { + + $headers = [ + 'Accept' => 'application/x-zot+json', + 'Content-Type' => 'application/x-zot+json', + 'X-Zot-Token' => random_string(), + 'Digest' => HTTPSig::generate_digest_header($data), + 'Host' => $m['host'], + '(request-target)' => 'post ' . get_request_string($newurl) + ]; + $h = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel),false); + } + else { + $h = [ 'Accept: application/x-zot+json' ]; + } + + $result = []; + + $redirects = 0; + $x = z_post_url($newurl,$data,$redirects, [ 'headers' => $h ] ); + if($x['success']) { + return $x; + } + } + + return $ret; + + } + + static public function is_zoturl($s) { + + if(strpos($url,'x-zot:') === 0) { + return true; + } + return false; + } + + + static public function lookup($portable_id) { + + $r = q("select * from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and site_dead = 0 order by hubloc_primary desc", + dbesc($portable_id) + ); + + if(! $r) { + // extend to network lookup + return false; + } + return ids_to_array($r,'hubloc_url'); + } + +}
\ No newline at end of file |