2018-04-23 01:51:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zotlabs\Module;
|
|
|
|
|
2021-12-02 22:33:36 +00:00
|
|
|
use App;
|
2019-02-19 01:28:29 +00:00
|
|
|
use Zotlabs\Lib\ZotURL;
|
2018-08-16 01:56:18 +00:00
|
|
|
use Zotlabs\Lib\Zotfinger;
|
2021-12-02 22:33:36 +00:00
|
|
|
use Zotlabs\Web\Controller;
|
2018-11-12 02:51:05 +00:00
|
|
|
use Zotlabs\Web\HTTPSig;
|
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
|
|
|
|
2021-12-02 23:02:31 +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')
|
|
|
|
]);
|
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
|
|
|
}
|