streams/Zotlabs/Lib/Zotfinger.php

50 lines
994 B
PHP
Raw Normal View History

2018-05-18 10:09:38 +00:00
<?php
namespace Zotlabs\Lib;
2018-06-20 02:33:50 +00:00
use Zotlabs\Web\HTTPSig;
2018-05-18 10:09:38 +00:00
class Zotfinger {
2018-05-24 04:48:19 +00:00
static function exec($resource,$channel = null) {
2018-05-18 10:09:38 +00:00
if(! $resource) {
return false;
}
2018-05-24 04:48:19 +00:00
if($channel) {
2018-06-20 02:33:50 +00:00
$headers = [
'Accept' => 'application/x-zot+json',
'X-Zot-Token' => random_string(),
];
$h = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel),false);
2018-05-24 04:48:19 +00:00
}
else {
$h = [ 'Accept: application/x-zot+json' ];
}
2018-05-18 10:09:38 +00:00
$result = [];
2018-05-18 10:09:38 +00:00
$redirects = 0;
2018-05-24 04:48:19 +00:00
$x = z_fetch_url($resource,false,$redirects, [ 'headers' => $h ] );
2018-05-18 10:09:38 +00:00
if($x['success']) {
$result['signature'] = HTTPSig::verify($x);
2018-05-18 10:09:38 +00:00
$result['data'] = json_decode($x['body'],true);
2018-05-24 04:48:19 +00:00
if($result['data'] && is_array($result['data']) && array_key_exists('encrypted',$result['data']) && $result['data']['encrypted']) {
2018-05-29 02:42:40 +00:00
$result['data'] = json_decode(crypto_unencapsulate($result['data'],get_config('system','prvkey')),true);
2018-05-24 04:48:19 +00:00
}
2018-05-29 02:42:40 +00:00
2018-05-18 10:09:38 +00:00
return $result;
}
return false;
}
}