2018-04-23 01:51:46 +00:00
|
|
|
<?php
|
|
|
|
|
2022-05-03 10:41:08 +00:00
|
|
|
namespace Code\Module\Dev;
|
2018-04-23 01:51:46 +00:00
|
|
|
|
2021-12-02 22:33:36 +00:00
|
|
|
use App;
|
2023-03-19 09:44:18 +00:00
|
|
|
use Code\Lib\Libzot;
|
2022-06-23 07:38:34 +00:00
|
|
|
use Code\Lib\Url;
|
2022-02-16 04:08:28 +00:00
|
|
|
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
|
|
|
|
2022-06-29 05:19:12 +00:00
|
|
|
$x = Zotfinger::exec($resource, $channel);
|
2018-05-18 10:09:38 +00:00
|
|
|
|
2022-06-29 05:19:12 +00:00
|
|
|
$o .= '<pre>' . htmlspecialchars(print_array($x)) . '</pre>';
|
2018-05-18 10:09:38 +00:00
|
|
|
|
2023-03-19 09:44:18 +00:00
|
|
|
$accepts = Libzot::getAccepts() . ', application/jrd+json, application/json';
|
2023-03-19 08:18:54 +00:00
|
|
|
$headers = 'Accept: ' . $accepts;
|
2018-04-23 01:51:46 +00:00
|
|
|
|
2022-06-29 05:19:12 +00:00
|
|
|
$x = Url::get($resource, ['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
|
|
|
}
|