streams/Zotlabs/Module/Zot_probe.php

55 lines
1.4 KiB
PHP
Raw Normal View History

2018-04-23 01:51:46 +00:00
<?php
namespace Zotlabs\Module;
2019-02-19 01:28:29 +00:00
use Zotlabs\Lib\ZotURL;
2018-08-16 01:56:18 +00:00
use Zotlabs\Lib\Zotfinger;
2019-02-19 01:28:29 +00:00
2018-11-12 02:51:05 +00:00
use Zotlabs\Web\HTTPSig;
2018-04-23 01:51:46 +00:00
class Zot_probe extends \Zotlabs\Web\Controller {
function get() {
2020-10-21 04:42:26 +00:00
$o = replace_macros(get_markup_template('zot_probe.tpl'), [
'$page_title' => t('Zot6 Probe Diagnostic'),
'$resource' => [ 'resource', t('Object URL') , $_REQUEST['resource'], EMPTY_STR ],
'$authf' => [ 'authf', t('Authenticated fetch'), $_REQUEST['authf'], EMPTY_STR, [ t('No'), t('Yes') ] ],
'$submit' => t('Submit')
]);
if(x($_GET,'resource')) {
$resource = $_GET['resource'];
$channel = (($_GET['authf']) ? \App::get_channel() : null);
if(strpos($resource,'x-zot:') === 0) {
$x = ZotURL::fetch($resource,$channel);
2019-02-19 01:28:29 +00:00
}
else {
2020-10-21 04:42:26 +00:00
$x = Zotfinger::exec($resource,$channel);
2018-05-18 10:09:38 +00:00
2019-02-19 01:28:29 +00:00
$o .= '<pre>' . htmlspecialchars(print_array($x)) . '</pre>';
2018-05-18 10:09:38 +00:00
2019-02-19 01:28:29 +00:00
$headers = 'Accept: application/x-zot+json, application/jrd+json, application/json';
2018-04-23 01:51:46 +00:00
2019-02-19 01:28:29 +00:00
$redirects = 0;
2020-10-21 04:42:26 +00:00
$x = z_fetch_url($resource,true,$redirects, [ 'headers' => [ $headers ]]);
2019-02-19 01:28:29 +00:00
}
2018-04-23 01:51:46 +00:00
if($x['success']) {
$o .= '<pre>' . htmlspecialchars($x['header']) . '</pre>' . EOL;
2020-08-08 12:07:15 +00:00
$o .= 'verify returns: ' . str_replace("\n",EOL,print_r(HTTPSig::verify($x, EMPTY_STR, 'zot6'),true)) . EOL;
2018-04-23 01:51:46 +00:00
$o .= '<pre>' . htmlspecialchars(json_encode(json_decode($x['body']),JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)) . '</pre>' . EOL;
}
}
return $o;
}
}