streams/Code/Module/Zot_probe.php

54 lines
1.7 KiB
PHP
Raw Normal View History

2018-04-23 01:51:46 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2018-04-23 01:51:46 +00:00
2021-12-02 22:33:36 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Lib\ZotURL;
use Code\Lib\Zotfinger;
use Code\Web\Controller;
use Code\Web\HTTPSig;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2018-04-23 01:51:46 +00:00
2021-12-02 23:02:31 +00:00
class Zot_probe extends Controller
{
2018-04-23 01:51:46 +00:00
2021-12-02 23:02:31 +00:00
public function get()
{
2020-10-21 04:42:26 +00:00
2022-02-12 20:43:29 +00:00
$o = replace_macros(Theme::get_template('zot_probe.tpl'), [
2021-12-02 23:02:31 +00:00
'$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')
]);
2020-10-21 04:42:26 +00:00
2021-12-02 23:02:31 +00:00
if (x($_GET, 'resource')) {
$resource = $_GET['resource'];
$channel = (($_GET['authf']) ? App::get_channel() : null);
2020-10-21 04:42:26 +00:00
2021-12-02 23:02:31 +00:00
if (strpos($resource, 'x-zot:') === 0) {
$x = ZotURL::fetch($resource, $channel);
} else {
$x = Zotfinger::exec($resource, $channel);
2018-05-18 10:09:38 +00:00
2021-12-02 23:02:31 +00:00
$o .= '<pre>' . htmlspecialchars(print_array($x)) . '</pre>';
2018-05-18 10:09:38 +00:00
2021-10-28 20:02:31 +00:00
$headers = 'Accept: application/x-nomad+json, application/x-zot+json, application/jrd+json, application/json';
2018-04-23 01:51:46 +00:00
2021-12-02 23:02:31 +00:00
$redirects = 0;
$x = z_fetch_url($resource, true, $redirects, ['headers' => [$headers]]);
}
2018-04-23 01:51:46 +00:00
2021-12-02 23:02:31 +00:00
if ($x['success']) {
$o .= '<pre>' . htmlspecialchars($x['header']) . '</pre>' . EOL;
2018-04-23 01:51:46 +00:00
2021-12-02 23:02:31 +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
2021-12-02 23:02:31 +00:00
$o .= '<pre>' . htmlspecialchars(json_encode(json_decode($x['body']), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) . '</pre>' . EOL;
}
}
return $o;
}
2018-04-23 01:51:46 +00:00
}